Archived

This topic is now archived and is closed to further replies.

Mage_gr

What 's the problem people?

Recommended Posts

Mage_gr    122
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)

Share this post


Link to post
Share on other sites
LessBread    1415
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.

Share this post


Link to post
Share on other sites
cMADsc    122
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;
}

//also

winclass.hBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

//missing

ShowWindow(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]

Share this post


Link to post
Share on other sites
myme15    122
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)

Share this post


Link to post
Share on other sites
SilentCoder    122
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]

Share this post


Link to post
Share on other sites
Mage_gr    122
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)

Share this post


Link to post
Share on other sites
jenova    122
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.

Share this post


Link to post
Share on other sites
SilentCoder    122
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.

Share this post


Link to post
Share on other sites