MFC的CDialog完全展开式解析

时间:2022-11-01 14:40:42

// mfc_notepad_execDlg.h : 头文件

#pragma once

// Cmfc_notepad_execDlg 对话框

class Cmfc_notepad_execDlg : publicCDialog

{

// 构造

public:

    Cmfc_notepad_execDlg(CWnd*pParent = NULL);   // 标准构造函数

// 对话框数据

    enum { IDD = IDD_MFC_NOTEPAD_EXEC_DIALOG };

    protected:

    virtual void DoDataExchange(CDataExchange*pDX); // DDX/DDV支持

// 实现

protected:

    HICON m_hIcon;

/*

DECLARE_HANDLE(HICON);

typedef void *HANDLE;
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name

struct HICON__ { int unused; }; 

typedef struct HICON__ *name

"HICON m_hIcon;"通过上面翻译下来就是:

struct HICON__ { int unused; }; 

typedef struct HICON__ *name m_hIcon;

*/

    // 生成的消息映射函数

    virtual BOOL OnInitDialog();

    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);//#define afx_msg 

    afx_msg void OnPaint();

    afx_msg void OnTimer(UINT_PTR nIDEvent);

    afx_msg HCURSOR OnQueryDragIcon();//typedef HICON HCURSOR;

    DECLARE_MESSAGE_MAP()

/*#define DECLARE_MESSAGE_MAP() 

protected: 
static const AFX_MSGMAP* PASCAL GetThisMessageMap(); //#define PASCAL      __stdcall
virtual const AFX_MSGMAP* GetMessageMap() const; 

struct AFX_MSGMAP
{
const AFX_MSGMAP* (PASCAL* pfnGetBaseMap)();
const AFX_MSGMAP_ENTRY* lpEntries;
};

struct AFX_MSGMAP_ENTRY
{
UINT nMessage;   // windows message
UINT nCode;      // control code or WM_NOTIFY code
UINT nID;        // control ID (or 0 for windows messages)
UINT nLastID;    // used for entries specifying a range of control id's
UINT_PTR nSig;       // signature type (action) or pointer to message #
AFX_PMSG pfn;    // routine to call (or special value)
};

typedef int                 INT;
typedef unsigned int        UINT;
typedef unsigned int        *PUINT;

typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;//#define _W64

typedef void (AFX_MSG_CALL CCmdTarget::*AFX_PMSG)(void);//#define AFX_MSG_CALL

翻译下来就是:

protected: 
static const AFX_MSGMAP* __stdcall GetThisMessageMap();      
virtual const AFX_MSGMAP* GetMessageMap() const; 

*/

public:

    afx_msg void OnBnClickedButtonConvertTo();

    CString mPathName;

    CString mPostfixType;//转换后后缀

    CString mPostfixPre;//转换前后缀

    CString strCurPath;

    BOOLEAN mConvertStart;

public:

    int ExecuteCommand(CString strCurFileName);

    void SetFolderPath(UINT uid);

    void BrowseCurrentAllFile(CString strDir);

    void BrowseCurrentDir(CString strDir);

    CString ReadReg();

    void WriteReg(CString m_strOwner);

public:

    afx_msg void OnBnClickedButtonLoadPath();

};

 

// mfc_notepad_execDlg.cpp :实现文件

#include "stdafx.h"

#include <atlbase.h>

#include "mfc_notepad_exec.h"

#include "mfc_notepad_execDlg.h"

#define TIMER1 1

static DWORD WINAPI  DownloadThread(void *pArg);

int mFileCount=0;

#ifdef _DEBUG

#define new DEBUG_NEW

#endif

// Cmfc_notepad_execDlg 对话框

Cmfc_notepad_execDlg::Cmfc_notepad_execDlg(CWnd*pParent /*=NULL*/)

    :CDialog(Cmfc_notepad_execDlg::IDD, pParent)

