Windows選單的建立

2021-07-03 05:32:52 字數 1975 閱讀 2740

1.建立乙個win32的空工程,然後新增乙個主檔案source.cpp:

#include "windows.h"                      

#include "header.h"

#include "tchar.h"

hmenu hmenu, haddmenu; //定義選單控制代碼

lresult callback wndproc(hwnd, uint, wparam, lparam);

int winapi winmain(hinstance hinstance, hinstance hprevinst, lpstr lpszcmdline, int ncmdshow)

hwnd = createwindow(lpszclassname,

lpsztitle,

cw_usedefault,

cw_usedefault,

cw_usedefault,

cw_usedefault,

null,

null,

hinstance,

null);

showwindow(hwnd, ncmdshow);

updatewindow(hwnd);

//載入加速鍵資源

haccel = loadaccelerators(hinstance, lpszmenuname);

while (getmessage(&msg, null, 0, 0)) }

return msg.wparam;

}lresult callback wndproc(hwnd hwnd, uint message, wparam wparam, lparam lparam)

break;

case wm_destroy:

postquitmessage(0);

break;

default:

return defwindowproc(hwnd, message, wparam, lparam);

} return 0;

}

2.新增乙個標頭檔案header.h檔案;

#define idm_addmenu 15

#define idm_delmenu 16

#define idm_exit 17

#define idm_help 22

#define idm_qiuhe 23

#define idm_fangcha 24

#define idm_pinjunzhi 25

#define idm_junfanggen 26

#include "header.h"

#include "windows.h"

menu menu discardable

begin

popup "檔案(&f)"

begin

menuitem "建立統計計算選單項(&p)\t ctrl+p", idm_addmenu

menuitem "刪除統計計算選單項(&d)\t ctrl+d", idm_delmenu, grayed

menuitem separator

menuitem "退出(&x)", idm_exit

endmenuitem "幫助(&h)", idm_help

endmenu accelerators moveable pure

begin

"^p", idm_addmenu, ascii

"^d", idm_delmenu, ascii

end

執行結果如下:

可以測試,快捷鍵都是可以使用的。

來自清華大學mooc課件

windows遊戲程式設計 三 建立選單資源

windows遊戲程式設計大師技巧第二版也是很老的書了,內容有些變化。使用vs2019建立選單資源 資源名稱修改為mainmenu.rc,檢視選單id 方法一 雙擊進入 選單id為idr menu1 雙擊開啟resource.件 這裡的id file open,id file close就是選單欄按...

動態選單 動態建立選單

動態建立選單 windows應用程式的介面,不僅僅是乙個簡單的窗體,每個窗體中都包含具體實現功 能的控制項,包括能夠顯示基本資訊的label控制項,能夠在其中輸入內容的文字框控制項,能 夠設定選項的選擇按鈕控制項等。net提供了很多使用簡單 功能強大的控制項,幫助程式設 計者快速有效地開發應用軟體。...

android 選單的建立

r.menu.main android id id add item android title add android id id remove item android title remove 然後開啟 firstactivity 重寫 oncreateoptionsmenu 方法,如下所示 ...