Jump to content
  • Advertisement
Sign in to follow this  
HolySheepy

Resources

This topic is 4833 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

Hi, i'm learning on how to make menus on Windows and how to use Resources so im using Code::Blocks IDE together with Microsoft Platform SDK and Microsoft Visual .NET Toolkit 2003. mainnewmenu.cpp(main.cpp just renamed cuz it overwrites that shit lol):
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
	switch(msg){
		case WM_COMMAND:
		{
            case MENUID_NEW:
            return(0);
            break;
            case MENUID_OPEN:
            return(0);
            break;
		} 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 sampleClass;                                 

sampleClass.cbSize =        sizeof(WNDCLASSEX);          
sampleClass.style =         CS_DBLCLKS | CS_OWNDC |
                            CS_HREDRAW | CS_VREDRAW;      
sampleClass.lpfnWndProc =   MsgHandler;                  
sampleClass.cbClsExtra =    0;                           
sampleClass.cbWndExtra =    0;                           
sampleClass.hInstance =     hinstance;                 
sampleClass.hIcon =         LoadIcon(NULL, IDI_WINLOGO);  
sampleClass.hCursor =       LoadCursor(NULL, IDC_ARROW);  
sampleClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);   
sampleClass.lpszMenuName =(LPCSTR) LoadMenu(hinstance, MAKEINTRESOURCE(MAIN_MENU));                      
sampleClass.lpszClassName = "Sample Class";              
sampleClass.hIconSm =       LoadIcon(NULL, IDI_WINLOGO);  
RegisterClassEx(&sampleClass);
HWND hwnd;
if (!(hwnd = CreateWindowEx(NULL,                   
                            "Sample Class",         
                            "Sample Window",        
                            WS_POPUP | WS_VISIBLE,  
                            0, 0, 320, 240,         
                            NULL,                   
                            NULL,                   
                            hinstance,              
                            NULL)))                 
    return(0);
    while(1){}
    return(0);
}
resource.h:
#define MENUID_NEW 1000
#define MENUID_OPEN 1001
#define MAIN_MENU 999

mainnewmenurc.rc:
#include "resource.h"
MAIN_MENU MENU
{
    POPUP "&File"
    {
        MENUITEM "&New",	MENUID_NEW
	MENUITEM "&Open",	MENUID_OPEN
    }
}
mainnewmenu.cpp errors: Line 7 error C2065: 'MENUID_NEW' : undeclared identifier Line 7 error C2051: case expression not constant Line 10 error C2065: 'MENUID_OPEN' : undeclared identifier Line 10 error C2051: case expression not constant Line 39 error C2065: 'MAIN_MENU' : undeclared identifier

Share this post


Link to post
Share on other sites
Advertisement
#include <resource.h>
dont works
only
#include "resource.h"

but for some reason my programm is crashing lol
it doesnt even show up i start it 10 secs later windows gives me a error
Win32GUI.exe blablahblah problem blahblahblah must be closed.

Share this post


Link to post
Share on other sites
Quote:
Original post by HolySheepy
#include <resource.h>
dont works
only
#include "resource.h"

Yeah, most people don't add the project directory to their permanent include directories list.

Quote:
but for some reason my programm is crashing lol
it doesnt even show up i start it 10 secs later windows gives me a error
Win32GUI.exe blablahblah problem blahblahblah must be closed.

Time to fire up the debugger.

Share this post


Link to post
Share on other sites
sampleClass.lpszMenuName =(LPCSTR)LoadMenu(hinstance, MAKEINTRESOURCE(MAIN_MENU));
i tried around and found out its this line =/
without (LPCSTR) it says
Line 42 error C2440: '=' : cannot convert from 'HMENU' to 'LPCSTR'
although this http://www.gamedev.net/reference/programming/features/gpgenesis2/page4.asp
says its
sampleClass.lpszMenuName = LoadMenu(hinstance, MAKEINTRESOURCE(MAIN_MENU));

Share this post


Link to post
Share on other sites
The Game Programming Genesis appears to be wrong, then...

// Instead of
sampleClass.lpszMenuName = LoadMenu(hinstance, MAKEINTRESOURCE(MAIN_MENU));
// use
sampleClass.lpszMenuName = (LPCTSTR)MAKEINTRESOURCE(MAIN_MENU);


I also noticed in your original code that your switch statement isn't built right. You need another switch statement within your WM_COMMAND case:

case WM_COMMAND:
switch (LOWORD(wParam))
{
case MENUID_NEW:
return(0);
break;
case MENUID_OPEN:
return(0);
break;
}
break;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!