{

    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void Cmfc_notepad_execDlg::DoDataExchange(CDataExchange* pDX)

{

    CDialog::DoDataExchange(pDX);

}

BEGIN_MESSAGE_MAP(Cmfc_notepad_execDlg, CDialog)

/*

#define BEGIN_MESSAGE_MAP(theClass, baseClass) 
PTM_WARNING_DISABLE 

    /*

    #define PTM_WARNING_DISABLE 
__pragma(warning( push )) 
__pragma(warning( disable : 4867 ))

    */
const AFX_MSGMAP* theClass::GetMessageMap() const //AFX_MSGMAP见上面翻译
{ return GetThisMessageMap(); } 
const AFX_MSGMAP* PASCAL theClass::GetThisMessageMap() 

typedef theClass ThisClass;   
typedef baseClass TheBaseClass;   
static const AFX_MSGMAP_ENTRY _messageEntries[] =  
{

翻译下来就是:

const AFX_MSGMAP* Cmfc_notepad_execDlg::GetMessageMap() const //AFX_MSGMAP见上面翻译
{ return GetThisMessageMap(); } 
const AFX_MSGMAP* PASCAL Cmfc_notepad_execDlg::GetThisMessageMap() 

typedef Cmfc_notepad_execDlg ThisClass;   
typedef CDialog TheBaseClass;   
static const AFX_MSGMAP_ENTRY _messageEntries[] =  
{

*/

    ON_WM_SYSCOMMAND()

/*

#define ON_WM_SYSCOMMAND() 
{ WM_SYSCOMMAND, 0, 0, 0, AfxSig_vwl, //#define WM_SYSCOMMAND                   0x0112//AfxSig_vwl = AfxSig_v_w_l,// void (UINT, LPARAM)
(AFX_PMSG)(AFX_PMSGW) //AFX_PMSG见下面翻译//
(static_cast< void (AFX_MSG_CALL CWnd::*)(UINT, LPARAM) > ( &ThisClass :: OnSysCommand)) },

typedef void (AFX_MSG_CALL CCmdTarget::*AFX_PMSG)(void);

typedef void (AFX_MSG_CALL CWnd::*AFX_PMSGW)(void);//#define AFX_MSG_CALL

翻译下来就是:

{ 0x0112, 0, 0, 0, AfxSig_vwl, (AFX_PMSG)(AFX_PMSGW)  (static_cast< void (CWnd::*)(UINT, LPARAM) > ( &ThisClass :: OnSysCommand)) },//共6个元素
//最后一个值的含义为:获取子类的函数地址,其被强制转化父类窗口的一个带void (CWnd::*)(UINT, LPARAM)的函数指针类型,接着被转换为void (CWnd::*)的无参函数指针类型,然后被转换为父类的父类的无参函数指针地址

*/

    ON_WM_PAINT()

/*

#define ON_WM_PAINT() 
{ WM_PAINT, 0, 0, 0, AfxSig_vv, //#define WM_PAINT                        0x000F//AfxSig_vv = AfxSig_v_v_v,      // void (void)
(AFX_PMSG)(AFX_PMSGW) 
(static_cast< void (AFX_MSG_CALL CWnd::*)(void) > ( &ThisClass :: OnPaint)) },

*/

    ON_WM_TIMER()

/*

#define ON_WM_TIMER() 
{ WM_TIMER, 0, 0, 0, AfxSig_vw, //#define WM_TIMER                        0x0113//AfxSig_vw = AfxSig_v_u_v,      // void (UINT)
(AFX_PMSG)(AFX_PMSGW) 
(static_cast< void (AFX_MSG_CALL CWnd::*)(UINT_PTR) > ( &ThisClass :: OnTimer)) },

*/

    ON_WM_QUERYDRAGICON()

/*

#define ON_WM_QUERYDRAGICON() 
{ WM_QUERYDRAGICON, 0, 0, 0, AfxSig_hv, 
void (CWnd::*AFX_PMSGW)(void);
(static_cast< HCURSOR (AFX_MSG_CALL CWnd::*)(void) > ( &ThisClass :: OnQueryDragIcon)) },

*/

    //}}AFX_MSG_MAP

    ON_BN_CLICKED(IDC_BUTTON_CONVERT_TO,OnBnClickedButtonConvertTo)//#define IDC_BUTTON_CONVERT_TO           1000

/*

#define ON_BN_CLICKED(id, memberFxn) //#define BN_CLICKED          0
ON_CONTROL(BN_CLICKED, id, memberFxn)

#define ON_CONTROL(wNotifyCode, id, memberFxn) 
{ WM_COMMAND, (WORD)wNotifyCode, (WORD)id, (WORD)id, AfxSigCmd_v, //#define WM_COMMAND  0x0111//

//typedef unsigned short      WORD;//AfxSigCmd_v, // void ()
(static_cast< AFX_PMSG > (memberFxn)) },//见上面翻译

翻译下来就是:

{  0x0111, (WORD)0, (WORD)1000, (WORD)1000 , AfxSigCmd_v, (static_cast< AFX_PMSG > (OnBnClickedButtonConvertTo)) },

*/

    ON_BN_CLICKED(IDC_BUTTON_LOAD_PATH,OnBnClickedButtonLoadPath)

END_MESSAGE_MAP()

/*

#define END_MESSAGE_MAP() 
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } //AfxSig_end = 0,
}; 
static const AFX_MSGMAP messageMap = 
{ &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; 
return &messageMap; 
}   
PTM_WARNING_RESTORE//__pragma(warning( pop ))

翻译下来就是:

{0, 0, 0, 0, 0, (AFX_PMSG)0 } //数组的最后一个元素
}; 
static const AFX_MSGMAP messageMap = 
{ &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; 
return &messageMap; 
}   

__pragma(warning( pop ))

*/

// Cmfc_notepad_execDlg 消息处理程序

BOOL Cmfc_notepad_execDlg::OnInitDialog()//typedef int                 BOOL;

{

    CDialog::OnInitDialog();

    // 关于...菜单项添加到系统菜单中。

    // IDM_ABOUTBOX 必须在系统命令范围内。

    ASSERT((IDM_ABOUTBOX& 0xFFF0) == IDM_ABOUTBOX);

/*

#define ASSERT(f)          DEBUG_ONLY((void) ((f) || !::AfxAssertFailedLine(THIS_FILE, __LINE__) || (AfxDebugBreak(), 0)))

//#define DEBUG_ONLY(f)      (f)

//BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine);//#define AFXAPI __stdcall

//#define THIS_FILE          __FILE__

//#define AfxDebugBreak() _CrtDbgBreak()//#define _CrtDbgBreak() __debugbreak()

翻译下来就是:

((IDM_ABOUTBOX& 0xFFF0) == IDM_ABOUTBOX) || !::AfxAssertFailedLine(__FILE__, __LINE__) || (__debugbreak(), 0)));

*/

    ASSERT(IDM_ABOUTBOX< 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);

    if (pSysMenu != NULL)

    {

       CString strAboutMenu;

       strAboutMenu.LoadString(IDS_ABOUTBOX);

       if (!strAboutMenu.IsEmpty())

       {

           pSysMenu->AppendMenu(MF_SEPARATOR);

           pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX,strAboutMenu);

       }

    }

    // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动

    //  执行此操作

    SetIcon(m_hIcon, TRUE);         // 设置大图标

    SetIcon(m_hIcon, FALSE);    // 设置小图标

    // TODO: 在此添加额外的初始化代码

     

    return TRUE;  // 除非将焦点设置到控件,否则返回TRUE

}

 

void Cmfc_notepad_execDlg::OnTimer(UINT_PTR nIDEvent)

{

}

void Cmfc_notepad_execDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

    if ((nID &0xFFF0) == IDM_ABOUTBOX)

    {

       //CAboutDlg dlgAbout;

       //dlgAbout.DoModal();

    }

    else

    {

       CDialog::OnSysCommand(nID, lParam);

    }

}

// 如果向对话框添加最小化按钮,则需要下面的代码

//  来绘制该图标。对于使用文档/视图模型的MFC 应用程序,

//  这将由框架自动完成。

 

void Cmfc_notepad_execDlg::OnPaint()

{

    if (IsIconic())

    {

       CPaintDC dc(this); // 用于绘制的设备上下文

       SendMessage(WM_ICONERASEBKGND,reinterpret_cast<WPARAM>(dc.GetSafeHdc()),0);

       // 使图标在工作矩形中居中

       int cxIcon = GetSystemMetrics(SM_CXICON);

       int cyIcon = GetSystemMetrics(SM_CYICON);

       CRect rect;

       GetClientRect(&rect);

       int x = (rect.Width() - cxIcon + 1) / 2;

       int y = (rect.Height() - cyIcon + 1) / 2;

       // 绘制图标

       dc.DrawIcon(x, y, m_hIcon);

    }

    else

    {

       CDialog::OnPaint();

    }

}

//当用户拖动最小化窗口时系统调用此函数取得光标显示。

HCURSOR Cmfc_notepad_execDlg::OnQueryDragIcon()

{

    return static_cast<HCURSOR>(m_hIcon);

}

void Cmfc_notepad_execDlg::OnBnClickedButtonConvertTo()

{

    // TODO: 在此添加控件通知处理程序代码

}

void Cmfc_notepad_execDlg::OnBnClickedButtonLoadPath()

{

    // TODO: 在此添加控件通知处理程序代码

}

 

// CDialog - a modal ormodeless dialog

class CDialog : public CWnd

{

    DECLARE_DYNAMIC(CDialog)

 

    // Modeless construct

public:

    CDialog();

 

    virtual BOOL Create(LPCTSTR lpszTemplateName, CWnd*pParentWnd = NULL);

    virtual BOOL Create(UINT nIDTemplate, CWnd* pParentWnd = NULL);

    virtual BOOL CreateIndirect(LPCDLGTEMPLATElpDialogTemplate, CWnd*pParentWnd = NULL,

       void* lpDialogInit =NULL);

    virtual BOOL CreateIndirect(HGLOBALhDialogTemplate, CWnd*pParentWnd = NULL);

 

    // Modal construct

public:

    explicit CDialog(LPCTSTR lpszTemplateName,CWnd* pParentWnd= NULL);

    explicit CDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL);

    BOOL InitModalIndirect(LPCDLGTEMPLATE lpDialogTemplate,CWnd* pParentWnd= NULL,

       void* lpDialogInit =NULL);

    BOOL InitModalIndirect(HGLOBAL hDialogTemplate,CWnd* pParentWnd= NULL);

 

// Attributes

public:

    void MapDialogRect(LPRECT lpRect)const;

    void SetHelpID(UINT nIDR);

 

// Operations

public:

    // modal processing

    virtual INT_PTR DoModal();

 

    // support for passing on tab control - use 'PostMessage'if needed

    void NextDlgCtrl() const;

    void PrevDlgCtrl() const;

    void GotoDlgCtrl(CWnd* pWndCtrl);

 

    // default button access

    void SetDefID(UINT nID);

    DWORD GetDefID() const;

 

    // termination

    void EndDialog(int nResult);

 

// Overridables (specialmessage map entries)

    virtual BOOL OnInitDialog();

    virtual void OnSetFont(CFont* pFont);

protected:

    virtual void OnOK();

    virtual void OnCancel();

 

// Implementation

public:

    virtual ~CDialog();

#ifdef _DEBUG

    virtual void AssertValid() const;

    virtual void Dump(CDumpContext&dc) const;

#endif

    virtual BOOL PreTranslateMessage(MSG*pMsg);

    virtual BOOL OnCmdMsg(UINT nID,int nCode,void* pExtra,

       AFX_CMDHANDLERINFO* pHandlerInfo);

    virtual BOOL CheckAutoCenter();

 

protected:

    UINT m_nIDHelp;                 //Help ID (0 for none, see HID_BASE_RESOURCE)

 

    // parameters for 'DoModal'

    LPCTSTR m_lpszTemplateName;     // name orMAKEINTRESOURCE

    HGLOBAL m_hDialogTemplate;      // indirect(m_lpDialogTemplate == NULL)

    LPCDLGTEMPLATE m_lpDialogTemplate;  // indirect if(m_lpszTemplateName == NULL)

    void* m_lpDialogInit;          // DLGINITresource data

    CWnd* m_pParentWnd;             //parent/owner window

    HWND m_hWndTop;                 //top level parent window (may be disabled)

 

#ifndef _AFX_NO_OCC_SUPPORT

    _AFX_OCC_DIALOG_INFO* m_pOccDialogInfo;

    virtual BOOL SetOccDialogInfo(_AFX_OCC_DIALOG_INFO*pOccDialogInfo);

    virtual _AFX_OCC_DIALOG_INFO*GetOccDialogInfo();

#endif

    virtual void PreInitDialog();

 

    // implementation helpers

    HWND PreModal();

    void PostModal();

 

    BOOL CreateIndirect(LPCDLGTEMPLATE lpDialogTemplate,CWnd* pParentWnd,

       void* lpDialogInit, HINSTANCE hInst);

    BOOL CreateIndirect(HGLOBAL hDialogTemplate,CWnd* pParentWnd,

       HINSTANCE hInst);

 

protected:

    //{{AFX_MSG(CDialog)

    afx_msg LRESULT OnCommandHelp(WPARAMwParam, LPARAMlParam);

    afx_msg LRESULT OnHelpHitTest(WPARAMwParam, LPARAMlParam);

    afx_msg LRESULT HandleInitDialog(WPARAM,LPARAM);

    afx_msg LRESULT HandleSetFont(WPARAM,LPARAM);

    afx_msg void OnPaint();

    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()

};

