What 's the problem people?

Started by
8 comments, last by Mage_gr 22 years ago
Guys I can''t understand what the problem is with this program(which I copied from a book) #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <windowsx.h> #include <stdio.h> #include <math.h> #define WINDOW_CLASS_NAME "WINCLASS1" LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch(msg) { case WM_CREATE: { return(0); }break; case WM_PAINT: { hdc = BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); return(0); }break; case WM_DESTROY: { PostQuitMessage(0); return(0); }break; default:break; } return (DefWindowProc(hwnd,msg,wparam,lparam)); } int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; HWND hwnd; MSG msg; winclass.cbSize=sizeof(WNDCLASSEX); winclass.nostyle=CS_DBLCLKS| CS_OWNDC| CS_HREDRAW|CS_VREDRAW; winclass.lpfnWndProc=WindowProc; winclass.cbClsExtra=0; winclass.cbWndExtra=0; winclass.hInstance=hinstance; winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); winclass.hCursor=LoadCursor(NULL,IDC_ARROW); winclass.hbrBackground=GetStockObject(BLACK_BRUSH); winclass.lpszMenuName=NULL; winclass.lpszClassName=WINDOW_CLASS_NAME; winclass.hIconSM=LoadIcon(NULL,IDI_APPLICATION); if(!RegisterClasEx(&winclass)) return(0); if(!(hwnd=CreateWindowEx(NULL, WINDOW_CLASS_NAME, "Your Basic Window", WS_OVERLAPPEDWINDOW|WS_VISIBLE, 0,0 400,400 NULL, NULL, hinstance, NULL))) return (0); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return(msg.wParam); } THE ERROR MESSAGES ARE THESE: Compiling... win.cpp C:\Program Files\Microsoft Visual Studio\MyProjects\windows\win.cpp(61) : error C2440: ''='' : cannot convert from ''void *'' to ''struct HBRUSH__ *'' Conversion from ''void*'' to pointer to non-''void'' requires an explicit cast C:\Program Files\Microsoft Visual Studio\MyProjects\windows\win.cpp(64) : error C2039: ''hIconSM'' : is not a member of ''tagWNDCLASSEXA'' c:\program files\microsoft visual studio\vc98\include\winuser.h(1139) : see declaration of ''tagWNDCLASSEXA'' C:\Program Files\Microsoft Visual Studio\MyProjects\windows\win.cpp(66) : error C2065: ''RegisterClasEx'' : undeclared identifier C:\Program Files\Microsoft Visual Studio\MyProjects\windows\win.cpp(74) : error C2143: syntax error : missing '')'' before ''constant'' C:\Program Files\Microsoft Visual Studio\MyProjects\windows\win.cpp(74) : error C2660: ''CreateWindowExA'' : function does not take 6 parameters C:\Program Files\Microsoft Visual Studio\MyProjects\windows\win.cpp(78) : error C2059: syntax error : '')'' Error executing cl.exe. windows.exe - 6 error(s), 0 warning(s)
When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.
Advertisement
Try pointing out to us whare all the error lines are, because its not funn counting the line number just to hep a newbie.

[ my engine ][ my game ][ my email ]
SPAM
Rate me up.
Try casting the background brush

winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

and don''t capitalize both S & M here

winclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);


On another note, "What''s the problem people" - sounds like the kind of thing a teacher says to a classroom full of misbehaving children. Some might think you''re giving a reprimand rather than asking for assistance "Newbie Windows Problem" would have been enough.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Ok, bare with me, it has been a while since I did some win32 programming. First off I would change the way where u register the class and get a handle to the window. Both of them just have (return 0) for errors. In my opinion I would make a message box to print a message, this way seems more helpful to me though.

    [code]if(!RegisterClassEx(&wc)){MessageBox("NULL, "Register Class Error"), szAppName,   MB_ICONERROR);return 0;}//alsowinclass.hBackground   =  (HBRUSH) GetStockObject (WHITE_BRUSH);//missingShowWindow(hwnd,iCmdShow);UpdateWindow(hwnd);[/code]    


hope this works some, have to go and get phone turned back on and dsl. :-(

return 0;


-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."



[edited by - cMADsc on March 19, 2002 4:51:52 PM]
-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
I suggest you don''t try to copy "Tricks" code by hand. Don''t you have the CD that contains all the source code and examples?

Anyway,

winclass.hbrBackground=GetStockObject(BLACK_BRUSH);

needs to be

winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

GetStockObject returns a void* and you need to cast it to an HBRUSH.

hIconSM needs to be hIconSm

RegisterClasEx needs to be RegisterClassEx (you misspelled class)

Learn how to read the errors your compiler gives you. Most of these are pretty simple errors to figure out. In Visual C++, you can hold F1 and click on an error in the output window and it will bring up a description of that error. Also, please listen to the advice we've been giving you in your other posts. Make sure you really know C/C++ well enough before you try and learn this stuff.

quote: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'


GetStockObject returns an HGDIOBJ type (which is just void*). You need to cast this to an HBRUSH to use it in the structure.

quote:'hIconSM' : is not a member of 'tagWNDCLASSEXA'


This error means exactly what it says, the variable you tried to use from the struct didn't exist. In this case, you misspelled it. Remember that identifiers in C are case sensitive.

quote:error C2065: 'RegisterClasEx' : undeclared identifier


You misspelled RegisterClassEx.

quote: syntax error : missing ')' before 'constant'
'CreateWindowExA' : function does not take 6 parameters


When you pass arguments to a function, you must seperate them with commas. You are missing plenty of commas in your call to CreateWindowEx().

[edited by - SilentCoder on March 19, 2002 4:50:39 PM]
My real problem is with only two errors Can u help me?

in.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\windows\win.cpp(61) : error C2440: ''='' : cannot convert from ''void *'' to ''struct HBRUSH__ *''
Conversion from ''void*'' to pointer to non-''void'' requires an explicit cast
C:\Program Files\Microsoft Visual Studio\MyProjects\windows\win.cpp(66) : error C2065: ''RegisterClasEx'' : undeclared identifier
Error executing cl.exe.

windows.exe - 2 error(s), 0 warning(s)
When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.
If you carefully read the above posts, you''ll see that your question has already been answered. Several times.
a) "RegisterClasEx" is NOT a Win32 function. learn to spell.

b) "(HBRUSH)". learn how to typecast (C++ requires it).


what baffles me; is VS error messages are pretty informative, except for block scope "{/}" type errors. yet, people seem to not understand them. (i.e. "undeclared identifier"; means the function is not declared).




To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Three people including me have told you what caused those two errors. Please read our posts before replying to them.

You''ve already mentioned from your other posts you haven''t finished learning C/C++ yet. I still suggest you finish learning before you go on to the Win32 API. Otherwise, you may have a lot of difficulties.

This topic is closed to new replies.

Advertisement