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.

462 lines
16 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/control_panel/functions.h
  3. *
  4. * Purpose: Control Panel functions.
  5. *
  6. * Created: 1st April 2006
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2006-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file winstl/control_panel/functions.h
  40. *
  41. * \brief [C, C++] Control Panel functions
  42. * (\ref group__library__windows_control_panel "Windows Control Panel" Library).
  43. */
  44. #ifndef WINSTL_INCL_WINSTL_CONTROL_PANEL_H_FUNCTIONS
  45. #define WINSTL_INCL_WINSTL_CONTROL_PANEL_H_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define WINSTL_VER_WINSTL_CONTROL_PANEL_H_FUNCTIONS_MAJOR 1
  48. # define WINSTL_VER_WINSTL_CONTROL_PANEL_H_FUNCTIONS_MINOR 0
  49. # define WINSTL_VER_WINSTL_CONTROL_PANEL_H_FUNCTIONS_REVISION 6
  50. # define WINSTL_VER_WINSTL_CONTROL_PANEL_H_FUNCTIONS_EDIT 14
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Compatibility
  54. */
  55. /*
  56. [Incompatibilies-start]
  57. STLSOFT_COMPILER_IS_GCC: __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 3)
  58. [Incompatibilies-end]
  59. */
  60. /* /////////////////////////////////////////////////////////////////////////
  61. * Includes
  62. */
  63. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  64. # include <winstl/winstl.h>
  65. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  66. #ifndef STLSOFT_INCL_H_CPL
  67. # define STLSOFT_INCL_H_CPL
  68. # include <cpl.h>
  69. #endif /* !STLSOFT_INCL_H_CPL */
  70. /* /////////////////////////////////////////////////////////////////////////
  71. * Namespace
  72. */
  73. #if !defined(_WINSTL_NO_NAMESPACE) && \
  74. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  75. # if defined(_STLSOFT_NO_NAMESPACE)
  76. /* There is no stlsoft namespace, so must define ::winstl */
  77. namespace winstl
  78. {
  79. # else
  80. /* Define stlsoft::winstl_project */
  81. namespace stlsoft
  82. {
  83. namespace winstl_project
  84. {
  85. # endif /* _STLSOFT_NO_NAMESPACE */
  86. #endif /* !_WINSTL_NO_NAMESPACE */
  87. /* /////////////////////////////////////////////////////////////////////////
  88. * Typedefs
  89. */
  90. /** \brief Function pointer representing the entry point provide by all
  91. * control panel applet modules.
  92. */
  93. typedef LONG (APIENTRY *control_panel_entry_t)(HWND , UINT , LONG , LONG );
  94. /* /////////////////////////////////////////////////////////////////////////
  95. * C functions
  96. */
  97. /** \brief [C, C++] Initialises a control panel applet module.
  98. *
  99. * \ingroup group__library__windows_control_panel
  100. */
  101. STLSOFT_INLINE BOOL winstl__control_panel_init(control_panel_entry_t entry, HWND hwnd)
  102. {
  103. WINSTL_ASSERT(NULL != entry);
  104. return (*entry)(hwnd, CPL_INIT, 0, 0);
  105. }
  106. /** \brief [C, C++] Uninitialises a control panel applet module.
  107. *
  108. * \ingroup group__library__windows_control_panel
  109. *
  110. */
  111. STLSOFT_INLINE void winstl__control_panel_uninit(control_panel_entry_t entry, HWND hwnd)
  112. {
  113. WINSTL_ASSERT(NULL != entry);
  114. stlsoft_static_cast(void, (*entry)(hwnd, CPL_EXIT, 0, 0));
  115. }
  116. /** \brief [C, C++] Retrieves the number of control panel applets within a control panel applet module.
  117. *
  118. * \ingroup group__library__windows_control_panel
  119. *
  120. */
  121. STLSOFT_INLINE ss_size_t winstl__control_panel_get_count(control_panel_entry_t entry, HWND hwnd)
  122. {
  123. WINSTL_ASSERT(NULL != entry);
  124. return stlsoft_static_cast(ss_size_t, (*entry)(hwnd, CPL_GETCOUNT, 0, 0));
  125. }
  126. /** \brief [C, C++] Issues an inquiry control (CPL_INQUIRE) to a control panel applet.
  127. *
  128. * \ingroup group__library__windows_control_panel
  129. *
  130. */
  131. STLSOFT_INLINE void winstl__control_panel_inquire(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LPCPLINFO info)
  132. {
  133. WINSTL_ASSERT(NULL != entry);
  134. WINSTL_ASSERT(NULL != info);
  135. WINSTL_ASSERT(index < winstl__control_panel_get_count(entry, hwnd));
  136. stlsoft_static_cast(void, (*entry)(hwnd, CPL_INQUIRE, stlsoft_static_cast(LONG, index), stlsoft_reinterpret_cast(LONG, info)));
  137. }
  138. /** \brief [C, C++] Issues a "new" inquiry control (CPL_NEWINQUIRE) to a control panel applet.
  139. *
  140. * \ingroup group__library__windows_control_panel
  141. *
  142. */
  143. STLSOFT_INLINE void winstl__control_panel_newinquire(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LPNEWCPLINFO info)
  144. {
  145. /* Some applets don't handle sizeof(NEWCPLINFOA), so we try with Unicode first. */
  146. union
  147. {
  148. NEWCPLINFOA infoa_;
  149. NEWCPLINFOW infow_;
  150. } u;
  151. WINSTL_ASSERT(NULL != entry);
  152. WINSTL_ASSERT(NULL != info);
  153. WINSTL_ASSERT(sizeof(NEWCPLINFOA) != info->dwSize || sizeof(NEWCPLINFOW) != info->dwSize);
  154. WINSTL_ASSERT(index < winstl__control_panel_get_count(entry, hwnd));
  155. u.infoa_.dwFlags = 0;
  156. u.infoa_.dwHelpContext = 0;
  157. u.infoa_.lData = 0;
  158. u.infoa_.hIcon = NULL;
  159. u.infoa_.szName[0] = L'\0';
  160. u.infoa_.szInfo[0] = L'\0';
  161. u.infoa_.szHelpFile[0] = L'\0';
  162. u.infow_.szName[0] = L'\0';
  163. u.infow_.szInfo[0] = L'\0';
  164. u.infow_.szHelpFile[0] = L'\0';
  165. if(sizeof(NEWCPLINFOW) == info->dwSize)
  166. {
  167. /* Try Unicode first. */
  168. LPNEWCPLINFOW infow = stlsoft_reinterpret_cast(LPNEWCPLINFOW, info);
  169. u.infow_.dwSize = sizeof(NEWCPLINFOW);
  170. stlsoft_static_cast(void, (*entry)(hwnd, CPL_NEWINQUIRE, stlsoft_static_cast(LONG, index), stlsoft_reinterpret_cast(LONG, &u.infow_)));
  171. if( u.infow_.dwSize == sizeof(NEWCPLINFOW) &&
  172. L'\0' != u.infow_.szName[0])
  173. {
  174. *infow = u.infow_;
  175. }
  176. else
  177. {
  178. /* Unicode failed, so try ANSI. */
  179. u.infoa_.dwSize = sizeof(NEWCPLINFOA);
  180. stlsoft_static_cast(void, (*entry)(hwnd, CPL_NEWINQUIRE, stlsoft_static_cast(LONG, index), stlsoft_reinterpret_cast(LONG, &u.infoa_)));
  181. STLSOFT_NS_GLOBAL(MultiByteToWideChar)(0, 0, u.infoa_.szName, -1, infow->szName, STLSOFT_NUM_ELEMENTS(u.infow_.szName));
  182. STLSOFT_NS_GLOBAL(MultiByteToWideChar)(0, 0, u.infoa_.szInfo, -1, infow->szInfo, STLSOFT_NUM_ELEMENTS(u.infow_.szInfo));
  183. STLSOFT_NS_GLOBAL(MultiByteToWideChar)(0, 0, u.infoa_.szHelpFile, -1, infow->szHelpFile, STLSOFT_NUM_ELEMENTS(u.infow_.szHelpFile));
  184. }
  185. }
  186. else
  187. {
  188. /* Try ANSI first. */
  189. LPNEWCPLINFOA infoa = stlsoft_reinterpret_cast(LPNEWCPLINFOA, info);
  190. u.infoa_.dwSize = sizeof(NEWCPLINFOA);
  191. stlsoft_static_cast(void, (*entry)(hwnd, CPL_NEWINQUIRE, stlsoft_static_cast(LONG, index), stlsoft_reinterpret_cast(LONG, &u.infoa_)));
  192. if( u.infoa_.dwSize == sizeof(NEWCPLINFOA) &&
  193. '\0' != u.infoa_.szName[0])
  194. {
  195. *infoa = u.infoa_;
  196. }
  197. else
  198. {
  199. /* ANSI failed, so try Unicode. */
  200. u.infow_.dwSize = sizeof(NEWCPLINFOW);
  201. stlsoft_static_cast(void, (*entry)(hwnd, CPL_NEWINQUIRE, stlsoft_static_cast(LONG, index), stlsoft_reinterpret_cast(LONG, &u.infow_)));
  202. STLSOFT_NS_GLOBAL(WideCharToMultiByte)(0, 0, u.infow_.szName, -1, infoa->szName, STLSOFT_NUM_ELEMENTS(u.infoa_.szName), NULL, NULL);
  203. STLSOFT_NS_GLOBAL(WideCharToMultiByte)(0, 0, u.infow_.szInfo, -1, infoa->szInfo, STLSOFT_NUM_ELEMENTS(u.infoa_.szInfo), NULL, NULL);
  204. STLSOFT_NS_GLOBAL(WideCharToMultiByte)(0, 0, u.infow_.szHelpFile, -1, infoa->szHelpFile, STLSOFT_NUM_ELEMENTS(u.infoa_.szHelpFile), NULL, NULL);
  205. }
  206. }
  207. }
  208. /** \brief [C, C++] Issues a run control (CPL_DBLCLK) to a control panel applet, including caller-supplied data.
  209. *
  210. * \ingroup group__library__windows_control_panel
  211. *
  212. */
  213. STLSOFT_INLINE BOOL winstl__control_panel_run_data(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LONG data)
  214. {
  215. WINSTL_ASSERT(NULL != entry);
  216. return !stlsoft_static_cast(BOOL, (*entry)(hwnd, CPL_DBLCLK, stlsoft_static_cast(LONG, index), data));
  217. }
  218. /** \brief [C, C++] Issues a run control (CPL_STARTWPARMSA) to a control panel applet, including caller-supplied parameter string.
  219. *
  220. * \ingroup group__library__windows_control_panel
  221. *
  222. */
  223. STLSOFT_INLINE BOOL winstl__control_panel_run_params_a(control_panel_entry_t entry, HWND hwnd, ss_size_t index, ws_char_a_t const* params)
  224. {
  225. WINSTL_ASSERT(NULL != entry);
  226. return stlsoft_static_cast(BOOL, (*entry)(hwnd, CPL_STARTWPARMSA, stlsoft_static_cast(LONG, index), (LONG)params));
  227. }
  228. /** \brief [C, C++] Issues a run control (CPL_STARTWPARMSW) to a control panel applet, including caller-supplied parameter string.
  229. *
  230. * \ingroup group__library__windows_control_panel
  231. *
  232. */
  233. STLSOFT_INLINE BOOL winstl__control_panel_run_params_w(control_panel_entry_t entry, HWND hwnd, ss_size_t index, ws_char_w_t const* params)
  234. {
  235. WINSTL_ASSERT(NULL != entry);
  236. return stlsoft_static_cast(BOOL, (*entry)(hwnd, CPL_STARTWPARMSW, stlsoft_static_cast(LONG, index), (LONG)params));
  237. }
  238. /** \brief [C, C++] Issues a stop control (CPL_STOP) to a control panel applet.
  239. *
  240. * \ingroup group__library__windows_control_panel
  241. *
  242. */
  243. STLSOFT_INLINE void winstl__control_panel_stop(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LONG data)
  244. {
  245. WINSTL_ASSERT(NULL != entry);
  246. stlsoft_static_cast(void, (*entry)(hwnd, CPL_STOP, stlsoft_static_cast(LONG, index), data));
  247. }
  248. /* /////////////////////////////////////////////////////////////////////////
  249. * Namespace
  250. */
  251. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  252. namespace winstl
  253. {
  254. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  255. /* /////////////////////////////////////////////////////////////////////////
  256. * C++ functions
  257. */
  258. #ifdef __cplusplus
  259. /* /////////////////////////////////////////////////////////////////////////
  260. *
  261. */
  262. /** \brief Initialises a control panel applet module.
  263. *
  264. * \ingroup group__library__windows_control_panel
  265. */
  266. inline BOOL control_panel_init(control_panel_entry_t entry, HWND hwnd)
  267. {
  268. return winstl__control_panel_init(entry, hwnd);
  269. }
  270. /** \brief Uninitialises a control panel applet module.
  271. *
  272. * \ingroup group__library__windows_control_panel
  273. *
  274. */
  275. inline void control_panel_uninit(control_panel_entry_t entry, HWND hwnd)
  276. {
  277. winstl__control_panel_uninit(entry, hwnd);
  278. }
  279. /** \brief Retrieves the number of control panel applets within a control panel applet module.
  280. *
  281. * \ingroup group__library__windows_control_panel
  282. *
  283. */
  284. inline ss_size_t control_panel_get_count(control_panel_entry_t entry, HWND hwnd)
  285. {
  286. return winstl__control_panel_get_count(entry, hwnd);
  287. }
  288. /** \brief Issues an inquiry control (CPL_INQUIRE) to a control panel applet.
  289. *
  290. * \ingroup group__library__windows_control_panel
  291. *
  292. */
  293. inline void control_panel_inquire(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LPCPLINFO info)
  294. {
  295. winstl__control_panel_inquire(entry, hwnd, index, info);
  296. }
  297. /** \brief Issues a "new" inquiry control (CPL_NEWINQUIRE) to a control panel applet.
  298. *
  299. * \ingroup group__library__windows_control_panel
  300. *
  301. */
  302. inline void control_panel_newinquire(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LPNEWCPLINFO info)
  303. {
  304. winstl__control_panel_newinquire(entry, hwnd, index, info);
  305. }
  306. /** \brief Issues a run control (CPL_DBLCLK) to a control panel applet, including caller-supplied data.
  307. *
  308. * \ingroup group__library__windows_control_panel
  309. *
  310. */
  311. inline BOOL control_panel_run_data(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LONG data)
  312. {
  313. return winstl__control_panel_run_data(entry, hwnd, index, data);
  314. }
  315. /** \brief Issues a run control (CPL_STARTWPARMSA) to a control panel applet, including caller-supplied parameter string.
  316. *
  317. * \ingroup group__library__windows_control_panel
  318. *
  319. */
  320. inline BOOL control_panel_run_params_a(control_panel_entry_t entry, HWND hwnd, ss_size_t index, ws_char_a_t const* params)
  321. {
  322. return winstl__control_panel_run_params_a(entry, hwnd, index, params);
  323. }
  324. /** \brief Issues a run control (CPL_STARTWPARMSW) to a control panel applet, including caller-supplied parameter string.
  325. *
  326. * \ingroup group__library__windows_control_panel
  327. *
  328. */
  329. inline BOOL control_panel_run_params_w(control_panel_entry_t entry, HWND hwnd, ss_size_t index, ws_char_w_t const* params)
  330. {
  331. return winstl__control_panel_run_params_w(entry, hwnd, index, params);
  332. }
  333. /** \brief Issues a run control (CPL_DBLCLK) to a control panel applet, including caller-supplied data.
  334. *
  335. * \ingroup group__library__windows_control_panel
  336. *
  337. */
  338. inline BOOL control_panel_run(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LONG data)
  339. {
  340. return control_panel_run_data(entry, hwnd, index, data);
  341. }
  342. /** \brief Issues a run control (CPL_STARTWPARMSA) to a control panel applet, including caller-supplied parameter string.
  343. *
  344. * \ingroup group__library__windows_control_panel
  345. *
  346. */
  347. inline BOOL control_panel_run(control_panel_entry_t entry, HWND hwnd, ss_size_t index, ws_char_a_t const* params)
  348. {
  349. return control_panel_run_params_a(entry, hwnd, index, params);
  350. }
  351. /** \brief Issues a run control (CPL_STARTWPARMSW) to a control panel applet, including caller-supplied parameter string.
  352. *
  353. * \ingroup group__library__windows_control_panel
  354. *
  355. */
  356. inline BOOL control_panel_run(control_panel_entry_t entry, HWND hwnd, ss_size_t index, ws_char_w_t const* params)
  357. {
  358. return control_panel_run_params_w(entry, hwnd, index, params);
  359. }
  360. /** \brief Issues a stop control (CPL_STOP) to a control panel applet.
  361. *
  362. * \ingroup group__library__windows_control_panel
  363. *
  364. */
  365. inline void control_panel_stop(control_panel_entry_t entry, HWND hwnd, ss_size_t index, LONG data)
  366. {
  367. winstl__control_panel_stop(entry, hwnd, index, data);
  368. }
  369. /* ////////////////////////////////////////////////////////////////////// */
  370. #endif /* __cplusplus */
  371. /* /////////////////////////////////////////////////////////////////////////
  372. * Unit-testing
  373. */
  374. #ifdef STLSOFT_UNITTEST
  375. # include "./unittest/functions_unittest_.h"
  376. #endif /* STLSOFT_UNITTEST */
  377. /* ////////////////////////////////////////////////////////////////////// */
  378. #ifndef _WINSTL_NO_NAMESPACE
  379. # if defined(_STLSOFT_NO_NAMESPACE) || \
  380. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  381. } /* namespace winstl */
  382. # else
  383. } /* namespace winstl_project */
  384. } /* namespace stlsoft */
  385. # endif /* _STLSOFT_NO_NAMESPACE */
  386. #endif /* !_WINSTL_NO_NAMESPACE */
  387. /* ////////////////////////////////////////////////////////////////////// */
  388. #endif /* WINSTL_INCL_WINSTL_CONTROL_PANEL_H_FUNCTIONS */
  389. /* ///////////////////////////// end of file //////////////////////////// */