class CWnd : public CCmdTarget

{

    DECLARE_DYNCREATE(CWnd)

protected:

    static const MSG* PASCAL GetCurrentMessage();

// Attributes

public:

    HWND m_hWnd;            // mustbe first data member

    operator HWND() const;

    BOOL operator==(const CWnd& wnd)const;

    BOOL operator!=(const CWnd& wnd)const;

    HWND GetSafeHwnd() const;

    DWORD GetStyle() const;

    DWORD GetExStyle() const;

    BOOL ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0);

    BOOL ModifyStyleEx(DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0);

    CWnd* GetOwner() const;

    void SetOwner(CWnd* pOwnerWnd);

#if(WINVER >= 0x0500)

    BOOL GetWindowInfo(PWINDOWINFO pwi) const;

    BOOL GetTitleBarInfo(PTITLEBARINFO pti) const;

#endif // WINVER >=0x0500

// Constructors and othercreation

    CWnd();

    static CWnd* PASCAL FromHandle(HWND hWnd);

    static CWnd* PASCAL FromHandlePermanent(HWND hWnd);

    static void PASCAL DeleteTempMap();

    BOOL Attach(HWND hWndNew);

    HWND Detach();

    // subclassing/unsubclassing functions

    virtual void PreSubclassWindow();

    BOOL SubclassWindow(HWND hWnd);

    BOOL SubclassDlgItem(UINT nID, CWnd* pParent);

    HWND UnsubclassWindow();

    // handling of RT_DLGINIT resource (extension to RT_DIALOG)

    BOOL ExecuteDlgInit(LPCTSTR lpszResourceName);

    BOOL ExecuteDlgInit(LPVOID lpResource);

public:

    // for child windows, views, panes etc

    virtual BOOL Create(LPCTSTR lpszClassName,

       LPCTSTR lpszWindowName,DWORD dwStyle,

       const RECT& rect,

       CWnd* pParentWnd, UINT nID,

       CCreateContext* pContext= NULL);

    // advanced creation (allows access to extended styles)

    virtual BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,

       LPCTSTR lpszWindowName,DWORD dwStyle,

       int x, int y, int nWidth, int nHeight,

       HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam = NULL);

    virtual BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,

       LPCTSTR lpszWindowName,DWORD dwStyle,

       const RECT& rect,

       CWnd* pParentWnd, UINT nID,

       LPVOID lpParam = NULL);

// Window-Management messagehandler member functions

