如何在WM平臺下, 給創(chuàng)建的Dialog添加菜單, 以下這段代碼添加在CFileAssociationDlg::OnInitDialog()方法內(nèi), CFileAssociationDlg是你要?jiǎng)?chuàng)建的對話框.
// 創(chuàng)建SHMENUBARINFO結(jié)構(gòu)體
SHMENUBARINFO mbi;
// 初始化, 每個(gè)字節(jié)都置為0
ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
// 設(shè)置結(jié)構(gòu)體SHMENUBARINFO的長度
mbi.cbSize = sizeof(SHMENUBARINFO);
// 設(shè)置控制菜單的窗口,即CFileAssociationDlg對話框
mbi.hwndParent = this->m_hWnd;
// IDR_HELLO_MENU為資源文件中的Menu ID, 需要?jiǎng)?chuàng)建該菜單
mbi.nToolBarId = IDR_HELLO_MENU;
// 應(yīng)用程序的實(shí)例
mbi.hInstRes = AfxGetInstanceHandle();
// Bitmap identifier used to load the bitmap resource for buttons with images from the instance specified by hInstRes.
mbi.nBmpId = 0;
// Number of images in the bitmap referred to by nBmpId.
mbi.cBmpImages = 0;
// 設(shè)置菜單屬性, 這里需要注意的是SHCMBF_HMENU , SHCMBF_HIDESIPBUTTON屬性, 前者必須要有, 否則菜單會創(chuàng)建失敗, 后者只應(yīng)用于Mobile
// 平臺, 用來隱藏輸入法菜單
mbi.dwFlags = SHCMBF_COLORBK | SHCMBF_HMENU | SHCMBF_HIDESIPBUTTON;
// 創(chuàng)建菜單
if(SHCreateMenuBar(&mbi))
{
}
else
{
::DestroyWindow(m_hWnd);
PostQuitMessage(1);
return(-1);
}