Source code of Windows XP (NT5)
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.

335 lines
12 KiB

  1. #include "pch.h"
  2. #include "resource.h"
  3. //-------------------------------------------------------------------------//
  4. // 'Styles' page impl
  5. //-------------------------------------------------------------------------//
  6. //
  7. // CreateIntance, DlgProc
  8. HWND CALLBACK StylesPage_CreateInstance( HWND hwndParent );
  9. INT_PTR CALLBACK StylesPage_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  10. //
  11. // Message handlers
  12. LRESULT CALLBACK StylesPage_OnInitDialog( HWND hwndPage, UINT, WPARAM, LPARAM );
  13. void CALLBACK StylesPage_OnCommand( HWND, UINT uCtlID, UINT uCode, HWND hwndCtl );
  14. // Utility methods
  15. void StylesPage_AddRemoveStyle( HWND hwnd, BOOL bAdd, DWORD dwStyle );
  16. void StylesPage_AddRemoveExStyle( HWND hwnd, BOOL bAdd, DWORD dwStyle );
  17. void StylesPage_CreateTestWindow( HWND hwndParent );
  18. void StylesPage_CreateTestDialog( HWND hwndParent );
  19. void StylesPage_SetTestStyles( HWND hwndPage );
  20. #define WMU_TESTWINDOWDIED (WM_USER + 0x301) // arbitrary.
  21. HWND _hwndTest = NULL;
  22. HWND _hwndPage = NULL;
  23. //-------------------------------------------------------------------------//
  24. INT_PTR CALLBACK StylesPage_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  25. {
  26. BOOL bHandled = TRUE;
  27. LRESULT lRet = 0L;
  28. _hwndPage = hwndPage;
  29. switch( uMsg )
  30. {
  31. case WM_INITDIALOG:
  32. lRet = StylesPage_OnInitDialog( hwndPage, uMsg, wParam, lParam );
  33. break;
  34. case WM_COMMAND:
  35. StylesPage_OnCommand( hwndPage, LOWORD(wParam), HIWORD(wParam), (HWND)lParam );
  36. break;
  37. case WM_NCDESTROY:
  38. _hwndPage = NULL;
  39. break;
  40. case WMU_TESTWINDOWDIED:
  41. StylesPage_OnCommand( hwndPage, 0, 0, NULL );
  42. break;
  43. default:
  44. bHandled = FALSE;
  45. break;
  46. }
  47. return bHandled;
  48. }
  49. //-------------------------------------------------------------------------//
  50. HWND CALLBACK StylesPage_CreateInstance( HWND hwndParent )
  51. {
  52. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_PAGE_STYLES),
  53. hwndParent, StylesPage_DlgProc );
  54. }
  55. //-------------------------------------------------------------------------//
  56. LRESULT CALLBACK StylesPage_OnInitDialog(
  57. HWND hwndPage, UINT, WPARAM, LPARAM )
  58. {
  59. DWORD dwStyle = GetWindowLong( g_hwndMain, GWL_STYLE );
  60. DWORD dwExStyle = GetWindowLong( g_hwndMain, GWL_EXSTYLE );
  61. CheckDlgButton( hwndPage, IDC_WS_MINIMIZEBOX, (dwStyle & WS_MINIMIZEBOX) != 0 );
  62. CheckDlgButton( hwndPage, IDC_WS_MAXIMIZEBOX, (dwStyle & WS_MAXIMIZEBOX) != 0 );
  63. CheckDlgButton( hwndPage, IDC_WS_CAPTION, (dwStyle & WS_CAPTION) != 0 );
  64. CheckDlgButton( hwndPage, IDC_WS_BORDER, (dwStyle & WS_BORDER) != 0 );
  65. CheckDlgButton( hwndPage, IDC_WS_DLGFRAME, (dwStyle & WS_DLGFRAME) != 0 );
  66. CheckDlgButton( hwndPage, IDC_WS_VSCROLL, (dwStyle & WS_VSCROLL) != 0 );
  67. CheckDlgButton( hwndPage, IDC_WS_HSCROLL, (dwStyle & WS_HSCROLL) != 0 );
  68. CheckDlgButton( hwndPage, IDC_WS_SYSMENU, (dwStyle & WS_SYSMENU) != 0 );
  69. CheckDlgButton( hwndPage, IDC_WS_THICKFRAME, (dwStyle & WS_THICKFRAME) != 0 );
  70. CheckDlgButton( hwndPage, IDC_WS_EX_DLGMODALFRAME, (dwExStyle & WS_EX_DLGMODALFRAME) );
  71. CheckDlgButton( hwndPage, IDC_WS_EX_TOOLWINDOW, (dwExStyle & WS_EX_TOOLWINDOW) );
  72. CheckDlgButton( hwndPage, IDC_WS_EX_WINDOWEDGE, (dwExStyle & WS_EX_WINDOWEDGE) );
  73. CheckDlgButton( hwndPage, IDC_WS_EX_CLIENTEDGE, (dwExStyle & WS_EX_CLIENTEDGE) );
  74. CheckDlgButton( hwndPage, IDC_WS_EX_CONTEXTHELP, (dwExStyle & WS_EX_CONTEXTHELP) );
  75. CheckDlgButton( hwndPage, IDC_WS_EX_RIGHT, (dwExStyle & WS_EX_RIGHT) );
  76. CheckDlgButton( hwndPage, IDC_WS_EX_LEFT, (dwExStyle & WS_EX_LEFT) );
  77. CheckDlgButton( hwndPage, IDC_WS_EX_RTLREADING, (dwExStyle & WS_EX_RTLREADING) );
  78. CheckDlgButton( hwndPage, IDC_WS_EX_LEFTSCROLLBAR, (dwExStyle & WS_EX_LEFTSCROLLBAR) );
  79. CheckDlgButton( hwndPage, IDC_WS_EX_RIGHTSCROLLBAR, (dwExStyle & WS_EX_RIGHTSCROLLBAR) );
  80. CheckDlgButton( hwndPage, IDC_WS_EX_STATICEDGE, (dwExStyle & WS_EX_STATICEDGE) );
  81. CheckDlgButton( hwndPage, IDC_WS_EX_APPWINDOW, (dwExStyle & WS_EX_APPWINDOW) );
  82. #ifdef WS_EX_LAYOUTRTL
  83. CheckDlgButton( hwndPage, IDC_WS_EX_LAYOUTRTL, (dwExStyle & WS_EX_LAYOUTRTL) );
  84. #endif WS_EX_LAYOUTRTL
  85. CheckDlgButton( hwndPage, IDC_WS_OVERLAPPED2, TRUE );
  86. StylesPage_SetTestStyles( hwndPage );
  87. return TRUE;
  88. }
  89. //-------------------------------------------------------------------------//
  90. void CALLBACK StylesPage_OnCommand(
  91. HWND hwndPage, UINT uCtlID, UINT uCode, HWND hwndCtl )
  92. {
  93. BOOL bChecked = IsDlgButtonChecked( hwndPage, uCtlID );
  94. switch( uCtlID )
  95. {
  96. case IDC_WS_MINIMIZEBOX:
  97. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_MINIMIZEBOX );
  98. break;
  99. case IDC_WS_MAXIMIZEBOX:
  100. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_MAXIMIZEBOX );
  101. break;
  102. case IDC_WS_CAPTION:
  103. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_CAPTION );
  104. break;
  105. case IDC_WS_BORDER:
  106. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_BORDER );
  107. break;
  108. case IDC_WS_DLGFRAME:
  109. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_DLGFRAME );
  110. break;
  111. case IDC_WS_VSCROLL:
  112. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_VSCROLL );
  113. break;
  114. case IDC_WS_HSCROLL:
  115. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_HSCROLL );
  116. break;
  117. case IDC_WS_SYSMENU:
  118. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_SYSMENU );
  119. break;
  120. case IDC_WS_THICKFRAME:
  121. StylesPage_AddRemoveStyle( g_hwndMain, bChecked, WS_THICKFRAME );
  122. break;
  123. case IDC_TEST_WINDOW:
  124. StylesPage_CreateTestWindow( hwndPage );
  125. break;
  126. case IDC_TEST_DIALOG:
  127. StylesPage_CreateTestDialog( hwndPage );
  128. break;
  129. case IDC_CLOSE_TEST_WINDOW:
  130. if( IsWindow( _hwndTest ) )
  131. {
  132. DestroyWindow( _hwndTest );
  133. _hwndTest = NULL;
  134. }
  135. break;
  136. case IDC_WS_OVERLAPPED2:
  137. case IDC_WS_POPUP2:
  138. case IDC_WS_CHILD2:
  139. StylesPage_SetTestStyles( hwndPage );
  140. break;
  141. }
  142. EnableWindow( GetDlgItem( hwndPage, IDC_TEST_WINDOW ), !IsWindow( _hwndTest ) );
  143. EnableWindow( GetDlgItem( hwndPage, IDC_TEST_DIALOG ), !IsWindow( _hwndTest ) );
  144. EnableWindow( GetDlgItem( hwndPage, IDC_CLOSE_TEST_WINDOW ), IsWindow( _hwndTest ) );
  145. }
  146. // Utility methods
  147. void StylesPage_AddRemoveStyle( HWND hwnd, BOOL bAdd, DWORD dwStyle )
  148. {
  149. DWORD style = GetWindowLong( hwnd, GWL_STYLE );
  150. if( bAdd )
  151. SetWindowLong( hwnd, GWL_STYLE, style | dwStyle );
  152. else
  153. SetWindowLong( hwnd, GWL_STYLE, style & ~dwStyle );
  154. SetWindowPos( hwnd, NULL, 0, 0, 0, 0,
  155. SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_DRAWFRAME );
  156. }
  157. void StylesPage_AddRemoveExStyle( HWND hwnd, BOOL bAdd, DWORD dwStyle )
  158. {
  159. DWORD style = GetWindowLong( hwnd, GWL_EXSTYLE );
  160. if( bAdd )
  161. SetWindowLong( hwnd, GWL_EXSTYLE, style | dwStyle );
  162. else
  163. SetWindowLong( hwnd, GWL_EXSTYLE, style & ~dwStyle );
  164. SetWindowPos( hwnd, NULL, 0, 0, 0, 0,
  165. SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_DRAWFRAME );
  166. }
  167. void StylesPage_ClearTestStyles( HWND hwndPage )
  168. {
  169. CheckDlgButton( hwndPage, IDC_WS_MINIMIZEBOX2, 0 );
  170. CheckDlgButton( hwndPage, IDC_WS_MAXIMIZEBOX2, 0 );
  171. CheckDlgButton( hwndPage, IDC_WS_CAPTION2, 0 );
  172. CheckDlgButton( hwndPage, IDC_WS_BORDER2, 0 );
  173. CheckDlgButton( hwndPage, IDC_WS_DLGFRAME2, 0 );
  174. CheckDlgButton( hwndPage, IDC_WS_VSCROLL2, 0 );
  175. CheckDlgButton( hwndPage, IDC_WS_HSCROLL2, 0 );
  176. CheckDlgButton( hwndPage, IDC_WS_SYSMENU2, 0 );
  177. CheckDlgButton( hwndPage, IDC_WS_THICKFRAME2, 0 );
  178. }
  179. void StylesPage_SetTestStyles( HWND hwndPage )
  180. {
  181. StylesPage_ClearTestStyles( hwndPage );
  182. if( IsDlgButtonChecked( hwndPage, IDC_WS_OVERLAPPED2 ) )
  183. {
  184. CheckDlgButton( hwndPage, IDC_WS_CAPTION2, TRUE );
  185. CheckDlgButton( hwndPage, IDC_WS_SYSMENU2, TRUE );
  186. CheckDlgButton( hwndPage, IDC_WS_THICKFRAME2, TRUE );
  187. CheckDlgButton( hwndPage, IDC_WS_CAPTION2, TRUE );
  188. CheckDlgButton( hwndPage, IDC_WS_MINIMIZEBOX2, TRUE );
  189. CheckDlgButton( hwndPage, IDC_WS_MAXIMIZEBOX2, TRUE );
  190. }
  191. else if ( IsDlgButtonChecked( hwndPage, IDC_WS_POPUP2 ) )
  192. {
  193. CheckDlgButton( hwndPage, IDC_WS_BORDER2, TRUE );
  194. CheckDlgButton( hwndPage, IDC_WS_SYSMENU2, TRUE );
  195. }
  196. }
  197. BOOL StylesPage_GetTestStyles(
  198. HWND hwndPage,
  199. OUT LPDWORD pdwStyle,
  200. OUT LPDWORD pdwExStyle )
  201. {
  202. *pdwStyle = *pdwExStyle = 0;
  203. #define ASSIGN_TEST_STYLE(uID, dwStyle) if( IsDlgButtonChecked(hwndPage, uID) ) {(*pdwStyle) |= dwStyle;}
  204. #define ASSIGN_TEST_EXSTYLE(uID, dwStyle) if( IsDlgButtonChecked(hwndPage, uID) ) {(*pdwExStyle) |= dwStyle;}
  205. ASSIGN_TEST_STYLE( IDC_WS_OVERLAPPED2, WS_OVERLAPPED );
  206. ASSIGN_TEST_STYLE( IDC_WS_POPUP2, WS_POPUP );
  207. ASSIGN_TEST_STYLE( IDC_WS_CHILD2, WS_CHILD );
  208. ASSIGN_TEST_STYLE( IDC_WS_MINIMIZEBOX2, WS_MINIMIZEBOX );
  209. ASSIGN_TEST_STYLE( IDC_WS_MAXIMIZEBOX2, WS_MAXIMIZEBOX );
  210. ASSIGN_TEST_STYLE( IDC_WS_CAPTION2, WS_CAPTION );
  211. ASSIGN_TEST_STYLE( IDC_WS_BORDER2, WS_BORDER );
  212. ASSIGN_TEST_STYLE( IDC_WS_DLGFRAME2, WS_DLGFRAME );
  213. ASSIGN_TEST_STYLE( IDC_WS_VSCROLL2, WS_VSCROLL );
  214. ASSIGN_TEST_STYLE( IDC_WS_HSCROLL2, WS_HSCROLL );
  215. ASSIGN_TEST_STYLE( IDC_WS_SYSMENU2, WS_SYSMENU );
  216. ASSIGN_TEST_STYLE( IDC_WS_THICKFRAME2, WS_THICKFRAME );
  217. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_DLGMODALFRAME2, WS_EX_DLGMODALFRAME );
  218. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_TOOLWINDOW2, WS_EX_TOOLWINDOW );
  219. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_WINDOWEDGE2, WS_EX_WINDOWEDGE );
  220. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_CLIENTEDGE2, WS_EX_CLIENTEDGE );
  221. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_CONTEXTHELP2, WS_EX_CONTEXTHELP );
  222. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_RIGHT2, WS_EX_RIGHT );
  223. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_LEFT2, WS_EX_LEFT );
  224. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_RTLREADING2, WS_EX_RTLREADING );
  225. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_LEFTSCROLLBAR2, WS_EX_LEFTSCROLLBAR );
  226. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_RIGHTSCROLLBAR2, WS_EX_RIGHTSCROLLBAR );
  227. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_STATICEDGE2, WS_EX_STATICEDGE );
  228. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_APPWINDOW2, WS_EX_APPWINDOW );
  229. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_OVERLAPPEDWINDOW2, WS_EX_OVERLAPPEDWINDOW );
  230. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_PALETTEWINDOW2, WS_EX_PALETTEWINDOW );
  231. ASSIGN_TEST_EXSTYLE( IDC_WS_EX_LAYOUTRTL2, WS_EX_LAYOUTRTL );
  232. return TRUE;
  233. }
  234. LRESULT CALLBACK StylesPage_TestWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  235. {
  236. switch(uMsg)
  237. {
  238. case WM_NCDESTROY:
  239. PostMessage( _hwndPage, WMU_TESTWINDOWDIED, 0, 0 );
  240. break;
  241. }
  242. return DefWindowProc( hwnd, uMsg, wParam, lParam );
  243. }
  244. void StylesPage_CreateTestWindow( HWND hwndParent )
  245. {
  246. DWORD dwStyle, dwExStyle;
  247. WNDCLASSEX wc;
  248. ZeroMemory( &wc, sizeof(wc) );
  249. wc.cbSize = sizeof(wc);
  250. wc.style = CS_HREDRAW|CS_VREDRAW;
  251. wc.lpfnWndProc = StylesPage_TestWndProc;
  252. wc.hInstance = g_hInst;
  253. wc.hIcon = NULL;
  254. wc.hCursor = NULL;
  255. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  256. wc.lpszMenuName = 0; //MAKEINTRESOURCE(pszTestMenu)
  257. wc.lpszClassName = TEXT("ThemeSelTestWindow");
  258. wc.hIconSm = NULL;
  259. RegisterClassEx( &wc );
  260. StylesPage_GetTestStyles( hwndParent, &dwStyle, &dwExStyle );
  261. int x = CW_USEDEFAULT, y = CW_USEDEFAULT, cx = CW_USEDEFAULT, cy = CW_USEDEFAULT;
  262. if( dwStyle & WS_CHILD|WS_POPUP )
  263. {
  264. x = y = 25;
  265. cx = cy = 250;
  266. }
  267. _hwndTest = CreateWindowEx( dwExStyle, wc.lpszClassName, TEXT("Theme Test Window"),
  268. dwStyle|WS_VISIBLE,
  269. x, y, cx, cy, hwndParent, 0, g_hInst, NULL );
  270. if( IsWindow( _hwndTest ) )
  271. {
  272. if( dwStyle & WS_CHILD )
  273. {
  274. //SetWindowPos( _hwndTest, HWND_TOP, 0, 0, 0, 0,
  275. // SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE );
  276. //InvalidateRect( _hwndTest, NULL, TRUE );
  277. }
  278. }
  279. }
  280. void StylesPage_CreateTestDialog( HWND hwndParent )
  281. {
  282. StylesPage_CreateTestWindow( hwndParent );
  283. }