protected:

    virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);

    virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);

 

    afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);

    afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);

    afx_msg LRESULT OnActivateTopLevel(WPARAM,LPARAM);

    afx_msg void OnCancelMode();

    afx_msg void OnChildActivate();

    afx_msg void OnClose();

    afx_msg void OnContextMenu(CWnd*pWnd, CPoint pos);

    afx_msg BOOL OnCopyData(CWnd* pWnd, COPYDATASTRUCT*pCopyDataStruct);

    afx_msg int OnCreate(LPCREATESTRUCTlpCreateStruct);

    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);

    afx_msg void OnDestroy();

    afx_msg void OnEnable(BOOL bEnable);

    afx_msg void OnEndSession(BOOL bEnding);

    afx_msg void OnEnterIdle(UINT nWhy, CWnd* pWho);

    afx_msg BOOL OnEraseBkgnd(CDC* pDC);

    afx_msg void OnGetMinMaxInfo(MINMAXINFO*lpMMI);

    afx_msg BOOL OnHelpInfo(HELPINFO*lpHelpInfo);

    afx_msg void OnIconEraseBkgnd(CDC*pDC);

    afx_msg void OnKillFocus(CWnd* pNewWnd);

    afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);

    afx_msg void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);

    afx_msg void OnMove(int x,int y);

    afx_msg void OnPaint();

public:

    // for modality

    virtual void BeginModalState();

    virtual void EndModalState();

    // for translating Windows messages in main message pump

    virtual BOOL PreTranslateMessage(MSG*pMsg);

// Implementation

public:

    virtual ~CWnd();

    virtual BOOL CheckAutoCenter();

#ifdef _DEBUG

    virtual void AssertValid() const;

    virtual void Dump(CDumpContext&dc) const;

#endif

public:

    HWND m_hWndOwner;   // implementationof SetOwner and GetOwner

    UINT m_nFlags;      // see WF_flags above

protected:

    // implementation of message dispatch/hooking

    friend LRESULT CALLBACK _AfxSendMsgHook(int, WPARAM, LPARAM);

    friend void AFXAPI _AfxStandardSubclass(HWND);

    friend LRESULT CALLBACK _AfxCbtFilterHook(int, WPARAM, LPARAM);

    friend LRESULT AFXAPI AfxCallWndProc(CWnd*, HWND, UINT, WPARAM, LPARAM);

    // standard message implementation

    afx_msg LRESULT OnNTCtlColor(WPARAMwParam, LPARAMlParam);

    afx_msg LRESULT OnDisplayChange(WPARAM,LPARAM);

    afx_msg LRESULT OnDragList(WPARAM, LPARAM);

    //{{AFX_MSG(CWnd)

    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()

private:

    CWnd(HWND hWnd);    // just for special initialization

};


#include "stdafx.h"

#include "occimpl.h"

#define new DEBUG_NEW

// AfxDlgProc - does nothing since all messages are handled via AfxWndProc

INT_PTR CALLBACK AfxDlgProc(HWNDhWnd, UINT message, WPARAM, LPARAM)

{

    if (message ==WM_INITDIALOG)

    {

       // special case for WM_INITDIALOG

       CDialog* pDlg = DYNAMIC_DOWNCAST(CDialog,CWnd::FromHandlePermanent(hWnd));

       if (pDlg !=NULL)

           return pDlg->OnInitDialog();

       else

           return 1;

    }

    return 0;

}

// CDialog - Modeless and Modal

BEGIN_MESSAGE_MAP(CDialog,CWnd)

    //{{AFX_MSG_MAP(CDialog)

    ON_COMMAND(IDOK, &CDialog::OnOK)

    ON_COMMAND(IDCANCEL, &CDialog::OnCancel)

    ON_MESSAGE(WM_COMMANDHELP, &CDialog::OnCommandHelp)

    ON_MESSAGE(WM_HELPHITTEST, &CDialog::OnHelpHitTest)

    ON_MESSAGE(WM_INITDIALOG, &CDialog::HandleInitDialog)

    ON_MESSAGE(WM_SETFONT, &CDialog::HandleSetFont)

    ON_WM_PAINT()

    //}}AFX_MSG_MAP

END_MESSAGE_MAP()

BOOL CDialog::PreTranslateMessage(MSG*pMsg)

{

    // for modeless processing (or modal)

    ASSERT(m_hWnd !=NULL);

    // allow tooltip messages to be filtered

    if (CWnd::PreTranslateMessage(pMsg))

       return TRUE;

    // don't translate dialog messages when in Shift+F1 help mode

    CFrameWnd* pFrameWnd = GetTopLevelFrame();

    if (pFrameWnd !=NULL && pFrameWnd->m_bHelpMode)

       return FALSE;

    // fix around for VK_ESCAPE in a multiline Edit that is on a Dialog

    // that doesn't have a cancel or the cancel is disabled.

    if (pMsg->message ==WM_KEYDOWN &&

       (pMsg->wParam ==VK_ESCAPE || pMsg->wParam ==VK_CANCEL) &&

       (::GetWindowLong(pMsg->hwnd,GWL_STYLE) & ES_MULTILINE) &&

       _AfxCompareClassName(pMsg->hwnd,_T("Edit")))

    {

       HWND hItem = ::GetDlgItem(m_hWnd,IDCANCEL);

       if (hItem ==NULL || ::IsWindowEnabled(hItem))

       {

           SendMessage(WM_COMMAND,IDCANCEL, 0);

           return TRUE;

       }

    }

    // filter both messages to dialog and from children

    return PreTranslateInput(pMsg);

}

BOOL CDialog::OnCmdMsg(UINTnID, int nCode, void* pExtra,

    AFX_CMDHANDLERINFO* pHandlerInfo)

{

    if (CWnd::OnCmdMsg(nID,nCode, pExtra, pHandlerInfo))

       return TRUE;

    if ((nCode !=CN_COMMAND && nCode !=CN_UPDATE_COMMAND_UI) ||

           !IS_COMMAND_ID(nID) ||nID >= 0xf000)

    {

       // control notification or non-command button or system command

       return FALSE;       // not routed any further

    }

    // if we have an owner window, give it second crack

    CWnd* pOwner = GetParent();

    if (pOwner !=NULL)

    {

       TRACE(traceCmdRouting, 1,"Routing command id 0x%04X to owner window.\n",nID);

 

       ASSERT(pOwner !=this);

       if (pOwner->OnCmdMsg(nID,nCode, pExtra, pHandlerInfo))

           return TRUE;

    }

    // last crack goes to the current CWinThread object

    CWinThread* pThread = AfxGetThread();

    if (pThread !=NULL)

    {

       TRACE(traceCmdRouting, 1,"Routing command id 0x%04X to app.\n", nID);

 

       if (pThread->OnCmdMsg(nID,nCode, pExtra, pHandlerInfo))

           return TRUE;

    }

    TRACE(traceCmdRouting, 1,"IGNORING command id 0x%04X sent to %hs dialog.\n",nID,

           GetRuntimeClass()->m_lpszClassName);

 

    return FALSE;

}

