请问使用dialogtemplate创建的对话框,怎么添加菜单啊

linxiong520 2018-03-29 05:52:16
mfc有使用dialogtemplate创建对话框的例子,但是那个例子创建的对话框是不带菜单的,加菜单要怎么写啊?求例子?
...全文
499 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
linxiong520 2018-03-30
  • 打赏
  • 举报
回复
引用 5 楼 schlafenhamster 的回复:
1 修改 DLGTEMPLATEEX 中的 menu

//Not documented !
#pragma pack(push, 1)
typedef struct {  
    WORD   dlgVer; 
    WORD   signature; 
    DWORD  helpID; 
    DWORD  exStyle; 
    DWORD  style; 
    WORD   cDlgItems; 
    short  x; 
    short  y; 
    short  cx; 
    short  cy; 
#if 0
    WORD   menu;       // if this word=0 no menu elseif this=0xFFFF follows another word stand for ID
    WORD   windowClass;// elseif not 0 | not -1 then follows the name
    WCHAR  title[1];   // title string of the dialog box
    short  pointsize;  // only if DS_SETFONT flag is set
    short  weight;     // only if DS_SETFONT flag is set
    short  bItalic;    // only if DS_SETFONT flag is set
    WCHAR  font[];     // typeface name, if DS_SETFONT is set
#endif
} DLGTEMPLATEEX,*LPDLGTEMPLATEEX; 
2 创建 对话框后 再 加 menu
对对对!msdn的例子就是这样的,word menu =0表示没有菜单,msdn的例子就是没有菜单的,我想在dialogtemplate这里加个菜单,可是不知道该怎么加,求指导!
schlafenhamster 2018-03-30
  • 打赏
  • 举报
回复
1 修改 DLGTEMPLATEEX 中的 menu

//Not documented !
#pragma pack(push, 1)
typedef struct {  
    WORD   dlgVer; 
    WORD   signature; 
    DWORD  helpID; 
    DWORD  exStyle; 
    DWORD  style; 
    WORD   cDlgItems; 
    short  x; 
    short  y; 
    short  cx; 
    short  cy; 
#if 0
    WORD   menu;       // if this word=0 no menu elseif this=0xFFFF follows another word stand for ID
    WORD   windowClass;// elseif not 0 | not -1 then follows the name
    WCHAR  title[1];   // title string of the dialog box
    short  pointsize;  // only if DS_SETFONT flag is set
    short  weight;     // only if DS_SETFONT flag is set
    short  bItalic;    // only if DS_SETFONT flag is set
    WCHAR  font[];     // typeface name, if DS_SETFONT is set
#endif
} DLGTEMPLATEEX,*LPDLGTEMPLATEEX; 
2 创建 对话框后 再 加 menu
linxiong520 2018-03-30
  • 打赏
  • 举报
回复
我希望的是不使用资源,直接在内存中创建菜单啊
zgl7903 2018-03-30
  • 打赏
  • 举报
回复

//To build this menu at run time, the following code may be used: 

   CMenu MainTPMMenu;
   CMenu MiscFruitMenu;

   MainTPMMenu.CreatePopupMenu();
   MainTPMMenu.AppendMenu(MF_STRING | MF_ENABLED, 42, "Apples");
   MainTPMMenu.AppendMenu(MF_STRING | MF_ENABLED, 43, "Pears");
   MainTPMMenu.AppendMenu(MF_STRING | MF_ENABLED, 43, "Grapes");
   MiscFruitMenu.CreatePopupMenu();
   MiscFruitMenu.AppendMenu(MF_STRING | MF_ENABLED, 40, "Mangos");
   MiscFruitMenu.AppendMenu(MF_STRING | MF_ENABLED, 41, "Tomatoes");
   MainTPMMenu.AppendMenu(MF_STRING | MF_POPUP | MF_ENABLED,
                          (UINT)MiscFruitMenu.m_hMenu,
                          "Other Misc. Fruit");
   MainTPMMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x,
                              pt.y, this, NULL);



zgl7903 2018-03-30
  • 打赏
  • 举报
回复
对话框资源属性中设置菜单ID就可以吧
linxiong520 2018-03-30
  • 打赏
  • 举报
回复
我用dialogtemplate创建对话框,用menutemplate创建菜单,然后setmenu就可以了。谢谢,结帖
schlafenhamster 2018-03-30
  • 打赏
  • 举报
