I just figured out how to write a simple windows application(A simple window)now I want to add a menu to it,with a file button...etc,How do I do that?Im writing it in win32 code.
I just figured out how to write a simple windows application(A simple window)now I want to add a menu to it,with a file button...etc,How do I do that?Im writing it in win32 code.
A menu is a resource, so you need a resource file call it menu.rc. Now you write your menu in it
menu.h contains the menu id values, so all our menu.h has in it isCode:#include "menu.h" MyMenu MENU { POPUP "File" { MENUITEM "Exit", IDM_EXIT } }
Now you need to add #include "menu.h" in your file which contains your window function as this needs to know the id values.Code:#define IDM_EXIT 100
In your window class definition change lpszMenuName from NULL to "MyMenu".
All you need do now is to add to your switch so it processes the menu message, somethin like
I think thats it, oh yeah if your compiler has a resource editor you can create resource's visually.Code:switch(message) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDM_EXIT: PostQuitMessage(0); break; } case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); }
Apologise's in advance if I left something out.
A good book is what you need.
I guess the easiest way would be to use a resource script, but the best way (IMHO) is with pure code:
Now if you want to intercept one of these when they're clicked on...Code:#define ID_FNEW 991 #define IF_FSAVE 992 //etc... //... HMENU hMenu = CreateMenu(), hMenuPop = CreateMenu(); //... case WM_CREATE: AppendMenu(hMenuPop, MF_STRING, ID_FNEW, "&New"); AppendMenu(hMenuPop, MF_STRING, ID_FSAVE, "&Save Code"); AppendMenu(hMenuPop, MF_STRING, ID_FSAVEAS, "&Save Code As..."); AppendMenu(hMenuPop, MF_STRING, ID_FCODE, "&View Code"); AppendMenu(hMenuPop, MF_STRING, ID_FEXIT, "&Exit"); AppendMenu(hMenu, MF_POPUP, (int)hMenuPop, "&File"); hMenuPop = CreateMenu(); AppendMenu(hMenuPop, MF_STRING, ID_IMENU, "&Menu"); AppendMenu(hMenuPop, MF_STRING, ID_IBUTTON, "&Button"); AppendMenu(hMenu, MF_POPUP, (int)hMenuPop, "&Insert"); AppendMenu(hMenu, MF_POPUP, ID_CLEARWIN, "&Clear"); SetMenu(hwnd, hMenu); return 0;
and on like that...get it?Code:case WM_COMMAND: switch(LOWORD(wParam) { case ID_FNEW: //create a new file... break; } return 0;
If your usings the resource file and header file i know you need to tell the window what the menu name is. I change the
winclass.lpszMenuName = "MyMenu";
line where it says "MyMenu" it would normally say NULL.
If this is wrong someone tell him, this worked for me but my programs r normally wierd written.