Sign in to follow this  
pavel989

C++, XP child windows

Recommended Posts

pavel989    114
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
Aardvajk    13207
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
Evil Steve    2017
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
pavel989    114

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
Codeka    1239
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
Evil Steve    2017
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
pavel989    114
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
Endurion    5411
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
Evil Steve    2017
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
pavel989    114
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this