• Advertisement
Sign in to follow this  

C++, XP child windows

This topic is 3355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
well i took the code from an msdn example, and changed it a bit.

giving the childwindow a name still did not work

Share this post


Link to post
Share on other sites
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.
?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Are you trying to create a tool window? If so you have conflicting styles. A tool window must not have WS_CHILD set. WS_CHILD is used if a control/window is to be embedded in the client area of a parent, not if it's free floating somewhere.

Share this post


Link to post
Share on other sites
Quote:
Original post by pavel989
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?
Put what in WM_CREATE?

You need a window class for every functionally different window you have (Not entirely true, but that's usually the case). So if the new window does something different, and you want to have a new WndProc called, you'll need a new window class.
You need to have the window class registered before you try to create a window using that class.

Share this post


Link to post
Share on other sites
i got it running a bit. im using the RegisterClassEx and createwindowex functions now. It doesn't give me and HWND, but when i do a getlasterror, it says the operation completed successfully.

am i missing something?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement