Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Controls
  New Posts New Posts RSS Feed - How to find the STATIC controls on a form
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to find the STATIC controls on a form

 Post Reply Post Reply
Author
Message
TrevorS View Drop Down
Newbie
Newbie


Joined: 09 December 2008
Location: Canada
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote TrevorS Quote  Post ReplyReply Direct Link To This Post Topic: How to find the STATIC controls on a form
    Posted: 09 December 2008 at 8:22am
I would like to find all of the static controls on a form view.
I want to disable all controls except the statics (to prevent accidental edits until the user has confirmed that they intend to edit).
 
I can't see a way to get at cs.lpszClass.
And the "un-attached" CWnd has a runtime class of CWnd, so I can't test the actual RUNTIME CLASS.
 
Unless I know the class, I don't think I can reliably test the style masks either?
 
Is there an easy way to do this?
 

for(pWnd = GetWindow(GW_CHILD); pWnd != NULL; pWnd = pWnd->GetWindow(GW_HWNDNEXT) )

{

CString sText;

pWnd->GetWindowText( sText );

TRACE( _T("Processing %s / %s\n"), pWnd->GetRuntimeClass()->m_lpszClassName, sText );

TRACE( _T("style 0X%08x\n"), pWnd->GetStyle() );

}
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2008 at 1:11am

Hi,

 

Use GetClassName:

 

TCHAR szClassName[10];
if ((!::GetClassName(m_hWnd, szClassName, 10)) ||  // didn't get class
   (lstrcmpi(szClassName, _T("Static"))))        

  {
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
TrevorS View Drop Down
Newbie
Newbie


Joined: 09 December 2008
Location: Canada
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote TrevorS Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2008 at 7:15am
Thanks. I discovered that after I posted here.
I still didn't find masks for filtering all of the styles. For example BS_PUSHBUTTON is 0. I can't use this technique for a value of zero.
 

if( (pWnd->GetStyle() & BS_GROUPBOX ) == BS_GROUPBOX )

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 10 December 2008 at 3:15pm
Yes, BS_PUSHBUTTON  is 0.

if( (pWnd->GetStyle() & 0xF) == BS_GROUPBOX )

...

if( (pWnd->GetStyle() & 0xF) == BS_PUSHBUTTON)

etc.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.