如何有效的使用对话框之二 visible = false;(1.2)重载 WM_WINDOWPOSCHANGING,并添加下面代码: void CTest_deleteDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { if(!visible) lpwndpos->flags &= ~SWP_SHOWWINDOW; CDialog::OnWindowPosChanging(lpwndpos);} (1.3)然后设布尔visible变量值为true,并在要显示窗口时,再用ShowWindow(SW_SHOW)既可。visible = true;ShowWindow(SW_SHOW); 对话框的全屏显示可以在OnInitDialog()中用 SetWindowPos 和 HWND_TOPMOST 来实现对话框的重新大小。 BOOL CFullScrDlgDlg::OnInitDialog(){ CDialog::OnInitDialog(); //... int cx, cy; HDC dc = ::GetDC(NULL); cx = GetDeviceCaps(dc,HORZRES) + GetSystemMetrics(SM_CXBORDER); cy = GetDeviceCaps(dc,VERTRES) + GetSystemMetrics(SM_CYBORDER); ::ReleaseDC(0,dc); //去除标题和边框 SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & (~(WS_CAPTION | WS_BORDER))); // 置对话框为最顶端并扩充到整个屏幕 ::SetWindowPos(m_hWnd, HWND_TOPMOST, -(GetSystemMetrics(SM_CXBORDER)+1), -(GetSystemMetrics(SM_CYBORDER)+1), cx+1,cy+1, SWP_NOZORDER); //... return TRUE; } 在2K/XP下我们可以用 AttachThreadInput 和SetForegroundWindow来有效的获取焦点。 //捕捉并设置当前焦点窗口为我们的窗口AttachThreadInput( GetWindowThreadProcessId( ::GetForegroundWindow(),NULL), GetCurrentThreadId(),TRUE);//置我们的为焦点窗口SetForegroundWindow();SetFocus(); //释放threadAttachThreadInput( GetWindowThreadProcessId( ::GetForegroundWindow(),NULL), GetCurrentThreadId(),FALSE); 可以直接在 OnInitDialog()中用SetWindowPos来实现。 SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);5. 如何动态放大/缩小对话框 还是可以用SetWindowPos或MoveWindow来实现它。 void CTest_deleteDlg::OnMakeSmall() { SetWindowPos(NULL,0,0,200,200,SWP_NOZORDER|SWP_NOMOVE); }void CTest_deleteDlg::OnExpand() { SetWindowPos(NULL,0,0,500,300,SWP_NOZORDER|SWP_NOMOVE); } 或://伸、缩在IDC_DYCREDITS和IDC_COPYRIGHT两STATIC控件间,做为分隔线BOOL CAbout::OnInitDialog() { CDialog::OnInitDialog();//"关于"对话框中对话框可收缩效果 CRect Rect1,Rect2; //对话框收缩时大小 GetDlgItem(IDC_DYCREDITS)->GetWindowRect(Rect1); GetDlgItem(IDC_COPYRIGHT)->GetWindowRect(Rect2); m_nReducedHeight = Rect1.Height()+(Rect1.top -Rect2.bottom)/2; //收缩后窗体高度 dlgRect.bottom -= (Rect1.Height()+(Rect1.top -Rect2.bottom)/2); MoveWindow(&dlgRect); //如果要显示对话框起始动态效果的话,不能使用该句 m_bVertical=false; //默认收缩对话框}// ---------------------------------------------------------// 名称: OnMore// 功能: 是否允许显示// 变量: 无// 返回: 无// 编写: 徐景周,2002.4.8// ---------------------------------------------------------void CAbout::OnMore() { m_bVertical = !m_bVertical; if(m_bVertical == FALSE) //不显示 { SetDlgItemText(ID_MORE,_T("更多>>")); SizeWindow(m_nReducedHeight,true);// m_DyCredits.En
|
0
顶一下

发表评论
告诉好友