Advertisement

arrrgh! help!

Started by April 13, 2000 06:07 PM
4 comments, last by Moe 24 years, 8 months ago
I recently purchase ''windows 98 programming from the ground up''. it has the source code for a windows 98 skeleton (just the bare bones of a window). I have tried everything within my power to get this to compile properly using visual C++ 6, but to no avail. Here is the code (i don''t know how to use that code tag thing yet): //minimal windows 98 skeleton #include LRESULT CALLBACK WindowFunc (HWND, UINT, WPARAM, LPARAM); char szWinName [] = "mywin"; //name of windows class int WINAPI WinMain (HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode) { HWND hwnd; MSG msg; WNDCLASSEX wcl; //define a window class wcl.cbSize = sizeof(WNDCLASSEX); wcl.hInstance = hThisInst; //handle to this instance wcl.lpszClassName = szWinName; //window class name wcl.lpfnWndProc = WindowFunc; //window function wcl.style = 0; //default style wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //standard icon wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO); wcl.hCusor = LoadCursor(NULL, IDI_ARROW); wcl.lpszMenuName = NULL; //no menu wcl.cbClsExtra = 0; //no extra info needed wcl.cbWndExtra = 0; //no extra info needed //make the window background white wcl.hbrBackGround = (HBRUSH) GetStockObject(WHITE_BRUSH); //register the window class if(!RegisterClassEx(&wcl)) return 0; //now that a window class has been registered, a window can be created hwnd = CreateWindow( szWinName, "Windows 98 Skeleton", //title WS_OVERLAPPEDWINDOW, //window style - normal CW_USEDEFAULT, //x co-ord CW_USEDEFAULT, //y co-ord CW_USEDEFAULT, //width- let windows decide CW_USEDEFAULT, //hight - let windows decide HWND_DESKTOP, //no parent window NULL, //no menu hThisInst; //handle of this instance of the program NULL, //no additional arguments ); //display the window ShowWindow(HWND, nWinMode); UpdateWindow (hwnd); //create message loop while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); //translate keyboard messages DispatchMessage(&msg); //return control to windows 98 } return msg.wParam; } //this function is called by windows 98 and is passed messages from the message queue LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: //terminate the program PostQuitMessage (0); break; default: // let windows 98 process any messages not specified in the preceding switch statement return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } Now here is the kicker. I get the following errors: D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(26) : error C2039: ''hCusor'' : is not a member of ''tagWNDCLASSEXA'' d:\vc98\include\winuser.h(1139) : see declaration of ''tagWNDCLASSEXA'' D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(26) : error C2065: ''IDI_ARROW'' : undeclared identifier D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(33) : error C2039: ''hbrBackGround'' : is not a member of ''tagWNDCLASSEXA'' d:\vc98\include\winuser.h(1139) : see declaration of ''tagWNDCLASSEXA'' D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(51) : warning C4003: not enough actual parameters for macro ''CreateWindowA'' D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(51) : error C2143: syntax error : missing '')'' before '';'' D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(51) : error C2660: ''CreateWindowExA'' : function does not take 11 parameters D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(51) : error C2059: syntax error : '')'' D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(51) : error C2059: syntax error : '';'' D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(54) : error C2275: ''HWND'' : illegal use of this type as an expression d:\vc98\include\windef.h(195) : see declaration of ''HWND'' I can''t figure out what the heck is going on here. can i please get some help???!? - Moe -
I can see that you are just starting up. Keep in mind that when programming, you have to be careful about variable names and lower and HIGHER case letters.

All of your errors where because of wrong syntax or missing characters, etc.. I''ll go your errors through one by one.

--------------------------
D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(26) : error C2039: ''hCusor'' : is not a member of ''tagWNDCLASSEXA''

hCusor is mispelled. It should say hCursor.
--------------------------
D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(26) : error C2065: ''IDI_ARROW'' : undeclared identifier

I''m not sure about this and I''m too lazy to check it up. But I would guess that this is mispelled too. Right constant would be IDC_ARROW. Recheck it from the book!
--------------------------
D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(33) : error C2039: ''hbrBackGround'' : is not a member of ''tagWNDCLASSEXA''

C and C++ are CaSe SeNsItIvE. The right parameter most likely is hbrBackground, and not hbrBackGround.
--------------------------
D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(51) : warning C4003: not enough actual parameters for macro ''CreateWindowA''

You have again a syntax error in CreateWindow procedure, after variable hThisInst you have a semicolon ; when you should have colon , (or is it colon, i don''t know..
----------------------------
D:\programming\MSDev98\MyProjects\hey10\hey10.cpp(54) : error C2275: ''HWND'' : illegal use of this type as an expression

Again. A syntax error. Here''s where error occurs:
ShowWindow(HWND, nWinMode);
You should pass hwnd as the first parameter, not HWND.
----------------------------


These are all simple errors, you just have to be more careful when you''re writing programs.. Remember that case matters. And since you''re using Visual C++, you can double click the error text and Visual Studio takes you right to the line where error occurs. So you can double check that line so that everything is correct...


Advertisement
Change wcl.hCusor to wcl.hCursor
Change wcl.hbrBackGround to wcl.hbrBackground

The first parameter of ShowWindow should be hwnd, not HWND.
Remove the space between UpdateWindow and (hwnd).

I don't know if this will rule out all the errors, but it should help a little.

Sorry, mussepigg beat me to the rescue

*Sparkle*

Edited by - Sparkle on 4/13/00 6:34:06 PM
Here''s some stuff you did wrong:

You spelled hCursor wrong here, and it''s IDC_ARROW, not IDI.
wcl.hCusor = LoadCursor(NULL, IDI_ARROW);

It''s wcl.hbrBackground, not Ground.
wcl.hbrBackGround = (HBRUSH) GetStockObject(WHITE_BRUSH);

In the Create window function, you put an extra comma at the end.

...
NULL, //no additional arguments
);

I think that''s it.

Hope this helped
Martin






______________Martin EstevaolpSoftware
Darn, two people beat me Oh yeah, forgot the HWND thing, change it to hwnd. Most of your errors are just silly syntax and case errors.

Martin
______________Martin EstevaolpSoftware
Now i know how to feel like an idiot. thanks a billion. that cleared up everything. And i thought i had accidentally messed up some header file. what a relief, let me tell you that! And to think about an hour ago i was ready to kick that darn book out the window.

BTW, that HWND was like that in the book, but oh, well now that things are fixed and working out!

- Moe -

This topic is closed to new replies.

Advertisement