锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
浣滆咃細
嫻呰皥wince搴旂敤紼嬪簭鐨勫彲縐繪鎬?/font>
聽聽聽聽聽 鐢變簬windows緇濆ぇ澶氭暟鎯呭喌涓嬭繍琛屼簬X86騫沖彴涓婏紝涔熷氨涓嶅瓨鍦ㄤ笉鍚屽鉤鍙扮殑鍙Щ妞嶆ч棶棰樸傜劧鑰學indows CE榪愯鍦ㄥ洓澶ф灦鏋勶紙X86錛孲Hx錛孧IPS錛孉RM錛夌殑CPU涓婏紝緙栧啓搴旂敤紼嬪簭鏃跺氨闇瑕佽冭檻瀹冪殑縐繪銆?br />聽聽聽聽聽聽 浠ヤ笅閫氳繃鍦╳ince緋葷粺涓嬭闂墿鐞嗗湴鍧錛屾潵鐪嬬湅濡備綍緙栧啓鍙Щ妞嶆ц緝濂界殑搴旂敤紼嬪簭銆?br />聽聽聽聽聽聽 棣栧厛蹇呴』鏄庣‘涓や釜姒傚康銆?br />聽聽聽聽聽聽 1銆傚湪X86騫沖彴涓嬫墠鏈塈/O鍦板潃榪欎竴璇達紝鍦ㄥ叾浠栦綋緋葷殑CPU錛堝ARM/MIPS錛変笅鏄病鏈塈/O绔彛鐨勩傚洜涓篨86涓嬫妸I/O鍜屽瓨鍌ㄥ櫒鍒嗗紑緙栧潃錛屽鑷村叾鏈変袱縐嶅湴鍧錛涜屽埆鐨凜PU鏄妸涓よ呯粺涓緙栧潃錛屽嵆鎶奍/O鏄犲皠鍒板瓨鍌ㄥ櫒涓娿?br />聽聽聽聽聽聽聽 2銆倃ince鐨勫瓨鍌ㄧ鐞嗘槸閫氳繃MMU瀹炵幇鐨勶紝鍦ㄧ郴緇熷惎鍔ㄥ悗錛屾垜浠彧鑳借闂櫄鎷熷瓨鍌ㄧ┖闂達紝蹇呴』緇忚繃MMU銆備絾鏄湪X86涓嬶紝璁塊棶I/O鍙e拰瀛樺偍鍣ㄨ蛋鐨勫湴鍧鎬葷嚎涓嶅悓錛屼笉鐢ㄧ粡榪嘙MU銆?br />聽聽聽聽聽聽聽聽聽姣斿鎴戜滑鎯寵璁塊棶鎸傚湪鏌愭葷嚎涓婄墿鐞嗗湴鍧涓?60h鐨勭鍙o紝瀵逛簬X86騫沖彴鎴戜滑鍙互鐩存帴宓屽叆姹囩紪鎿嶄綔鐗╃悊鍦板潃錛?鎴栬呬嬌鐢ㄥ湴鍧鎸囬拡璁塊棶鐗╃悊鍦板潃銆備絾瀵逛簬鍏朵粬騫沖彴錛屾垜浠繀欏誨厛浣滀竴涓墿鐞嗗湴鍧鍒拌櫄鎷熷湴鍧鐨勬槧灝勶紝鐒跺悗鎿嶄綔鍏惰櫄鎷熷湴鍧銆傝繖鏍鋒樉鐒剁▼搴忕殑鍙Щ妞嶆т笉濂斤紝鎴戜滑闇瑕佸畾涔壜?#ifdef __x86....#elif defined __arm聽 浣垮緱鍦ㄤ笉鍚屽鉤鍙頒笅紼嬪簭鑳藉欏哄埄榪愯銆?br />聽聽聽聽聽聽聽聽聽 濡傛灉浣跨敤涓嬮潰鐨勪唬鐮佹垜浠氨鍙互涓嶇敤榪欎箞璐瑰姴鐨勫畾涔変笉鍚屽鉤鍙頒簡錛?br />聽聽聽聽聽聽聽聽鍏堝畾涔?br />聽聽聽聽 inIoSpace = 1;
聽聽聽 ioPhysicalBase.QuadPart = 0x360;
if( HalTranslateBusAddress( Isa,聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //姝ゅ嚱鏁版妸ISA鎬葷嚎涓婄墿鐞嗗湴鍧鏄犲皠涓虹郴緇熺墿鐞嗗湴鍧
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 0,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ioPhysicalBase,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 &inIoSpace,聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //姝ゅ弬鏁?1璇存槑杞寲鐨勬槸I/O絀洪棿鍦板潃錛?0鏃跺瓨鍌ㄥ櫒鍦板潃
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 &ioPhysicalBase ) )
{
聽聽聽 if( !inIoSpace )聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ////濡傛灉鏄瓨鍌ㄥ櫒鍦板潃錛岄拡瀵歸潪X86 騫沖彴
聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 ioPortBase = ( PUCHAR ) MmMapIoSpace(聽聽聽聽聽聽聽聽聽聽聽 //姝ゅ嚱鏁版妸緋葷粺鐗╃悊鍦板潃杞寲涓鴻櫄鎷熷湴鍧
聽聽聽聽聽聽聽聽聽聽聽 ioPhysicalBase,
聽聽聽聽聽聽聽聽聽聽聽 IoLen,
聽聽聽聽聽聽聽聽聽聽聽 FALSE );
聽聽聽聽聽聽聽 if( ioPortBase == NULL )
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 //TODO: Error handling
聽聽聽聽聽聽聽 }
聽聽聽 }
聽聽聽 else聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //濡傛灉鏄疘/O錛屽嵆X86聽涓嬶紝涓嶉渶瑕佸仛鍦板潃鏄犲皠
聽聽聽 {
聽聽聽聽聽聽聽 ioPortBase = ( PUCHAR ) ioPhysicalBase.LowPart;
聽聽聽 }
}
else
{
聽聽聽 //TODO: Error Handling
}
聽聽聽聽聽聽聽闅忓悗瀵逛簬绔彛鐨勬搷浣滐紙 ioPortBase錛夛紝鎴戜滑涔熷彲浠ュ厖鍒嗘寲鎺樺畠鐨勫彲縐繪鎬с傞氳繃浣跨敤READ_PORT_UCHAR,
WRITE_PORT_UCHAR榪欎簺wince涓嬬殑瀹忔潵瀹炵幇绔彛璇誨啓銆傝屼笉鏄湪X86涓嬬敤鎸囬拡鎿嶄綔錛堜笉浠呯Щ妞嶆у樊錛岃屼笖瀹規槗浜х敓闂錛夈侰E涓嬬殑瀹忓湪鍐呴儴鏄皝瑁呭ソ鐨凙PI鍑芥暟銆備緥濡俉RITE_PORT_UCHAR榪欎釜瀹忓湪X86 澶勭悊鍣ㄤ笂杞寲涓轟竴鏉UT鐨勬眹緙栨寚浠わ紱鑰屽湪ARM澶勭悊鍣ㄤ笂浼氳漿鍖栨垚涓鏉″铏氭嫙鍦板潃鐨勫啓鎸囦護銆?
鍦ㄨ繘琛宑e鐨勫紑鍙戞椂錛岀粡甯歌璁″埌瀛楃鐨勮漿鎹紝鐗瑰埆鏄郴緇熶腑鍖呭惈緗戠粶閫氳鏃訛紝鏇存槸濡傛銆俢e涓潎鏄疷nicode緙栫爜錛岃岀綉緇滈氳涓鑸兘浣跨敤BYTE榪涜鏁版嵁浼犺緭銆?/p>
浠ヤ笅鏄湪緗戜笂鎵懼埌鐨勪竴綃囨枃绔狅紝浠嬬粛鐨勫緢璇︾粏銆?/p>
聽1.浣跨敤鏂規硶璇﹁В
聽 鍦ㄦ湰鏂囧紑濮嬩箣澶?鍏堢畝瑕佸湴璇翠竴涓嬩綍涓虹煭瀛楃鍜屽瀛楃.
聽 鎵璋撶殑鐭瓧絎?灝辨槸鐢?bit鏉ヨ〃紺虹殑瀛楃,鍏稿瀷鐨勫簲鐢ㄦ槸ASCII鐮?鑰屽瀛楃,欏懼悕鎬濅箟,灝辨槸鐢?6bit琛ㄧず鐨勫瓧絎?鍏稿瀷鐨勬湁UNICODE.鍏充簬windows涓嬬殑ASCII鍜孶NICODE鐨勬洿澶氫俊鎭?鍙互鍙傝冭繖涓ゆ湰緇忓吀钁椾綔:銆妛indows 紼嬪簭璁捐銆?銆妛indows 鏍稿績緙栫▼銆?榪欎袱鏈功鍏充簬榪欎袱縐嶅瓧絎﹂兘鏈夋瘮杈冭緇嗙殑瑙h.
聽
聽 瀹藉瓧絎﹁漿鎹負澶氫釜鐭瓧絎︽槸涓涓毦鐐?涓嶈繃鎴戜滑鍙鎺屾彙鍒板叾涓殑瑕侀,渚垮彲濡傞奔寰楁按.
聽 濂藉惂,閭e氨璁╂垜浠紑濮嬪惂.
聽
聽 榪欎釜鏄垜浠渶瑕佽漿鍖栫殑澶氬瓧鑺傚瓧絎︿覆: 聽
聽 char sText[20] = {"澶氬瓧鑺傚瓧絎︿覆!OK!"};
聽
聽 鎴戜滑闇瑕佺煡閬撹漿鍖栧悗鐨勫瀛楃闇瑕佸灝戜釜鏁扮粍絀洪棿.铏界劧鍦ㄨ繖涓噷紼嬮噷闈?鎴戜滑鍙互鐩存帴瀹氫箟涓涓?0*2瀹藉瓧絎︾殑鏁扮粍,騫朵笖浜嬪疄涓婂皢榪愯寰楅潪甯歌交鏉炬剦蹇?浣嗗亣濡傚瀛楄妭瀛楃涓叉洿澶?杈懼埌涓婂崈涓箖鑷充笂涓囦釜,鎴戜滑灝嗕細鍙戠幇鍏朵腑嫻垂鐨勫唴瀛樺皢浼氳秺鏉ヨ秺澶?鎵浠ヤ互澶氬瓧鑺傚瓧絎︾殑涓暟鐨勪袱鍊嶄綔涓哄瀛楃鏁扮粍涓嬫爣鐨勫0鏄庣粷瀵逛笉鏄竴涓ソ涓繪剰.
聽 鎵騫?鎴戜滑鑳藉紜煡鎵闇瑕佺殑鏁扮粍絀洪棿.
聽 鎴戜滑鍙渶瑕佸皢MultiByteToWideChar()鐨勭鍥涗釜褰㈠弬璁句負-1,鍗沖彲榪斿洖鎵闇鐨勭煭瀛楃鏁扮粍絀洪棿鐨勪釜鏁?
聽 DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, sText, -1, NULL, 0);
聽
聽 鎺ヤ笅鏉?鎴戜滑鍙渶瑕佸垎閰嶅搷搴旂殑鏁扮粍絀洪棿:
聽 wchar_t *pwText;
聽 pwText = new wchar_t[dwNum];
聽 if(!pwText)
聽 {
聽聽 delete []pwText;
聽 }
聽
聽 鎺ョ潃,鎴戜滑灝卞彲浠ョ潃鎵嬭繘琛岃漿鎹簡.鍦ㄨ繖閲屼互杞崲鎴怉SCII鐮佸仛涓轟緥瀛?
聽 MultiByteToWideChar (CP_ACP, 0, psText, -1, sText, dwSize);
聽
聽 鏈鍚?浣跨敤瀹屾瘯褰撶劧瑕佽寰楅噴鏀懼崰鐢ㄧ殑鍐呭瓨:
聽 delete []psText;
聽
聽
聽 鍚岀悊,瀹藉瓧絎﹁漿涓哄瀛楄妭瀛楃鐨勪唬鐮佸涓? 聽
聽 wchar_t wText[20] = {L"瀹藉瓧絎﹁漿鎹㈠疄渚?OK!"};
聽 DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,NULL,0,NULL,FALSE);
聽 char *psText;
聽 psText = new char[dwNum];
聽 if(!psText)
聽 {
聽聽 delete []psText;
聽 }
聽 WideCharToMultiByte (CP_OEMCP,NULL,lpcwszStr,-1,psText,dwNum,NULL,FALSE);
聽 delete []psText;
聽
聽聽 濡傛灉涔嬪墠鎴戜滑宸茬粡鍒嗛厤濂界┖闂?騫朵笖鐢變簬瀛楃涓茶緝鐭?鍙互涓嶇悊浼氭氮璐圭殑絀洪棿,浠呬粎鍙槸鎯崇畝鍗曞湴灝嗙煭瀛楃鍜屽瀛楃鐩鎬簰杞崲,閭f湁娌℃湁浠涔堢畝渚跨殑鏂規硶鍛?
聽聽 WIN32 API閲屾病鏈夌鍚堣繖縐嶈姹傜殑鍑芥暟,浣嗘垜浠彲浠ヨ嚜宸辮繘琛屽皝瑁?
聽聽聽 聽
聽 //-------------------------------------------------------------------------------------
聽 //Description:
聽 // This function maps a character string to a wide-character (Unicode) string
聽 //
聽 //Parameters:
聽 // lpcszStr: [in] Pointer to the character string to be converted
聽 // lpwszStr: [out] Pointer to a buffer that receives the translated string.
聽 // dwSize: [in] Size of the buffer
聽 //
聽 //Return Values:
聽 // TRUE: Succeed
聽 // FALSE: Failed
聽 //
聽 //Example:
聽 // MByteToWChar(szA,szW,sizeof(szW)/sizeof(szW[0]));
聽 //---------------------------------------------------------------------------------------
聽 BOOL MByteToWChar(LPCSTR lpcszStr, LPWSTR lpwszStr, DWORD dwSize)
聽 {
聽聽聽 // Get the required size of the buffer that receives the Unicode
聽聽聽 // string.
聽聽聽 DWORD dwMinSize;
聽聽聽 dwMinSize = MultiByteToWideChar (CP_ACP, 0, lpcszStr, -1, NULL, 0);
聽
聽聽聽 if(dwSize < dwMinSize)
聽聽聽 {
聽聽聽聽 return FALSE;
聽聽聽 }
聽
聽聽 聽
聽聽聽 // Convert headers from ASCII to Unicode.
聽聽聽 MultiByteToWideChar (CP_ACP, 0, lpcszStr, -1, lpwszStr, dwMinSize); 聽
聽聽聽 return TRUE;
聽 }
聽
聽 //-------------------------------------------------------------------------------------
聽 //Description:
聽 // This function maps a wide-character string to a new character string
聽 //
聽 //Parameters:
聽 // lpcwszStr: [in] Pointer to the character string to be converted
聽 // lpszStr: [out] Pointer to a buffer that receives the translated string.
聽 // dwSize: [in] Size of the buffer
聽 //
聽 //Return Values:
聽 // TRUE: Succeed
聽 // FALSE: Failed
聽 //
聽 //Example:
聽 // MByteToWChar(szW,szA,sizeof(szA)/sizeof(szA[0]));
聽 //---------------------------------------------------------------------------------------
聽 BOOL WCharToMByte(LPCWSTR lpcwszStr, LPSTR lpszStr, DWORD dwSize)
聽 {
聽聽 DWORD dwMinSize;
聽聽 dwMinSize = WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,NULL,0,NULL,FALSE);
聽聽 if(dwSize < dwMinSize)
聽聽 {
聽聽聽 return FALSE;
聽聽 }
聽聽 WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,lpszStr,dwSize,NULL,FALSE);
聽聽 return TRUE;
聽 }
聽
聽
聽 浣跨敤鏂規硶涔熷緢綆鍗?紺轟緥濡備笅:
聽 wchar_t wText[10] = {L"鍑芥暟紺轟緥"};
聽 char sText[20]= {0};
聽 WCharToMByte(wText,sText,sizeof(sText)/sizeof(sText[0]));
聽 MByteToWChar(sText,wText,sizeof(wText)/sizeof(wText[0]));
聽
聽 榪欎袱涓嚱鏁扮殑緙虹偣鍦ㄤ簬鏃犳硶鍔ㄦ佸垎閰嶅唴瀛?鍦ㄨ漿鎹㈠緢闀跨殑瀛楃涓叉椂鍙兘浼氭氮璐硅緝澶氬唴瀛樼┖闂?浼樼偣鏄?鍦ㄤ笉鑰冭檻嫻垂絀洪棿鐨勬儏鍐典笅杞崲杈冪煭瀛楃涓查潪甯告柟渚?
聽
2.MultiByteToWideChar()鍑芥暟涔辯爜鐨勯棶棰?br />
聽 鏈夌殑鏈嬪弸鍙兘宸茬粡鍙戠幇,鍦ㄦ爣鍑嗙殑WinCE4.2鎴朩inCE5.0 SDK妯℃嫙鍣ㄤ笅,榪欎釜鍑芥暟閮芥棤娉曟甯稿伐浣?鍏惰漿鎹箣鍚庣殑瀛楃鍏ㄦ槸涔辯爜.鍙婃椂鏇存敼MultiByteToWideChar()鍙傛暟涔熶緷鐒跺姝?
聽 涓嶈繃榪欎釜涓嶆槸浠g爜闂,鍏剁粨鐥囧湪浜庢墍瀹氬埗鐨勬搷浣滅郴緇?濡傛灉鎴戜滑瀹氬埗鐨勬搷浣滅郴緇熼粯璁よ璦涓嶆槸涓枃,涔熶細鍑虹幇榪欑鎯呭喌.鐢變簬鏍囧噯鐨凷DK榛樿璇█涓鴻嫳鏂?鎵浠ヨ偗瀹氫細鍑虹幇榪欎釜闂.鑰岃繖涓棶棰樼殑瑙e喅,涓嶈兘鍦ㄧ畝鍗曞湴鏇存敼鎺у埗闈㈡澘鐨?鍖哄煙閫夐」"鐨?榛樿璇█",鑰屾槸瑕佸湪緋葷粺瀹氬埗鐨勬椂鍊?閫夋嫨榛樿璇█涓?涓枃".
聽 緋葷粺瀹氬埗鏃墮夋嫨榛樿璇█鐨勪綅緗簬:
聽 Platform -> Setting... -> locale -> default language ,閫夋嫨"涓枃",鐒跺悗緙栬瘧鍗沖彲.
///////////////////////////////////////////////////
//
// CDialogSK : dialog skin
//
// writer: erran
//
// time: 2006-03-24
//
///////////////////////////////////////////////////
錛僫 nclude "BaseSK.h" /// EVC涓嬪疄鐜癢inCE杞歡鎹㈣偆涔嬪嚱鏁癟ransparentBitBlt
錛僫 nclude "BitmapSK.h" /// EVC涓嬪疄鐜癢inCE杞歡鎹㈣偆涔嬫崲鑲ゅ熀紜綾籆BitmapSK 銆
class CDialogSK: public CDialog
{
public:
// constructor and Destructor
CDialogSK();
CDialogSK(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL);
CDialogSK(UINT nIDTemplate, CWnd* pParentWnd = NULL);
~CDialogSK();
protected:
// common constructor
Constructor();
// Destructor,Release the bitmap
Destructor();
protected:
//window title text
CString m_titleText;
protected:
//interface bitmap
CBitmapSK m_bmpLeft; //dialog border left bitmap
CBitmapSK m_bmpRight; //dialog border right bitmap
CBitmapSK m_bmpBottom;//dialog border bottom bitmap
CBitmapSK m_bmpTitle; //two bitmap, dlg active and disactive
CBitmapSK m_bmpTitleBtn;//max min close btn bitmap
CBitmapSK m_bmpBkDlg; //dialog back ground bitmap
protected:
//transparent color of bitmap
COLORREF m_transColorLeft;
COLORREF m_transColorRight;
COLORREF m_transColorBottom;
COLORREF m_transColorTitle;
COLORREF m_transColorTitleBtn;
COLORREF m_transColorBackDlg;
protected:
//window border width and height
// the border can not more than the border bmp size
int m_borderLeftWidth;
int m_borderRightWidth;
int m_borderBottomHeight;
int m_titleHeight;
//offset in the bitmap
int m_offsetLeft1, m_offsetLeft2;
int m_offsetRight1, m_offsetRight2;
int m_offsetBottom1, m_offsetBottom2;
int m_offsetTitle1, m_offsetTitle2;
public:
//window style
BOOL m_titlable;
BOOL m_sizable;
BOOL m_minable;
BOOL m_maxable;
BOOL m_sysmenu;
BOOL m_isActive;
public:
BOOL m_winTransable;
public:
//msg
void OnPaint();
BOOL OnEraseBkgnd(CDC* pDC);
public:
// draw skin (x,y) is this dialog region
BOOL DrawRight(CDC *pDC, int x, int y, int height, int state);
BOOL DrawLeft(CDC *pDC, int x, int y, int height, int state);
BOOL DrawBottom(CDC *pDC, int x, int y, int width, int state);
BOOL DrawTitle(CDC *pDC, int x, int y, int width, int state);
BOOL DrawFrame(CDC *pDC, int x, int y,int width, int height, int state);
BOOL DrawBkDlg(CDC *pDC, int x, int y,int width, int height, int state);
BOOL DrawButton( CDC * pDC, int i, int state );
};
錛僫 nclude "stdafx.h"
錛僫 nclude "DialogSK.h"
/////////////////////////////////////////////////////////////////////////////
// CDialogSK dialog
CDialogSK::CDialogSK()
:CDialog()
{
}
CDialogSK::CDialogSK(LPCTSTR lpszTemplateName, CWnd* pParentWnd/*= NULL*/)
:CDialog(lpszTemplateName, pParentWnd)
{
}
CDialogSK::CDialogSK(UINT nIDTemplate, CWnd* pParentWnd/*/= NULL*/)
:CDialog(nIDTemplate, pParentWnd)
{
}
CDialogSK::~CDialogSK()
{
}
CDialogSK::Constructor()
{
/*嫻嬭瘯鐢?br> m_bmpLeft.LoadBitmapEx(NULL, IDB_LEFT);
m_bmpRight.LoadBitmapEx(NULL, IDB_RIGHT);
m_bmpBottom.LoadBitmapEx(NULL, IDB_BOTTOM);
m_bmpTitle.LoadBitmapEx(NULL, IDB_TOP);
m_titleHeight = m_bmpTitle.Height()/2;
m_borderLeftWidth = m_bmpLeft.Width()/2;
m_borderRightWidth = m_bmpRight.Width()/2;
m_borderBottomHeight = m_bmpBottom.Height()/2;
m_offsetLeft1 = 10;
m_offsetLeft2 = 10;
m_offsetRight1 = 10;
m_offsetRight2 = 10;
m_offsetBottom1 = 10;
m_offsetBottom2 = 10;
m_offsetTitle1 = 10;
m_offsetTitle2 = 10;
*/
}
CDialogSK::Destructor()
{
}
BOOL CDialogSK::DrawRight(CDC *pDC, int x, int y, int height, int state)
{
int bmpwidth, bmpheight;
m_bmpRight.Size(bmpwidth, bmpheight);
//bitmap rect
RECT srctop, srcmid, desmid, srcdown;
if (state == 0)
{
srctop = CRect(0, 0, m_borderRightWidth, m_offsetRight1);
srcmid = CRect(0, m_offsetRight1, m_borderRightWidth, m_offsetRight2);
srcdown = CRect(0, m_offsetRight2, m_borderRightWidth, bmpheight);
}
else
{
srctop = CRect(m_borderRightWidth, 0, bmpwidth, m_offsetRight1);
srcmid = CRect(m_borderRightWidth, m_offsetRight1, bmpwidth, m_offsetRight2);
srcdown = CRect(m_borderRightWidth, m_offsetRight2, bmpwidth, bmpheight);
}
desmid = CRect(x, y+m_offsetRight1, x+m_borderRightWidth, y+height-bmpheight+m_offsetRight2);
m_bmpRight.Draw(pDC, x, y, &srctop);
m_bmpRight.Fill(pDC, &desmid, &srcmid);
m_bmpRight.Draw(pDC, x, y+height-bmpheight+m_offsetRight2, &srcdown);
return TRUE;
}
BOOL CDialogSK::DrawLeft(CDC *pDC, int x, int y, int height, int state)
{
int bmpwidth, bmpheight;
m_bmpLeft.Size(bmpwidth, bmpheight);
//bitmap rect
RECT srctop, srcmid, desmid, srcdown;
if (state == 0)
{
srctop = CRect(0, 0, m_borderLeftWidth, m_offsetLeft1);
srcmid = CRect(0, m_offsetLeft1, m_borderLeftWidth, m_offsetLeft2);
srcdown = CRect(0, m_offsetLeft2, m_borderLeftWidth, bmpheight);
}
else
{
srctop = CRect(m_borderLeftWidth, 0, bmpwidth, m_offsetRight1);
srcmid = CRect(m_borderLeftWidth, m_offsetLeft1, bmpwidth, m_offsetLeft2);
srcdown = CRect(m_borderLeftWidth, m_offsetLeft2, bmpwidth, bmpheight);
}
desmid = CRect(x, y+m_offsetLeft1, x+m_borderLeftWidth, y+height-bmpheight+m_offsetLeft2);
m_bmpLeft.Draw(pDC, x, y, &srctop);
m_bmpLeft.Fill(pDC, &desmid, &srcmid);
m_bmpLeft.Draw(pDC, x, y+height-bmpheight+m_offsetLeft2, &srcdown);
return TRUE;
}
BOOL CDialogSK::DrawBottom(CDC *pDC, int x, int y, int width, int state)
{
int bmpwidth, bmpheight;
m_bmpBottom.Size(bmpwidth, bmpheight);
RECT srcleft, srcmid, desmid, srcright;
if (state == 0)
{
srcleft = CRect(0, 0, m_offsetBottom1, m_borderBottomHeight);
srcmid = CRect(m_offsetBottom1, 0, m_offsetBottom2, m_borderBottomHeight);
srcright = CRect(m_offsetBottom2, 0, bmpwidth, m_borderBottomHeight);
}
else
{
srcleft = CRect(0, m_borderBottomHeight, m_offsetBottom1, bmpheight);
srcmid = CRect(m_offsetBottom1, m_borderBottomHeight, m_offsetBottom2, bmpheight);
srcright = CRect(m_offsetBottom2, m_borderBottomHeight, bmpwidth, bmpheight);
}
desmid = CRect(x+m_offsetBottom1, y, x+width-bmpwidth+m_offsetBottom2, y+m_borderBottomHeight);
m_bmpBottom.Draw(pDC, x, y, &srcleft);
m_bmpBottom.Fill(pDC, &desmid, &srcmid);
m_bmpBottom.Draw(pDC, x+width-bmpwidth+m_offsetBottom2, y, &srcright);
return TRUE;
}
BOOL CDialogSK::DrawTitle(CDC *pDC, int x, int y, int width, int state)
{
int bmpwidth, bmpheight;
m_bmpTitle.Size(bmpwidth, bmpheight);
RECT srcleft, srcmid, desmid, srcright;
if (state == 0)
{
srcleft = CRect(0, 0, m_offsetTitle1, m_titleHeight);
srcmid = CRect(m_offsetTitle1, 0, m_offsetTitle2, m_titleHeight);
srcright = CRect(m_offsetTitle2, 0, bmpwidth, m_titleHeight);
}
else
{
srcleft = CRect(0, m_titleHeight, m_offsetTitle1, bmpheight);
srcmid = CRect(m_offsetTitle1, m_titleHeight, m_offsetTitle2, bmpheight);
srcright = CRect(m_offsetTitle2, m_titleHeight, bmpwidth, bmpheight);
}
desmid = CRect(x+m_offsetTitle1, y, x+width-bmpwidth+m_offsetTitle2, y+m_titleHeight);
m_bmpTitle.Draw(pDC, x, y, &srcleft);
m_bmpTitle.Fill(pDC, &desmid, &srcmid);
m_bmpTitle.Draw(pDC, x+width-bmpwidth+m_offsetTitle2, y, &srcright);
return TRUE;
}
BOOL CDialogSK::DrawFrame(CDC *pDC, int x, int y,int width, int height, int state)
{
DrawTitle(pDC, x+m_borderLeftWidth, y, width-m_borderLeftWidth-m_borderRightWidth, state);
DrawLeft(pDC, x, y, height, state);
DrawRight(pDC, x+width-m_borderRightWidth, y, height, state);
DrawBottom(pDC, x+m_borderLeftWidth, y+height-m_borderBottomHeight, width-m_borderLeftWidth-m_borderRightWidth, state);
return TRUE;
}
BOOL CDialogSK::DrawBkDlg(CDC *pDC, int x, int y,int width, int height, int state)
{
int bmpwidth, bmpheight;
m_bmpBkDlg.Size(bmpwidth, bmpheight);
RECT des, src;
des = CRect(x,y, x+width, y+height);
src = CRect(0, 0, bmpwidth, bmpheight);
m_bmpBkDlg.Fill(pDC, &des, &src);
return TRUE;
}
BOOL CDialogSK::OnEraseBkgnd(CDC* pDC)
{
CRect rtClient = CClientRect(m_hWnd);
DrawFrame(pDC, rtClient.left, rtClient.top, rtClient.Width(), rtClient.Height(),0);
DrawBkDlg(pDC, rtClient.left+m_borderLeftWidth, rtClient.top+m_titleHeight,
rtClient.Width()-m_borderLeftWidth-m_borderRightWidth,
rtClient.Height()-m_titleHeight-m_borderBottomHeight,
0);
return TRUE;
}
鍛靛懙錛屽氨榪欎箞澶氫簡錛岃繖閲屼笉鏂逛究璐村浘錛岃涓嶅彲浠ョ湅鍒版晥鏋滅殑錛屽懙鍛碉紝嬈㈣繋鎸囨暀銆?/font>
//load bitmap by resource file path
BOOL LoadBitmapEx(LPCTSTR lpszFileName);
//load bitmap by resource name or ID
BOOL LoadBitmapEx(LPCTSTR lpszResourceName, UINT nIDResource);
//attaches a hBitmap to a CBitmap object.
BOOL Attach(HBITMAP hbmp)
{
return CBitmap::Attach(hbmp);
}
void Size(int &width, int &height)
{
BITMAP bm;
memset(&bm, 0, sizeof(bm));
CBitmap::GetBitmap(&bm);
width = bm.bmWidth;
height = bm.bmHeight;
}
//bitmap width
int Width(void)
{
BITMAP bm;
memset(&bm, 0, sizeof(bm));
CBitmap::GetBitmap(&bm);
return bm.bmWidth;
}
//bitmap height
int Height()
{
BITMAP bm;
memset(&bm, 0, sizeof(bm));
CBitmap::GetBitmap(&bm);
return bm.bmHeight;
}
/////// src(bmp) ---> Des(pDC)
//draw current bitmap to device(pDC rect(lpr))
BOOL Draw(CDC *pDC, LPRECT lprDes);
//draw current bitmap to device(pDC rect(lpr)) , transparent
BOOL Draw(CDC *pDC, LPRECT lprDes, COLORREF crTrans, BOOL isTrans);
//draw sub bitmap(the rect lprSrc of current bitmap) to special point( the begin point (x,y) of pDC device)
BOOL Draw(CDC *pDC, int x, int y, LPRECT lprSrc);
//draw sub bitmap to special point
BOOL Draw(CDC *pDC, int x, int y, LPRECT lprSrc, COLORREF crTrans, BOOL isTrans);
BOOL Fill(CDC *pDC, LPRECT lprDes);
BOOL Fill(CDC *pDC, LPRECT lprDes, COLORREF crTrans, BOOL isTrans);
BOOL Fill(CDC *pDC, LPRECT lprDes, LPRECT lprSrc);
BOOL Fill(CDC *pDC, LPRECT lprDes, LPRECT lprSrc, COLORREF crTrans, BOOL isTrans);
//Drawing Transparent Bitmaps,Copies a bitmap transparently onto the destination DC
BOOL TransparentDraw(CDC * pDC, int x, int y, COLORREF crColour);
//Copies a bitmap from a source rectangle into a destination rectangle,
//stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle.
BOOL StretchDraw(CDC *pDC, LPRECT lprDes, LPRECT lprSrc);
//Copies a bitmap from a source rectangle into a destination rectangle,
//stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle.
BOOL StretchDraw(CDC *pDC, LPRECT lprSrc);
//make a region from bitmap, It will show as a window ::: faulse function :::
//HRGN CreateRegion(COLORREF crColour, BOOL isTrans = TRUE);
};
////for class CBitmapSK
CBitmapSK::CBitmapSK()
{
}
CBitmapSK::~CBitmapSK()
{
}
BOOL CBitmapSK::LoadBitmapEx(LPCTSTR lpszFileName)
{
DeleteObject();
ASSERT(m_hObject==NULL);
HBITMAP hBitmap = NULL;
hBitmap = (HBITMAP)::LoadImage(0, lpszFileName, IMAGE_BITMAP, 0, 0, 0);
if(hBitmap == NULL) return FALSE;
return CBitmap::Attach(hBitmap);
}
BOOL CBitmapSK::LoadBitmapEx(LPCTSTR lpszResourceName, UINT nIDResource)
{
DeleteObject();
ASSERT(m_hObject==NULL);
if (lpszResourceName != NULL)
{
return CBitmap::LoadBitmap(lpszResourceName);
}
if (nIDResource != 0)
{
return CBitmap::LoadBitmap(nIDResource);
}
return FALSE;
}
BOOL CBitmapSK::Draw(CDC *pDC, LPRECT lprDes)
{
ASSERT(pDC!=NULL);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *bmp = dc.SelectObject(this);
pDC->BitBlt(lprDes->left, lprDes->top,
lprDes->right - lprDes->left, lprDes->bottom - lprDes->top,
&dc, 0, 0, SRCCOPY);
dc.SelectObject(bmp);
dc.DeleteDC();
bmp = NULL;
return TRUE;
}
BOOL CBitmapSK::Draw(CDC *pDC, LPRECT lprDes, COLORREF crTrans, BOOL isTrans)
{
ASSERT(pDC!=NULL);
if (!isTrans)
{
return Draw(pDC, lprDes);
}
else
{
return TransparentBitBlt(pDC->GetSafeHdc(),
lprDes->left,lprDes->top,Width(),Height(),
(HBITMAP)this->GetSafeHandle(),0,0,crTrans,NULL);
}
}
BOOL CBitmapSK::Draw( CDC *pDC, int x, int y, LPRECT lprSrc)
{
ASSERT(pDC!=NULL);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *pOldbmp = dc.SelectObject(this);
if (lprSrc != NULL)
{
//Copies a bitmap from the source device context to this current device context
pDC->BitBlt(x, y, lprSrc->right - lprSrc->left, lprSrc->bottom - lprSrc->top,
&dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
else
{
pDC->BitBlt(x, y, Width(), Height(), &dc, 0, 0, SRCCOPY);
}
dc.SelectObject(pOldbmp);
dc.DeleteDC();
pOldbmp = NULL;
return TRUE;
}
BOOL CBitmapSK::Draw( CDC *pDC, int x, int y, LPRECT lprSrc, COLORREF crTrans, BOOL isTrans)
{
ASSERT(pDC!=NULL);
if (!isTrans)
{
return Draw(pDC, x, y, lprSrc);
}
else
{
return TransparentBitBlt(pDC->GetSafeHdc(), x, y, lprSrc->right - lprSrc->left, lprSrc->bottom - lprSrc->top,
(HBITMAP)this->GetSafeHandle(), lprSrc->left, lprSrc->top, crTrans, NULL );
}
}
BOOL CBitmapSK::Fill(CDC *pDC, LPRECT lprDes, LPRECT lprSrc)
{
ASSERT(pDC!=NULL);
int widthDes, widthSrc, heightDes, heightSrc;
widthDes = abs(lprDes->right - lprDes->left);
widthSrc = abs(lprSrc->right - lprSrc->left);
heightDes = abs(lprDes->bottom - lprDes->top);
heightSrc = abs(lprSrc->bottom - lprSrc->top);
int paddingx, paddingy, i, j;
paddingx = int(widthDes / widthSrc);
paddingy = int(heightDes / heightSrc);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *pOldbmp = dc.SelectObject(this);
if (widthDes <= widthSrc)
{
if (heightDes <= heightSrc)
{
Draw(pDC, lprDes);
}
else
{
for (i=1; i<paddingy; i++)
{
pDC->BitBlt(lprDes->left, lprDes->top + heightSrc*(i-1), widthDes, heightSrc,&dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
pDC->BitBlt(lprDes->left,lprDes->top + heightSrc*(i-1), widthDes, heightDes - heightSrc*(i-1), &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
}
else
{
if (heightDes <= heightSrc)
{
for (i=1; i<paddingx; i++)
{
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top, widthSrc, heightDes, &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top, widthDes - widthSrc*(i-1), heightDes, &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
else
{
for (j=1; j<=paddingy; j++)
{
for (i=1; i<=paddingx; i++)
{
pDC->BitBlt(lprDes->left + widthSrc*(i-1),lprDes->top + heightSrc*(j-1), widthSrc, heightSrc, &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top + heightSrc*(j-1),widthDes - widthSrc*(i-1), heightSrc, &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
}
for (i=1; i<=paddingx; i++)
{
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top + heightSrc*(j-1), widthSrc, heightDes - heightSrc*(j-1), &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
pDC->BitBlt(lprDes->left + widthSrc*(i-1), lprDes->top + heightSrc*(j-1), widthDes - widthSrc*(i-1),
heightDes - heightSrc*(j-1), &dc, lprSrc->left, lprSrc->top, SRCCOPY);
}
dc.SelectObject(pOldbmp);
dc.DeleteDC();
pOldbmp = NULL;
return TRUE;
}
BOOL CBitmapSK::TransparentDraw(CDC * pDC, int x, int y, COLORREF crTrans)
{
ASSERT(pDC!=NULL);
return TransparentBitBlt(pDC->GetSafeHdc(), x, y, Width(), Height(), (HBITMAP)this->GetSafeHandle(),
0, 0, crTrans, NULL );
}
BOOL CBitmapSK::StretchDraw(CDC *pDC, LPRECT lprDes, LPRECT lprSrc)
{
ASSERT(pDC!=NULL);
if(lprDes == NULL) return FALSE;
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *pOldbmp = dc.SelectObject(this);
//SetStretchBltMode(pDC->GetSafeHdc(), COLORONCOLOR);
if(!lprSrc)
{
pDC->StretchBlt(lprDes->left, lprDes->top, lprDes->right, lprDes->bottom, &dc, 0, 0, Width(), Height(), SRCCOPY);
}
else
{
pDC->StretchBlt(lprDes->left, lprDes->top, lprDes->right - lprDes->left, lprDes->bottom - lprDes->top,
&dc, lprSrc->left, lprSrc->top, lprSrc->right - lprSrc->left, lprSrc->bottom - lprSrc->top,SRCCOPY);
}
dc.SelectObject(pOldbmp);
dc.DeleteDC();
pOldbmp = NULL;
return TRUE;
}
BOOL CBitmapSK::StretchDraw(CDC *pDC, LPRECT lprSrc)
{
ASSERT(pDC!=NULL);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap *pOldbmp = dc.SelectObject(this);
pDC->StretchBlt(lprSrc->left, lprSrc->top, lprSrc->right, lprSrc->bottom, &dc,
0, 0, Width(), Height(), SRCCOPY);
dc.SelectObject(pOldbmp);
dc.DeleteDC();
pOldbmp = NULL;
return TRUE;
}
浣跨敤榪欎釜綾誨疄鐜頒簡瀵硅瘽絳愮殑鎹㈣偆錛屾祴璇曡繕琛屻?/font>
鏆傛椂榪樻病鍙戠幇ce涓嬬殑鎹㈣偆絎笁鏂規帶浠訛紝瑙佽繃鏈濂界殑涔熷氨鏄偅涓狢CeButton浜嗭紝榪樻槸鍦‥VC3.0涓嬪紑鍙戠殑銆傘傘?/font>
{
ASSERT(hdcDes!=NULL);//if(hdcDes == NULL) return FALSE;
ASSERT(hbmSrc!=NULL);//if(hbmSrc == NULL) return FALSE;
CDC dc, memDC, maskDC, tempDC;
dc.Attach(hdcDes);
maskDC.CreateCompatibleDC(&dc);
CBitmap maskBmp;
//add these to store return of SelectObject() calls
CBitmap *pOldMemBmp = NULL;
CBitmap *pOldMaskBmp = NULL;
HBITMAP hOldTempBmp = NULL;
memDC.CreateCompatibleDC(&dc);
tempDC.CreateCompatibleDC(&dc);
CBitmap bmpImage;
bmpImage.CreateCompatibleBitmap(&dc, width, height);
pOldMemBmp = memDC.SelectObject(&bmpImage);
// Select and realize the palette
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && hPal )
{
::SelectPalette(dc, hPal, FALSE);
dc.RealizePalette();
::SelectPalette(memDC, hPal, FALSE);
}
hOldTempBmp = (HBITMAP)::SelectObject(tempDC.m_hDC, hbmSrc);
memDC.BitBlt(0, 0, width, height, &tempDC, xSrc, ySrc, SRCCOPY);
// Create monochrome bitmap for the mask
maskBmp.CreateBitmap(width, height, 1, 1, NULL);
pOldMaskBmp = maskDC.SelectObject(&maskBmp);
memDC.SetBkColor(crTrans);
// Create the mask from the memory DC
maskDC.BitBlt(0, 0, width, height, &memDC, 0, 0, SRCCOPY);
// Set the background in memDC to black. Using SRCPAINT with black
// and any other color results in the other color, thus making
// black the transparent color
memDC.SetBkColor(RGB(0,0,0));
memDC.SetTextColor(RGB(255,255,255));
memDC.BitBlt(0, 0, width, height, &maskDC, 0, 0, SRCAND);
// Set the foreground to black. See comment above.
dc.SetBkColor(RGB(255,255,255));
dc.SetTextColor(RGB(0,0,0));
dc.BitBlt(xDes, yDes, width, height, &maskDC, 0, 0, SRCAND);
// Combine the foreground with the background
dc.BitBlt(xDes, yDes, width, height, &memDC, 0, 0, SRCPAINT);
if (hOldTempBmp)
::SelectObject(tempDC.m_hDC, hOldTempBmp);
if (pOldMaskBmp)
maskDC.SelectObject(pOldMaskBmp);
if (pOldMemBmp)
memDC.SelectObject(pOldMemBmp);
dc.Detach();
maskBmp.DeleteObject();
bmpImage.DeleteObject();
maskDC.DeleteDC();
memDC.DeleteDC();
tempDC.DeleteDC();
pOldMemBmp = NULL;
pOldMaskBmp = NULL;
hOldTempBmp = NULL;
return TRUE;
}
///}}} for global function
鍙︿笁涓緢鏈夋剰鎬濈殑綾伙紝浠庨珮鎵嬮偅“鐩?#8221;鏉ョ殑錛屽懙鍛?
class CWinRect: public CRect
{
public:
CWinRect(HWND hWnd)
{
::GetWindowRect(hWnd, this);
}
CWinRect(const CWnd *pWnd)
{
::GetWindowRect(pWnd->GetSafeHwnd(), this);
}
};
class CWinText: public CString
{
public:
CWinText(HWND hWnd)
{
(CWnd::FromHandle(hWnd))->GetWindowText(*this);
}
CWinText(const CWnd *pWnd)
{
pWnd->GetWindowText(*this);
}
};
class CClientRect: public CRect
{
public:
CClientRect(HWND hWnd)
{
::GetClientRect(hWnd, this);
}
CClientRect(CWnd *pWnd)
{
::GetClientRect(pWnd->GetSafeHwnd(), this);
}
};
鍦ㄦ鍋氫簡涓畝鍗曠殑ocx璇曚簡璇曪紝鑳藉鍦?span lang=EN-US>EVC4.2/妯℃嫙鍣?span lang=EN-US>wince4.2涓嬫垚鍔熴傚叿浣撴楠ゅ涓嬶細
1. 寮鍙?span lang=EN-US>CE鐗?span lang=EN-US>OCX鎺т歡銆傚厛鍦?span lang=EN-US>EVC涓紑鍙戣嚜宸辯殑OCX鎺т歡銆傜紪璇戞垚鍔熶互鍚庯紝ocx浼氳鑷姩涓嬭澆鍒版ā鎷熷櫒閲屽幓銆?br>
2. 鍦ㄦā鎷熷櫒涓敞鍐岃鎺т歡.娉ㄥ唽鏂規硶錛氱敤EVC鐨?span lang=EN-US>remote filter viewer鍔犺澆鐩綍C:\Program Files\Microsoft eMbedded C++ 4.0\EVC\WCE400\TARGET\X86\regsvrce.exe鍒版ā鎷熷櫒windows鐩綍涓嬨傛垨鑰呯洿鎺ユ嫹璐濊regsvrce.exe鍒版ā鎷熷櫒閲屻傛嫹璐濇垚鍔熷悗錛屽湪妯℃嫙鍣ㄤ笂榪愯regsvrce.exe錛屾敞鍐屾帶浠訛紝濡傝繍琛?#8220;regsvrce CEActivexBtn.ocx”,鍗蟲敞鍐屼簡CEActivexBtn 鎺т歡銆?br>
4. 寮鍙?span lang=EN-US>win32鐗?span lang=EN-US>OCX鎺т歡銆傚湪VC涓垱寤轟竴涓拰浠ヤ笂宸ョ▼鍚嶅瓧涓鏍風殑宸ョ▼錛堝繀欏諱竴鏍鳳紝鍚﹀垯鍥炰笉鎴愬姛錛夛紝鎶婅宸ョ▼錛?span lang=EN-US>vc宸ョ▼錛変笅鐨?涓や釜宸ョ▼鏂囦歡dsw鍜?span lang=EN-US>dsp鎷瘋礉鍒?span lang=EN-US>CE鐗堟帶浠跺伐紼嬬殑鐩綍涓嬶紝鍜?span lang=EN-US>vcw鍜?span lang=EN-US>vcp鏀懼埌鍚屼竴涓洰褰曚笅錛岀劧鍚庢墦寮榪欎釜鐩綍涓嬬殑VC宸ョ▼錛屽彂鐜扮紪璇戦厤緗噷閫夋嫨鐨勬槸“Win32 Unicode Debug”錛岀紪璇戯紝鍙兘浼氫駭鐢熼摼鎺ラ敊璇紝鍗沖樊mfc42ud;lib銆傚綋鐒跺鏋?span lang=EN-US>VC瀹夎鐨勫緢瀹屽杽鐨勮瘽錛屼笉浼氫駭鐢熻繖涓敊璇備笉榪囦篃娌″叧緋伙紝鎶婇偅涓厤緗敼浜嗭紝鏀規垚“Win32 Debug”錛岃繖鏍峰氨鑳界紪璇戞垚鍔熶簡銆傜紪璇戝畬鎴愶紝VC浼氳嚜鍔ㄦ敞鍐岃win32鐗堢殑ocx鎺т歡銆?br>
銆銆5錛庡湪EVC涓婃坊鍔犺Win32鐗堢殑錛堜笉鏄?span lang=EN-US>CE鐗堢殑錛?span lang=EN-US>ocx鎺т歡銆傛柟娉曪紝鍒涘緩涓涓?span lang=EN-US>demo宸ョ▼錛屽湪璇ュ伐紼嬬殑瀵硅瘽絳愮紪杈戝櫒閲岋紝鍙抽敭鑿滃崟“Insert ActiveX Controls”錛屽嚭鐜?span lang=EN-US>Insert ActiveX Controls紿楀彛錛岀偣鍑?#8220;Add Controls”鎸夐挳錛屾壘鍒扮敤VC緙栬瘧鐨?span lang=EN-US>Win32鐗?span lang=EN-US>ocx鎺т歡錛屾坊鍔犮?br>
銆銆OK錛佺幇鍦ㄥ彲浠ュ湪EVC涓婅皟鐢ㄨocx緙栫▼浜嗐?br>
鏈鍒濅嬌鐢ㄧ殑鎴睆鏂規硶璇存潵榪樼湡鏈変簺涓漢錛屼竴涓竴涓偣鐨勫彇寰楅鑹插鹼紝鍐嶄繚瀛樺埌bmp鏂囦歡涓幓錛岃繖鏍風▼搴忚繍琛岀殑閫熷害瓚呮參錛屼繚瀛樹竴涓?00X600鐨刡mp宸笉澶氳涓涓ゅ垎閽燂紙鐮斿崕8251鏉匡級錛岃寰楁湁浜涗笉瀵瑰ご錛屽喅瀹氭兂鍔炴硶鏀硅繘涓涓嬶紝灝變嬌鍔插湴鐪嬩簡涓涓婥harles Petzold鍏堢敓鐨勩奝rogramming Windows銆嬶紙榪欐湰涔﹀緢緇忓吀錛屽煎緱濂藉ソ鐮旂┒涓涓嬶級錛岀粓浜庢妸鏃墮棿緙╃煭鍒板嚑縐掗挓浜嗭紝涓嬮潰榪欎釜鍑芥暟鍦╡vc鍜寁c涓嬮兘test pass(涓嶇敤鏇存敼)錛屾湁涓嶈凍涔嬪嬈㈣繋鎸囨錛屽嚱鏁幫細
// this function create a bmp file to save the current screen;
// supported eVC++ 4.0 (wince 4.0) and vc++ 6.0 , test pass;
void CSnapDlg::OnScreenSave(const char *filename)
{
HDC hScrDC, hMemDC;
int width, height;
//the pointer will save all pixel point's color value
BYTE *lpBitmapBits = NULL;
//creates a device context for the screen device
hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
//get the screen point size
width = GetDeviceCaps(hScrDC, HORZRES);
height = GetDeviceCaps(hScrDC, VERTRES);
//creates a memory device context (DC) compatible with the screen device(hScrDC)
hMemDC = CreateCompatibleDC(hScrDC);
//initialise the struct BITMAPINFO for the bimap infomation錛?/font>
//in order to use the function CreateDIBSection
// on wince os, each pixel stored by 24 bits(biBitCount=24)
//and no compressing(biCompression=0)
BITMAPINFO RGB24BitsBITMAPINFO;
ZeroMemory(&RGB24BitsBITMAPINFO, sizeof(BITMAPINFO));
RGB24BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB24BitsBITMAPINFO.bmiHeader.biWidth = width;
RGB24BitsBITMAPINFO.bmiHeader.biHeight = height;
RGB24BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB24BitsBITMAPINFO.bmiHeader.biBitCount = 24;
//use the function CreateDIBSection and SelectObject
//in order to get the bimap pointer : lpBitmapBits
HBITMAP directBmp = CreateDIBSection(hMemDC, (BITMAPINFO*)&RGB24BitsBITMAPINFO,
DIB_RGB_COLORS, (void **)&lpBitmapBits, NULL, 0);
HGDIOBJ previousObject = SelectObject(hMemDC, directBmp);
// copy the screen dc to the memory dc
BitBlt(hMemDC, 0, 0, width, height, hScrDC, 0, 0, SRCCOPY);
//if you only want to get the every pixel color value,
//you can begin here and the following part of this function will be unuseful;
//the following part is in order to write file;
//bimap file header in order to write bmp file
BITMAPFILEHEADER bmBITMAPFILEHEADER;
ZeroMemory(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER));
bmBITMAPFILEHEADER.bfType = 0x4d42; //bmp
bmBITMAPFILEHEADER.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmBITMAPFILEHEADER.bfSize = bmBITMAPFILEHEADER.bfOffBits + ((width*height)*3); ///3=(24 / 8)
//write into file
FILE *mStream = NULL;
if((mStream = fopenfilename, "wb")))
{
//write bitmap file header
fwrite(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER), 1, mStream);
//write bitmap info
fwrite(&(RGB24BitsBITMAPINFO.bmiHeader), sizeof(BITMAPINFOHEADER), 1, mStream);
//write bitmap pixels data
fwrite(lpBitmapBits, 3*width*height, 1, mStream);
//close file
fclose(mStream);
}
//delete
DeleteObject(hMemDC);
DeleteObject(hScrDC);
DeleteObject(directBmp);
DeleteObject(previousObject);
}
榪樻槸鐢ㄨ嫳璇綔浜嗘敞閲婏紝铏界劧鑻辮瀛︾殑寰堢碂緋曪紝榪樻槸瑙夊緱榪欎釜涔犳儻姣旇緝濂絶~ ..