别人的小冬冬

来源:互联网 发布:java 开源连接池 编辑:程序博客网 时间:2024/05/16 06:21
 最近有弄了个 838 在学 WM5编程 [原]

www.biplip.com
www.pocketpcdn.com
www.smartphonedn.com
www.xda-developers.com
www.codeproject.com
www.codeguru.com

一些小代码

获取系统通话记录的函数:

HRESULT PhoneOpenCallLog (HANDLE * ph);
HRESULT PhoneCloseCallLog (HANDLE h);
HRESULT PhoneGetCallLogEntry (HANDLE h, PCALLLOGENTRY pentry);

主要是最后一个,其中返回值:
ftStartTime, ftEndTime 开始结束时间。
iom:通话记录类型。 包括未接,已接,拔出
fConnected: 线路是否实际连上
fEnded 是否手动挂断(正常中止)
fRoam 是否漫游

======================================================================

音量相关

1)setVolume
//**********************************************************************
//Set The System Volume
//Steps (0,13107,26214,39321,52428,65535)
DWORD setVolume(DWORD dwVolume)
{
if (dwVolume > 0xFFFF)
dwVolume = 0xFFFF;

if (dwVolume < 0x0000)
dwVolume = 0x0000;

DWORD ret;
switch ((ret = waveOutSetVolume(0, dwVolume)))
{
case MMSYSERR_NOERROR:
break;
case MMSYSERR_ERROR:
break;
default :
break;
}

return 0;
}

2)getVolume
//**********************************************************************
//Get The System Volume
DWORD getVolume()
{
DWORD dwVolume;
DWORD ret;
switch ((ret = waveOutGetVolume(0, &dwVolume)))
{
case MMSYSERR_NOERROR:
break;
case MMSYSERR_ERROR:
break;
default :
break;
}

dwVolume = (dwVolume & 0xFFFF);

return dwVolume;
}

3)How can I change sound volume from my program?
//Read existing volume settings
DWORD dwSavedVolume;
waveOutGetVolume(NULL, &dwSavedVolume);

//Change sound volume
int dwCurVolumePercents = DWORD(0.5 + double(dwSavedVolume & 0xFFFF)*100 / double(0xFFFF));
dwSoundVolumePercents = dwCurVolumePercents-20;
if (dwSoundVolumePercents<0) {
dwSoundVolumePercents = 0;
}
DWORD dwNewVolumene = (DWORD)(0xFFFF*1.0*dwSoundVolumePercents/100.0);
waveOutSetVolume(NULL, dwNewVolumene);

//Write new volume settings
CVORegistry regVolume(HKEY_CURRENT_USER, _T("ControlPanel//Volume"));
regVolume.WriteDWORD(_T("Volume"), dwNewVolumene);

AudioUpdateFromRegistry();


//Turn the KeyClick on/off
HKEY hKey = NULL;
RegOpenKeyEx(HKEY_CURRENT_USER, _T("ControlPanel//Volume"), 0, 0, &hKey);
if (hKey)
{
DWORD dwValue = 0;
if (bKeyClick)
{
dwValue = 65538;
}
else
{
dwValue = 0;
}
RegSetValueEx(hKey, _T("Key"), 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
LPFNUPDATEAUDIOREG lpfnFunc = NULL;
HINSTANCE hCoreDll = LoadLibrary(TEXT("coredll.dll"));
if (hCoreDll)
{
lpfnFunc = (LPFNUPDATEAUDIOREG)GetProcAddress(hCoreDll, _T("AudioUpdateFromRegistry"));
if (lpfnFunc)
{
(lpfnFunc)();
}
FreeLibrary(hCoreDll);
}
RegCloseKey(hKey);
}

===========================================================================

获取当前剩余物理内存:
MEMORYSTATUS Status;
Status.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&Status);
return Status.dwAvailPhys;

获取电池电量剩余百分比:
SYSTEM_POWER_STATUS_EX stat;
GetSystemPowerStatusEx(&stat, TRUE);
if (stat.BatteryLifePercent > 100)
return -1;
else
return stat.BatteryLifePercent;

获取磁盘剩余空间:
GetDiskFreeSpaceEx(NULL,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);

=============================================================================

To lock the keypad (Smartphone):

TCHAR *name = _T("Tray");
HWND hwnd = FindWindow(name, NULL);
if (hwnd != 0)
SendMessage(hwnd, 0x312, 0x16D,0xc60000);



To unlock the keypad:
TCHAR *name = _T("Tray");
HWND hwnd = FindWindow(name, NULL);
if (hwnd != 0)      {
SendMessage(hwnd, 0x312, 0,    0x700000);
SendMessage(hwnd, 0x312, 0,    0x701000);
HWND hwnd = FindWindow(NULL, unlock);
if (hwnd != 0) {
SendMessage(hwnd, WM_KEYDOWN, VK_TPOUND, 1);
SendMessage(hwnd, WM_KEYUP,   VK_TPOUND, 1);
}
}

===========================================================================

修改情景模式:


Try calling DMProcessConfigXml and passing it the following xml:



<wap-provisioningdoc>
 <characteristic type="Registry">
  <characteristic type="HKCU/ControlPanel/Profiles">
   <parm name="ActiveProfile" value="Silent"/>
  </characteristic>
 </characteristic>
</wap-provisioningdoc>

=============================================================================

隐藏进程:

Remove the GUI.  Don't call CreateWindow.



Or, if you want to keep the GUI but just don't want it to show in Tasks,
give WS_EX_TOOLWINDOW style.  That should do it.

=============================================================================

关于震动API的问题