// Modeless Dialogs have 2-phase construction

CDialog::CDialog()

{

    ASSERT(m_hWnd ==NULL);

    AFX_ZERO_INIT_OBJECT(CWnd);

}

CDialog::~CDialog()

{

    if (m_hWnd !=NULL)

    {

       TRACE(traceAppMsg, 0,"Warning: calling DestroyWindow in CDialog::~CDialog --\n");

       TRACE(traceAppMsg, 0,"\tOnDestroy or PostNcDestroy in derived class will not be called.\n");

       DestroyWindow();

    }

}

void CDialog::OnPaint()

{

    CPaintDC dc(this);

    if (PaintWindowlessControls(&dc))

       return;

    Default();

}

BOOL CDialog::Create(LPCTSTRlpszTemplateName, CWnd*pParentWnd)

{

    ASSERT(IS_INTRESOURCE(lpszTemplateName) ||

       AfxIsValidString(lpszTemplateName));

    m_lpszTemplateName = lpszTemplateName// used for help

    if (IS_INTRESOURCE(m_lpszTemplateName) &&m_nIDHelp == 0)

       m_nIDHelp = LOWORD((DWORD_PTR)m_lpszTemplateName);

#ifdef _DEBUG

    if (!_AfxCheckDialogTemplate(lpszTemplateName,FALSE))

    {

       ASSERT(FALSE);         // invalid dialog template name

       PostNcDestroy();        // cleanup if Create fails too soon

       return FALSE;

    }

#endif //_DEBUG

    HINSTANCE hInst = AfxFindResourceHandle(lpszTemplateName,RT_DIALOG);

    HRSRC hResource = ::FindResource(hInst,lpszTemplateName, RT_DIALOG);

    HGLOBAL hTemplate = LoadResource(hInst,hResource);

    BOOL bResult = CreateIndirect(hTemplate,pParentWnd, hInst);

    FreeResource(hTemplate);

    return bResult;

}

// for backward compatibility

BOOL CDialog::CreateIndirect(HGLOBALhDialogTemplate, CWnd*pParentWnd)

{

    return CreateIndirect(hDialogTemplate, pParentWnd, NULL);

}

BOOL CDialog::CreateIndirect(HGLOBALhDialogTemplate, CWnd*pParentWnd,

    HINSTANCE hInst)

{

    ASSERT(hDialogTemplate !=NULL);

    LPCDLGTEMPLATE lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);

    BOOL bResult = CreateIndirect(lpDialogTemplate,pParentWnd, NULL,hInst);

    UnlockResource(hDialogTemplate);

    return bResult;

}

// for backward compatibility

BOOL CDialog::CreateIndirect(LPCDLGTEMPLATElpDialogTemplate, CWnd*pParentWnd,

    void* lpDialogInit)

{

    return CreateIndirect(lpDialogTemplate, pParentWnd, lpDialogInit, NULL);

}

BOOL CDialog::CreateIndirect(LPCDLGTEMPLATElpDialogTemplate, CWnd*pParentWnd,

    void* lpDialogInit, HINSTANCE hInst)

{

    ASSERT(lpDialogTemplate !=NULL);

 

    if (pParentWnd ==NULL)

       pParentWnd = AfxGetMainWnd();

    m_lpDialogInit = lpDialogInit;

 

    return CreateDlgIndirect(lpDialogTemplate, pParentWnd, hInst);

}

 

BOOL CWnd::CreateDlg(LPCTSTRlpszTemplateName, CWnd*pParentWnd)

{

    // load resource

    LPCDLGTEMPLATE lpDialogTemplate = NULL;

    HGLOBAL hDialogTemplate = NULL;

    HINSTANCE hInst = AfxFindResourceHandle(lpszTemplateName,RT_DIALOG);

    HRSRC hResource = ::FindResource(hInst,lpszTemplateName, RT_DIALOG);

    hDialogTemplate = LoadResource(hInst, hResource);

    if (hDialogTemplate !=NULL)

       lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);

    ASSERT(lpDialogTemplate !=NULL);

 

    // create a modeless dialog

    BOOL bSuccess = CreateDlgIndirect(lpDialogTemplate,pParentWnd, hInst);

 

    // free resource

    UnlockResource(hDialogTemplate);

    FreeResource(hDialogTemplate);

 

    return bSuccess;

}

 

BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATElpDialogTemplate,

    CWnd* pParentWnd, HINSTANCE hInst)

{

    ASSERT(lpDialogTemplate !=NULL);

    if (pParentWnd !=NULL)

       ASSERT_VALID(pParentWnd);

 

    if(!hInst)

       hInst = AfxGetResourceHandle();

 

#ifndef _AFX_NO_OCC_SUPPORT

    _AFX_OCC_DIALOG_INFO occDialogInfo;

    COccManager* pOccManager = afxOccManager;

#endif

 

    HGLOBAL hTemplate = NULL;

 

    HWND hWnd = NULL;

#ifdef _DEBUG

    DWORD dwError = 0;

#endif

 

    TRY

    {

       VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));

       AfxDeferRegisterClass(AFX_WNDCOMMCTLSNEW_REG);

 

#ifndef _AFX_NO_OCC_SUPPORT

       // separately create OLE controls in the dialog template

       if (pOccManager !=NULL)

       {

           if (!SetOccDialogInfo(&occDialogInfo))

              return FALSE;

 

           lpDialogTemplate = pOccManager->PreCreateDialog(&occDialogInfo,

              lpDialogTemplate);

       }

 

       if (lpDialogTemplate ==NULL)

           return FALSE;

#endif //!_AFX_NO_OCC_SUPPORT

 

       // If no font specified, set the system font.

       CString strFace;

       WORD wSize = 0;

       BOOL bSetSysFont = !CDialogTemplate::GetFont(lpDialogTemplate,strFace,

           wSize);

 

       if (afxData.bWin95 && !bSetSysFont &&GetSystemMetrics(SM_DBCSENABLED))

       {

           bSetSysFont = (strFace ==_T("MS Shell Dlg"));

           if (bSetSysFont && (wSize == 8))

              wSize = 0;

       }

 

       if (bSetSysFont)

       {

           CDialogTemplate dlgTemp(lpDialogTemplate);

           dlgTemp.SetSystemFont(wSize);

           hTemplate = dlgTemp.Detach();

       }

 

       if (hTemplate !=NULL)

           lpDialogTemplate = (DLGTEMPLATE*)GlobalLock(hTemplate);

 

       // setup for modal loop and creation

       m_nModalResult = -1;

       m_nFlags |= WF_CONTINUEMODAL;

 

       // create modeless dialog

       AfxHookWindowCreate(this);

       hWnd = ::CreateDialogIndirect(hInst,lpDialogTemplate,

           pParentWnd->GetSafeHwnd(),AfxDlgProc);

