|
-
Dec 12th, 2001, 10:32 PM
#1
Thread Starter
Hyperactive Member
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.
Amon Ra
The Power of Learning.
-
Dec 12th, 2001, 10:41 PM
#2
transcendental analytic
I think you forgot the height of the window (after 300)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 12th, 2001, 11:12 PM
#3
Thread Starter
Hyperactive Member
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..
Amon Ra
The Power of Learning.
-
Dec 12th, 2001, 11:17 PM
#4
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 12th, 2001, 11:36 PM
#5
Thread Starter
Hyperactive Member
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)
??
Amon Ra
The Power of Learning.
-
Dec 12th, 2001, 11:43 PM
#6
transcendental analytic
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.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 12th, 2001, 11:47 PM
#7
Thread Starter
Hyperactive Member
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".
Amon Ra
The Power of Learning.
-
Dec 12th, 2001, 11:50 PM
#8
transcendental analytic
Nope, it's probably embeded in what you've got in those variables. Have you got the window class registered?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 13th, 2001, 12:03 AM
#9
Thread Starter
Hyperactive Member
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
Amon Ra
The Power of Learning.
-
Dec 13th, 2001, 12:15 AM
#10
transcendental analytic
put this one in too:
wc.cbSize = sizeof(WNDCLASSEX);
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 13th, 2001, 12:27 AM
#11
Thread Starter
Hyperactive Member
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
Amon Ra
The Power of Learning.
-
Dec 13th, 2001, 12:29 AM
#12
Thread Starter
Hyperactive Member
yea, ijust checked and there is an error in the registration
Amon Ra
The Power of Learning.
-
Dec 13th, 2001, 12:38 AM
#13
Thread Starter
Hyperactive Member
i got rid of the registration erro by adding in
wc.IconSm = ...
but i still have a creation error..
Amon Ra
The Power of Learning.
-
Dec 13th, 2001, 12:39 AM
#14
transcendental analytic
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 13th, 2001, 11:03 AM
#15
Thread Starter
Hyperactive Member
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?
Amon Ra
The Power of Learning.
-
Dec 13th, 2001, 11:48 AM
#16
You have not enough normal window styles. e.g. you don't specify what border you want (WS_BORDER, WS_SIZEBOX, WS_THICKBORDER etc.)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 13th, 2001, 12:05 PM
#17
Monday Morning Lunatic
WS_OVERLAPPEDWINDOW is a good start (just use that, it's a combination of other styles).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 13th, 2001, 07:04 PM
#18
Thread Starter
Hyperactive Member
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...
Amon Ra
The Power of Learning.
-
Dec 13th, 2001, 11:02 PM
#19
Thread Starter
Hyperactive Member
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
Amon Ra
The Power of Learning.
-
Dec 14th, 2001, 07:43 AM
#20
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 14th, 2001, 05:30 PM
#21
Thread Starter
Hyperactive Member
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..
Amon Ra
The Power of Learning.
-
Dec 15th, 2001, 07:33 AM
#22
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 15th, 2001, 01:14 PM
#23
Thread Starter
Hyperactive Member
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
Amon Ra
The Power of Learning.
-
Dec 15th, 2001, 01:27 PM
#24
Thread Starter
Hyperactive Member
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
Amon Ra
The Power of Learning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|