My question is: What needs to be done to make a functional edit control in a child window with a caption?
I've been developing a wrapper for Win32 and ran into a little trouble. Overlapped Windows with child captioned windows don't seem to fully activate or receive focus. Maybe it's because of this lack of focus that an edit control in the child captioned window will not function.
The experiment to isolate my error is as follows:
- Setup a window class
- Register that class
- Create an overlapped window with the class
- Create a child window with a caption using the same class
- Create an edit control in the child window
The observations are in accordance with my wrapper project: The child window can be moved and sized depending on style bits. While being selected, its caption doesn't change color to imply that it is in focus. The Edit control does not respond to clicking. No caret appears. Button controls within the child window respond normally.
Additionally, removing the caption from the child window allows the edit control to be interacted with properly.
Here is the test code:
// Create a WNDCLASSEX for registering windows
WNDCLASSEX wndclass;
ZeroMemory(&wndclass, sizeof(WNDCLASSEX));
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = L"MyTestClassForText";
// Check for register problem
if (!RegisterClassEx(&wndclass))
{
MessageBox( NULL , L"Window Couldn't be Created" , L"Error" , MB_OK );
return false;
}
// Create a child window to the main window and put an edit contol inside. What happends?
HWND parWnd = CreateWindowEx( NULL , L"MyTestClassForText" , L"Parent Window" , WS_OVERLAPPEDWINDOW | WS_VISIBLE ,0 ,0 ,340 ,240 , NULL , NULL , hInstance , NULL );
HWND childWnd = CreateWindowEx( NULL , L"MyTestClassForText" , L"Child Window" , WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPEDWINDOW ,0 ,0 ,300 ,200 , parWnd , NULL , hInstance , NULL );
HWND editWnd = CreateWindowEx( WS_EX_CLIENTEDGE , L"EDIT" , L"Try To Edit This." , WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL ,4 ,4 ,270 ,40 , childWnd , NULL , hInstance , NULL );
HWND buttonWnd = CreateWindowEx( NULL , L"BUTTON" , L"This Works" , WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,4 ,52 ,100 ,30 , childWnd , NULL , hInstance , NULL );
You can assume the windows default process is used sufficiently in the mentioned WndProc and that hInstance is consistent throughout the program. Changing the style flag in the child window from WS_OVERLAPPEDWINDOW to WS_CAPTION results in the same problem.
I understand having a window directly within another window isn't normal, but it should be possible.
Your help and consideration are much appreciated,
Caleb