菜单的主题框架
#include<windows.h>
#include"Menu.h"
long WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
HWND hWndMain;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
MSG Message;
HACCEL hAccel;
char lpszMenuName[]="Menu";
if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
hAccel=LoadAccelerators(hInstance,lpszMenuName);
while(GetMessage(&Message,NULL,0,0))
{
if(!TranslateAccelerator(hWndMain,hAccel,&Message))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
}
return Message.wParam;
}
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
char lpszClassName[]="windows";
wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
// wndclass.hbrBackground=NULL;
// wndclass.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE + 1);
wndclass.lpszMenuName="Menu";
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
return TRUE;
}
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
char lpszClassName[]="windows";
char lpszTitle[]="eattonton";
hWndMain=CreateWindow
(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hWndMain,nCmdShow);
UpdateWindow(hWndMain);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
菜单的资源文件
#include "windows.h"
#include "Menu.h"
/
//
// Menu
//
Menu MENU MOVEABLE
BEGIN
POPUP "Menu"
BEGIN
MENUITEM "new", IDM_NEW
MENUITEM "open", IDM_OPEN
MENUITEM "close", IDM_CLOSE
MENUITEM "save", IDM_SAVE
MENUITEM "save as", IDM_SAVEAS
MENUITEM "exit", IDM_EXIT
END
END
资源文件的ID说明
#define IDM_NEW 1
#define IDM_OPEN 2
#define IDM_CLOSE 3
#define IDM_SAVE 4
#define IDM_SAVEAS 5
#define IDM_EXIT 6
/*
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Menu.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
*/