在CDialog和CWnd中使用Create动态创建一个窗体的方式
class CDisplayDlg : public CDialog
{
/* Construct function */
CDisplayDlg(CWnd* pParent = NULL)
{
RECT rRect = {0, 0, DSP_SCREEN_WIDTH, DSP_SCREEN_HEIGHT};
CWnd* pWnd = NULL;
if ( GetDlgItem(IDC_STATIC_SHOW) == NULL )
{
if ( this->m_ShowPic.Create((LPCTSTR)_T("STATIC_SHOW"),
(DWORD)(WS_CHILD | WS_VISIBLE),
rRect,
this,
IDC_STATIC_SHOW))
{
this->m_ShowPic.ShowWindow(SW_SHOW);
pWnd = &this->m_ShowPic;
/* WINDOW_WIDTH + 1 is necessary,but the reason is uncertainty */
::SetWindowPos(GetDlgItem(IDC_STATIC_SHOW)->m_hWnd, HWND_TOPMOST, 0, 0, DSP_SCREEN_WIDTH + 1, DSP_SCREEN_HEIGHT, (UINT)SWP_NOMOVE);
this->SetFocus();
}
}
}
CStatic m_ShowPic;
}
class CViewCameraDetection : public CWnd
{
/* Construct function */
CViewCameraDetection(CWnd* pParentWnd)
{
this->m_pParentWnd = pParentWnd;
RECT rRect = {0, 0, WINDOW_WIDTH, WINDOW_HIGHT};
/** - 2.Create a new Form. */
if ( !this->Create((LPCTSTR)_T("STATIC"),
NULL,
(DWORD)(WS_CHILD | WS_VISIBLE),
rRect,
pParentWnd,
(UINT)0))
{
throw CCommonException(EFW_IO_ERROR, _T("%S(%d)-%S:Form created Fail!\r\n"), THROWARGS);
}
this->ShowWindow(SW_HIDE);
}
}
CDialog 继承 CWnd,CStatic继承CWnd,但是CDialog改写了Create