VC小知识

来源:互联网 发布:周杰伦和吴宗宪 知乎 编辑:程序博客网 时间:2024/06/06 19:36

1.通过代码获得应用程序主窗口的指针

主窗口的指针保存在CWinThread::m_pMain中,调用AfxGetMainWnd()函数实现。

AfxGetMainWnd->ShowWindow(SW_SHOWMAXMIZED)     //使程序最大化

2.改变窗口的图标

向窗口发送WM_SECTION消息。

举例:

HICON hIcon = AfxGetApp()->LoadIcon(IDI_ICON)

ASSERThIcon);

AfxGetMainWnd()->SendMessage(WM_SECTION, TRUE, (LPARAM)hIcon);

3.改变窗口缺省的风格

重载CWnd::PreWindow并修改CREATESTRUCT结构来指定窗口风格和其他创建信息。

举例:Delete "Max"Button and St Original

Window's Position and Size

BOOL CMainFrame::PreWindow (CREATESTRUCT &cs)

{

cs.style &= ~WS_MAXINIZEMOX;

cs.x = cs.y = 0;

cs.cx = GetSystemMetrics(SM_CXSCREEN/2);

cs.cy = GetSystemMetrics(SM_CYSCREEN/2);

Return CMDIFramewnd::PreWindow(cs);

}

4.将窗口居中显示.

举例: 调用函数:CWnd::Center Windows

1.Center Window();  //Relative to its parent

2.Center WindowCWnd::GetDesktopWindow()); // 相对于屏幕

AfxGetMainWnd()->Center Window//相对于应用程序主窗口