Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1102 lines
27 KiB

  1. #define WIN32_LEAN_AND_MEAN
  2. #include <windows.h>
  3. #include "winapi.h"
  4. #ifdef UNDER_CE // not support IsWindowUnicode
  5. inline BOOL IsWindowUnicode(HWND){return TRUE;}
  6. #endif // UNDER_CE
  7. #define MemAlloc(a) GlobalAlloc(GMEM_FIXED, (a))
  8. #define MemFree(a) GlobalFree((a))
  9. #if !(defined(UNICODE) || defined(_UNICODE) || !defined(AWBOTH))
  10. LRESULT WINAPI WinSendMessage(
  11. HWND hWnd,
  12. UINT Msg,
  13. WPARAM wParam,
  14. LPARAM lParam)
  15. {
  16. if(::IsWindowUnicode(hWnd)) {
  17. return ::SendMessageW(hWnd, Msg, wParam, lParam);
  18. }
  19. else {
  20. return ::SendMessageA(hWnd, Msg, wParam, lParam);
  21. }
  22. }
  23. BOOL WINAPI WinPostMessage(
  24. HWND hWnd,
  25. UINT Msg,
  26. WPARAM wParam,
  27. LPARAM lParam)
  28. {
  29. if(::IsWindowUnicode(hWnd)) {
  30. return ::PostMessageW(hWnd, Msg, wParam, lParam);
  31. }
  32. else {
  33. return ::PostMessageA(hWnd, Msg, wParam, lParam);
  34. }
  35. }
  36. BOOL WINAPI WinPeekMessage(
  37. LPMSG lpMsg,
  38. HWND hWnd ,
  39. UINT wMsgFilterMin,
  40. UINT wMsgFilterMax,
  41. UINT wRemoveMsg)
  42. {
  43. if(::IsWindowUnicode(hWnd)) {
  44. return ::PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
  45. }
  46. else {
  47. return ::PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
  48. }
  49. }
  50. LRESULT WINAPI WinDispatchMessage(
  51. CONST MSG *lpMsg)
  52. {
  53. if(::IsWindowUnicode(lpMsg->hwnd)) {
  54. return ::DispatchMessageW(lpMsg);
  55. }
  56. else {
  57. return ::DispatchMessageA(lpMsg);
  58. }
  59. }
  60. #define WinTranslateMessage TranslateMessage
  61. LONG WINAPI WinSetWindowLong(
  62. HWND hWnd,
  63. int nIndex,
  64. LONG dwNewLong)
  65. {
  66. if(::IsWindowUnicode(hWnd)) {
  67. return ::SetWindowLongW(hWnd, nIndex, dwNewLong);
  68. }
  69. else {
  70. return ::SetWindowLongA(hWnd, nIndex, dwNewLong);
  71. }
  72. }
  73. LONG WINAPI WinGetWindowLong(
  74. HWND hWnd,
  75. int nIndex)
  76. {
  77. if(::IsWindowUnicode(hWnd)) {
  78. return ::GetWindowLongW(hWnd, nIndex);
  79. }
  80. else {
  81. return ::GetWindowLongA(hWnd, nIndex);
  82. }
  83. }
  84. #ifdef STRICT
  85. LRESULT WINAPI WinCallWindowProc(
  86. WNDPROC lpPrevWndFunc,
  87. HWND hWnd,
  88. UINT Msg,
  89. WPARAM wParam,
  90. LPARAM lParam)
  91. {
  92. if(::IsWindowUnicode(hWnd)) {
  93. return CallWindowProcW(lpPrevWndFunc, hWnd, Msg, wParam, lParam);
  94. }
  95. else {
  96. return CallWindowProcA(lpPrevWndFunc, hWnd, Msg, wParam, lParam);
  97. }
  98. }
  99. #else /* !STRICT */
  100. LRESULT WINAPI WinCallWindowProc(
  101. FARPROC lpPrevWndFunc,
  102. HWND hWnd,
  103. UINT Msg,
  104. WPARAM wParam,
  105. LPARAM lParam)
  106. {
  107. if(::IsWindowUnicode(hWnd)) {
  108. return CallWindowProcW((FARPROC)lpPrevWndFunc, hWnd, Msg, wParam, lParam);
  109. }
  110. else {
  111. return CallWindowProcA((FARPROC)lpPrevWndFunc, hWnd, Msg, wParam, lParam);
  112. }
  113. }
  114. #endif /* STRICT */
  115. LRESULT WINAPI WinDefWindowProc(
  116. HWND hWnd,
  117. UINT Msg,
  118. WPARAM wParam,
  119. LPARAM lParam)
  120. {
  121. if(::IsWindowUnicode(hWnd)) {
  122. return ::DefWindowProcW(hWnd, Msg, wParam, lParam);
  123. }
  124. else {
  125. return ::DefWindowProcA(hWnd, Msg, wParam, lParam);
  126. }
  127. }
  128. BOOL WINAPI WinIsDialogMessage(
  129. HWND hDlg,
  130. LPMSG lpMsg)
  131. {
  132. if(::IsWindowUnicode(hDlg)) {
  133. return ::IsDialogMessageW(hDlg, lpMsg);
  134. }
  135. else {
  136. return ::IsDialogMessageA(hDlg, lpMsg);
  137. }
  138. }
  139. //----------------------------------------------------------------
  140. // WinSetWindowTextA_CP
  141. // WinGetWindowTextA_CP
  142. // WinSetWindowTextW_CP
  143. // WinGetWindowTextW_CP
  144. //----------------------------------------------------------------
  145. //////////////////////////////////////////////////////////////////
  146. // Function : WinSetWindowTextA_CP
  147. // Type : BOOL WINAPI
  148. // Purpose :
  149. // Args :
  150. // : UINT codePage
  151. // : HWND hWnd
  152. // : LPCSTR lpString
  153. // Return :
  154. // DATE : Fri Jul 16 04:21:05 1999
  155. // Histroy :
  156. //////////////////////////////////////////////////////////////////
  157. #ifndef UNDER_CE
  158. BOOL WINAPI
  159. WinSetWindowTextA_CP(UINT codePage, HWND hWnd, LPCSTR lpString)
  160. {
  161. if(::IsWindowUnicode(hWnd)) {
  162. INT len = ::lstrlenA(lpString);
  163. if(len == 0) {
  164. ::SetWindowTextW(hWnd, L"");
  165. }
  166. else {
  167. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  168. if(lpwstr) {
  169. ::MultiByteToWideChar(codePage, MB_PRECOMPOSED, lpString, -1,
  170. lpwstr, len+1);
  171. ::SetWindowTextW(hWnd, lpwstr);
  172. MemFree(lpwstr);
  173. }
  174. }
  175. }
  176. else {
  177. ::SetWindowTextA(hWnd, lpString);
  178. }
  179. return 0;
  180. }
  181. //////////////////////////////////////////////////////////////////
  182. // Function : WinGetWindowTextA_CP
  183. // Type : int WINAPI
  184. // Purpose :
  185. // Args :
  186. // : UINT codePage
  187. // : HWND hWnd
  188. // : LPSTR lpString
  189. // : int nMaxCount
  190. // Return :
  191. // DATE : Fri Jul 16 04:25:37 1999
  192. // Histroy :
  193. //////////////////////////////////////////////////////////////////
  194. int WINAPI
  195. WinGetWindowTextA_CP(UINT codePage, HWND hWnd, LPSTR lpString, int nMaxCount)
  196. {
  197. int result =0;
  198. if(::IsWindowUnicode(hWnd)) {
  199. INT len = ::GetWindowTextLengthW(hWnd);
  200. LPWSTR lpwstr;
  201. if(len > 0) {
  202. lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len+1));
  203. if(lpwstr) {
  204. result = ::GetWindowTextW(hWnd, lpwstr, len+1);
  205. ::WideCharToMultiByte(codePage, WC_COMPOSITECHECK,
  206. lpwstr, -1,
  207. lpString,
  208. nMaxCount,
  209. NULL, NULL);
  210. MemFree(lpwstr);
  211. }
  212. }else{
  213. lstrcpy(lpString, "");
  214. }
  215. }
  216. else {
  217. result = ::GetWindowTextA(hWnd, lpString, nMaxCount);
  218. }
  219. return(result);
  220. }
  221. #endif //UNDER_CE
  222. //////////////////////////////////////////////////////////////////
  223. // Function : WinSetWindowTextW_CP
  224. // Type : BOOL WINAPI
  225. // Purpose :
  226. // Args :
  227. // : UINT codePage
  228. // : HWND hWnd
  229. // : LPCWSTR lpString
  230. // Return :
  231. // DATE : Fri Jul 16 04:22:42 1999
  232. // Histroy :
  233. //////////////////////////////////////////////////////////////////
  234. BOOL WINAPI
  235. WinSetWindowTextW_CP(UINT codePage, HWND hWnd, LPCWSTR lpString)
  236. {
  237. if(!lpString) {
  238. return 0;
  239. }
  240. if(::IsWindowUnicode(hWnd)) {
  241. ::SetWindowTextW(hWnd, lpString);
  242. }
  243. else {
  244. INT len = ::lstrlenW(lpString);
  245. if(len > 0) {
  246. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  247. if(lpstr) {
  248. ::WideCharToMultiByte(codePage, WC_COMPOSITECHECK,
  249. lpString, -1,
  250. lpstr,
  251. sizeof(WCHAR)*(len+1),
  252. NULL, NULL);
  253. ::SetWindowTextA(hWnd, lpstr);
  254. MemFree(lpstr);
  255. }
  256. }
  257. else {
  258. ::SetWindowTextA(hWnd, "");
  259. }
  260. }
  261. return 0;
  262. }
  263. int WINAPI
  264. WinGetWindowTextW_CP(UINT codePage, HWND hWnd, LPWSTR lpString, int nMaxCount)
  265. {
  266. int result = 0;
  267. if(!lpString) {
  268. return 0;
  269. }
  270. if(nMaxCount <= 0) {
  271. return 0;
  272. }
  273. if(::IsWindowUnicode(hWnd)) {
  274. result = ::GetWindowTextW(hWnd, lpString, nMaxCount);
  275. }
  276. else {
  277. INT size = ::GetWindowTextLengthA(hWnd);
  278. LPSTR lpstr;
  279. if(size > 0) {
  280. lpstr = (LPSTR)MemAlloc((size+1)* sizeof(CHAR));
  281. if(lpstr) {
  282. result = ::GetWindowTextA(hWnd, lpstr, size+1);
  283. result = ::MultiByteToWideChar(codePage, MB_PRECOMPOSED, lpstr, -1,
  284. lpString, nMaxCount);
  285. MemFree(lpstr);
  286. }
  287. }
  288. else {
  289. *lpString = (WCHAR)0x0000;
  290. }
  291. }
  292. return(result);
  293. }
  294. #ifndef UNDER_CE
  295. int WINAPI
  296. WinGetWindowTextLengthA_CP(UINT codePage, HWND hWnd)
  297. {
  298. if(::IsWindowUnicode(hWnd)) {
  299. INT len = ::GetWindowTextLengthW(hWnd);
  300. if(len > 0) {
  301. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len+1));
  302. if(lpwstr) {
  303. ::GetWindowTextW(hWnd, lpwstr, len+1);
  304. INT size = WideCharToMultiByte(codePage, WC_COMPOSITECHECK,
  305. lpwstr, -1,
  306. NULL, NULL, 0, 0);
  307. MemFree(lpwstr);
  308. return size;
  309. }
  310. }
  311. }
  312. else {
  313. return ::GetWindowTextLengthA(hWnd);
  314. }
  315. return 0;
  316. }
  317. #endif //UNDER_CE
  318. //////////////////////////////////////////////////////////////////
  319. // Function : WinGetWindowTextLengthW_CP
  320. // Type : int WINAPI
  321. // Purpose :
  322. // Args :
  323. // : UINT codePage
  324. // : HWND hWnd
  325. // Return :
  326. // DATE : Fri Jul 16 04:31:18 1999
  327. // Histroy :
  328. //////////////////////////////////////////////////////////////////
  329. int WINAPI
  330. WinGetWindowTextLengthW_CP(UINT codePage, HWND hWnd)
  331. {
  332. if(::IsWindowUnicode(hWnd)) {
  333. return ::GetWindowTextLengthA(hWnd);
  334. }
  335. else {
  336. INT size = ::GetWindowTextLengthA(hWnd);
  337. if(size > 0) {
  338. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(CHAR)*(size+1));
  339. if(lpstr) {
  340. ::GetWindowTextA(hWnd, lpstr, size+1);
  341. INT len = MultiByteToWideChar(codePage, MB_PRECOMPOSED,
  342. lpstr, -1,
  343. NULL, NULL);
  344. MemFree(lpstr);
  345. return len;
  346. }
  347. }
  348. }
  349. return 0;
  350. }
  351. //--------- for Win64 -------------------------------------------
  352. #ifdef _WIN64
  353. //////////////////////////////////////////////////////////////////
  354. // Function : WinSetUserData
  355. // Type : LONG_PTR WINAPI
  356. // Purpose : Wrapper for Win64 SetWindowLongPtr(.., GWLP_USERDATA,..) ;
  357. // Args :
  358. // :
  359. // : HWND hwnd
  360. // : LONG_PTR lUserData
  361. // Return :
  362. // DATE : Mon Jul 12 18:26:41 1999
  363. // Histroy :
  364. //////////////////////////////////////////////////////////////////
  365. static LONG_PTR WINAPI
  366. WinSetUserDataTemplate(HWND hwnd, LONG_PTR lUserData, INT iOffset)
  367. {
  368. if(::IsWindowUnicode(hwnd)) {
  369. return ::SetWindowLongPtrW(hwnd, iOffset, lUserData);
  370. }
  371. else {
  372. return ::SetWindowLongPtrA(hwnd, iOffset, lUserData);
  373. }
  374. }
  375. inline LONG_PTR WINAPI WinSetUserData(HWND hwnd, LONG_PTR lUserData){
  376. return(WinSetUserDataTemplate(hwnd, lUserData, GWLP_USERDATA));
  377. }
  378. inline LONG_PTR WINAPI WinSetUserDlgData(HWND hwnd, LONG_PTR lUserData){
  379. return(WinSetUserDataTemplate(hwnd, lUserData, DWLP_USER));
  380. }
  381. inline LONG_PTR WINAPI WinSetMsgResult(HWND hwnd, LONG_PTR lUserData){
  382. return(WinSetUserDataTemplate(hwnd, lUserData, DWLP_MSGRESULT));
  383. }
  384. //////////////////////////////////////////////////////////////////
  385. // Function : WinGetUserData
  386. // Type : LONG_PTR WINAPI
  387. // Purpose : Wrapper for Win64 GetWindowLongPtr(..,GWLP_USERDATA,.. );
  388. // Args :
  389. // : HWND hwnd
  390. // Return :
  391. // DATE : Mon Jul 12 18:28:07 1999
  392. // Histroy :
  393. //////////////////////////////////////////////////////////////////
  394. static LONG_PTR WINAPI
  395. WinGetUserDataTemplate(HWND hwnd, INT iOffset)
  396. {
  397. if(::IsWindowUnicode(hwnd)) {
  398. return ::GetWindowLongPtrW(hwnd, iOffset);
  399. }
  400. else {
  401. return ::GetWindowLongPtrA(hwnd, iOffset);
  402. }
  403. }
  404. inline LONG_PTR WINAPI WinGetUserData(HWND hwnd){
  405. return(WinGetUserDataTemplate(hwnd, GWLP_USERDATA));
  406. }
  407. inline LONG_PTR WINAPI WinGetUserDlgData(HWND hwnd){
  408. return(WinGetUserDataTemplate(hwnd, DWLP_USER));
  409. }
  410. inline LONG_PTR WINAPI WinGetMsgResult(HWND hwnd){
  411. return(WinGetUserDataTemplate(hwnd, DWLP_MSGRESULT));
  412. }
  413. #else //!_WIN64
  414. //------- for Win32 ------------------------------------------
  415. //////////////////////////////////////////////////////////////////
  416. // Function : WinSetUserData
  417. // Type : LONG WINAPI
  418. // Purpose :
  419. // Args :
  420. // : HWND hwnd
  421. // : LONG lUserData
  422. // Return :
  423. // DATE : Mon Jul 12 18:29:21 1999
  424. // Histroy :
  425. //////////////////////////////////////////////////////////////////
  426. static LONG WINAPI
  427. WinSetUserDataTemplate(HWND hwnd, LONG lUserData, INT iOffset)
  428. {
  429. #ifdef UNDER_CE
  430. return SetWindowLong(hwnd, iOffset, lUserData);
  431. #else //!UNDER_CE
  432. if(::IsWindowUnicode(hwnd)) {
  433. return ::SetWindowLongW(hwnd, iOffset, lUserData);
  434. }
  435. else {
  436. return ::SetWindowLongA(hwnd, iOffset, lUserData);
  437. }
  438. #endif
  439. }
  440. inline LONG WINAPI WinSetUserData(HWND hwnd, LONG lUserData){
  441. return(WinSetUserDataTemplate(hwnd, lUserData, GWL_USERDATA));
  442. }
  443. inline LONG WINAPI WinSetUserDlgData(HWND hwnd, LONG lUserData){
  444. return(WinSetUserDataTemplate(hwnd, lUserData, DWL_USER));
  445. }
  446. inline LONG WINAPI WinSetMsgResult(HWND hwnd, LONG lUserData){
  447. return(WinSetUserDataTemplate(hwnd, lUserData, DWL_MSGRESULT));
  448. }
  449. //////////////////////////////////////////////////////////////////
  450. // Function : WinGetUserData
  451. // Type : LONG WINAPI
  452. // Purpose :
  453. // Args :
  454. // : HWND hwnd
  455. // Return :
  456. // DATE : Mon Jul 12 18:29:43 1999
  457. // Histroy :
  458. //////////////////////////////////////////////////////////////////
  459. static LONG WINAPI
  460. WinGetUserDataTemplate(HWND hwnd, INT iOffset)
  461. {
  462. #ifdef UNDER_CE
  463. return GetWindowLong(hwnd, iOffset);
  464. #else //!UNDER_CE
  465. if(::IsWindowUnicode(hwnd)) {
  466. return ::GetWindowLongW(hwnd, iOffset);
  467. }
  468. else {
  469. return ::GetWindowLongA(hwnd, iOffset);
  470. }
  471. #endif
  472. }
  473. inline LONG WINAPI WinGetUserData(HWND hwnd){
  474. return(WinGetUserDataTemplate(hwnd, GWL_USERDATA));
  475. }
  476. inline LONG WINAPI WinGetUserDlgData(HWND hwnd){
  477. return(WinGetUserDataTemplate(hwnd, DWL_USER));
  478. }
  479. inline LONG WINAPI WinGetMsgResult(HWND hwnd){
  480. return(WinGetUserDataTemplate(hwnd, DWL_MSGRESULT));
  481. }
  482. #endif //_WIN64
  483. //////////////////////////////////////////////////////////////////
  484. // Function : WinSetWndProc
  485. // Type : WNDPROC WINAPI
  486. // Purpose :
  487. // Args :
  488. // : HWND hwnd
  489. // : WNDPROC lpfnWndProc
  490. // Return :
  491. // DATE : Mon Jul 12 18:13:47 1999
  492. // Histroy :
  493. //////////////////////////////////////////////////////////////////
  494. WNDPROC WINAPI
  495. WinSetWndProc(HWND hwnd, WNDPROC lpfnWndProc)
  496. {
  497. #ifdef _WIN64
  498. if(::IsWindowUnicode(hwnd)) {
  499. return (WNDPROC)::SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)lpfnWndProc);
  500. }
  501. else {
  502. return (WNDPROC)::SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)lpfnWndProc);
  503. }
  504. #else //!_WIN64
  505. #ifdef UNDER_CE
  506. return (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG)lpfnWndProc);
  507. #else //!UNDER_CE
  508. if(::IsWindowUnicode(hwnd)) {
  509. return (WNDPROC)::SetWindowLongW(hwnd, GWL_WNDPROC, (LONG)lpfnWndProc);
  510. }
  511. else {
  512. return (WNDPROC)::SetWindowLongA(hwnd, GWL_WNDPROC, (LONG)lpfnWndProc);
  513. }
  514. #endif //end UNDER_CE
  515. #endif //_WIN64
  516. }
  517. LPVOID WINAPI
  518. WinSetUserPtr(HWND hwnd, LPVOID lpVoid)
  519. {
  520. #ifdef _WIN64
  521. return (LPVOID)WinSetUserData(hwnd, (LONG_PTR)lpVoid);
  522. #else
  523. return (LPVOID)WinSetUserData(hwnd, (LONG)lpVoid);
  524. #endif
  525. }
  526. LPVOID WINAPI WinGetUserPtr(HWND hwnd)
  527. {
  528. return (LPVOID)WinGetUserData(hwnd);
  529. }
  530. //////////////////////////////////////////////////////////////////
  531. // Function : WinGetWndProc
  532. // Type : WNDPROC WINAPI
  533. // Purpose :
  534. // Args :
  535. // : HWND hwnd
  536. // Return :
  537. // DATE : Mon Jul 12 18:30:22 1999
  538. // Histroy :
  539. //////////////////////////////////////////////////////////////////
  540. WNDPROC WINAPI
  541. WinGetWndProc(HWND hwnd)
  542. {
  543. #ifdef _WIN64
  544. if(::IsWindowUnicode(hwnd)) {
  545. return (WNDPROC)::GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
  546. }
  547. else {
  548. return (WNDPROC)::GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
  549. }
  550. #else //!_WIN64
  551. # ifdef UNDER_CE
  552. return (WNDPROC)GetWindowLong(hwnd, GWL_WNDPROC);
  553. # else
  554. if(::IsWindowUnicode(hwnd)) {
  555. return (WNDPROC)::GetWindowLongW(hwnd, GWL_WNDPROC);
  556. }
  557. else {
  558. return (WNDPROC)::GetWindowLongA(hwnd, GWL_WNDPROC);
  559. }
  560. # endif //end UNDER_CE
  561. #endif //_WIN64
  562. }
  563. DWORD WINAPI
  564. WinSetStyle(HWND hwnd, DWORD dwStyle)
  565. {
  566. #ifdef UNDER_CE
  567. return (DWORD)::SetWindowLong(hwnd, GWL_STYLE, (LONG)dwStyle);
  568. #else //!UNDER_CE
  569. if(::IsWindowUnicode(hwnd)) {
  570. return (DWORD)::SetWindowLongW(hwnd, GWL_STYLE, (LONG)dwStyle);
  571. }
  572. else {
  573. return (DWORD)::SetWindowLongA(hwnd, GWL_STYLE, (LONG)dwStyle);
  574. }
  575. #endif //End UNDER_CE
  576. }
  577. DWORD WINAPI
  578. WinGetStyle(HWND hwnd)
  579. {
  580. #ifdef UNDER_CE
  581. return (DWORD)::GetWindowLong(hwnd, GWL_STYLE);
  582. #else //!UNDER_CE
  583. if(::IsWindowUnicode(hwnd)) {
  584. return (DWORD)::GetWindowLongW(hwnd, GWL_STYLE);
  585. }
  586. else {
  587. return (DWORD)::GetWindowLongA(hwnd, GWL_STYLE);
  588. }
  589. #endif //End UNDER_CE
  590. }
  591. DWORD WINAPI
  592. WinSetExStyle(HWND hwnd, DWORD dwStyle)
  593. {
  594. #ifdef UNDER_CE
  595. return (DWORD)::SetWindowLong(hwnd, GWL_EXSTYLE, (LONG)dwStyle);
  596. #else //!UNDER_CE
  597. if(::IsWindowUnicode(hwnd)) {
  598. return (DWORD)::SetWindowLongW(hwnd, GWL_EXSTYLE, (LONG)dwStyle);
  599. }
  600. else {
  601. return (DWORD)::SetWindowLongA(hwnd, GWL_EXSTYLE, (LONG)dwStyle);
  602. }
  603. #endif //End UNDER_CE
  604. }
  605. DWORD WINAPI
  606. WinGetExStyle(HWND hwnd)
  607. {
  608. #ifdef UNDER_CE
  609. return (DWORD)::GetWindowLong(hwnd, GWL_EXSTYLE);
  610. #else //!UNDER_CE
  611. if(::IsWindowUnicode(hwnd)) {
  612. return (DWORD)::GetWindowLongW(hwnd, GWL_EXSTYLE);
  613. }
  614. else {
  615. return (DWORD)::GetWindowLongA(hwnd, GWL_EXSTYLE);
  616. }
  617. #endif //End UNDER_CE
  618. }
  619. HINSTANCE WINAPI
  620. WinGetInstanceHandle(HWND hwnd)
  621. {
  622. #ifdef _WIN64
  623. if(::IsWindowUnicode(hwnd)) {
  624. return (HINSTANCE)::GetWindowLongPtrW(hwnd, GWLP_HINSTANCE);
  625. }
  626. else {
  627. return (HINSTANCE)::GetWindowLongPtrA(hwnd, GWLP_HINSTANCE);
  628. }
  629. #else //!_WIN64
  630. #ifdef UNDER_CE
  631. return (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
  632. #else //!UNDER_CE
  633. if(::IsWindowUnicode(hwnd)) {
  634. return (HINSTANCE)::GetWindowLongW(hwnd, GWL_HINSTANCE);
  635. }
  636. else {
  637. return (HINSTANCE)::GetWindowLongA(hwnd, GWL_HINSTANCE);
  638. }
  639. #endif //end UNDER_CE
  640. #endif //_WIN64
  641. }
  642. #endif //#if !(defined(UNICODE) || defined(_UNICODE) || !defined(AWBOTH))
  643. #ifndef UNDER_CE // always Unicode
  644. INT LB_AddStringA(HWND hwndCtl, LPCSTR lpsz)
  645. {
  646. INT ret;
  647. if(::IsWindowUnicode(hwndCtl)) {
  648. INT len = ::lstrlenA(lpsz);
  649. if(len > 0) {
  650. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  651. if(lpwstr) {
  652. ::MultiByteToWideChar(932, MB_PRECOMPOSED, lpsz, -1,
  653. lpwstr, len+1);
  654. ret = (INT)::SendMessageW(hwndCtl, LB_ADDSTRING, 0, (LPARAM)lpwstr);
  655. MemFree(lpwstr);
  656. return ret;
  657. }
  658. }else{
  659. return(INT)(::SendMessageW(hwndCtl, LB_ADDSTRING, 0, (LPARAM)L""));
  660. }
  661. }
  662. else {
  663. return (INT)::SendMessageA(hwndCtl, LB_ADDSTRING, 0, (LPARAM)lpsz);
  664. }
  665. return 0;
  666. }
  667. #endif // UNDER_CE
  668. INT LB_AddStringW(HWND hwndCtl, LPCWSTR lpsz)
  669. {
  670. if(!lpsz) {
  671. return -1;
  672. }
  673. if(::IsWindowUnicode(hwndCtl)) {
  674. ::SendMessageW(hwndCtl, LB_ADDSTRING, 0, (LPARAM)lpsz);
  675. }
  676. else {
  677. #ifndef UNDER_CE // always Unicode
  678. INT len = ::lstrlenW(lpsz);
  679. if(len > 0) {
  680. INT ret;
  681. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  682. if(lpstr) {
  683. ::WideCharToMultiByte(932, WC_COMPOSITECHECK,
  684. lpsz, -1,
  685. lpstr,
  686. sizeof(WCHAR)*(len+1),
  687. NULL, NULL);
  688. ret = (INT)::SendMessageA(hwndCtl, LB_ADDSTRING, 0, (LPARAM)lpstr);
  689. MemFree(lpstr);
  690. return ret;
  691. }
  692. }else{
  693. return(INT)(::SendMessageA(hwndCtl, LB_ADDSTRING, 0, (LPARAM)""));
  694. }
  695. #endif // UNDER_CE
  696. }
  697. return 0;
  698. }
  699. #ifndef UNDER_CE // always Unicode
  700. INT CB_AddStringA(HWND hwndCtl, LPCSTR lpsz)
  701. {
  702. if(!lpsz) {
  703. return 0;
  704. }
  705. if(::IsWindowUnicode(hwndCtl)) {
  706. INT len = ::lstrlenA(lpsz);
  707. if(len > 0) {
  708. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  709. if(lpwstr) {
  710. ::MultiByteToWideChar(932, MB_PRECOMPOSED, lpsz, -1,
  711. lpwstr, len+1);
  712. ::SendMessageW(hwndCtl, CB_ADDSTRING, 0, (LPARAM)lpwstr);
  713. MemFree(lpwstr);
  714. }
  715. }else{
  716. ::SendMessageW(hwndCtl, CB_ADDSTRING, 0, (LPARAM)L"");
  717. }
  718. }
  719. else {
  720. ::SendMessageA(hwndCtl, CB_ADDSTRING, 0, (LPARAM)lpsz);
  721. }
  722. return 0;
  723. }
  724. #endif // UNDER_CE
  725. INT CB_AddStringW(HWND hwndCtl, LPCWSTR lpsz)
  726. {
  727. if(!lpsz) {
  728. return -1;
  729. }
  730. if(::IsWindowUnicode(hwndCtl)) {
  731. ::SendMessageW(hwndCtl, CB_ADDSTRING, 0, (LPARAM)lpsz);
  732. }
  733. else {
  734. #ifndef UNDER_CE // always Unicode
  735. INT len = ::lstrlenW(lpsz);
  736. if(len > 0) {
  737. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  738. if(lpstr) {
  739. ::WideCharToMultiByte(932, WC_COMPOSITECHECK,
  740. lpsz, -1,
  741. lpstr,
  742. sizeof(WCHAR)*(len+1),
  743. NULL, NULL);
  744. ::SendMessageA(hwndCtl, CB_ADDSTRING, 0, (LPARAM)lpstr);
  745. MemFree(lpstr);
  746. }
  747. }else{
  748. ::SendMessageA(hwndCtl, CB_ADDSTRING, 0, (LPARAM)"");
  749. }
  750. #endif // UNDER_CE
  751. }
  752. return 0;
  753. }
  754. #ifndef UNDER_CE // always Unicode
  755. INT CB_InsertStringA(HWND hwndCtl, INT index, LPCSTR lpsz)
  756. {
  757. if(!lpsz) {
  758. return 0;
  759. }
  760. if(::IsWindowUnicode(hwndCtl)) {
  761. INT len = ::lstrlenA(lpsz);
  762. if(len > 0) {
  763. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  764. if(lpwstr) {
  765. ::MultiByteToWideChar(932, MB_PRECOMPOSED, lpsz, -1,
  766. lpwstr, len+1);
  767. ::SendMessageW(hwndCtl, CB_INSERTSTRING, index, (LPARAM)lpwstr);
  768. MemFree(lpwstr);
  769. }
  770. }else{
  771. ::SendMessageW(hwndCtl, CB_INSERTSTRING, index, (LPARAM)L"");
  772. }
  773. }
  774. else {
  775. ::SendMessageA(hwndCtl, CB_INSERTSTRING, index, (LPARAM)lpsz);
  776. }
  777. return 0;
  778. }
  779. #endif // UNDER_CE
  780. INT CB_InsertStringW(HWND hwndCtl, INT index, LPCWSTR lpsz)
  781. {
  782. if(!lpsz) {
  783. return -1;
  784. }
  785. if(::IsWindowUnicode(hwndCtl)) {
  786. ::SendMessageW(hwndCtl, CB_INSERTSTRING, index, (LPARAM)lpsz);
  787. }
  788. else {
  789. #ifndef UNDER_CE // always Unicode
  790. INT len = ::lstrlenW(lpsz);
  791. if(len > 0) {
  792. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  793. if(lpstr) {
  794. ::WideCharToMultiByte(932, WC_COMPOSITECHECK,
  795. lpsz, -1,
  796. lpstr,
  797. sizeof(WCHAR)*(len+1),
  798. NULL, NULL);
  799. ::SendMessageA(hwndCtl, CB_INSERTSTRING, index, (LPARAM)lpstr);
  800. MemFree(lpstr);
  801. }
  802. }else{
  803. ::SendMessageA(hwndCtl, CB_INSERTSTRING, index, (LPARAM)"");
  804. }
  805. #endif // UNDER_CE
  806. }
  807. return 0;
  808. }
  809. #ifndef UNDER_CE // always Unicode
  810. INT CB_GetLBTextA(HWND hwndCtl, INT index, LPSTR lpszBuffer)
  811. {
  812. if(!lpszBuffer) {
  813. return 0;
  814. }
  815. if(::IsWindowUnicode(hwndCtl)) {
  816. INT len = WinComboBox_GetLBTextLen(hwndCtl, index);
  817. if(len > 0) {
  818. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  819. if(lpwstr) {
  820. ::SendMessageW(hwndCtl, CB_GETLBTEXT, (WPARAM)index, (LPARAM)lpwstr);
  821. ::WideCharToMultiByte(932, WC_COMPOSITECHECK,
  822. lpwstr, -1,
  823. lpszBuffer,
  824. sizeof(WCHAR)*(len+1),
  825. NULL, NULL);
  826. MemFree(lpwstr);
  827. }
  828. }
  829. }
  830. else {
  831. ::SendMessageA(hwndCtl, CB_GETLBTEXT, (WPARAM)index, (LPARAM)lpszBuffer);
  832. }
  833. return 0;
  834. }
  835. #endif // UNDER_CE
  836. INT CB_GetLBTextW(HWND hwndCtl, INT index, LPWSTR lpszBuffer)
  837. {
  838. if(!lpszBuffer) {
  839. return 0;
  840. }
  841. if(::IsWindowUnicode(hwndCtl)) {
  842. ::SendMessageW(hwndCtl, CB_GETLBTEXT, (WPARAM)index, (LPARAM)lpszBuffer);
  843. }
  844. else {
  845. #ifndef UNDER_CE // always Unicode
  846. INT len = WinComboBox_GetLBTextLen(hwndCtl, index);
  847. if(len > 0) {
  848. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  849. if(lpstr) {
  850. ::SendMessageA(hwndCtl, CB_GETLBTEXT, (WPARAM)index, (LPARAM)lpstr);
  851. ::MultiByteToWideChar(932, MB_PRECOMPOSED, lpstr, -1,
  852. lpszBuffer, len+1);
  853. MemFree(lpstr);
  854. }
  855. }
  856. #endif // UNDER_CE
  857. }
  858. return 0;
  859. }
  860. #ifndef UNDER_CE // always Unicode
  861. INT CB_FindStringA(HWND hwndCtl, INT indexStart, LPCSTR lpszFind)
  862. {
  863. INT result = 0;
  864. if(!lpszFind) {
  865. return 0;
  866. }
  867. if(::IsWindowUnicode(hwndCtl)) {
  868. INT len = ::lstrlenA(lpszFind);
  869. if(len > 0) {
  870. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  871. if(lpwstr) {
  872. ::MultiByteToWideChar(932, MB_PRECOMPOSED, lpszFind, -1,
  873. lpwstr, len+1);
  874. result = (INT)::SendMessageW(hwndCtl, CB_FINDSTRING, (WPARAM)indexStart, (LPARAM)lpwstr);
  875. MemFree(lpwstr);
  876. }
  877. }
  878. }
  879. else {
  880. result = (INT)::SendMessageA(hwndCtl, CB_FINDSTRING, (WPARAM)indexStart, (LPARAM)lpszFind);
  881. }
  882. return(result);
  883. }
  884. #endif // UNDER_CE
  885. INT CB_FindStringW(HWND hwndCtl, INT indexStart, LPCWSTR lpszFind)
  886. {
  887. INT result = 0;
  888. if(!lpszFind) {
  889. return 0;
  890. }
  891. if(::IsWindowUnicode(hwndCtl)) {
  892. result = (INT)::SendMessageW(hwndCtl, CB_FINDSTRING, (WPARAM)indexStart, (LPARAM)lpszFind);
  893. }
  894. else {
  895. #ifndef UNDER_CE // always Unicode
  896. INT len = ::lstrlenW(lpszFind);
  897. if(len > 0) {
  898. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  899. if(lpstr) {
  900. ::WideCharToMultiByte(932, WC_COMPOSITECHECK,
  901. lpszFind, -1,
  902. lpstr,
  903. sizeof(WCHAR)*(len+1),
  904. NULL, NULL);
  905. result = (INT)::SendMessageA(hwndCtl, CB_FINDSTRING, (WPARAM)indexStart, (LPARAM)lpstr);
  906. MemFree(lpstr);
  907. }
  908. }
  909. #endif // UNDER_CE
  910. }
  911. return(result);
  912. }
  913. #ifndef UNDER_CE // always Unicode
  914. INT CB_FindStringExactA(HWND hwndCtl, INT indexStart, LPCSTR lpszFind)
  915. {
  916. INT result = 0;
  917. if(!lpszFind) {
  918. return 0;
  919. }
  920. if(::IsWindowUnicode(hwndCtl)) {
  921. INT len = ::lstrlenA(lpszFind);
  922. if(len > 0) {
  923. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  924. if(lpwstr) {
  925. ::MultiByteToWideChar(932, MB_PRECOMPOSED, lpszFind, -1,
  926. lpwstr, len+1);
  927. result = (INT)::SendMessageW(hwndCtl, CB_FINDSTRINGEXACT, (WPARAM)indexStart, (LPARAM)lpwstr);
  928. MemFree(lpwstr);
  929. }
  930. }
  931. }
  932. else {
  933. result = (INT)::SendMessageA(hwndCtl, CB_FINDSTRINGEXACT, (WPARAM)indexStart, (LPARAM)lpszFind);
  934. }
  935. return(result);
  936. }
  937. #endif // UNDER_CE
  938. INT CB_FindStringExactW(HWND hwndCtl, INT indexStart, LPCWSTR lpszFind)
  939. {
  940. INT result = 0;
  941. if(!lpszFind) {
  942. return 0;
  943. }
  944. if(::IsWindowUnicode(hwndCtl)) {
  945. result = (INT)::SendMessageW(hwndCtl, CB_FINDSTRINGEXACT, (WPARAM)indexStart, (LPARAM)lpszFind);
  946. }
  947. else {
  948. #ifndef UNDER_CE // always Unicode
  949. INT len = ::lstrlenW(lpszFind);
  950. if(len > 0) {
  951. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  952. if(lpstr) {
  953. ::WideCharToMultiByte(932, WC_COMPOSITECHECK,
  954. lpszFind, -1,
  955. lpstr,
  956. sizeof(WCHAR)*(len+1),
  957. NULL, NULL);
  958. result = (INT)::SendMessageA(hwndCtl, CB_FINDSTRINGEXACT, (WPARAM)indexStart, (LPARAM)lpstr);
  959. MemFree(lpstr);
  960. }
  961. }
  962. #endif // UNDER_CE
  963. }
  964. return(result);
  965. }
  966. #ifndef UNDER_CE // always Unicode
  967. INT CB_SelectStringA(HWND hwndCtl, INT indexStart, LPCSTR lpszSelect)
  968. {
  969. INT ret = CB_ERR;
  970. if(!lpszSelect) {
  971. return CB_ERR;
  972. }
  973. if(::IsWindowUnicode(hwndCtl)) {
  974. INT len = ::lstrlenA(lpszSelect);
  975. if(len > 0) {
  976. LPWSTR lpwstr = (LPWSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  977. if(lpwstr) {
  978. ::MultiByteToWideChar(932, MB_PRECOMPOSED, lpszSelect, -1,
  979. lpwstr, len+1);
  980. ret = (INT)::SendMessageW(hwndCtl, CB_SELECTSTRING, (WPARAM)indexStart, (LPARAM)lpwstr);
  981. MemFree(lpwstr);
  982. }
  983. }
  984. }
  985. else {
  986. ret = (INT)::SendMessageA(hwndCtl, CB_SELECTSTRING, (WPARAM)indexStart, (LPARAM)lpszSelect);
  987. }
  988. return ret;
  989. }
  990. #endif // UNDER_CE
  991. INT CB_SelectStringW(HWND hwndCtl, INT indexStart, LPCWSTR lpszSelect)
  992. {
  993. INT ret = CB_ERR;
  994. if(!lpszSelect) {
  995. return CB_ERR;
  996. }
  997. if(::IsWindowUnicode(hwndCtl)) {
  998. ret = (INT)::SendMessageW(hwndCtl, CB_SELECTSTRING, (WPARAM)indexStart, (LPARAM)lpszSelect);
  999. }
  1000. else {
  1001. #ifndef UNDER_CE // always Unicode
  1002. INT len = ::lstrlenW(lpszSelect);
  1003. if(len > 0) {
  1004. LPSTR lpstr = (LPSTR)MemAlloc(sizeof(WCHAR)*(len + 1));
  1005. if(lpstr) {
  1006. ::WideCharToMultiByte(932, WC_COMPOSITECHECK,
  1007. lpszSelect, -1,
  1008. lpstr,
  1009. sizeof(WCHAR)*(len+1),
  1010. NULL, NULL);
  1011. ret = (INT)::SendMessageA(hwndCtl, CB_SELECTSTRING, (WPARAM)indexStart, (LPARAM)lpstr);
  1012. MemFree(lpstr);
  1013. }
  1014. }
  1015. #endif // UNDER_CE
  1016. }
  1017. return ret;
  1018. }