Advertisement

Hell with menus (.rc file's)

Started by May 27, 2001 05:51 PM
1 comment, last by tryforfulluse 23 years, 8 months ago
Hello, Im sorry for the title, but its really what im experimenting. I am just trying to start a side-scroller im going to develop this summer (I will really) and Im getting the map-editor up. The game is being made for Windows using DirectX- for graphics DDraw. Well I am just trying to get the top menu up, but it will not show. Going back to my old days of reading Trick of Win G. Guru, I went to see how to load .rc files, and have been trying for a while to get my own to work, with no luck. I am using Vc++. I make a new project, I have my main code that loads the .rc file in. (right here) // DEMO3_3.CPP - Loading a MENU resource // INCLUDES /////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN // just say no to MFC #include // include all the windows headers #include // include useful macros #include // very important and include WINMM.LIB too! #include #include #include #include "resource.h" // DEFINES //////////////////////////////////////////////// // defines for windows #define WINDOW_CLASS_NAME "WINCLASS1" // GLOBALS //////////////////////////////////////////////// HWND main_window_handle = NULL; // globally track main window HINSTANCE hinstance_app = NULL; // globally track hinstance // FUNCTIONS ////////////////////////////////////////////// LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { // this is the main message handler of the system PAINTSTRUCT ps; // used in WM_PAINT HDC hdc; // handle to a device context // what is the message switch(msg) { case WM_CREATE: { // do initialization stuff here // return success return(0); } break; case WM_PAINT: { // simply validate the window hdc = BeginPaint(hwnd,&ps); // you would do all your painting here EndPaint(hwnd,&ps); // return success return(0); } break; case WM_DESTROY: { // kill the application, this sends a WM_QUIT message PostQuitMessage(0); // return success return(0); } break; default:break; } // end switch // process any messages that we didn''t take care of return (DefWindowProc(hwnd, msg, wparam, lparam)); } // end WinProc // WINMAIN //////////////////////////////////////////////// int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg; // generic message // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = 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 = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // save hinstance in global hinstance_app = hinstance; // register the window class if (!RegisterClassEx(&winclass)) return(0); // create the window if (!(hwnd = CreateWindowEx(NULL, // extended style WINDOW_CLASS_NAME, // class "Menu Resource Demo", // title WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, // initial x,y 400,400, // initial width, height NULL, // handle to parent NULL, // handle to menu, note it''s null hinstance,// instance of this application NULL))) // extra creation parms return(0); // save main window handle main_window_handle = hwnd; // load the menu resource HMENU hmenuhandle = LoadMenu(hinstance, "MainMenu"); // attach the menu to the window SetMenu(hwnd, hmenuhandle); // enter main event loop, but this time we use PeekMessage() // instead of GetMessage() to retrieve messages while(TRUE) { // test if there is a message in queue, if so get it if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } // end if // main game processing goes here // Game_Main(); // or whatever your loop is called } // end while // return to Windows like this return(msg.wParam); } // end WinMain /////////////////////////////////////////////////////////// now I have this code in. I go to insert resource, then menu New. And in the first box type in file and give it an id of ID_FILE, but when i compile i dont get my Menu, i name the menu MainMenu and when i load it i load MainMenu. but i cant get it to show, i can only get a. lamothes to work. So you guys know I have made 3 directx based games before, so I do know what im doing. And I just took a. lamothes code for this, just to try to get a .rc file to work, if i can get it work, i will use all my own stuff. Thankyou to anyone who can help me... And thanks for reading this long post
bad!
I can't see anything wrong with the code. My little menu resource demo (also from LaMothe) is almost identical and it works. Perhaps it's your header or rc file. I know that mvc++ really can mangle rc files, perhaps if you hand code it... Here's mine:

      #include "RESOURCE.H"MainMenu MENU DISCARDABLE  {  POPUP "File"    {    MENUITEM "Open",  MENU_FILE_ID_OPEN    MENUITEM "Close", MENU_FILE_ID_CLOSE    MENUITEM "Save",  MENU_FILE_ID_SAVE    MENUITEM "Exit",  MENU_FILE_ID_EXIT  } // end popupPOPUP "Help"  {  MENUITEM "About",  MENU_HELP_ABOUT    POPUP "Extra"      {      MENUITEM "More", MENU_HELP_EXTRA_MORE      MENUITEM "Stuff", MENU_HELP_EXTRA_STUFF      }	  } // end popup} // end top level menu    And RESOURCE.H for completeness:            // defines for the top level menu FILE#define MENU_FILE_ID_OPEN  1000//#define MENU_FILE_ID_CLOSE 1001//#define MENU_FILE_ID_SAVE  1002//#define MENU_FILE_ID_EXIT  1003// defines for the top level menu HELP#define MENU_HELP_ABOUT 2000// defines for cascading menu EXTRA#define MENU_HELP_EXTRA_MORE  2100#define MENU_HELP_EXTRA_STUFF 2200    


Hope this helps.

--------------------------
thi sis my si gitzt hebezt

Edited by - petalbloom on May 27, 2001 7:22:23 PM [ugg code mess]

Edited by - petalbloom on May 27, 2001 7:24:16 PM
thi sis my si gitzt hebezt
Advertisement
Thankyou, I got it to work, after trying bout 40 times, it just randomly worked, dont know why. Thanks for posting.
bad!

This topic is closed to new replies.

Advertisement