C++, XP child windows

Started by
12 comments, last by pavel989 15 years, 4 months ago
Hey guys, im trying to create a child window, but no matter what values i change, i cannot get a HWND for it. just keeps failing. are there like specific rules in making one? im Using createwindowexa() -- or something like that, but my point is, i know which parameter is which, but like are there rules for the params themselves?
Advertisement
Of course there are rules.

You'll have to provide some actual code for us to know what the actaul problem actually is, though.
a) Don't use the *A and *W forms of the API calls unless you have a very good reason - use the normal ones and let you project's UNICODE settings decide which one to use.

b) Post some code so we can figure out what is wrong.
Quote:Original post by EasilyConfused
a) Don't use the *A and *W forms of the API calls unless you have a very good reason - use the normal ones and let you project's UNICODE settings decide which one to use.

b) Post some code so we can figure out what is wrong.


c) Tell us what GetLastError() returns after CreateWindow() fails

d) Put a breakpoint in your window proc and see if it's ever called - If so, make sure you're processing WM_CREATE properly, and returning 0 for that message.
if(!CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,                                "ChildWClass",                                (LPCTSTR) NULL,                                WS_CHILD | WS_BORDER,                                0,0,100,100,                                hWnd, NULL,                                hInstance,                                NULL)					)	 {		 MessageBox(NULL,"Child Window Creation Error.",		"ERROR",MB_OK|MB_ICONEXCLAMATION);		 return 0;		 }    LPTSTR pszMessage;    DWORD dwLastError = GetLastError();     FormatMessage(        FORMAT_MESSAGE_ALLOCATE_BUFFER |         FORMAT_MESSAGE_FROM_SYSTEM        ,        NULL,        dwLastError,        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),        (LPTSTR)&pszMessage,        0, NULL );	wprintf(L"%s failed with error %d: ", (LPSTR) dwLastError, pszMessage);


create window ex returns null if it failed, wprintf says (null) failed with error: 1500872


-- it seems to not extract the Dword error. i took the format message code from msdn.
Quote:Original post by pavel989
wprintf(L"%s failed with error %d: ", (LPSTR) dwLastError, pszMessage)


You've got dwLastError and pszMessage backwards. The text of the message "failed with error" also doesn't make sense with the parameters you're passing in.

My guess is the problem is you're passing NULL for the window title. I think you need to pass a valid value.
well i took the code from an msdn example, and changed it a bit.

giving the childwindow a name still did not work
Have you registered the ChildWClass window class with RegisterClass or RegisterClassEx?
Quote:Original post by pavel989
*** Source Snippet Removed ***

create window ex returns null if it failed, wprintf says (null) failed with error: 1500872


-- it seems to not extract the Dword error. i took the format message code from msdn.
That means that dwLastError is 0, which is "No error".

Did you try this:
Quote:Original post by Evil Steve
d) Put a breakpoint in your window proc and see if it's ever called - If so, make sure you're processing WM_CREATE properly, and returning 0 for that message.
?
Sorry for the late response. Was on a break :)

Do I have to put it in wm_create?

And do I need to register a new window class?
If so, after or befor I call this createwindow func?

This topic is closed to new replies.

Advertisement