-
CreateWindow Problem
PHP Code:
//create the window
g_Hwnd = ::CreateWindow ( g_szClassName,
g_szCaption,
WS_MINIMIZEBOX | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT,
300,
NULL,
NULL,
hInstance,
NULL);
if (g_Hwnd == NULL)
{
MessageBox (NULL, "Window Creation failed", "PAManipulator Error", MB_OK);
return 0;
}
when i do this, it gives me the following errors:
Code:
C:\My Documents\C++ Projects (Clean + Efficient)\Parrallel Port Assignment\Init.cpp(45) : warning C4003: not enough actual parameters for macro 'CreateWindowA'
C:\My Documents\C++ Projects (Clean + Efficient)\Parrallel Port Assignment\Init.cpp(45) : error C2059: syntax error : ')'
Error executing cl.exe.
-
I think you forgot the height of the window (after 300)
-
i thought about this too, but when i open the bracket in VC++ and it shows me the parameters, there is no nHeight parameter..
i checked in the MSDN and it did show nHeight as being in the parameters..
-
rightclick createwindow and press definition, then you should see something like this as you do the same with CreateWindowA:
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
Paste it here, if it doesn't have that nHeight parameter
-
huh?? i checked and it is there!
that's exactly what i have
PHP Code:
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
??
-
well eh, maybe you have another function somewhere where you forgot to put in nHeight. Id doesn't matter what VC++ pop up in the tool tip (btw when theres several with the same name you can scroll them) just type in the height and it should choose the correct overloaded function.
-
ok i did it and i got no errors
but sorry to bother but in this
PHP Code:
BOOL InitInstance (void)
{
BOOL bRet = FALSE;
g_Hwnd = CreateWindow (
g_szClassName,
g_szCaption,
WS_MINIMIZEBOX | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT,
300, 200,
NULL,
NULL,
g_hInstance,
NULL,
);
ShowWindow (g_Hwnd, SW_SHOW);
UpdateWindow (g_Hwnd);
if (g_Hwnd == 0)
{
MessageBox (NULL, "Window Creation Error", "PAManipulator Error", MB_OK);
bRet = FALSE;
}
else
bRet = TRUE;
return bRet;
}
do you see any errors because when i run the program it does pop the "Window Creation Error".
-
Nope, it's probably embeded in what you've got in those variables. Have you got the window class registered?
-
yea with another one of my funcs
PHP Code:
BOOL InitApplication (void)
{
BOOL bRet = FALSE;
WNDCLASS wc;
//set up info
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.hCursor = LoadCursor (g_hInstance, IDC_ARROW);
wc.hIcon = LoadCursor (g_hInstance, MAKEINTRESOURCE (IDI_ICON));
wc.hInstance = g_hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = g_szClassName;
wc.lpszMenuName = NULL;
bRet = RegisterClass (&wc);
return bRet;
}
these are teh variables i use
PHP Code:
char* g_szClassName = "Port Manipulator";
HINSTANCE g_hInstance;
HWND g_Hwnd; //storage for the handle of our window
char* g_szCaption = "Port Manipulator"; //caption of window
-
put this one in too:
wc.cbSize = sizeof(WNDCLASSEX);
-
so now i have
PHP Code:
BOOL InitApplication (void)
{
BOOL bRet = FALSE;
WNDCLASSEX wc;
//set up info
wc.style = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.hCursor = LoadCursor (g_hInstance, IDC_ARROW);
wc.hIcon = LoadCursor (g_hInstance, MAKEINTRESOURCE (IDI_ICON));
wc.hInstance = g_hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = g_szClassName;
wc.lpszMenuName = NULL;
bRet = RegisterClassEx (&wc);
return bRet;
}
no errors, but nothing shows..since i didn't add any error messages in that function, there is probably an error in the registration
-
yea, ijust checked and there is an error in the registration
-
i got rid of the registration erro by adding in
wc.IconSm = ...
but i still have a creation error.. :(
-
-
well...i had this problem before and so i was using createwindowex with a non-ex style as the dwexstyle param.. but cornedbee pointed out to me that it was WRONG so if it doesn't work when i call CreateWindow, what should i do?
-
You have not enough normal window styles. e.g. you don't specify what border you want (WS_BORDER, WS_SIZEBOX, WS_THICKBORDER etc.)
-
WS_OVERLAPPEDWINDOW is a good start (just use that, it's a combination of other styles).
-
i still get that stupid message box with "Window Creation Failed"
i changed the style to WS_OVERLAPPEDWINDOW
PHP Code:
BOOL InitInstance (void)
{
BOOL bRet = FALSE;
g_Hwnd = CreateWindow (
g_szClassName,
g_szCaption,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
300, 200,
NULL,
NULL,
g_hInstance,
NULL,
);
if (g_Hwnd == 0)
{
MessageBox (NULL, "Window Creation Error", "PAManipulator Error", MB_OK);
bRet = FALSE;
}
else
{
bRet = TRUE;
}
ShowWindow (g_Hwnd, SW_SHOW);
UpdateWindow (g_Hwnd);
return bRet;
}
but no difference... :(
-
i looked everywhere, i dont get it.. i think that i shouldn't have tried to add the nHeight value when there is n't any parameter of that name when VC++ shows the tool tip..that's prob what makes the msgbox pop up..
anyone have any ideas? thanks
-
Yeah. Upload the whole thing.
The VC++ bug with CreateWindow lacking the height parameter in the tooltip is known (at least to me :) ). You'll have to remember it for this common-used function.
-
1 Attachment(s)
ok there..and like you also told me i had a bad coding style..i am trying to make it better... :)
i just started this so it wont do anything.. :)
-
Your WndProc is malformed. Here is a corrected version:
Code:
LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:
DestroyWindow (hwnd);
Clean ();
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, msg, wParam, lParam);
}
I replaced APIENTRY with CALLBACK. While this is not necessary, it is good coding as it marks the function as a callback function.
I also changed the switch statement to a more commonly used form. But the most important thing is that you need to use the hwnd that is passed to the function, as the WM_CREATE message is sent BEFORE CreateWindow returns, and therefore the g_Hwnd is not valid yet! (I found the error only because I thought it bad coding style not to use the hwnd passed to the WndProc, and only now I see the reason why it is so.)
Your call to CreateWindow also has a syntax error: you have a comma after the last argument.
And PLEASE, don't use goto in normal programming, especially not like you do in your WinMain. It is better to use multiple return instructions than doing such things. I would also forget the bRet variable in InitApplication and InitInstance, especially since it causes you to call ShowWindow and UpdateWindow even when g_Hwnd is NULL.
-
ok thanks..i am gonna try that...and i'll forget about about the goto which i saw on the msdn..thank you for pointing out bad things... :)
thanks
-
thanks a lot ...it worked... :)
i wouldn't mind if you could tell me whether there's is a thing i should change in my coding.. :)
thanks