Creating a child window
I am trying to make a simple control, by creating a child window. I have already created another window successfully, who's handle is "h_parent". (My application instance is "h_instance".) I have then tried to create the child window, using the code below, but it does not work. The program freezes for a few seconds at the CreateWindowEx function, and then gives me an unhandled exception from the file <xutility>. Any ideas what I am doing wrong? Thanks.
HWND CreateControl(HWND h_parent, HINSTANCE h_instance)
DWORD extended_window_style = 0;
LPCSTR window_class_name = "my_control";
LPCSTR window_name = "";
DWORD window_style = WS_CHILD | WS_VISIBLE;
int x = 0;
int y = 0;
int width = 100;
int height = 100;
HWND parent_window_handle = h_parent;
HMENU menu_handle = NULL;
HINSTANCE app_instance_handle = h_instance;
LPVOID window_creation_data = NULL;
HWND h_control = CreateWindowEx(extended_window_style, window_class_name, window_name, window_style, x, y, width, height, parent_window_handle, menu_handle, app_instance_handle, window_creation_data);
You have to use the control's class name, and it's case sensitive... For an edit control your window_class_name would be "EDIT"
But why are you doing it the hard way, you could simply do this...
There's no reason to pass everything through intermediate variables, that's just a waste of space.
// text display window
Wind = CreateWindowEx(WS_EX_CLIENTEDGE,L"STATIC",RM_VERSION,
WS_CHILD | WS_VISIBLE |
SS_CENTER | SS_CENTERIMAGE | SS_NOTIFY,
Thanks for the help. I understand that I need to use the control's class name - this is in fact exactly "my_control" which was used to register the class.
I've figured out some more information that might help. If I set the window style to "0", then it runs fine. However, if either "WS_CHILD" or "WS_VISIBLE" are present, then the CreateWindowEx() does not work. ALl other window styles that I have tried seem to work fine. But I need WS_CHILD, because I want it to be a child window, so it is odd that it causes an error...
Any ideas? Thanks.
Please post the code for the custom control... I suspect that's where your problem is...
Also you really should clean up that subroutine you posted. Using intermediate variables like that is just plain silly.