定数 | 解説 |
---|---|
CHECKED | チェックを持つメニューアイテム トップレベルのメニューには無効 |
GRAYED | グレー表示で、入力を受けないメニュー |
HELP | ヘルプアイテム |
INACTIVE | 選択できないメニュー |
MENUBARBREAK | メニューバーのポップアップを次の行に配置します |
MENUBREAK | メニューアイテムを次の新しいラインに配置します |
/*リソーススクリプト*/ KITTY MENU { POPUP "cat girls" { MENUITEM "Kitty on your lap" , 40001 MENUITEM "Tokyo mew mew" , 40002 MENUITEM SEPARATOR POPUP "Magical nyan nyan TARUTO" { MENUITEM "たると" , 40003 MENUITEM "シャルロッテ" , 40004 MENUITEM "ちとせ" , 40005 } } POPUP "Card Captor Sakura" { MENUITEM "さくら" , 40006 MENUITEM "知世" , 40007 } }今回、メッセージは扱わないので メニューID は適当でかまいません
#include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) { HWND hwnd; MSG msg; WNDCLASS winc; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = TEXT("KITTY"); winc.lpszClassName = TEXT("KITTY"); if (!RegisterClass(&winc)) return -1; hwnd = CreateWindow( TEXT("KITTY") , TEXT("Kitty on your lap") , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hwnd == NULL) return -1; while(GetMessage(&msg , NULL , 0 , 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
/*リソーススクリプト*/ KITTY MENU { POPUP "Kitty on your lap" { MENUITEM "レナ" , 40001 } POPUP "Di Gi Charat" , MENUBARBREAK { MENUITEM "でじこ" , 40002 , CHECKED MENUITEM "ぷちこ" , 40003 , GRAYED MENUITEM "ラビアンローズ" , 40004 , MENUBREAK MENUITEM "ピョコラ・アナローグ三世" , 40005 , INACTIVE } POPUP "Card Captor Sakura" { MENUITEM "さくら" , 40006 } }
/*リソーススクリプト*/ KITTY MENU { POPUP "FILE(&F)" { MENUITEM "新規作成(&N)" , 40001 MENUITEM "開く(&O)" , 40002 MENUITEM "終了(&X)" , 40003 } POPUP "EDIT(&E)" { MENUITEM "切り取り(&T)" , 40004 MENUITEM "コピー(&C)" , 40005 MENUITEM "貼り付け(&P)" , 40006 } }
/*リソーススクリプト*/ KITTY MENU { POPUP "Kitty" { MENUITEM "Kitty on your lap" , 40001 } }
#include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) { HWND hwnd; MSG msg; WNDCLASS winc; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = NULL; winc.lpszClassName = TEXT("KITTY"); if (!RegisterClass(&winc)) return -1; hwnd = CreateWindow( TEXT("KITTY") , TEXT("Kitty on your lap") , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , LoadMenu(hInstance , TEXT("KITTY")) , hInstance , NULL ); if (hwnd == NULL) return -1; while(GetMessage(&msg , NULL , 0 , 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }LoadMenu() 関数を用いて CreateWindow() 関数にメニューのハンドルを渡しています
#include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CREATE: SetMenu(hwnd , LoadMenu( ((LPCREATESTRUCT)(lp))->hInstance , TEXT("KITTY") ) ); return 0; } return DefWindowProc(hwnd , msg , wp , lp); } int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) { HWND hwnd; MSG msg; WNDCLASS winc; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL , IDI_APPLICATION); winc.hCursor = LoadCursor(NULL , IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = NULL; winc.lpszClassName = TEXT("KITTY"); if (!RegisterClass(&winc)) return -1; hwnd = CreateWindow( TEXT("KITTY") , TEXT("Kitty on your lap") , WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , NULL , NULL , hInstance , NULL ); if (hwnd == NULL) return -1; while(GetMessage(&msg , NULL , 0 , 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }この方法でも、ウィンドウにメニューが与えられています