int EditBoardText::DoModal() { CDialogTemplate dlt; int nResult; // load dialog template if (!dlt.Load(MAKEINTRESOURCE(EditBoardText::IDD))) return -1; // set your own font, for example "Arial", 10 pts. dlt.SetFont(m_strFaceName, 10); // get pointer to the modified dialog template LPSTR pdata = (LPSTR)GlobalLock(dlt.m_hTemplate); // let MFC know that you are using your own template m_lpszTemplateName = NULL; m_hDialogTemplate = NULL; InitModalIndirect(pdata); // display dialog box nResult = CDialog::DoModal(); // unlock memory object GlobalUnlock(dlt.m_hTemplate); return nResult; }
CXTPCalendarEventRecurrenceDlg::CXTPCalendarEventRecurrenceDlg(CXTPCalendarEvent* pMasterEvent, CWnd* pParent, UINT nIDTemplate) : m_nOccurNum(10), m_dtEndDate(COleDateTime::GetCurrentTime()), m_nDayInterval(1), m_nWeeklyInterval(1), m_bMonday(TRUE), m_bTuesday(FALSE), m_bWednesday(FALSE), m_bThursday(FALSE), m_bFriday(FALSE), m_bSaturday(FALSE), m_bSunday(FALSE), m_MonthDate(1), m_nMonthInterval(1), m_nMonthInterval2(1), m_nDayOfMonth(m_dtEndDate.GetDay()), m_ptrMasterEvent(pMasterEvent, TRUE), m_bDisableRemove(FALSE) { InitModalIndirect(XTPResourceManager()->LoadDialogTemplate(nIDTemplate), pParent); ASSERT(m_ptrMasterEvent); m_ptrPattern = m_ptrMasterEvent->GetRecurrencePattern(); m_dtStart = m_ptrPattern->GetStartTime(); m_dtEnd = m_dtStart + m_ptrPattern->GetDuration(); m_dtStartDate = m_ptrPattern->GetPatternStartDate(); }
INT_PTR CXTPTaskDialogFrame::DoModal() { ReleaseCapture(); if (m_lpDlgTemplate == NULL) { const int nDlgTemplateSize = sizeof(DLGTEMPLATE) + sizeof(DWORD) * 8; m_lpDlgTemplate = (DLGTEMPLATE*)malloc(nDlgTemplateSize); ZeroMemory(m_lpDlgTemplate, nDlgTemplateSize); } if (!m_lpDlgTemplate) return -1; m_lpDlgTemplate->style = GetFrameStyle(); m_lpDlgTemplate->dwExtendedStyle = m_pConfig->dwFlags & TDF_RTL_LAYOUT ? WS_EX_LAYOUTRTL : 0; if (m_lpDialogTemplate == 0) { InitModalIndirect(m_lpDlgTemplate); } return CDialog::DoModal(); }
BOOL CBaseDlg::CreateModeDlg(CString strCaption, CRect rect, BOOL bMode /*= TRUE*/, CWnd* pParent /*= NULL*/) { m_bMode = bMode; BOOL bResult = FALSE; DLGTEMPLATE* pTemp = NULL; // 先获得dpi HDC hdc = ::GetDC(0); int nDpiX = GetDeviceCaps(hdc, LOGPIXELSX); int nDpiY = GetDeviceCaps(hdc, LOGPIXELSY); ::ReleaseDC(0, hdc); ASSERT(nDpiX = nDpiY); double fScaleData = 64.0 / nDpiX; #ifdef WINCE fScaleData = fScaleData * 0.859; #endif rect.left = (int)(rect.left*fScaleData); rect.top = (int)(rect.top*fScaleData); rect.right = (int)(rect.right*fScaleData); rect.bottom = (int)(rect.bottom*fScaleData); pTemp = m_dlgTemp.CreateTemplate(WS_POPUPWINDOW | DS_MODALFRAME | WS_CAPTION, rect, strCaption); if (bMode) { bResult = InitModalIndirect(pTemp, pParent); } else { bResult = CreateIndirect(pTemp, pParent); } return bResult; }
CAuthDlg::CAuthDlg(CWnd* pParent /*=NULL*/) : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CAuthDlg::IDD), pParent); //{{AFX_DATA_INIT(CAuthDlg) //}}AFX_DATA_INIT }
CXTPNewToolbarDlg::CXTPNewToolbarDlg(CWnd* pParent, CXTPCommandBars* pCommandBars, CXTPCommandBar* pCommandBar) : m_pCommandBars(pCommandBars), m_pCommandBar(pCommandBar) { InitModalIndirect(XTPResourceManager()->LoadDialogTemplate(XTP_IDD_NEWTOOLBAR), pParent); m_strToolbar = _T(""); m_nNewID = 0; }
CMountPointsDlg::CMountPointsDlg(CWnd* pParent /*=NULL*/) : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CMountPointsDlg::IDD), pParent); //{{AFX_DATA_INIT(CMountPointsDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT }
UINT CMessageBox::GoModal(CWnd * pWnd, const CString& title, const CString& msg, int nDefaultButton) { // pre Vista struct, needed for Windows XP struct OLD_NONCLIENTMETRICS { UINT cbSize; int iBorderWidth; int iScrollWidth; int iScrollHeight; int iCaptionWidth; int iCaptionHeight; LOGFONT lfCaptionFont; int iSmCaptionWidth; int iSmCaptionHeight; LOGFONT lfSmCaptionFont; int iMenuWidth; int iMenuHeight; LOGFONT lfMenuFont; LOGFONT lfStatusFont; LOGFONT lfMessageFont; }; const UINT cbProperSize = sizeof(OLD_NONCLIENTMETRICS); NONCLIENTMETRICS ncm; memset(&ncm,0,sizeof(NONCLIENTMETRICS)); ncm.cbSize = cbProperSize; SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0); memcpy(&m_LogFont, &(ncm.lfMessageFont), sizeof(LOGFONT)); //the problem with the LOGFONT lfHeight is that it is not in pixels, //but the dialog template needs the height in pixels. //We need to convert those values first: CDC * pDC; if (pWnd) pDC = pWnd->GetDC(); else pDC = GetDesktopWindow()->GetDC(); int pix = -MulDiv(m_LogFont.lfHeight, 72, GetDeviceCaps(pDC->m_hDC, LOGPIXELSY)); CDlgTemplate dialogTemplate = CDlgTemplate(title, WS_CAPTION | DS_CENTER, 0, 0, 0, 0, m_LogFont.lfFaceName, pix); dialogTemplate.AddButton(_T("Button1"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | ((nDefaultButton == 1) ? BS_DEFPUSHBUTTON : 0), 0, 2 + 3, 62, 56, 13, IDC_MESSAGEBOX_BUTTON1); dialogTemplate.AddButton(_T("Button2"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | ((nDefaultButton == 2) ? BS_DEFPUSHBUTTON : 0), 0, 2 + 3, 62, 56, 13, IDC_MESSAGEBOX_BUTTON2); dialogTemplate.AddButton(_T("Button3"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | ((nDefaultButton == 3) ? BS_DEFPUSHBUTTON : 0), 0, 2 + 3, 62, 56, 13, IDC_MESSAGEBOX_BUTTON3); dialogTemplate.AddButton(_T("Checkbox"), WS_CHILD | WS_TABSTOP | BS_AUTOCHECKBOX, 0, 0, 0, 0, 0, IDC_MESSAGEBOX_CHECKBOX); m_nDefButton = nDefaultButton; m_sMessage = msg; InitModalIndirect(dialogTemplate, pWnd); return (UINT)DoModal(); }
CSubmountsDlg::CSubmountsDlg() : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CSubmountsDlg::IDD)); //{{AFX_DATA_INIT(CSubmountsDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_bAddOnlyMode = FALSE; }
CMakeSymbolicLinkDlg::CMakeSymbolicLinkDlg(CWnd* pParent /*=NULL*/) : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CMakeSymbolicLinkDlg::IDD), pParent); //{{AFX_DATA_INIT(CMakeSymbolicLinkDlg) m_strName = _T(""); m_strDir = _T(""); //}}AFX_DATA_INIT }
CClearAclDlg::CClearAclDlg(CWnd* pParent /*=NULL*/) : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CClearAclDlg::IDD), pParent); //{{AFX_DATA_INIT(CClearAclDlg) m_bNegative = FALSE; m_bNormal = FALSE; //}}AFX_DATA_INIT }
CPartitionInfoDlg::CPartitionInfoDlg(CWnd* pParent /*=NULL*/) : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CPartitionInfoDlg::IDD), pParent); //{{AFX_DATA_INIT(CPartitionInfoDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_nSize = 0; m_nFree = 0; }
CMakeMountPointDlg::CMakeMountPointDlg(CWnd* pParent /*=NULL*/) : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CMakeMountPointDlg::IDD), pParent); //{{AFX_DATA_INIT(CMakeMountPointDlg) m_nType = -1; //}}AFX_DATA_INIT m_bMade = FALSE; }
// CXTPCalendarOccurSeriesChooseDlg dialog CXTPCalendarOccurSeriesChooseDlg::CXTPCalendarOccurSeriesChooseDlg(CWnd* pParent, UINT nIDResourceLabels, LPCTSTR lpszResourceIcon, UINT nIDTemplate) { InitModalIndirect(XTPResourceManager()->LoadDialogTemplate(nIDTemplate), pParent); m_bOccur = TRUE; m_nIDResourceLabels = nIDResourceLabels; m_hIcon = XTPLoadIconEx(lpszResourceIcon); SetEvent(NULL); }
CVolumeInfo::CVolumeInfo(CWnd* pParent /*=NULL*/) : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CVolumeInfo::IDD), pParent); //{{AFX_DATA_INIT(CVolumeInfo) m_nNewQuota = 0; //}}AFX_DATA_INIT m_pVolInfo = 0; m_nCurIndex = -1; }
CXTPCalendarTimeScalePropertiesDlg::CXTPCalendarTimeScalePropertiesDlg(CWnd* pParent, UINT nIDTemplate) { InitModalIndirect(XTPResourceManager()->LoadDialogTemplate(nIDTemplate), pParent); m_bShowScale2 = FALSE; TIME_ZONE_INFORMATION m_tziScale2; ::ZeroMemory(&m_tziScale2, sizeof(m_tziScale2)); VERIFY(::GetTimeZoneInformation(&m_tziScale2) != TIME_ZONE_ID_INVALID); m_bAutoAdjustDayLight2 = FALSE; }
CAddSubmtDlg::CAddSubmtDlg(CWnd* pParent /*=NULL*/) : CDialog() { InitModalIndirect (TaLocale_GetDialogResource (CAddSubmtDlg::IDD), pParent); //{{AFX_DATA_INIT(CAddSubmtDlg) m_strShareName = _T(""); m_strPathName = _T(""); //}}AFX_DATA_INIT m_bAdd = TRUE; m_bSave = FALSE; }
// Replaces CDialog::DoModal INT_PTR CGeneralMsgBox::DoModal() { InitModalIndirect((LPCDLGTEMPLATE)_dlgData, m_pParentWnd); bool bAccEn = app.IsAcceleratorEnabled(); if (bAccEn) app.DisableAccelerator(); CPWDialog::GetDialogTracker()->AddOpenDialog(this); INT_PTR rc = CDialog::DoModal(); CPWDialog::GetDialogTracker()->RemoveOpenDialog(this); if (bAccEn) app.EnableAccelerator(); return rc; }
void CMessageBox::Init() { m_pFont=CFont::FromHandle(HFONT(GetStockObject(DEFAULT_GUI_FONT))); m_nFocusButton=-1; m_nEscapeButton=-1; m_nJustify=SS_LEFT; m_nDefaultButton=0; m_hIcon=NULL; m_pStaticText=NULL; m_pStaticIcon=NULL; m_bTopMost=false; m_bModeless=false; m_bDialogCreated=false; m_pParentNotify=NULL; m_crText=GetSysColor(COLOR_BTNTEXT); InitModalIndirect (&DlgData.tmpl,NULL); }
CNewFilterGroupDlg::CNewFilterGroupDlg() { m_nCurSelectedIndex = -100; DWORD style = DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | DS_SETFONT; m_dlgTemplate = new CDlgTemplate(_T(""), style, 0, 0, 600, 35, _T("MS Sans Serif"), 8); m_pLangRuleDlg = new CLangRuleDlg(); m_pFilterNameLabel = new CStatic(); m_pLangRuleTypeLabel = new CStatic(); m_pFilterName = new CEdit(); m_pLangRuleType = new CComboBox(); m_pOkButton = new CButton(); m_pCancelButton = new CButton(); InitModalIndirect(*m_dlgTemplate); }
INT_PTR CWaterAttachment::DoModal() { // TODO: Add your specialized code here and/or call the base class CDialogTemplate dlt; int nResult; // load dialog template if (!dlt.Load(MAKEINTRESOURCE(CWaterAttachment::IDD))) return -1; // set the font, for example "Arial", 10 pts. dlt.SetFont("Arial", 8); // get pointer to the modified dialog template LPSTR pdata = (LPSTR)GlobalLock(dlt.m_hTemplate); // let MFC know that you are using your own template m_lpszTemplateName = NULL; InitModalIndirect(pdata); // display dialog box nResult = CDialog::DoModal(); // unlock memory object GlobalUnlock(dlt.m_hTemplate); return nResult; }
int CButtonDialog::DoModal() { ASSERT(m_strArray.GetSize() != 0); if (m_strArray.GetSize() == 0) return (m_nCancel != -1) ? m_nCancel : 0; // compute size of header // Fixed portions of DLG template header = sizeof(DLGTEMPLATE); // One null byte for menu name and one for class name = 2 // Caption text plus NULL = m_strCaption.GetLength()+1 int nSize = sizeof(DLGTEMPLATE); nSize += (2 + m_strCaption.GetLength()+1+lstrlen(theApp.m_lf.lfFaceName)+1)*2 +sizeof(WORD); m_hDlgTmp = GlobalAlloc(GPTR, nSize); if (m_hDlgTmp == NULL) return IDCANCEL; LPDLGTEMPLATE lpDlgTmp = (LPDLGTEMPLATE)GlobalLock(m_hDlgTmp); FillInHeader(lpDlgTmp); GlobalUnlock(m_hDlgTmp); InitModalIndirect(m_hDlgTmp); return (int)CCSDialog::DoModal(); }
////////////////// // Create string dialog. If no icon specified, use IDI_QUESTION. Note that // the order in which the controls are added is the TAB order. // BOOL CInputDialog::Init(LPCTSTR caption, LPCTSTR prompt, CWnd* pParent, WORD nIDIcon) { const DWORD CXDIALOG = 200; // dialog width const DWORD DLGMARGIN = 7; // margins all around const DWORD CYSTATIC = 8; // height of static text const DWORD CYEDIT = 12; // height of edit control const DWORD CYSPACE = 5; // vertical space between controls const DWORD CXBUTTON = 40; // button width... const DWORD CYBUTTON = 15; // ..and height CDlgTemplateBuilder& dtb = m_dtb; CRect rc( CPoint(0,0), CSize(CXDIALOG, CYSTATIC + CYEDIT + CYBUTTON + 2*DLGMARGIN + 2*CYSPACE)); // create dialog header DLGTEMPLATE* pTempl = dtb.Begin(WS_POPUPWINDOW|DS_MODALFRAME|WS_DLGFRAME,rc,caption); // shrink main rect by margins rc.DeflateRect(CSize(DLGMARGIN,DLGMARGIN)); // create icon if needed if (nIDIcon) { if (nIDIcon >= (WORD)IDI_APPLICATION) { // if using a system icon, I load it here and set it in OnInitDialog // because can't specify system icon in template, only icons from // application resource file. m_hIcon = ::LoadIcon(NULL, MAKEINTRESOURCE(nIDIcon)); nIDIcon = 0; } else { m_hIcon = NULL; } // The size is calculated in pixels, but it seems to work OK--??? CSize sz(GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON)); CRect rcIcon(rc.TopLeft(), sz); dtb.AddItem(CDlgTemplateBuilder::STATIC, // add icon WS_VISIBLE|WS_CHILD|SS_LEFT|SS_ICON, rc, nIDIcon, IDICON); rc.left += sz.cx; // shrink main rect by width of icon } // add prompt rc.bottom = rc.top + CYSTATIC; // height = height of static dtb.AddItem(CDlgTemplateBuilder::STATIC, // add it WS_VISIBLE|WS_CHILD|SS_LEFT, rc, prompt); // add edit control rc += CPoint(0, rc.Height() + CYSPACE); // move below static rc.bottom = rc.top + CYEDIT; // height = height of edit control dtb.AddItem(CDlgTemplateBuilder::EDIT, // add it ES_AUTOHSCROLL must be add WS_VISIBLE|WS_CHILD|WS_BORDER|WS_TABSTOP|ES_AUTOHSCROLL, rc, m_str, IDEDIT); // add OK button rc += CPoint(0, rc.Height() + CYSPACE); // move below edit control rc.bottom = rc.top + CYBUTTON; // height = button height rc.left = rc.right - CXBUTTON; // width = button width rc -= CPoint(CXBUTTON + DLGMARGIN,0); // move left one button width dtb.AddItem(CDlgTemplateBuilder::BUTTON, // add it WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON, rc, _T("&OK"), IDOK); // add Cancel button rc += CPoint(CXBUTTON + DLGMARGIN,0); // move right again dtb.AddItem(CDlgTemplateBuilder::BUTTON, // add Cancel button WS_VISIBLE|WS_CHILD|WS_TABSTOP, rc, _T("&Cancel"), IDCANCEL); return InitModalIndirect(pTempl, pParent); }
INT_PTR CCustomDialog::DoModal(void) { // get the custom font information CUpdateItApp* pApp = DYNAMIC_DOWNCAST(CUpdateItApp, AfxGetApp()); CString strFaceName = pApp->GetConfigString(SZ_ARG_FONT_FACENAME, SZ_REGK_FONT, SZ_REGV_FONT_FACENAME); WORD wFontSize = LOWORD(pApp->GetConfigUInt(SZ_ARG_FONT_POINTSIZE, SZ_REGK_FONT, SZ_REGV_FONT_SIZE, 0)); if (!strFaceName.IsEmpty() && wFontSize > 0) { // try to load dialog template CDialogTemplate dlgtRes; if (!dlgtRes.Load(m_lpszTemplateName)) { return (-1); } // set specified custom font dlgtRes.SetFont(strFaceName, wFontSize); // get pointer to the modified dialog template DLGTEMPLATE* pTemplate = reinterpret_cast<DLGTEMPLATE*>(::GlobalLock(dlgtRes.m_hTemplate)); // try to load coresponding DLGINIT resource (if any) HGLOBAL hResData = NULL; void* pvDlgInit = NULL; HINSTANCE hResInst = AfxGetResourceHandle(); HRSRC hResInfo = ::FindResource(hResInst, m_lpszTemplateName, RT_DLGINIT); if (hResInfo != NULL) { hResData = ::LoadResource(hResInst, hResInfo); ASSERT(hResData != NULL); pvDlgInit = ::LockResource(hResData); ASSERT(pvDlgInit != NULL); } // let MFC know that we are using our own template LPCTSTR pszTemplateName = m_lpszTemplateName; m_lpszTemplateName = NULL; InitModalIndirect(pTemplate, NULL, pvDlgInit); // display dialog box INT_PTR nResult = __super::DoModal(); if (hResData != NULL) { ::UnlockResource(hResData); ::FreeResource(hResData); } // unlock memory object ::GlobalUnlock(dlgtRes.m_hTemplate); m_lpszTemplateName = pszTemplateName; m_lpDialogTemplate = NULL; return (nResult); } else { // no custom font is specified return (__super::DoModal()); } }
void CBCGPMessageBox::Initialize () { CWnd* pParent = CWnd::FromHandle (m_Params.hwndOwner); if (pParent == NULL) { pParent = CWnd::GetActiveWindow(); if (pParent != NULL) { CWnd* pPopup = pParent->GetLastActivePopup(); if (pPopup != NULL) { pParent = pPopup; } } } // Loading an icon LPTSTR iconID = NULL; switch (m_Params.dwStyle & MB_ICONMASK) { case MB_ICONASTERISK: iconID = IDI_ASTERISK; break; case MB_ICONEXCLAMATION: iconID = IDI_EXCLAMATION; break; case MB_ICONHAND: iconID = IDI_HAND; break; case MB_ICONQUESTION: iconID = IDI_QUESTION; break; } m_hMessageIcon = NULL; if (iconID) { m_hMessageIcon = ::LoadIcon (NULL, MAKEINTRESOURCE(iconID)); } if (m_Params.dwStyle & MB_USERICON) { m_hMessageIcon = ::LoadIcon (m_Params.hInstance, m_Params.lpszIcon); } m_rectIcon.SetRectEmpty (); if (m_hMessageIcon != NULL) { m_rectIcon.right = ::GetSystemMetrics(SM_CXICON); m_rectIcon.bottom = ::GetSystemMetrics(SM_CYICON); } m_strMessageCaption = GetString (m_Params.lpszCaption, _T("Error")); m_strMessageText = GetString (m_Params.lpszText); m_strCheckBox = GetString (m_Params.lpszCheckBoxText); switch (m_Params.dwStyle & MB_DEFMASK) { case MB_DEFBUTTON1: m_nDefaultButtonIndex = 0; break; case MB_DEFBUTTON2: m_nDefaultButtonIndex = 1; break; case MB_DEFBUTTON3: m_nDefaultButtonIndex = 2; break; case MB_DEFBUTTON4: m_nDefaultButtonIndex = 3; break; default: m_nDefaultButtonIndex = -1; break; } // Creating dialog template m_pTemplate = (DLGTEMPLATE*)::GlobalAlloc (GPTR, 1024); m_pTemplate->x = 0; m_pTemplate->y = 0; m_pTemplate->cx = 62; m_pTemplate->cy = 40; m_pTemplate->cdit = 0; m_pTemplate->style = WS_CAPTION | WS_VISIBLE | WS_SYSMENU | WS_POPUP | DS_MODALFRAME | DS_CENTER; m_pTemplate->dwExtendedStyle = 0; m_bRightAlignment = (m_Params.dwStyle & MB_RIGHT) != 0; if (m_Params.dwStyle & MB_RTLREADING) { //// Uncomment to enable RTL //m_pTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL; //m_bRightAlignment = !m_bRightAlignment; } if (m_Params.dwStyle & MB_SYSTEMMODAL) { m_pTemplate->style |= DS_SYSMODAL; } WORD* pEnd = (WORD*)(m_pTemplate + 1); *pEnd = 0; InitModalIndirect (m_pTemplate, pParent); // Calculating margins, sizes and spacings m_rectClientMargins.SetRect (7, 7, 5, 7); m_szButton.cx = 52; m_szButton.cy = 14; m_cxIconSpacing = 12; // spacing between an icon and message text m_cyCheckBoxHeight = 10; m_cxButtonSpacing = 4; // gap between buttons m_cyVerticalSpacing = 11; // vertical spacing between text, optional check box and buttons }
int CDynDialogEx::DoModal() { //Do we need OK and Cancel buttons?? if (m_bAddSystemButtons) { AddSystemButtons(); } // // Get font info from mainwindow of the application // CFont* pParentFont = m_pFont; if (pParentFont == NULL && m_pParentWnd != NULL) { pParentFont = m_pParentWnd->GetFont(); } if (pParentFont == NULL && AfxGetApp()->m_pActiveWnd != NULL) { pParentFont = AfxGetApp()->m_pActiveWnd->GetFont(); } LOGFONT LogFont; memset(&LogFont, 0x00, sizeof(LogFont)); if (pParentFont != NULL) { pParentFont->GetLogFont(&LogFont); } else { // Can do better??? strcpy(LogFont.lfFaceName, _T("MS Sans Serif")); LogFont.lfHeight = 8; } //Prework for setting font in dialog... int cWC = MultiByteToWideChar(CP_ACP, 0, LogFont.lfFaceName, -1, NULL, 0); int nFontNameLen = cWC + 1; WCHAR *szFontName = new WCHAR[nFontNameLen]; // Copy the string MultiByteToWideChar(CP_ACP, 0, LogFont.lfFaceName, -1, (LPWSTR) szFontName, cWC); szFontName[cWC] = 0; nFontNameLen = (cWC) * sizeof(WCHAR); if (m_wFontSize == 0) { m_wFontSize = (unsigned short)LogFont.lfHeight; } //Prework for setting caption in dialog... cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0); int szBoxLen = cWC + 1; WCHAR *szBoxCaption = new WCHAR[szBoxLen]; // Copy the string MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR) szBoxCaption, cWC); szBoxCaption[cWC] = 0; szBoxLen = (cWC) * sizeof(WCHAR); int iRet = -1; //Here 's the stuff to build the dialog template in memory //without the controls being in the template //(Our first try, was this same template with some additional code //for each control placed on it, that's why this class is cold Ex :) //This gave some problems on WIN9x systems, where EDIT boxes //were not shown with 3D-look, but as flat controls) int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) /*menu and class*/ + szBoxLen /*size of caption*/ + sizeof(WORD) /*fontsize*/ + nFontNameLen /*size of fontname*/; //Are there any subclassed controls... if (m_DialogTemplate.cdit > 0) { nBufferSize = (nBufferSize + 3) & ~3; // adjust size to make first control DWORD aligned CDynDialogItemEx *pDynDialogItemEx = NULL; for (int i = 0; i < m_arrDlgItemPtr.GetSize(); i++) { pDynDialogItemEx = m_arrDlgItemPtr[i]; if (pDynDialogItemEx != NULL) { if (pDynDialogItemEx->IsDlgItemSubclassed()) { int nItemLength = sizeof(DLGITEMTEMPLATE) + 3 * sizeof(WORD); nItemLength += (pDynDialogItemEx->GetCaptionLength() + 1) * sizeof(WCHAR); if (i != m_DialogTemplate.cdit - 1) { // the last control does not need extra bytes nItemLength = (nItemLength + 3) & ~3; // take into account gap so next control is DWORD aligned } nBufferSize += nItemLength; } } } } HLOCAL hLocal = LocalAlloc(LHND, nBufferSize); if (hLocal != NULL) { BYTE* pBuffer = (BYTE*)LocalLock(hLocal); if (pBuffer == NULL) { LocalFree(hLocal); AfxMessageBox(_T("CDynDialogEx::DoModal() : LocalLock Failed")); } BYTE *pdest = pBuffer; // transfer DLGTEMPLATE structure to the buffer memcpy(pdest, &m_DialogTemplate, sizeof(DLGTEMPLATE)); // DLGTemplate pdest += sizeof(DLGTEMPLATE); *(WORD*)pdest = 0; // no menu -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment *(WORD*)(pdest + 1) = 0; // use default window class -- WORD to say it is 0 bytes pdest += sizeof(WORD); // Increment memcpy(pdest, szBoxCaption, szBoxLen); // Caption pdest += szBoxLen; *(WORD*)pdest = m_wFontSize; // font size pdest += sizeof(WORD); memcpy(pdest, szFontName, nFontNameLen); // font name pdest += nFontNameLen; // will now transfer the information for each one of subclassed controls... if (m_DialogTemplate.cdit > 0) { CDynDialogItemEx *pDynDialogItemEx = NULL; for (int i = 0; i < m_arrDlgItemPtr.GetSize(); i++) { pDynDialogItemEx = m_arrDlgItemPtr[i]; if (pDynDialogItemEx != NULL) { if (pDynDialogItemEx->IsDlgItemSubclassed()) { pdest = pDynDialogItemEx->FillBufferWithItemTemplate(pdest); } } } } ASSERT(pdest - pBuffer == nBufferSize); // just make sure we did not overrun the heap //Next lines to make sure that MFC makes no ASSERTION when PREVIOUS/NEXT is pressed:) if (m_lpDialogTemplate != NULL) { m_lpDialogTemplate = NULL; } //These are the MFC functions, which do the job... if (m_bModelessDlg) { iRet = CreateIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd); } else { InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd); iRet = CDialog::DoModal(); } LocalUnlock(hLocal); LocalFree(hLocal); delete [] szBoxCaption; delete [] szFontName; return iRet; } else { AfxMessageBox(_T("CDynDialogEx::DoModal() : LocalAllock Failed")); return -1; } }
CMemoryInfoEdit::CMemoryInfoEdit(CWnd* pParent /*=NULL*/) :d_hDialogInit(0) //CDialog(CMemoryInfoEdit::IDD, pParent) { VERIFY( InitModalIndirect( initDialog(hInstance,MAKEINTRESOURCE(CMemoryInfoEdit::IDD)), pParent ) ); }