#ifdef _DEBUG

       dwError = ::GetLastError();

#endif

    }

    CATCH_ALL(e)

    {

       DELETE_EXCEPTION(e);

       m_nModalResult = -1;

    }

    END_CATCH_ALL

 

#ifndef _AFX_NO_OCC_SUPPORT

    if (pOccManager !=NULL)

    {

       pOccManager->PostCreateDialog(&occDialogInfo);

       if (hWnd !=NULL)

           SetOccDialogInfo(NULL);

    }

#endif //!_AFX_NO_OCC_SUPPORT

 

    if (!AfxUnhookWindowCreate())

       PostNcDestroy();        // cleanup if Create fails too soon

 

    // handle EndDialog calls during OnInitDialog

#ifdef _DEBUG

#ifndef _AFX_NO_OCC_SUPPORT

    DWORD dwOldFlags = m_nFlags;

#endif

#endif

    if (hWnd !=NULL && !(m_nFlags &WF_CONTINUEMODAL))

    {

       ::DestroyWindow(hWnd);

       hWnd = NULL;

    }

 

    if (hTemplate !=NULL)

    {

       GlobalUnlock(hTemplate);

       GlobalFree(hTemplate);

    }

 

    // help with error diagnosis (only if WM_INITDIALOG didn't EndDialog())

    if (hWnd ==NULL)

    {

#ifdef _DEBUG

#ifndef _AFX_NO_OCC_SUPPORT

       if (dwOldFlags &WF_CONTINUEMODAL)

       {

           if (afxOccManager ==NULL)

           {

              TRACE(traceAppMsg, 0,">>> If this dialog has OLE controls:\n");

              TRACE(traceAppMsg, 0,">>> AfxEnableControlContainer has not been called yet.\n");

              TRACE(traceAppMsg, 0,">>> You should call it in your app's InitInstance function.\n");

           }

           else if (dwError != 0)

           {

              TRACE(traceAppMsg, 0,"Warning: Dialog creation failed!  GetLastError returns 0x%8.8X\n",dwError);

           }

       }

#endif //!_AFX_NO_OCC_SUPPORT

#endif //_DEBUG

       return FALSE;

    }

 

    ASSERT(hWnd ==m_hWnd);

    return TRUE;

}

 

#ifndef _AFX_NO_OCC_SUPPORT

 

BOOL CDialog::SetOccDialogInfo(_AFX_OCC_DIALOG_INFO*pOccDialogInfo)

{

    m_pOccDialogInfo = pOccDialogInfo;

    return TRUE;

}

 

_AFX_OCC_DIALOG_INFO* CDialog::GetOccDialogInfo()

{

    return m_pOccDialogInfo;

}

 

#endif

 

/////////////////////////////////////////////////////////////////////////////

// Modal Dialogs

 

// Modal Constructors just save parameters

CDialog::CDialog(LPCTSTRlpszTemplateName, CWnd*pParentWnd)

{

    ASSERT(IS_INTRESOURCE(lpszTemplateName) ||

       AfxIsValidString(lpszTemplateName));

 

    AFX_ZERO_INIT_OBJECT(CWnd);

 

    m_pParentWnd = pParentWnd;

    m_lpszTemplateName = lpszTemplateName;

    if (IS_INTRESOURCE(m_lpszTemplateName))

       m_nIDHelp = LOWORD((DWORD_PTR)m_lpszTemplateName);

}

 

CDialog::CDialog(UINTnIDTemplate, CWnd*pParentWnd)

{

    AFX_ZERO_INIT_OBJECT(CWnd);

 

    m_pParentWnd = pParentWnd;

    m_lpszTemplateName = MAKEINTRESOURCE(nIDTemplate);

    m_nIDHelp = nIDTemplate;

}

 

BOOL CDialog::InitModalIndirect(HGLOBALhDialogTemplate, CWnd*pParentWnd)

{

    // must be called on an empty constructed CDialog

    ASSERT(m_lpszTemplateName ==NULL);

    ASSERT(m_hDialogTemplate ==NULL);

    ASSERT(hDialogTemplate !=NULL);

 

    if (m_pParentWnd ==NULL)

       m_pParentWnd = pParentWnd;

 

    m_hDialogTemplate = hDialogTemplate;

 

    return TRUE;    // always ok (DoModal actually brings up dialog)

}

 

BOOL CDialog::InitModalIndirect(LPCDLGTEMPLATElpDialogTemplate, CWnd*pParentWnd,

    void* lpDialogInit)

{

    // must be called on an empty constructed CDialog

    ASSERT(m_lpszTemplateName ==NULL);

    ASSERT(m_lpDialogTemplate ==NULL);

    ASSERT(lpDialogTemplate !=NULL);

 

    if (m_pParentWnd ==NULL)

       m_pParentWnd = pParentWnd;

 

    m_lpDialogTemplate = lpDialogTemplate;

    m_lpDialogInit = lpDialogInit;

 

    return TRUE;    // always ok (DoModal actually brings up dialog)

}

 

HWND CDialog::PreModal()

{

    // cannot call DoModal on a dialog already constructed as modeless

    ASSERT(m_hWnd ==NULL);

 

    // allow OLE servers to disable themselves

    CWinApp* pApp = AfxGetApp();

    if (pApp !=NULL)

       pApp->EnableModeless(FALSE);

 

    // find parent HWND

    HWND hWnd = CWnd::GetSafeOwner_(m_pParentWnd->GetSafeHwnd(), &m_hWndTop);

 

    // hook for creation of dialog

    AfxHookWindowCreate(this);

 

    // return window to use as parent for dialog

    return hWnd;

}

 

void CDialog::PostModal()

{

    AfxUnhookWindowCreate();   // just in case

    Detach();               // just in case

 

    // re-enable windows

    if (::IsWindow(m_hWndTop))

       ::EnableWindow(m_hWndTop,TRUE);

    m_hWndTop = NULL;

    CWinApp* pApp = AfxGetApp();

    if (pApp !=NULL)

       pApp->EnableModeless(TRUE);

}

 

INT_PTR CDialog::DoModal()

{

    // can be constructed with a resource template or InitModalIndirect

    ASSERT(m_lpszTemplateName !=NULL || m_hDialogTemplate !=NULL ||

       m_lpDialogTemplate != NULL);

 

    // load resource as necessary

    LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;

    HGLOBAL hDialogTemplate = m_hDialogTemplate;

    HINSTANCE hInst = AfxGetResourceHandle();

    if (m_lpszTemplateName !=NULL)

    {

       hInst = AfxFindResourceHandle(m_lpszTemplateName,RT_DIALOG);

       HRSRC hResource = ::FindResource(hInst,m_lpszTemplateName, RT_DIALOG);

       hDialogTemplate = LoadResource(hInst, hResource);

    }

    if (hDialogTemplate !=NULL)

       lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);

 

    // return -1 in case of failure to load the dialog template resource

    if (lpDialogTemplate ==NULL)

       return -1;

 

    // disable parent (before creating dialog)

    HWND hWndParent = PreModal();

    AfxUnhookWindowCreate();

    BOOL bEnableParent = FALSE;

