winundef.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: winundef.h
  3. // Purpose: undefine the common symbols #define'd by <windows.h>
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 16.05.99
  7. // Copyright: (c) wxWidgets team
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. /* THIS SHOULD NOT BE USED since you might include it once e.g. in window.h,
  11. * then again _AFTER_ you've included windows.h, in which case it won't work
  12. * a 2nd time -- JACS
  13. #ifndef _WX_WINUNDEF_H_
  14. #define _WX_WINUNDEF_H_
  15. */
  16. // ----------------------------------------------------------------------------
  17. // windows.h #defines the following identifiers which are also used in wxWin so
  18. // we replace these symbols with the corresponding inline functions and
  19. // undefine the macro.
  20. //
  21. // This looks quite ugly here but allows us to write clear (and correct!) code
  22. // elsewhere because the functions, unlike the macros, respect the scope.
  23. // ----------------------------------------------------------------------------
  24. // CreateDialog
  25. #if defined(CreateDialog)
  26. #undef CreateDialog
  27. inline HWND CreateDialog(HINSTANCE hInstance,
  28. LPCTSTR pTemplate,
  29. HWND hwndParent,
  30. DLGPROC pDlgProc)
  31. {
  32. #ifdef _UNICODE
  33. return CreateDialogW(hInstance, pTemplate, hwndParent, pDlgProc);
  34. #else
  35. return CreateDialogA(hInstance, pTemplate, hwndParent, pDlgProc);
  36. #endif
  37. }
  38. #endif
  39. // CreateFont
  40. #ifdef CreateFont
  41. #undef CreateFont
  42. inline HFONT CreateFont(int height,
  43. int width,
  44. int escapement,
  45. int orientation,
  46. int weight,
  47. DWORD italic,
  48. DWORD underline,
  49. DWORD strikeout,
  50. DWORD charset,
  51. DWORD outprecision,
  52. DWORD clipprecision,
  53. DWORD quality,
  54. DWORD family,
  55. LPCTSTR facename)
  56. {
  57. #ifdef _UNICODE
  58. return CreateFontW(height, width, escapement, orientation,
  59. weight, italic, underline, strikeout, charset,
  60. outprecision, clipprecision, quality,
  61. family, facename);
  62. #else
  63. return CreateFontA(height, width, escapement, orientation,
  64. weight, italic, underline, strikeout, charset,
  65. outprecision, clipprecision, quality,
  66. family, facename);
  67. #endif
  68. }
  69. #endif // CreateFont
  70. // CreateWindow
  71. #if defined(CreateWindow)
  72. #undef CreateWindow
  73. inline HWND CreateWindow(LPCTSTR lpClassName,
  74. LPCTSTR lpWndClass,
  75. DWORD dwStyle,
  76. int x, int y, int w, int h,
  77. HWND hWndParent,
  78. HMENU hMenu,
  79. HINSTANCE hInstance,
  80. LPVOID lpParam)
  81. {
  82. #ifdef _UNICODE
  83. return CreateWindowW(lpClassName, lpWndClass, dwStyle, x, y, w, h,
  84. hWndParent, hMenu, hInstance, lpParam);
  85. #else
  86. return CreateWindowA(lpClassName, lpWndClass, dwStyle, x, y, w, h,
  87. hWndParent, hMenu, hInstance, lpParam);
  88. #endif
  89. }
  90. #endif
  91. // LoadMenu
  92. #ifdef LoadMenu
  93. #undef LoadMenu
  94. inline HMENU LoadMenu(HINSTANCE instance, LPCTSTR name)
  95. {
  96. #ifdef _UNICODE
  97. return LoadMenuW(instance, name);
  98. #else
  99. return LoadMenuA(instance, name);
  100. #endif
  101. }
  102. #endif
  103. // FindText
  104. #ifdef FindText
  105. #undef FindText
  106. inline HWND APIENTRY FindText(LPFINDREPLACE lpfindreplace)
  107. {
  108. #ifdef _UNICODE
  109. return FindTextW(lpfindreplace);
  110. #else
  111. return FindTextA(lpfindreplace);
  112. #endif
  113. }
  114. #endif
  115. // GetCharWidth
  116. #ifdef GetCharWidth
  117. #undef GetCharWidth
  118. inline BOOL GetCharWidth(HDC dc, UINT first, UINT last, LPINT buffer)
  119. {
  120. #ifdef _UNICODE
  121. return GetCharWidthW(dc, first, last, buffer);
  122. #else
  123. return GetCharWidthA(dc, first, last, buffer);
  124. #endif
  125. }
  126. #endif
  127. // FindWindow
  128. #ifdef FindWindow
  129. #undef FindWindow
  130. #ifdef _UNICODE
  131. inline HWND FindWindow(LPCWSTR classname, LPCWSTR windowname)
  132. {
  133. return FindWindowW(classname, windowname);
  134. }
  135. #else
  136. inline HWND FindWindow(LPCSTR classname, LPCSTR windowname)
  137. {
  138. return FindWindowA(classname, windowname);
  139. }
  140. #endif
  141. #endif
  142. // PlaySound
  143. #ifdef PlaySound
  144. #undef PlaySound
  145. #ifdef _UNICODE
  146. inline BOOL PlaySound(LPCWSTR pszSound, HMODULE hMod, DWORD fdwSound)
  147. {
  148. return PlaySoundW(pszSound, hMod, fdwSound);
  149. }
  150. #else
  151. inline BOOL PlaySound(LPCSTR pszSound, HMODULE hMod, DWORD fdwSound)
  152. {
  153. return PlaySoundA(pszSound, hMod, fdwSound);
  154. }
  155. #endif
  156. #endif
  157. // GetClassName
  158. #ifdef GetClassName
  159. #undef GetClassName
  160. #ifdef _UNICODE
  161. inline int GetClassName(HWND h, LPWSTR classname, int maxcount)
  162. {
  163. return GetClassNameW(h, classname, maxcount);
  164. }
  165. #else
  166. inline int GetClassName(HWND h, LPSTR classname, int maxcount)
  167. {
  168. return GetClassNameA(h, classname, maxcount);
  169. }
  170. #endif
  171. #endif
  172. // GetClassInfo
  173. #ifdef GetClassInfo
  174. #undef GetClassInfo
  175. #ifdef _UNICODE
  176. inline BOOL GetClassInfo(HINSTANCE h, LPCWSTR name, LPWNDCLASSW winclass)
  177. {
  178. return GetClassInfoW(h, name, winclass);
  179. }
  180. #else
  181. inline BOOL GetClassInfo(HINSTANCE h, LPCSTR name, LPWNDCLASSA winclass)
  182. {
  183. return GetClassInfoA(h, name, winclass);
  184. }
  185. #endif
  186. #endif
  187. // LoadAccelerators
  188. #ifdef LoadAccelerators
  189. #undef LoadAccelerators
  190. #ifdef _UNICODE
  191. inline HACCEL LoadAccelerators(HINSTANCE h, LPCWSTR name)
  192. {
  193. return LoadAcceleratorsW(h, name);
  194. }
  195. #else
  196. inline HACCEL LoadAccelerators(HINSTANCE h, LPCSTR name)
  197. {
  198. return LoadAcceleratorsA(h, name);
  199. }
  200. #endif
  201. #endif
  202. // DrawText
  203. #ifdef DrawText
  204. #undef DrawText
  205. #ifdef _UNICODE
  206. inline int DrawText(HDC h, LPCWSTR str, int count, LPRECT rect, UINT format)
  207. {
  208. return DrawTextW(h, str, count, rect, format);
  209. }
  210. #else
  211. inline int DrawText(HDC h, LPCSTR str, int count, LPRECT rect, UINT format)
  212. {
  213. return DrawTextA(h, str, count, rect, format);
  214. }
  215. #endif
  216. #endif
  217. // StartDoc
  218. #ifdef StartDoc
  219. #undef StartDoc
  220. // Work around a bug in very old MinGW headers that didn't define DOCINFOW
  221. // and DOCINFOA but only DOCINFO in both ANSI and Unicode.
  222. #if defined( __GNUG__ )
  223. #if !wxCHECK_W32API_VERSION( 0, 5 )
  224. #define DOCINFOW DOCINFO
  225. #define DOCINFOA DOCINFO
  226. #endif
  227. #endif
  228. #ifdef _UNICODE
  229. inline int StartDoc(HDC h, CONST DOCINFOW* info)
  230. {
  231. return StartDocW(h, (DOCINFOW*) info);
  232. }
  233. #else
  234. inline int StartDoc(HDC h, CONST DOCINFOA* info)
  235. {
  236. return StartDocA(h, (DOCINFOA*) info);
  237. }
  238. #endif
  239. #endif
  240. // GetObject
  241. #ifdef GetObject
  242. #undef GetObject
  243. inline int GetObject(HGDIOBJ h, int i, LPVOID buffer)
  244. {
  245. #ifdef _UNICODE
  246. return GetObjectW(h, i, buffer);
  247. #else
  248. return GetObjectA(h, i, buffer);
  249. #endif
  250. }
  251. #endif
  252. // GetMessage
  253. #ifdef GetMessage
  254. #undef GetMessage
  255. inline int GetMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax)
  256. {
  257. #ifdef _UNICODE
  258. return GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
  259. #else
  260. return GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
  261. #endif
  262. }
  263. #endif
  264. // LoadIcon
  265. #ifdef LoadIcon
  266. #undef LoadIcon
  267. inline HICON LoadIcon(HINSTANCE hInstance, LPCTSTR lpIconName)
  268. {
  269. #ifdef _UNICODE
  270. return LoadIconW(hInstance, lpIconName);
  271. #else // ANSI
  272. return LoadIconA(hInstance, lpIconName);
  273. #endif // Unicode/ANSI
  274. }
  275. #endif // LoadIcon
  276. // LoadBitmap
  277. #ifdef LoadBitmap
  278. #undef LoadBitmap
  279. inline HBITMAP LoadBitmap(HINSTANCE hInstance, LPCTSTR lpBitmapName)
  280. {
  281. #ifdef _UNICODE
  282. return LoadBitmapW(hInstance, lpBitmapName);
  283. #else // ANSI
  284. return LoadBitmapA(hInstance, lpBitmapName);
  285. #endif // Unicode/ANSI
  286. }
  287. #endif // LoadBitmap
  288. // LoadLibrary
  289. #ifdef LoadLibrary
  290. #undef LoadLibrary
  291. #ifdef _UNICODE
  292. inline HINSTANCE LoadLibrary(LPCWSTR lpLibFileName)
  293. {
  294. return LoadLibraryW(lpLibFileName);
  295. }
  296. #else
  297. inline HINSTANCE LoadLibrary(LPCSTR lpLibFileName)
  298. {
  299. return LoadLibraryA(lpLibFileName);
  300. }
  301. #endif
  302. #endif
  303. // FindResource
  304. #ifdef FindResource
  305. #undef FindResource
  306. #ifdef _UNICODE
  307. inline HRSRC FindResource(HMODULE hModule, LPCWSTR lpName, LPCWSTR lpType)
  308. {
  309. return FindResourceW(hModule, lpName, lpType);
  310. }
  311. #else
  312. inline HRSRC FindResource(HMODULE hModule, LPCSTR lpName, LPCSTR lpType)
  313. {
  314. return FindResourceA(hModule, lpName, lpType);
  315. }
  316. #endif
  317. #endif
  318. // IsMaximized
  319. #ifdef IsMaximized
  320. #undef IsMaximized
  321. inline BOOL IsMaximized(HWND WXUNUSED_IN_WINCE(hwnd))
  322. {
  323. #ifdef __WXWINCE__
  324. return FALSE;
  325. #else
  326. return IsZoomed(hwnd);
  327. #endif
  328. }
  329. #endif
  330. // GetFirstChild
  331. #ifdef GetFirstChild
  332. #undef GetFirstChild
  333. inline HWND GetFirstChild(HWND WXUNUSED_IN_WINCE(hwnd))
  334. {
  335. #ifdef __WXWINCE__
  336. return 0;
  337. #else
  338. return GetTopWindow(hwnd);
  339. #endif
  340. }
  341. #endif
  342. // GetFirstSibling
  343. #ifdef GetFirstSibling
  344. #undef GetFirstSibling
  345. inline HWND GetFirstSibling(HWND hwnd)
  346. {
  347. return GetWindow(hwnd,GW_HWNDFIRST);
  348. }
  349. #endif
  350. // GetLastSibling
  351. #ifdef GetLastSibling
  352. #undef GetLastSibling
  353. inline HWND GetLastSibling(HWND hwnd)
  354. {
  355. return GetWindow(hwnd,GW_HWNDLAST);
  356. }
  357. #endif
  358. // GetPrevSibling
  359. #ifdef GetPrevSibling
  360. #undef GetPrevSibling
  361. inline HWND GetPrevSibling(HWND hwnd)
  362. {
  363. return GetWindow(hwnd,GW_HWNDPREV);
  364. }
  365. #endif
  366. // GetNextSibling
  367. #ifdef GetNextSibling
  368. #undef GetNextSibling
  369. inline HWND GetNextSibling(HWND hwnd)
  370. {
  371. return GetWindow(hwnd,GW_HWNDNEXT);
  372. }
  373. #endif
  374. // For WINE
  375. #if defined(GetWindowStyle)
  376. #undef GetWindowStyle
  377. #endif
  378. // For ming and cygwin
  379. // GetFirstChild
  380. #ifdef GetFirstChild
  381. #undef GetFirstChild
  382. inline HWND GetFirstChild(HWND h)
  383. {
  384. return GetTopWindow(h);
  385. }
  386. #endif
  387. // GetNextSibling
  388. #ifdef GetNextSibling
  389. #undef GetNextSibling
  390. inline HWND GetNextSibling(HWND h)
  391. {
  392. return GetWindow(h, GW_HWNDNEXT);
  393. }
  394. #endif
  395. #ifdef Yield
  396. #undef Yield
  397. #endif
  398. #if defined(__WXWINCE__) && defined(DrawIcon) //#ifdef DrawIcon
  399. #undef DrawIcon
  400. inline BOOL DrawIcon(HDC hdc, int x, int y, HICON hicon)
  401. {
  402. return DrawIconEx(hdc,x,y,hicon,0,0,0,NULL, DI_NORMAL) ;
  403. }
  404. #endif
  405. // GetWindowProc
  406. //ifdef GetWindowProc
  407. // #undef GetWindowProc
  408. //endif
  409. //ifdef GetNextChild
  410. // #undef GetNextChild
  411. //endif
  412. // #endif // _WX_WINUNDEF_H_