#include "stdafx.h"
#include "CeDebug.h"
#include "CeMisc.h"
#include "CeModule.h"
HWND CeGetAppWindow()
{
CeAppModule* pApp = CeAppModule::CeGetApp();
if (NULL == pApp || NULL == pApp->GetMainWindow())
// this windows in probably the active windows, since the GUI probably
// wouldn't even be active if it weren't top level
return GetActiveWindow();
else
// the user assigned a main window, use it
return pApp->GetMainWindow();
}
HINSTANCE CeGetAppInstance()
{
#if (_WIN32_WCE >= 210) || !UNDER_CE
return (HINSTANCE) GetModuleHandle(NULL);
#elif _WIN32_WCE_EMULATION
MEMORY_BASIC_INFORMATION mbi={0};
VirtualQuery(CeGetAppInstance, &mbi, sizeof mbi);
return (HINSTANCE) mbi.AllocationBase;
#else
return (HINSTANCE) GetCurrentProcessId();
#endif
}
#ifdef _WIN32_WCE_PSPC
#include <aygshell.h>
BOOL CeShowSip(BOOL bShow)
{
SIPINFO si;
memset(&si,0, sizeof(si)); // to initialize si to zero.
si.cbSize = sizeof(si);
if ( SHSipInfo( SPI_GETSIPINFO, 0, &si, 0))
{
if(bShow)
si.fdwFlags |= SIPF_ON;
else
si.fdwFlags &= ~SIPF_ON;
return SHSipInfo( SPI_SETSIPINFO, 0, &si, 0);
}
return FALSE;
}
BOOL CeSipSizeWindow( HWND hwnd )
{
SIPINFO si;
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
if ( SHSipInfo( SPI_GETSIPINFO, 0, &si, 0) )
{
CeRect rc = si.rcVisibleDesktop;
MoveWindow( hwnd, rc.left, rc.top, rc.Width(), rc.Height(), TRUE);
return TRUE;
}
return FALSE;
}
BOOL CeSipCenterWindow( HWND hwnd )
{
// if (GetParent(hwnd))
// // only top level windows!!!
// return FALSE;
SIPINFO si;
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
if ( SHSipInfo( SPI_GETSIPINFO, 0, &si, 0) )
{
CeRect rc;
GetWindowRect(hwnd, &rc);
// center within open screen coordinates
CeRect rcArea = si.rcVisibleDesktop;
// find dialog's upper left based on rcCenter
int xLeft = (rcArea.Width()) / 2 - rc.Width() / 2;
int yTop = (rcArea.Height()) / 2 - rc.Height() / 2;
// if the dialog is outside the screen, move it inside
if (xLeft < rcArea.left)
xLeft = rcArea.left;
else if(xLeft + rc.Width() > rcArea.right)
xLeft = rcArea.right - rc.Width();
if (yTop < rcArea.top)
yTop = rcArea.top;
else if(yTop + rc.Height() > rcArea.bottom)
yTop = rcArea.bottom - rc.Height();
MoveWindow(hwnd, xLeft, yTop, rc.Width(), rc.Height(), TRUE);
return TRUE;
}
return FALSE;
}
#endif