#ifndef _AFX_NO_OLE_SUPPORT

    CWnd* pMainWnd = NULL;

    BOOL bEnableMainWnd = FALSE;

#endif

    if (hWndParent &&hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent))

    {

       ::EnableWindow(hWndParent,FALSE);

       bEnableParent = TRUE;

#ifndef _AFX_NO_OLE_SUPPORT

       pMainWnd = AfxGetMainWnd();

       if (pMainWnd &&pMainWnd->IsFrameWnd() &&pMainWnd->IsWindowEnabled())

       {

           //

           // We are hosted by non-MFC container

           //

           pMainWnd->EnableWindow(FALSE);

           bEnableMainWnd = TRUE;

       }

#endif

    }

 

    TRY

    {

       // create modeless dialog

       AfxHookWindowCreate(this);

       if (CreateDlgIndirect(lpDialogTemplate,

                     CWnd::FromHandle(hWndParent),hInst))

       {

           if (m_nFlags &WF_CONTINUEMODAL)

           {

              // enter modal loop

              DWORD dwFlags = MLF_SHOWONIDLE;

              if (GetStyle() &DS_NOIDLEMSG)

                  dwFlags |= MLF_NOIDLEMSG;

              VERIFY(RunModalLoop(dwFlags) ==m_nModalResult);

           }

 

           // hide the window before enabling the parent, etc.

           if (m_hWnd !=NULL)

              SetWindowPos(NULL, 0, 0, 0, 0,SWP_HIDEWINDOW|

                  SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);

       }

    }

    CATCH_ALL(e)

    {

       DELETE_EXCEPTION(e);

       m_nModalResult = -1;

    }

    END_CATCH_ALL

 

#ifndef _AFX_NO_OLE_SUPPORT

    if (bEnableMainWnd)

       pMainWnd->EnableWindow(TRUE);

#endif

    if (bEnableParent)

       ::EnableWindow(hWndParent,TRUE);

    if (hWndParent !=NULL && ::GetActiveWindow() ==m_hWnd)

       ::SetActiveWindow(hWndParent);

 

    // destroy modal window

    DestroyWindow();

    PostModal();

 

    // unlock/free resources as necessary

    if (m_lpszTemplateName !=NULL || m_hDialogTemplate !=NULL)

       UnlockResource(hDialogTemplate);

    if (m_lpszTemplateName !=NULL)

       FreeResource(hDialogTemplate);

 

    return m_nModalResult;

}

 

void CDialog::EndDialog(intnResult)

{

    ASSERT(::IsWindow(m_hWnd));

 

    if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL))

       EndModalLoop(nResult);

 

    ::EndDialog(m_hWnd,nResult);

}

 

/////////////////////////////////////////////////////////////////////////////

// Standard CDialog implementation

 

LRESULT CDialog::HandleSetFont(WPARAMwParam, LPARAM)

{

    OnSetFont(CFont::FromHandle((HFONT)wParam));

    return Default();

}

 

void CDialog::PreInitDialog()

{

    // ignore it

}

 

LRESULT CDialog::HandleInitDialog(WPARAM,LPARAM)

{

    PreInitDialog();

 

#ifndef _AFX_NO_OCC_SUPPORT

    // create OLE controls

    COccManager* pOccManager = afxOccManager;

    if ((pOccManager !=NULL) && (m_pOccDialogInfo !=NULL))

    {

       BOOL bDlgInit;

       if (m_lpDialogInit !=NULL)

           bDlgInit = pOccManager->CreateDlgControls(this,m_lpDialogInit,

              m_pOccDialogInfo);

       else

           bDlgInit = pOccManager->CreateDlgControls(this,m_lpszTemplateName,

              m_pOccDialogInfo);

 

       if (!bDlgInit)

       {

           TRACE(traceAppMsg, 0,"Warning: CreateDlgControls failed during dialog init.\n");

           EndDialog(-1);

           return FALSE;

       }

    }

#endif

 

    // Default will call the dialog proc, and thus OnInitDialog

    LRESULT bResult = Default();

 

#ifndef _AFX_NO_OCC_SUPPORT

    if (bResult && (m_nFlags &WF_OLECTLCONTAINER))

    {

       CWnd* pWndNext = GetNextDlgTabItem(NULL);

       if (pWndNext !=NULL)

       {

           pWndNext->SetFocus();  // UI Activate OLE control

           bResult = FALSE;

       }

    }

#endif

 

    return bResult;

}

 

BOOL AFXAPIAfxHelpEnabled()

{

    if (AfxGetApp() ==NULL)

       return FALSE;

 

    // help is enabled if the app has a handler for ID_HELP

    AFX_CMDHANDLERINFO info;

 

    // check main window first

    CWnd* pWnd = AfxGetMainWnd();

    if (pWnd !=NULL && pWnd->OnCmdMsg(ID_HELP,CN_COMMAND, NULL, &info))

       return TRUE;

 

    // check app last

    return AfxGetApp()->OnCmdMsg(ID_HELP,CN_COMMAND, NULL, &info);

}

 

void CDialog::OnSetFont(CFont*)

{

    // ignore it

}

 

BOOL CDialog::OnInitDialog()

{

    // execute dialog RT_DLGINIT resource

    BOOL bDlgInit;

    if (m_lpDialogInit !=NULL)

       bDlgInit = ExecuteDlgInit(m_lpDialogInit);

    else

       bDlgInit = ExecuteDlgInit(m_lpszTemplateName);

 

    if (!bDlgInit)

    {

       TRACE(traceAppMsg, 0,"Warning: ExecuteDlgInit failed during dialog init.\n");

       EndDialog(-1);

       return FALSE;

    }

 

    // transfer data into the dialog from member variables

    if (!UpdateData(FALSE))

    {

       TRACE(traceAppMsg, 0,"Warning: UpdateData failed during dialog init.\n");

       EndDialog(-1);

       return FALSE;

    }

 

    // enable/disable help button automatically

    CWnd* pHelpButton = GetDlgItem(ID_HELP);

    if (pHelpButton !=NULL)

       pHelpButton->ShowWindow(AfxHelpEnabled() ?SW_SHOW : SW_HIDE);

 

    return TRUE;    // set focus to first one

}

 

void CDialog::OnOK()

