Skip to main content
gamedev.net
🔒 Locked

win32 problem

Started by bratsj Apr 25, 2003 at 5:02 PM 5 replies 1.3k views
Original Post
bratsj
bratsj
If I 1. Create Window A (global mother window) 2. Create Window B (as a child of window A) 3. Create an edit control E (as a child of window B) creatively represented thus: A->B->E the edit control E cannot be edited :-( It''s completely dead ! Why ?? I do not want to use MDI for this thx in advance ;-)
Pipo DeClown
Pipo DeClown
EnableWindow( GetDlgItem( HWND_OF_B, EDITCONTROLNAME ), TRUE );

Enable it? Dunno exactly!

.lick
Nostalgia
Nostalgia
Bratsj: Could you post the code you''re using? I''m pretty good with Win32.

-Joe

Nostalgia, an Intellivision Emulator
http://www.gotmaille.com/nostalgia/
Nostalgia, an Intellivision Emulatorhttp://www.gotmaille.com/nostalgia/
bratsj
bratsj
Hi Joe

Thx for your willingness to help out :-)
I could post some code
I could in fact sing it for you

However, I just discovered something about the nature of the
obstacle

If my children (within children etc..) do not have
the WS_CAPTION style (eg. just WS_BORDER f.inst)
it all works fine !!

It''s almost like the caption style is meant only for the
mother window, and perhaps also for MDI client windows

But I do not wasnt to use MDI at this point

My winodws creation is pretty straight forward, and
it can have nothing to do with windows classes,
because the same problem occurs if I let all my windows
be, say, simple edit contols ("edit")

No, all controls withing a WS_CAPTION style window
that is also a child, are dead :-(
Nytegard
Nytegard
From MSDN. This is off my DVD, and I don''t know exactly where to search for it to give you a link
quote:

PRB: Can''t Set Focus to an Edit Control When its Parent Is an Inactive Captioned Child Window
ID: Q230587



--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), included with:
Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1, 4.2, 5.0, 6.0

--------------------------------------------------------------------------------


SYMPTOMS
When an edit control is in an inactive captioned child window, you cannot set focus to it with the mouse. For example, if you have a modeless dialog box with the WS_CAPTION and WS_CHILD styles, and it has an edit control, you cannot set focus to the edit control with the mouse.

NOTE: All captioned child windows display an inactive caption bar.



CAUSE
The default WM_LBUTTONDOWN handler for edit controls will not set focus to the edit control if its parent is an inactive captioned child window. This code is implemented as part of the Windows API function, DefWindowProc().



RESOLUTION
There are not many good ways to work around this limitation because it is Windows itself that is intentionally causing this behavior.

The best way to prevent the problem is to prevent the parent of the edit control from being an inactive captioned child. For the above example, specify the WS_POPUP style for the dialog box instead of WS_CHILD.



STATUS
This behavior is by design.



MORE INFORMATION

Steps to Reproduce Behavior
Create an AppWizard-generated MFC dialog box application.


Add a second dialog box resource to the project. Right-click the dialog resource to change the properties, and give it a Title Bar and a Child window style.


Add an edit control to the new dialog box resource.


Use class wizard to create a new class for the new dialog box resource.


Override CDialog:ostNCDestroy for this class and add the following line:

delete this;



Add a member variable to the application dialog box class that is a type of the class created above, and name the variable m_pDlg.


In the OnInitDialog() function of the application dialog box class, create a new modeless dialog box as shown here:

m_pDlg = new CModelessDlg;
m_pDlg->Create(IDD_MODELESS2, this);
m_pDlg->ShowWindow(SW_SHOWNORMAL);



Try and set focus to the edit control.



Additional query words:

Keywords : kbActiveX kbCtrl kbCtrlCreate kbMFC kbVC400 kbVC410 kbVC420 kbVC500 kbVC600 kbDSupport kbGrpMFCATL
Version : winnt:4.0,4.1,4.2,5.0,6.0
Platform : winnt
Issue type : kbprb



Last Reviewed: August 5, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.



Now, what you can do, and this is the easiest fix, but gets a little messy, is before you translate the message, see if its the edit box''s window handle, and set the focus to it. Otherwise, disable the focus. Granted, this causes a little mess.

I usually do something like:

if(msg.message = WM_LBUTTONDOWN)
{
HWND tempGetFocus();

if(msg.hwnd == hWndMyEditBox)
{
if(focuswin != prevfoc)
SetFocus(msg.hwnd);
}
}
bratsj
bratsj
Nytegard - a zillion thanks :-)

As this has been bugging me for some time now,
your answer was very illuminating !

I''ll spare you an armadillo

Jostein
steg
steg
Maybe you could override the PreTranslateMessage function within your child window to capture messages before the parent window snatches them ?

Regards,
Steve
If it isn't working, take a bath, have a think and try again...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.