最近公司有个项目,要求手机实现全屏,捣鼓了半天终于解决了。。
开发环境:Visual Studio 2005
SDK:POCKET PC, CE5.0, CE6.0
void CCEMainDlg::SetScreenMode(BOOL bFullScreen)
{
if (bFullScreen)
{
// 隐藏输入面板
SIPINFO si;
memset(&si, 0, sizeof(SIPINFO));
si.cbSize = sizeof(SIPINFO);
SHSipInfo(SPI_GETSIPINFO, 0, &si, 0);
if (si.fdwFlags & SIPF_ON)
{
si.cbSize = sizeof(SIPINFO);
si.fdwFlags = SIPF_OFF;
SHSipInfo(SPI_SETSIPINFO, 0, &si, 0);
}
// 隐藏命令栏
HWND hWnd = SHFindMenuBar(m_hWnd);
::CommandBar_Show(hWnd, FALSE);
// SHFullScreen fails if dialog box is not foreground.
SetForegroundWindow();
// 隐藏任务栏
SHFullScreen(m_hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON|SHFS_HIDESTARTICON);
// Resize the window over the taskbar area.
CRect rcScreen;
rcScreen.SetRect( 0,
0,
GetSystemMetrics( SM_CXSCREEN ),
GetSystemMetrics( SM_CYSCREEN ));
MoveWindow(&rcScreen, TRUE);
}
else
{
// 显示任务栏
SHFullScreen(m_hWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
// 显示命令栏
HWND hWnd = SHFindMenuBar(m_hWnd);
::CommandBar_Show(hWnd, TRUE);
// 显示任务栏
HWND hWndTaskBar = ::FindWindow(TEXT("HHTaskBar"), NULL);
if (hWndTaskBar != NULL)
{
::ShowWindow(hWndTaskBar, SW_SHOW);
}
}
}
BOOL CCEMainDlg::OnInitDialog()
{
m_bFullScreen = FALSE; // 这是个布尔变量,当它为TRUE时,对话框全屏;
// 为FALSE时,对话框为实际大小
CDialog::OnInitDialog();
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_FULLSCREENNOMENUBAR;
shidi.hDlg = m_hWnd;
::SHInitDialog(&shidi); //
SetScreenMode(TRUE); // 设置窗口全屏模式
...
}
BOOL CCEMonitorDlg::DestroyWindow()
{
...
SetScreenMode(FALSE); // 设置退出窗口全屏模式
...
}
提示:
如果主窗口上有其它子窗口的话,采用上面的代码的同时,加上这句话哦:
BOOL CCEChildDlg::OnInitDialog()
{
m_bFullScreen = FALSE; // 测试发下如果没这句话,还会导致整个窗口不能全屏的。。
CDialog::OnInitDialog();
...
}
参考资料:
http://blog.csdn.net/habit2/archive/2004/12/05/205283.aspx
http://support.microsoft.com/kb/266244/
关联问题:
全屏,但有些窗口要客户输入信息,郁闷,输入面板调不出来了。郁闷。。