呵呵,用MSDN里面的例子代码没有效果:
Vibrate (0, NULL, TRUE, 2000); 运行以后没任何反映,检查返回值是E_NOTIMPL,
也就是说没有实现。呵呵,没有实现的示例,害人啊。

改为这样就好了:
Vibrate(0, NULL, TRUE, INFINITE);
::Sleep(2000);
VibrateStop();


程序代码以及经验积累

解决我遇到的各种问题时在网上找到的一些经验,代码片断等,具体来源很多,已经记不清楚了,如果有侵权的请及时指出。

我发一些到这里,希望对大家有帮助。都是c/c++方面的。

using STL with msevc

(STL = standard template library)
msevc v3.0 does not come standard with a STL implementation, a good STL port to windows CE is stl_evc
msevc v4.0 does have STL, problem is though that if you don't add "#pragma warning(disable: 4786)" you will get thousands of useless warnings. and also, the v4.0 stl uses exceptions, which will cause the compiler to complain that exceptions are not actually supported.
what is lacking in msevc is RTTI ( runtime type information ), because of this you cannot throw and catch exceptions in a standard C++ way. You can however use something that microsoft calls 'structured exception handling', with __try, __except, RaiseException, __finally.

==================================================================

how to trap the hardware phone buttons in PPC:

use GetAsyncKeyState(key), to poll the state of specific keys
these are the key codes for the xda:
// these constants are xda-specific:
#define VK_HANGUP 0x73 // VK_F4
#define VK_ANSWER 0x72 // VK_F5
#define VK_TOUCHPAD 0x01 // VK_LBUTTON
#define VK_VOLUME 0x75 // VK_F6

#define VK_TOPBUTTONS 0x5b // VK_LWIN
// VK_TOPBUTTONS is sent together with one of these:
#define VK_CALENDER 0xc1
#define VK_CONTACTS 0xc2

// note that when holding the navigator button down continuously,
// occasionally the OS will report no keys pressed down.

#define VK_NAVIGATOR_MOVE 0x84 // VK_F21
// VK_NAVIGATOR_MOVE is sent together with one of these:
#define VK_NAVIGATE_LEFT 0x25 // VK_LEFT
#define VK_NAVIGATE_UP 0x26 // VK_UP
#define VK_NAVIGATE_RIGHT 0x27 // VK_RIGHT
#define VK_NAVIGATE_DOWN 0x28 // VK_DOWN

#define VK_NAVIGATOR_SELECT 0x86 // VK_F23
#define VK_ONOFF 0xdf // VK_OFF

==============================================================

代码签名

代码签名(Code Signing)可以使开发人员和发布人员可以确保其基于Windows MobileTM操作系统的Smartphone手机上的应用程序在传递和执行的时候是安全可信的。
基于Windows MobileTM操作系统的Smartphone设备都内置了一定的应用程序安全级别,来验证需要安装的应用程序,根据不同的授权允许安装不同安全级别的应用程序,同时还可以保证Smartphone设备在安装应用程序时不会因为安装程序不完整或者缺失而导致系统的不稳定。
基于Windows MobileTM操作系统的Smartphone设备的应用程序安全级别设计的非常灵活,以便于可以满足各个不同移动运营商的需求。该安全级别主要可以分为拥有授权的和没有授权的两种,这两种级别在定义上的区分是应用程序在访问操作系统和系统API时有不同的要求:
 拥有授权:应用程序拥有高可信度的证书,可以完全访问到操作系统底层API。
 没有授权:应用程序拥有受限制的授权,并且受限访问操作系统底层API。
 不被信任:应用程序不允许在Smartphone设备上运行,并且不能访问系统底层API。

世界各地的移动运营商或者硬件设备生产厂商就会根据上述安全级别对自己Smartphone设备进行安全级别定义。对于定义安全级别较高的Smartphone设备,无法安装没有经过代码签名的应用程序。对于一般安全级别的Smartphone设备,安装没有经过代码签名的应用程序时会有明显的程序不被信任提示,会警告最终用户正在安装不安全的应用程序。而很少会有Smartphone设备被定义成低安全级别和无安全级别。
进行代码签名的另外一个优势是可以确保应用程序在传递和分发时的完整性和一致性。代码签名的规范要求独立软件开发商(ISV)将开发的应用程序关键文件都进行代码签名,并且对整个安装程序包进行代码签名。当安装程序包或者安装程序中的任何一个关键文件被无意或者非法修改之后,预先附着的代码签名就会失效。因此代码签名可以为软件产品提供很好的完整性和一致性保证,并且可以保护软件产品的版权。

===========================================================================

设置粗体字

// default GUI font helper
inline HFONT GetDefaultGuiFont()
{
return (HFONT)::GetStockObject(SYSTEM_FONT);
}

// bold font helper (NOTE: Caller owns the font, and should destroy it when done using it)
inline HFONT CreateBoldFont(HFONT hFont = NULL)
{
if(hFont == NULL)
hFont = GetDefaultGuiFont();

HFONT hFontBold = NULL;
LOGFONT lf = { 0 };
if(::GetObject(hFont, sizeof(LOGFONT), &lf) == sizeof(LOGFONT))
{
lf.lfWeight = FW_BOLD;
hFontBold = ::CreateFontIndirect(&lf);
}
else
{
}
return hFontBold;
}

============================================================================

这篇文章包括大量实用的代码和经验:
例如获取卡的目录,多语言支持,开始菜单,
获取系统颜色等等,十分推荐:

http://homepages.inspire.net.nz/~gambit/Article/
原创粉丝点击