15,979
社区成员
发帖
与我相关
我的任务
分享
//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
//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);
//
#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;
}