Well, i'd like to share with community this piece of code i made in order to get device orientation (as said fast_rx, is NOT the pockethal one!)
Starting from this code, i'm going to code a correct stylus/dpad mapping also for devices not in portrait mode (as soon fast_rx confirms me that he had to modify PFrog too

)
Basically it's only an API call, but this is available only on PPC2003 Second Edition devices and later so this code try to call the function dynamically and works well also on ppc2002 and ppc2003 and it compiles well also on EVC++3.
This code is a patch for pocketfrog 0.8.1 source.
In game.h find struct Config and add:
- Code:
int iDeviceScreenRotation;
So it will look like:
- Code:
// Configuration
struct Config
{
LPCTSTR szWindowName; // Window title
Orientation orientation; // Screen orientation (default = ORIENTATION_NORTH)
int iDeviceScreenRotation; // device orientation
}
In game.cpp add this code on in Game::Init (i added it just before):
- Code:
// Init input
if (!PHAL::GetKeyList( &m;_keys, m_config.orientation ))
return false;
I had to declare also some structs that the API call will fill because they're not present in ppc2002 sdk.
- Code:
/////////////////////////////////////////////////
//
//
// Detect pocketpc screen orientation
// this is NOT the pockethal one!
#if defined(FROG_PPC)
typedef struct d_evicemodeA {
BYTE dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
BYTE dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
DWORD dmDisplayFlags;
DWORD dmDisplayFrequency;
DWORD dmICMMethod;
DWORD dmICMIntent;
DWORD dmMediaType;
DWORD dmDitherType;
DWORD dmICCManufacturer;
DWORD dmICCModel;
DWORD dmPanningWidth;
DWORD dmPanningHeight;
DWORD dmDisplayOrientation;
} DEVMODEA_WM5, *PDEVMODEA_WM5, *NPDEVMODEA_WM5, *LPDEVMODEA_WM5;
typedef struct d_evicemodeW {
WCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
WCHAR dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
DWORD dmDisplayFlags;
DWORD dmDisplayFrequency;
DWORD dmDisplayOrientation;
} DEVMODEW_WM5, *PDEVMODEW_WM5, *NPDEVMODEW_WM5, *LPDEVMODEW_WM5;
#ifdef UNICODE
typedef DEVMODEW_WM5 DEVMODE_WM5;
typedef PDEVMODEW_WM5 PDEVMODE_WM5;
typedef NPDEVMODEW_WM5 NPDEVMODE_WM5;
typedef LPDEVMODEW_WM5 LPDEVMODE_WM5;
#else
typedef DEVMODEA_WM5 DEVMODE_WM5;
typedef PDEVMODEA_WM5 PDEVMODE_WM5;
typedef NPDEVMODEA_WM5 NPDEVMODE_WM5;
typedef LPDEVMODEA_WM5 LPDEVMODE_WM5;
#endif
// start DLL API call
typedef LONG (CALLBACK* LPFNDLLFUNC1)(LPCTSTR, LPDEVMODE_WM5, HWND, DWORD, LPVOID);
LPFNDLLFUNC1 lpfnDllFunc1;
HINSTANCE h = LoadLibrary(_T("CoreDLL.dll"));
if (h != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(h,_T("ChangeDisplaySettingsEx"));
if (lpfnDllFunc1) {
/*DEVMODE */DEVMODE_WM5 devmode = {0};
devmode.dmSize = sizeof(DEVMODE_WM5);
devmode.dmFields = /*DM_DISPLAYORIENTATION*/0x00800000L;
lpfnDllFunc1(NULL, &devmode;, 0, /*CDS_TEST*/0x00000002, NULL);
if (devmode.dmDisplayOrientation==0 /*DMDO_0*/)
m_config.iDeviceScreenRotation=0;
else if (devmode.dmDisplayOrientation==1 /*DMDO_90*/)
m_config.iDeviceScreenRotation=90;
else if (devmode.dmDisplayOrientation==2 /*DMDO_180*/)
m_config.iDeviceScreenRotation=180;
else if (devmode.dmDisplayOrientation==4 /*DMDO_270*/)
m_config.iDeviceScreenRotation=270;
else
m_config.iDeviceScreenRotation=0;
} else {
// GetProcAddress failed! We'll assume standard orientation
m_config.iDeviceScreenRotation=0;
}
FreeLibrary(h);
} else {
// LoadLibrary failed - we'll assume standard orientation
m_config.iDeviceScreenRotation=0;
}
#else
// On desktop, assume always standard orientation
m_config.iDeviceScreenRotation=0;
#endif
//
//
// End of PocketPC Screen orientation detect
/////////////////////////////////////////////////
Now on my pfrog games, i can get real pocketpc orientation with:
- Code:
m_config.iDeviceScreenRotation
it will be 0,90,180,270 according to current device orientation.
While with:
- Code:
m_config.orientation
i have PocketHal screen orientation
I tested on my wm5 device and it gave correct values on all orientations, i don't know if this will be useful for someone, but who knows..
