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.

254 lines
6.1 KiB

  1. #define WIN32_LEAN_AND_MEAN
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <commctrl.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "resource.h"
  8. #include "dbg.h"
  9. #include "exbtn.h"
  10. char g_szClass[]="TestMain";
  11. HINSTANCE g_hInst;
  12. BOOL InitApplication(HINSTANCE hInst, LPSTR lpstrClass, WNDPROC lpfnWndProc)
  13. {
  14. return 0;
  15. }
  16. LPWSTR GetWText(HWND hwnd, INT wID)
  17. {
  18. CHAR szBuf[256];
  19. static WCHAR wchBuf[512];
  20. Edit_GetText(GetDlgItem(hwnd, wID), szBuf, sizeof(szBuf));
  21. MultiByteToWideChar(CP_ACP,
  22. MB_PRECOMPOSED,
  23. szBuf, -1,
  24. (WCHAR*)wchBuf, sizeof(wchBuf)/sizeof(WCHAR) );
  25. return wchBuf;
  26. }
  27. typedef struct tagVALLIST {
  28. INT wID;
  29. INT lParam;
  30. }VALLIST;
  31. VALLIST slist[] = {
  32. { IDC_EXBS_TEXT, EXBS_TEXT },
  33. { IDC_EXBS_ICON, EXBS_ICON },
  34. { IDC_EXBS_THINEDGE, EXBS_THINEDGE },
  35. { IDC_EXBS_FLAT, EXBS_FLAT },
  36. { IDC_EXBS_TOGGLE, EXBS_TOGGLE },
  37. };
  38. typedef struct tagICONLIST {
  39. INT wID;
  40. INT lParam;
  41. INT width;
  42. INT height;
  43. }ICONLIST;
  44. ICONLIST iconList[]={
  45. { IDC_RADIO_ICON1, IDI_ICON1, 16, 16, },
  46. { IDC_RADIO_ICON2, IDI_ICON1, 32, 32, },
  47. { IDC_RADIO_ICON3, IDI_ICON2, 16, 16, },
  48. { IDC_RADIO_ICON4, IDI_ICON2, 32, 32, },
  49. };
  50. HWND MainCreateWindow(HINSTANCE hInst, HWND hwndOwner, LPSTR lpstrClass, LPVOID lpVoid)
  51. {
  52. HWND hwnd;
  53. hwnd = CreateDialogParam(hInst,
  54. g_szClass,
  55. hwndOwner,
  56. NULL,
  57. (LPARAM)lpVoid);
  58. if(!hwnd) {
  59. return (HWND)NULL;
  60. }
  61. UpdateWindow(hwnd);
  62. return hwnd;
  63. }
  64. #define ArrayCount(a) (sizeof(a)/sizeof(a[0]))
  65. #define MAX(a, b) ( a > b ? a : b)
  66. #define IDC_EXBID 4096
  67. LRESULT CALLBACK MainWndProc(HWND hwnd,
  68. UINT uMsg,
  69. WPARAM wParam,
  70. LPARAM lParam)
  71. {
  72. PAINTSTRUCT ps;
  73. HDC hDC;
  74. RECT rc;
  75. static INT iIndex;
  76. switch(uMsg) {
  77. case WM_CREATE:
  78. {
  79. HWND hwndEXB = EXButton_CreateWindow(g_hInst, hwnd, EXBS_TEXT,
  80. IDC_EXBID,
  81. 20,
  82. 30,
  83. 35,
  84. 18);
  85. EXButton_SetText(hwndEXB, L"�J�^");
  86. }
  87. SetTimer(hwnd, 0x9999, 50, NULL);
  88. return 1;
  89. case WM_TIMER:
  90. {
  91. KillTimer(hwnd, wParam);
  92. INT i;
  93. for(i = 0; i < sizeof(iconList)/sizeof(iconList[0]); i++) {
  94. HICON hIcon = LoadImage(g_hInst,
  95. MAKEINTRESOURCE(iconList[i].lParam),
  96. IMAGE_ICON,
  97. iconList[i].width,
  98. iconList[i].height,
  99. LR_DEFAULTCOLOR);
  100. SendMessage(GetDlgItem(hwnd, iconList[i].wID),
  101. BM_SETIMAGE,
  102. (WPARAM)IMAGE_ICON,
  103. (LPARAM)hIcon);
  104. }
  105. }
  106. break;
  107. case WM_SYSCOMMAND:
  108. if(wParam == SC_CLOSE) {
  109. PostQuitMessage(0);
  110. }
  111. break;
  112. case WM_COMMAND:
  113. {
  114. WORD wNotifyCode = HIWORD(wParam); // notification code
  115. WORD wID = LOWORD(wParam); // item, control, or accelerator identifier
  116. HWND hwndCtl = (HWND) lParam; // handle of control
  117. HWND hwndEXB = (HWND) GetDlgItem(hwnd, IDC_EXBID);
  118. switch(wID) {
  119. case IDC_EXBID:
  120. {
  121. switch(wNotifyCode) {
  122. case EXBN_CLICKED:
  123. DBG(("EXBN_CLICKED come\n"));
  124. break;
  125. case EXBN_DOUBLECLICKED:
  126. DBG(("EXBN_DOUBLECLICKED come\n"));
  127. break;
  128. case EXBN_ARMED:
  129. DBG(("EXBN_ARMED come\n"));
  130. EXButton_SetText(hwndEXB, L"�Ђ�");
  131. break;
  132. case EXBN_DISARMED:
  133. DBG(("EXBN_DISARMED come\n"));
  134. EXButton_SetText(hwndEXB, L"�J�^");
  135. break;
  136. default:
  137. DBG(("ERROR Unknown Notify\n"));
  138. break;
  139. }
  140. }
  141. break;
  142. break;
  143. case IDC_SETTEXT:
  144. {
  145. EXButton_SetText(hwndEXB, GetWText(hwnd, IDC_EDIT_SETTEXT));
  146. }
  147. break;
  148. case IDC_SETICON:
  149. {
  150. INT i;
  151. for(i = 0; i < sizeof(iconList)/sizeof(iconList[0]); i++) {
  152. if(Button_GetCheck(GetDlgItem(hwnd, iconList[i].wID))) {
  153. HICON hIcon = LoadImage(g_hInst,
  154. MAKEINTRESOURCE(iconList[i].lParam),
  155. IMAGE_ICON,
  156. iconList[i].width,
  157. iconList[i].height,
  158. LR_DEFAULTCOLOR);
  159. EXButton_SetIcon(hwndEXB, hIcon);
  160. }
  161. }
  162. }
  163. break;
  164. case IDC_SETCHECK_TRUE:
  165. EXButton_SetCheck(hwndEXB, TRUE);
  166. break;
  167. case IDC_SETCHECK_FALSE:
  168. EXButton_SetCheck(hwndEXB, FALSE);
  169. break;
  170. case IDC_SETSTYLE:
  171. {
  172. INT i;
  173. DWORD dwStyle = 0;
  174. for(i = 0; i < sizeof(slist)/sizeof(slist[0]); i++) {
  175. INT ret = Button_GetCheck(GetDlgItem(hwnd, slist[i].wID));
  176. if(ret) {
  177. dwStyle |= slist[i].lParam;
  178. }
  179. }
  180. EXButton_SetStyle(hwndEXB, dwStyle);
  181. }
  182. break;
  183. case IDC_ENABLE_TRUE:
  184. EnableWindow(hwndEXB, TRUE);
  185. break;
  186. case IDC_ENABLE_FALSE:
  187. EnableWindow(hwndEXB, FALSE);
  188. break;
  189. }
  190. }
  191. break;
  192. case WM_PAINT:
  193. hDC = BeginPaint(hwnd, &ps);
  194. GetClientRect(hwnd, &rc);
  195. FillRect(hDC, &rc, (HBRUSH)(COLOR_3DFACE + 1));
  196. EndPaint(hwnd, &ps);
  197. break;
  198. }
  199. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  200. }
  201. int WINAPI WinMain(HINSTANCE hInstance,
  202. HINSTANCE hPrevInstance,
  203. LPSTR lpCmdLine,
  204. int nCmdShow)
  205. {
  206. MSG msg;
  207. HWND hwnd;
  208. // INT ret;
  209. g_hInst = hInstance;
  210. WNDCLASSEX wc;
  211. ZeroMemory(&wc, sizeof(wc));
  212. wc.cbSize = sizeof(wc);
  213. wc.style = CS_HREDRAW | CS_VREDRAW; /* Class style(s). */
  214. wc.lpfnWndProc = (WNDPROC)MainWndProc;
  215. wc.cbClsExtra = 0; /* No per-class extra data.*/
  216. wc.cbWndExtra = DLGWINDOWEXTRA; /* No per-window extra data. */
  217. wc.hInstance = hInstance; /* Application that owns the class. */
  218. wc.hIcon = NULL; //LoadIcon(hInstance, MAKEINTRESOURCE(SCROLL32_ICON));
  219. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  220. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); //UGetStockObject(LTGRAY_BRUSH); //WHITE_BRUSH);
  221. wc.lpszMenuName = NULL; //g_szClass; /* Name of menu resource in .RC file. */
  222. wc.lpszClassName = g_szClass; /* Name used in call to CreateWindow. */
  223. wc.hIconSm = NULL;
  224. RegisterClassEx(&wc);
  225. hwnd = CreateDialog(hInstance,
  226. g_szClass,
  227. 0,
  228. NULL);
  229. UpdateWindow(hwnd);
  230. ShowWindow(hwnd, SW_SHOW);
  231. while (GetMessage(&msg, NULL, 0, 0)){
  232. TranslateMessage(&msg);
  233. DispatchMessage(&msg);
  234. }
  235. return 0;
  236. }