{

    if (!UpdateData(TRUE))

    {

       TRACE(traceAppMsg, 0,"UpdateData failed during dialog termination.\n");

       // the UpdateData routine will set focus to correct item

       return;

    }

    EndDialog(IDOK);

}

 

void CDialog::OnCancel()

{

    EndDialog(IDCANCEL);

}

 

BOOL CDialog::CheckAutoCenter()

{

    // load resource as necessary

    LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;

    HGLOBAL hDialogTemplate = m_hDialogTemplate;

    if (m_lpszTemplateName !=NULL)

    {

       HINSTANCE hInst = AfxFindResourceHandle(m_lpszTemplateName,RT_DIALOG);

       HRSRC hResource = ::FindResource(hInst,m_lpszTemplateName, RT_DIALOG);

       hDialogTemplate = LoadResource(hInst, hResource);

    }

    if (hDialogTemplate !=NULL)

       lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);

 

    // determine if dialog should be centered

    BOOL bResult = TRUE;

 

    if (lpDialogTemplate !=NULL)

    {

       DWORD dwStyle = lpDialogTemplate->style;

       short x;

       short y;

 

       if (((DLGTEMPLATEEX*)lpDialogTemplate)->signature == 0xFFFF)

       {

           // it's a DIALOGEX resource

           dwStyle = ((DLGTEMPLATEEX*)lpDialogTemplate)->style;

           x = ((DLGTEMPLATEEX*)lpDialogTemplate)->x;

           y = ((DLGTEMPLATEEX*)lpDialogTemplate)->y;

       }

       else

       {

           // it's a DIALOG resource

           x = lpDialogTemplate->x;

           y = lpDialogTemplate->y;

       }

 

       bResult = !(dwStyle & (DS_CENTER|DS_CENTERMOUSE|DS_ABSALIGN)) &&

           x == 0 && y == 0;

    }

 

    // unlock/free resources as necessary

    if (m_lpszTemplateName !=NULL || m_hDialogTemplate !=NULL)

       UnlockResource(hDialogTemplate);

    if (m_lpszTemplateName !=NULL)

       FreeResource(hDialogTemplate);

 

    return bResult; // TRUE if auto-center is ok

}

 

/////////////////////////////////////////////////////////////////////////////

// CDialog support for context sensitive help.

 

LRESULT CDialog::OnCommandHelp(WPARAM,LPARAM lParam)

{

    if (lParam == 0 &&m_nIDHelp != 0)

       lParam = HID_BASE_RESOURCE + m_nIDHelp;

    if (lParam != 0)

    {

       CWinApp* pApp = AfxGetApp();

       if (pApp !=NULL)

           pApp->WinHelpInternal(lParam);

       return TRUE;

    }

    return FALSE;

}

 

LRESULT CDialog::OnHelpHitTest(WPARAM,LPARAM)

{

    if (m_nIDHelp != 0)

       return HID_BASE_RESOURCE + m_nIDHelp;

    return 0;

}

 

/////////////////////////////////////////////////////////////////////////////

// CDialog Diagnostics

 

#ifdef _DEBUG

void CDialog::AssertValid()const

{

    CWnd::AssertValid();

}

 

void CDialog::Dump(CDumpContext&dc) const

{

    CWnd::Dump(dc);

 

    dc << "m_lpszTemplateName = ";

    if (IS_INTRESOURCE(m_lpszTemplateName))

       dc << (int)LOWORD((DWORD_PTR)m_lpszTemplateName);

    else

       dc << m_lpszTemplateName;

 

    dc << "\nm_hDialogTemplate = " << (void*)m_hDialogTemplate;

    dc << "\nm_lpDialogTemplate = " << (void*)m_lpDialogTemplate;

    dc << "\nm_pParentWnd = " << (void*)m_pParentWnd;

    dc << "\nm_nIDHelp = " << m_nIDHelp;

 

    dc << "\n";

}

 

// diagnostic routine to check for and decode dialog templates

// return FALSE if a program error occurs (i.e. bad resource ID or

//   bad dialog styles).

BOOL AFXAPI_AfxCheckDialogTemplate(LPCTSTRlpszResource, BOOLbInvisibleChild)

{

    ASSERT(lpszResource !=NULL);

    HINSTANCE hInst = AfxFindResourceHandle(lpszResource,RT_DIALOG);

    HRSRC hResource = ::FindResource(hInst,lpszResource, RT_DIALOG);

    if (hResource ==NULL)

    {

       if (DWORD_PTR(lpszResource) > 0xffff)

           TRACE(traceAppMsg, 0,_T("ERROR: Cannot find dialog template named '%s'.\n"),

              lpszResource);

       else

           TRACE(traceAppMsg, 0,"ERROR: Cannot find dialog template with IDD 0x%04X.\n",

              LOWORD((DWORD_PTR)lpszResource));

       return FALSE;

    }

 

    if (!bInvisibleChild)

       return TRUE;        // that's all we need to check

 

    // we must check that the dialog template is for an invisible child

    //  window that can be used for a form-view or dialog-bar

    HGLOBAL hTemplate = LoadResource(hInst,hResource);

    if (hTemplate ==NULL)

    {

       TRACE(traceAppMsg, 0,"Warning: LoadResource failed for dialog template.\n");

       // this is only a warning, the real call to CreateDialog will fail

       return TRUE;        // not a program error - just out of memory

    }

    DLGTEMPLATEEX* pTemplate = (DLGTEMPLATEEX*)LockResource(hTemplate);

    DWORD dwStyle;

    if (pTemplate->signature == 0xFFFF)

       dwStyle = pTemplate->style;

    else

       dwStyle = ((DLGTEMPLATE*)pTemplate)->style;

    UnlockResource(hTemplate);

    FreeResource(hTemplate);

 

    if (dwStyle &WS_VISIBLE)

    {

       if (DWORD_PTR(lpszResource) > 0xffff)

           TRACE(traceAppMsg, 0,_T("ERROR: Dialog named '%s' must be invisible.\n"),

              lpszResource);

       else

           TRACE(traceAppMsg, 0,"ERROR: Dialog with IDD 0x%04X must be invisible.\n",

              LOWORD((DWORD_PTR)lpszResource));

       return FALSE;

    }

    if (!(dwStyle &WS_CHILD))

    {

       if (DWORD_PTR(lpszResource) > 0xffff)

           TRACE(traceAppMsg, 0,_T("ERROR: Dialog named '%s' must have the child style.\n"),

              lpszResource);

       else

           TRACE(traceAppMsg, 0,"ERROR: Dialog with IDD 0x%04X must have the child style.\n",

              LOWORD((DWORD_PTR)lpszResource));

       return FALSE;

    }

 

    return TRUE;

}

#endif //_DEBUG

IMPLEMENT_DYNAMIC(CDialog,CWnd)