回复
其中: //Make point DWORD alignment LPDWORD lpdwAlign(LPDWORD lpIn) { ULONG ul; ul=(ULONG)lpIn; ul+=3; ul>>=2; ul<<=2; return((LPDWORD)ul); }
schlafenhamster 2018-03-30
  • 打赏
  • 举报
回复
给你一个例子: 改变对话框 style

//
#define TEMPLATE_SIZE 2048  // increate it if the dlg has many items

BOOL CMainFrame::ChangeDlgStyle(int resInt)
{
	HINSTANCE hInst=AfxFindResourceHandle(MAKEINTRESOURCE(resInt),RT_DIALOG);
	HRSRC hRes=::FindResource(hInst,MAKEINTRESOURCE(resInt),RT_DIALOG);
	HGLOBAL hTemplate=::LoadResource(hInst,hRes);
	DLGTEMPLATEEX *pTemplate=(DLGTEMPLATEEX *)LockResource(hTemplate);
	HWND hDlg=0;
	BYTE *pByte=new BYTE[TEMPLATE_SIZE];
//
	if(pTemplate->signature==0xFFFF)
	{//ex
		DLGTEMPLATEEX *pNewTmp=(DLGTEMPLATEEX *)lpdwAlign((LPDWORD)pByte);
		CopyMemory(pNewTmp,pTemplate,TEMPLATE_SIZE);
		pNewTmp->style &= ~WS_CAPTION;
		pNewTmp->style &= ~DS_MODALFRAME;
		pNewTmp->style &= ~WS_POPUP;
		pNewTmp->style &= ~WS_VISIBLE;
		pNewTmp->style |= WS_BORDER;
		pNewTmp->style |= WS_CHILD;
		hDlg= CreateDialogIndirect(hInst,     // handle to application instance
				(const DLGTEMPLATE *)pNewTmp, // pointer to dialog box template
								this->m_hWnd, // handle to owner window
								0);           // pointer to dialog box procedure
	}
	else
	{//
		DLGTEMPLATE *pNewTmp=(DLGTEMPLATE *)lpdwAlign((LPDWORD)pByte);
		CopyMemory(pNewTmp,pTemplate,TEMPLATE_SIZE);
		pNewTmp->style &= ~WS_CAPTION;
		pNewTmp->style &= ~DS_MODALFRAME;
		pNewTmp->style &= ~WS_POPUP;
		pNewTmp->style &= ~WS_VISIBLE;
		pNewTmp->style |= WS_BORDER;
		pNewTmp->style |= WS_CHILD;
		hDlg= CreateDialogIndirect(hInst,     // handle to application instance
				(const DLGTEMPLATE *)pNewTmp, // pointer to dialog box template
								this->m_hWnd, // handle to owner window
								0);           // pointer to dialog box procedure
	}
	UnlockResource(hTemplate);
	FreeResource(hTemplate);
	delete [] pByte;
//
	if(hDlg)
	{
		m_Dlg.SubclassWindow(hDlg);
		CRect rc;
		GetClientRect(&rc);
		CRect tbRc;
		m_wndToolBar.GetToolBarCtrl().GetWindowRect(&tbRc);// h=26
		CRect sbRc;
		m_wndStatusBar.GetStatusBarCtrl().GetWindowRect(&sbRc);// h=25
// view border 2
		m_Dlg.MoveWindow(0,tbRc.Height()-1,rc.Width(),rc.Height()-tbRc.Height()-sbRc.Height()+1,FALSE);
		m_Dlg.ShowWindow(SW_SHOW);
		return TRUE;
	}
	return FALSE;
}
schlafenhamster 2018-03-30
  • 打赏
  • 举报
回复
如果 menu == 0xFFFF 那么 它后面的 一个 word 就是 MenuID 。
linxiong520 2018-03-30
  • 打赏
  • 举报
回复
不明白紧跟一个word是什么意思。

//菜单
*ptemp++=0xffff;
...//这里怎么写

//class
*ptemp++=0;

schlafenhamster 2018-03-30
  • 打赏
  • 举报
回复
紧跟一个 word 表示 menuID
schlafenhamster 2018-03-30
  • 打赏
  • 举报
回复
WORD menu; // if this word=0 no menu elseif this=0xFFFF follows another word stand for ID // WORD windowClass;// elseif not 0 | not -1 then follows the name
linxiong520 2018-03-29
  • 打赏
  • 举报
回复
原来可以直接用setmenu将菜单加上去,但是用menutemplate创建菜单又该怎么弄呢

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