Jump to content
  • Advertisement

Archived

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

ryancpp

Errors: WNDCLASSEX::lpszMenuName = LoadMenu(...);

This topic is 5384 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive got a single problem thats really gettin on my nerves. Here's the code: main.cpp #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <windowsx.h> #include "resource.h" #ifndef Q_PROG #define Q_PROG #endif LRESULT CALLBACK MsgHandler(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { if(msg==WM_COMMAND) { switch(LOWORD(wparam)) { case MAIN_MENU_IDCLOSE: #undef Q_PROG break; default: return(DefWindowProc(hwnd,msg,wparam,lparam)); break; } } return 0; } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { WNDCLASSEX wndClass; wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = MsgHandler; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(ICON_MAIN)); wndClass.hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(ICON_MAIN)); wndClass.hInstance = hInstance; wndClass.lpszClassName = "wndClass"; wndClass.lpszMenuName = LoadMenu(NULL,MAKEINTRESOURCE(MAIN_MENU)); RegisterClassEx(&wndClass); HWND hwnd; if(!(hwnd = CreateWindowEx(NULL, "wndClass", "My Windowz", WS_OVERLAPPED | WS_VISIBLE, 0,0,320,240, NULL, MAKEINTRESOURCE(MAIN_MENU), hInstance, NULL))) return 0; //ShowWindow(hwnd,nCmdShow); int quit=1; do { MSG msg; if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } #ifndef Q_PROG quit=0; #endif }while(quit); return 0; } resource.h #define ICON_MAIN 1000 #define MAIN_MENU 8001 #define MAIN_MENU_IDCLOSE 4001 resource.rc #include "resource.h" //Main Icon ICON_MAIN ICON myicon.ico //Main Menu MAIN_MENU MENU { POPUP "&File" { MENUITEM "&Close", MAIN_MENU_IDCLOSE } } When I compile, i get the following errors in main.cpp: --------------------Configuration: Windows Force Shutdown - Win32 Debug-------------------- Compiling... main.cpp F:\C++\Windows Projects Workspace\Windows Force Shutdown\main.cpp(44) : error C2440: '=' : cannot convert from 'struct HMENU__ *' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast F:\C++\Windows Projects Workspace\Windows Force Shutdown\main.cpp(57) : error C2664: 'CreateWindowExA' : cannot convert parameter 10 from 'char *' to 'struct HMENU__ *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe. main.obj - 2 error(s), 0 warning(s) What am I missing here? Compiler: MSVC++ 6.0 Any help would be great. Thanks. ------------------------------------- -RyanC++ personClass.life = LoadLife("RyanC++", MAKEINTRESOURCE(NONE)); [edited by - ryancpp on November 18, 2003 1:45:53 AM]

Share this post


Link to post
Share on other sites
Advertisement
Note: I''ve tried changing up my resource script to:
MAIN_MENU MENU
BEGIN
POPUP "&File"
BEGIN
...
END
END

but that didnt change things.


Is there something wrong in my resource.h file? such as my definition of MAIN_MENU?

-Dazed and Confused

-------------------------------------
-RyanC++

personClass.life = LoadLife("RyanC++", MAKEINTRESOURCE(NONE));

Share this post


Link to post
Share on other sites
Just a simple type conversion from const char* to HMENU will do the trick. And the way you''re using defines just won''t work. The preprocessor does not take into account any non-preprocessor code when defining, including etc.

Share this post


Link to post
Share on other sites
Ok, I did that. It compiles. But Im not quite sure I get that typecasting.

Here''s the compiling code:


//Code that was changed in the WNDCLASSEX ini
//...

wndClass.lpszMenuName = (char*)LoadMenu(NULL,MAKEINTRESOURCE(MAIN_MENU));


//..



//Code that was changed in the CreateWindowEX() Fn.
//..
(HMENU)MAKEINTRESOURCE(MAIN_MENU),
//..
//..

I don''t see how VC knows to convert an HMENU variable to a const char*. But anyways. Im getting a new error now. Maybe that has to do with this. Its a Windows Error Report(lol, i love these things) saying that (when debugged) that a peice of memory is trying to access another peice, and that second peice cannot be read. Its very vague i know, but is there any fundamental flaws in my coding?

Oh and yes, i took out the #define stuff. I knew it prob wouldn''t work, i was just testing it. Im just now getting into Windows API so bare with me (even though #define''s arent WINAPI, but you know).

-Grateful


-------------------------------------
-RyanC++

personClass.life = LoadLife("RyanC++", MAKEINTRESOURCE(NONE));

Share this post


Link to post
Share on other sites
Change:

wndClass.lpszMenuName = (char*)LoadMenu(NULL,MAKEINTRESOURCE(MAIN_MENU));

to:

wndClass.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU);



With CreateWindowEx either use NULL to use the Menu you set in the class or use MAIN_MENU directly.

All clearly stated in the MSDN. Just a F1-press away.


Share this post


Link to post
Share on other sites
Ok Endurion, i changed the code in my wndClass ini, and I also changed the code in the CreateWindowEx() to "(HMENU)MAIN_MENU," (cause it still needs a typecast. Now im getting no compile errors, no run-time errors, but the window does not get created. I tested it with my if statement to see if CreateWindowEx returns NULL, and it did. Therefore, i think there''s something wrong with my CreateWindowEx(). Any suggestions?

-Again grateful

-------------------------------------
-RyanC++

personClass.life = LoadLife("RyanC++", MAKEINTRESOURCE(NONE));

Share this post


Link to post
Share on other sites
quote:
Original post by Endurion
Change:

wndClass.lpszMenuName = (char*)LoadMenu(NULL,MAKEINTRESOURCE(MAIN_MENU));

to:

wndClass.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU);



I''d personally change

wndClass.lpszMenuName = (char*)LoadMenu(NULL,MAKEINTRESOURCE(MAIN_MENU));

to

wndClass.lpszMenuName = (char*)LoadMenu(hInstance,MAKEINTRESOURCE(MAIN_MENU));

Share this post


Link to post
Share on other sites
no difference...


-------------------------------------
-RyanC++

personClass.life = LoadLife("RyanC++", MAKEINTRESOURCE(NONE));

Share this post


Link to post
Share on other sites
Has anyone ever coded there own resources????
Somebody has got to know whats wrong with this code...
-Still wondering

-------------------------------------
-RyanC++

personClass.life = LoadLife("RyanC++", MAKEINTRESOURCE(NONE));

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!