WINCE中的一些常用代码
一、窗口全屏显示,去掉任务栏
创新互联公司于2013年创立,先为海原等服务建站,海原等地企业,进行企业商务咨询服务。为海原企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
//全屏显示 //隐藏HHTaskBar窗口代码如下: HWND hTaskBar = ::FindWindow(TEXT("HHTaskBar"), NULL); if (hTaskBar != NULL) { ::EnableWindow(hTaskBar, FALSE); ::ShowWindow(hTaskBar, SW_HIDE); } int iFullWidth = GetSystemMetrics(SM_CXSCREEN); int iFullHeight = GetSystemMetrics(SM_CYSCREEN); ::SetWindowPos(this->m_hWnd, HWND_TOPMOST, 0, 0, iFullWidth, iFullHeight, SWP_NOOWNERZORDER|SWP_SHOWWINDOW);
二、获取当前程序路径
CString CscaleweightDlg::GetAppllicationPath() { WCHAR buff[255]={0}; ::GetModuleFileName(0,buff,255); CString strAppFullName; strAppFullName.Format(_T("%s"),buff); CString strAppPath = _T(""); strAppPath = strAppFullName.Left(strAppFullName.ReverseFind('\\')+1); return strAppPath; }
三、加载字库
//加载字体 CString strFontPath = GetAppllicationPath()+_T("msyh.ttf"); if (NULL != AddFontResource(strFontPath)) { ::SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0); } else { AfxMessageBox(L"字体加载失败"); }
程序退出时,卸载字库
CString strFontPath = GetApplicationPath()+_T("msyh.ttf"); if(RemoveFontResource(strFontPath)) { ::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0); } else AfxMessageBox(L"Failed to UNLOAD font!");
四、加载位图用LoadImage无效
HBITMAP hBitmap = (HBITMAP)::SHLoadDIBitmap(szBitmapFile);
五、要以共享MFC的DLL库的方式发布程序,须将如下目录中DLL全部复制到目标机器上。
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\ce\Dll\armv4i
六、wchar_t*转char*
如,sCaption为 LPCTSTR类型字符串,要转成char *字符串,如下:
int num = WideCharToMultiByte(CP_OEMCP, NULL, sCaption, -1, NULL, 0, NULL, FALSE); char *pChar = new char[num]; WideCharToMultiByte(CP_OEMCP, NULL, sCaption, -1, pChar, num, NULL, FALSE);
七、字体平滑,需要修改注册表
HKEY_LOCAL_MACHINE\\System\\GDI\\ClearType Default=2
八、不关闭屏幕,常期显示工作界面
//电源参数请求更新 HANDLE hevReloadActivityTimeouts = OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("PowerManager/ReloadActivityTimeouts")); if (hevReloadActivityTimeouts) { SetEvent(hevReloadActivityTimeouts); CloseHandle(hevReloadActivityTimeouts); }
同时,在注册表中也要修改超时设置。
九、Sqlite数据库读写
void CSimpleModeData::TempTableWrite(CString CarNo,CString strWeight,CString GoodsName, CString Time) { CString str ; str.Format(_T("insert into SimpleModeTempTable(CarNo,GoodsName,Weight,Time)\ values('%s','%s','%s','%s')"),CarNo,strWeight,GoodsName, Time); TRACE(str); m_sqliteDB.execQuery(str); } BOOL CSimpleModeData::TempTableRead(CString strCarNo) { CString str ; str.Format(_T("select * from SimpleModeTempTable where CarNo = '%s'")); TRACE(str); CppSQLite3Query query = m_sqliteDB.execQuery(str); if(!query.eof()) { wcscpy_s(CGlobal::g_TempTable.CarNo,20,query.fieldValue(1)); wcscpy_s(CGlobal::g_TempTable.GoodsName,20 ,query.fieldValue(2)); wcscpy_s(CGlobal::g_TempTable.Weight,20,query.fieldValue(3)); return TRUE; } query.finalize(); return FALSE; }
十、软件重启
#include "windows.h" #include "winioctl.h" #define POWER_STATE_RESET (DWORD)(0x00800000) #define POWER_FORCE (DWORD)(0x00001000) extern "C" __declspec(dllimport) DWORD SetSystemPowerState(LPCWSTR pwsSystemState, DWORD StateFlags,DWORD Options); void CtestDlg::OnBnClickedButton2() { SetSystemPowerState(NULL, POWER_STATE_RESET, POWER_FORCE); }
十一、字符串转浮点数
_tstof在WinCE中未实现,需要自己实现。如果转成double型可以如下:
double StringToDouble(LPCTSTR lpszSrc) { TCHAR * endptr; return _tcstod(lpszSrc, &endptr); }
网站题目:WINCE中的一些常用代码
链接URL:http://scyanting.com/article/gdpjid.html