CreateMenuItem(hFileMenu,"&Quit",i++,
CM_FILE_QUIT,NULL,FALSE,MFT_STR
В меню не подчеркивается буквы быстрого доступа
Получается File а не File, Quit а не Quit
Код:
и т.д.
Код:
#include <windows.h>
#include <windowsx.h>
#define SimWnd_DefProc DefWindowProc
#define CM_FILE_QUIT 1001
#define CM_VIEW_PICTURE 2001
#define CM_VIEW_TEXT 2002
#define CM_VIEW_NONE 2003
#define CM_HELP_ABOUT 3001
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL Register(HINSTANCE hInstance);
HWND Create(HINSTANCE hInstance, int nCmdShow);
static char szAppName[] = "sample";
static HWND hMainWindow;
void SimWnd_OnDestroy(HWND hwnd);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
MSG Msg;
if (!Register(hInstance))
return FALSE;
if (!Create(hInstance, nCmdShow))
return FALSE;
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
BOOL Register(HINSTANCE hInstance)
{
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(hInstance, "#102");
WndClass.hCursor = LoadCursor(hInstance, "#103");
WndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = szAppName;
return (RegisterClass(&WndClass) != 0);
}
BOOL CreateMenuItem(HMENU hMenu,char *str, UINT uIns,
UINT uCom,HMENU hSubMenu,BOOL flag,UINT fType)
{ MENUITEMINFO mii;
mii.cbSize=sizeof(MENUITEMINFO);
mii.fMask=MIIM_STATE|MIIM_TYPE|MIIM_SUBMENU|MIIM_ID;
mii.fType=fType;
mii.fState=MFS_ENABLED;
mii.dwTypeData=str;
mii.cch=sizeof(str);
mii.wID=uCom;
mii.hSubMenu=hSubMenu;
return InsertMenuItem(hMenu,uIns,flag,&mii);
}
HWND Create(HINSTANCE hInstance, int nCmdShow)
{
HWND hwnd = CreateWindow(szAppName, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL)
return FALSE;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message,
WPARAM wParam, LPARAM lParam)
{ static HMENU hMainMenu,hFileMenu,hViewMenu,hHelpMenu;
switch (Message)
{case WM_CREATE:
{ hMainMenu=CreateMenu();
hFileMenu=CreatePopupMenu();
int i=0;
CreateMenuItem(hFileMenu,"&Quit",i++,
CM_FILE_QUIT,NULL,FALSE,MFT_STRING);
hViewMenu=CreatePopupMenu();
i=0;
CreateMenuItem(hViewMenu,"&Text",i++,
CM_VIEW_TEXT,NULL,FALSE,MFT_STRING);
CreateMenuItem(hViewMenu,"&Picture",i++,
CM_VIEW_PICTURE,NULL,FALSE,MFT_STRING);
CreateMenuItem(hViewMenu,"&None",i++,
CM_VIEW_NONE,NULL,FALSE,MFT_STRING);
hHelpMenu=CreatePopupMenu();
i=0;
CreateMenuItem(hHelpMenu,"&About",i++,
CM_HELP_ABOUT,NULL,FALSE,MFT_STRING);
i=0;
CreateMenuItem(hMainMenu,"&File",i++,
0,hFileMenu,FALSE,MFT_STRING);
CreateMenuItem(hMainMenu,"&View",i++,
0,hViewMenu,FALSE,MFT_STRING);
CreateMenuItem(hMainMenu,"&Help",i++,
0,hHelpMenu,FALSE,MFT_STRING);
SetMenu(hwnd,hMainMenu);
DrawMenuBar(hwnd);
return 0;
}
case WM_COMMAND:
{ switch(LOWORD(wParam))
{ case CM_FILE_QUIT:
{ MessageBox(hwnd,"Команда CM_FILE_QUIT",
"Меню",MB_OK); return 0;
}
case CM_VIEW_TEXT:
{ MessageBox(hwnd,"Команда CM_VIEW_TEXT",
"Меню",MB_OK); return 0;
}
case CM_VIEW_PICTURE:
{ MessageBox(hwnd,"Команда CM_VIEW_PICTURE",
"Меню",MB_OK); return 0;
}
case CM_VIEW_NONE:
{ MessageBox(hwnd,"Команда CM_VIEW_NONE",
"Меню",MB_OK); return 0;
}
case CM_HELP_about :
{ MessageBox(hwnd,"Команда CM_HELP_ABOUT",
"Меню",MB_OK); return 0;
}
}
return 0;
}
case WM_DESTROY: {PostQuitMessage(0);return(0);}
}
return SimWnd_DefProc(hwnd,Message,wParam,lParam);
}
#include <windowsx.h>
#define SimWnd_DefProc DefWindowProc
#define CM_FILE_QUIT 1001
#define CM_VIEW_PICTURE 2001
#define CM_VIEW_TEXT 2002
#define CM_VIEW_NONE 2003
#define CM_HELP_ABOUT 3001
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL Register(HINSTANCE hInstance);
HWND Create(HINSTANCE hInstance, int nCmdShow);
static char szAppName[] = "sample";
static HWND hMainWindow;
void SimWnd_OnDestroy(HWND hwnd);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
MSG Msg;
if (!Register(hInstance))
return FALSE;
if (!Create(hInstance, nCmdShow))
return FALSE;
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
BOOL Register(HINSTANCE hInstance)
{
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(hInstance, "#102");
WndClass.hCursor = LoadCursor(hInstance, "#103");
WndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = szAppName;
return (RegisterClass(&WndClass) != 0);
}
BOOL CreateMenuItem(HMENU hMenu,char *str, UINT uIns,
UINT uCom,HMENU hSubMenu,BOOL flag,UINT fType)
{ MENUITEMINFO mii;
mii.cbSize=sizeof(MENUITEMINFO);
mii.fMask=MIIM_STATE|MIIM_TYPE|MIIM_SUBMENU|MIIM_ID;
mii.fType=fType;
mii.fState=MFS_ENABLED;
mii.dwTypeData=str;
mii.cch=sizeof(str);
mii.wID=uCom;
mii.hSubMenu=hSubMenu;
return InsertMenuItem(hMenu,uIns,flag,&mii);
}
HWND Create(HINSTANCE hInstance, int nCmdShow)
{
HWND hwnd = CreateWindow(szAppName, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL)
return FALSE;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message,
WPARAM wParam, LPARAM lParam)
{ static HMENU hMainMenu,hFileMenu,hViewMenu,hHelpMenu;
switch (Message)
{case WM_CREATE:
{ hMainMenu=CreateMenu();
hFileMenu=CreatePopupMenu();
int i=0;
CreateMenuItem(hFileMenu,"&Quit",i++,
CM_FILE_QUIT,NULL,FALSE,MFT_STRING);
hViewMenu=CreatePopupMenu();
i=0;
CreateMenuItem(hViewMenu,"&Text",i++,
CM_VIEW_TEXT,NULL,FALSE,MFT_STRING);
CreateMenuItem(hViewMenu,"&Picture",i++,
CM_VIEW_PICTURE,NULL,FALSE,MFT_STRING);
CreateMenuItem(hViewMenu,"&None",i++,
CM_VIEW_NONE,NULL,FALSE,MFT_STRING);
hHelpMenu=CreatePopupMenu();
i=0;
CreateMenuItem(hHelpMenu,"&About",i++,
CM_HELP_ABOUT,NULL,FALSE,MFT_STRING);
i=0;
CreateMenuItem(hMainMenu,"&File",i++,
0,hFileMenu,FALSE,MFT_STRING);
CreateMenuItem(hMainMenu,"&View",i++,
0,hViewMenu,FALSE,MFT_STRING);
CreateMenuItem(hMainMenu,"&Help",i++,
0,hHelpMenu,FALSE,MFT_STRING);
SetMenu(hwnd,hMainMenu);
DrawMenuBar(hwnd);
return 0;
}
case WM_COMMAND:
{ switch(LOWORD(wParam))
{ case CM_FILE_QUIT:
{ MessageBox(hwnd,"Команда CM_FILE_QUIT",
"Меню",MB_OK); return 0;
}
case CM_VIEW_TEXT:
{ MessageBox(hwnd,"Команда CM_VIEW_TEXT",
"Меню",MB_OK); return 0;
}
case CM_VIEW_PICTURE:
{ MessageBox(hwnd,"Команда CM_VIEW_PICTURE",
"Меню",MB_OK); return 0;
}
case CM_VIEW_NONE:
{ MessageBox(hwnd,"Команда CM_VIEW_NONE",
"Меню",MB_OK); return 0;
}
case CM_HELP_about :
{ MessageBox(hwnd,"Команда CM_HELP_ABOUT",
"Меню",MB_OK); return 0;
}
}
return 0;
}
case WM_DESTROY: {PostQuitMessage(0);return(0);}
}
return SimWnd_DefProc(hwnd,Message,wParam,lParam);
}