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.

324 lines
7.9 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 "ddbtn.h"
  10. #include "../ptt/ptt.h"
  11. char g_szClass[]="TestMain";
  12. HINSTANCE g_hInst;
  13. BOOL InitApplication(HINSTANCE hInst, LPSTR lpstrClass, WNDPROC lpfnWndProc)
  14. {
  15. return 0;
  16. }
  17. LPWSTR GetWText(HWND hwnd, INT wID)
  18. {
  19. CHAR szBuf[256];
  20. static WCHAR wchBuf[512];
  21. Edit_GetText(GetDlgItem(hwnd, wID), szBuf, sizeof(szBuf));
  22. MultiByteToWideChar(CP_ACP,
  23. MB_PRECOMPOSED,
  24. szBuf, -1,
  25. (WCHAR*)wchBuf, sizeof(wchBuf)/sizeof(WCHAR) );
  26. return wchBuf;
  27. }
  28. INT GetINT(HWND hwnd, INT wID)
  29. {
  30. CHAR szBuf[32];
  31. Edit_GetText(GetDlgItem(hwnd, wID), szBuf, sizeof(szBuf));
  32. return atoi(szBuf);
  33. }
  34. typedef struct tagVALLIST {
  35. INT wID;
  36. INT lParam;
  37. }VALLIST;
  38. VALLIST slist[] = {
  39. { IDC_DDBS_TEXT, DDBS_TEXT },
  40. { IDC_DDBS_ICON, DDBS_ICON },
  41. { IDC_DDBS_THINEDGE, DDBS_THINEDGE },
  42. { IDC_DDBS_FLAT, DDBS_FLAT },
  43. { IDC_DDBS_NOSEPARATEDBUTTON, DDBS_NOSEPARATED},
  44. };
  45. typedef struct tagICONLIST {
  46. INT wID;
  47. INT lParam;
  48. INT width;
  49. INT height;
  50. }ICONLIST;
  51. ICONLIST iconList[]={
  52. { IDC_RADIO_ICON1, IDI_ICON1, 16, 16, },
  53. { IDC_RADIO_ICON2, IDI_ICON1, 32, 32, },
  54. { IDC_RADIO_ICON3, IDI_ICON2, 16, 16, },
  55. { IDC_RADIO_ICON4, IDI_ICON2, 32, 32, },
  56. };
  57. HWND MainCreateWindow(HINSTANCE hInst, HWND hwndOwner, LPSTR lpstrClass, LPVOID lpVoid)
  58. {
  59. HWND hwnd;
  60. hwnd = CreateDialogParam(hInst,
  61. g_szClass,
  62. hwndOwner,
  63. NULL,
  64. (LPARAM)lpVoid);
  65. if(!hwnd) {
  66. return (HWND)NULL;
  67. }
  68. UpdateWindow(hwnd);
  69. return hwnd;
  70. }
  71. #define ArrayCount(a) (sizeof(a)/sizeof(a[0]))
  72. #define MAX(a, b) ( a > b ? a : b)
  73. #define IDC_DDBID 4096
  74. #define IDC_SWITCHVIEW 8888
  75. HWND CreateSwitchViewButton(HINSTANCE hInst, HWND hwndParent, INT wID)
  76. {
  77. HWND hwnd = DDButton_CreateWindow(hInst,
  78. hwndParent,
  79. DDBS_ICON,
  80. wID,
  81. 80,
  82. 30,
  83. 36,
  84. 24);
  85. HICON hIcon = LoadImage(hInst,
  86. MAKEINTRESOURCE(IDI_ICON2),
  87. IMAGE_ICON,
  88. 16, 16,
  89. LR_DEFAULTCOLOR);
  90. DDButton_SetIcon(hwnd, hIcon);
  91. DDBITEM ddbItem;
  92. ZeroMemory(&ddbItem, sizeof(ddbItem));
  93. ddbItem.cbSize = sizeof(ddbItem);
  94. ddbItem.lpwstr = L"�ڍו\��";
  95. DDButton_AddItem(hwnd, &ddbItem);
  96. ddbItem.lpwstr = L"�g���\��";
  97. DDButton_AddItem(hwnd, &ddbItem);
  98. DDButton_SetCurSel(hwnd, 0);
  99. return hwnd;
  100. }
  101. LRESULT CALLBACK MainWndProc(HWND hwnd,
  102. UINT uMsg,
  103. WPARAM wParam,
  104. LPARAM lParam)
  105. {
  106. PAINTSTRUCT ps;
  107. HDC hDC;
  108. RECT rc;
  109. static INT iIndex;
  110. switch(uMsg) {
  111. case WM_CREATE:
  112. {
  113. DDButton_CreateWindow(g_hInst, hwnd, DDBS_ICON,
  114. IDC_DDBID,
  115. 20,
  116. 30,
  117. 36,
  118. 24);
  119. CreateSwitchViewButton(g_hInst, hwnd, IDC_SWITCHVIEW);
  120. }
  121. SetTimer(hwnd, 0x9999, 50, NULL);
  122. return 1;
  123. case WM_TIMER:
  124. {
  125. KillTimer(hwnd, wParam);
  126. INT i;
  127. for(i = 0; i < sizeof(iconList)/sizeof(iconList[0]); i++) {
  128. HICON hIcon = LoadImage(g_hInst,
  129. MAKEINTRESOURCE(iconList[i].lParam),
  130. IMAGE_ICON,
  131. iconList[i].width,
  132. iconList[i].height,
  133. LR_DEFAULTCOLOR);
  134. SendMessage(GetDlgItem(hwnd, iconList[i].wID),
  135. BM_SETIMAGE,
  136. (WPARAM)IMAGE_ICON,
  137. (LPARAM)hIcon);
  138. }
  139. HWND hwndDDB = GetDlgItem(hwnd, IDC_DDBID);
  140. for(i = 0; i < 23; i++) {
  141. DDBITEM ddbItem;
  142. WCHAR wchBuf[256];
  143. ZeroMemory(&ddbItem, sizeof(ddbItem));
  144. ddbItem.cbSize = sizeof(ddbItem);
  145. ddbItem.lpwstr = wchBuf;
  146. swprintf(wchBuf, L"Item %2d", i);
  147. DDButton_AddItem(hwndDDB, &ddbItem);
  148. }
  149. }
  150. break;
  151. case WM_SYSCOMMAND:
  152. if(wParam == SC_CLOSE) {
  153. PostQuitMessage(0);
  154. }
  155. break;
  156. case WM_COMMAND:
  157. {
  158. WORD wNotifyCode = HIWORD(wParam); // notification code
  159. WORD wID = LOWORD(wParam); // item, control, or accelerator identifier
  160. HWND hwndCtl = (HWND) lParam; // handle of control
  161. HWND hwndDDB = GetDlgItem(hwnd, IDC_DDBID);
  162. switch(wID) {
  163. case IDC_DDBID:
  164. {
  165. switch(wNotifyCode) {
  166. case DDBN_CLICKED:
  167. DBG(("DDBN_CLICKED come\n"));
  168. break;
  169. case DDBN_SELCHANGE:
  170. DBG(("DDBN_SELCHANGE come\n"));
  171. break;
  172. case DDBN_DROPDOWN:
  173. DBG(("DDBN_DROPDOWN come\n"));
  174. break;
  175. case DDBN_CLOSEUP:
  176. DBG(("DDBN_CLOSEUP come\n"));
  177. break;
  178. default:
  179. DBG(("ERROR Unknown Notify\n"));
  180. break;
  181. }
  182. }
  183. break;
  184. case IDC_ADDITEM:
  185. {
  186. DDBITEM ddbItem;
  187. ZeroMemory(&ddbItem, sizeof(ddbItem));
  188. ddbItem.cbSize = sizeof(ddbItem);
  189. ddbItem.lpwstr = GetWText(hwnd, IDC_EDIT_ADDITEM);
  190. DDButton_AddItem(hwndDDB, &ddbItem);
  191. iIndex++;
  192. }
  193. break;
  194. case IDC_INSERTITEM:
  195. {
  196. DDBITEM ddbItem;
  197. INT index;
  198. WCHAR wchItem[256];
  199. ZeroMemory(&ddbItem, sizeof(ddbItem));
  200. ddbItem.cbSize = sizeof(ddbItem);
  201. ddbItem.lpwstr = GetWText(hwnd, IDC_EDIT_INSERTITEM);
  202. index = GetINT(hwnd, IDC_EDIT_INSERTITEM_INDEX);
  203. DDButton_InsertItem(hwndDDB, iIndex, &ddbItem);
  204. }
  205. break;
  206. case IDC_GETCURSEL:
  207. {
  208. INT i;
  209. char szBuf[256];
  210. i = DDButton_GetCurSel(hwndDDB);
  211. wsprintf(szBuf, "Cur Sel Index %d", i);
  212. Static_SetText(GetDlgItem(hwnd, IDC_STATIC_GETCURSEL), szBuf);
  213. }
  214. break;
  215. case IDC_SETTEXT:
  216. {
  217. DDButton_SetText(hwndDDB, GetWText(hwnd, IDC_EDIT_SETTEXT));
  218. }
  219. break;
  220. case IDC_SETCURSEL:
  221. {
  222. DDButton_SetCurSel(hwndDDB, GetINT(hwnd, IDC_EDIT_SETCURSEL));
  223. }
  224. break;
  225. case IDC_SETICON:
  226. {
  227. INT i;
  228. for(i = 0; i < sizeof(iconList)/sizeof(iconList[0]); i++) {
  229. if(Button_GetCheck(GetDlgItem(hwnd, iconList[i].wID))) {
  230. HICON hIcon = LoadImage(g_hInst,
  231. MAKEINTRESOURCE(iconList[i].lParam),
  232. IMAGE_ICON,
  233. iconList[i].width,
  234. iconList[i].height,
  235. LR_DEFAULTCOLOR);
  236. DDButton_SetIcon(hwndDDB, hIcon);
  237. }
  238. }
  239. }
  240. break;
  241. case IDC_SETSTYLE:
  242. {
  243. INT i;
  244. DWORD dwStyle = 0;
  245. for(i = 0; i < sizeof(slist)/sizeof(slist[0]); i++) {
  246. INT ret = Button_GetCheck(GetDlgItem(hwnd, slist[i].wID));
  247. if(ret) {
  248. dwStyle |= slist[i].lParam;
  249. }
  250. }
  251. DDButton_SetStyle(hwndDDB, dwStyle);
  252. }
  253. break;
  254. }
  255. }
  256. break;
  257. case WM_PAINT:
  258. hDC = BeginPaint(hwnd, &ps);
  259. GetClientRect(hwnd, &rc);
  260. FillRect(hDC, &rc, (HBRUSH)(COLOR_3DFACE + 1));
  261. EndPaint(hwnd, &ps);
  262. break;
  263. }
  264. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  265. }
  266. int WINAPI WinMain(HINSTANCE hInstance,
  267. HINSTANCE hPrevInstance,
  268. LPSTR lpCmdLine,
  269. int nCmdShow)
  270. {
  271. MSG msg;
  272. HWND hwnd;
  273. INT ret;
  274. g_hInst = hInstance;
  275. WNDCLASSEX wc;
  276. ZeroMemory(&wc, sizeof(wc));
  277. wc.cbSize = sizeof(wc);
  278. wc.style = CS_HREDRAW | CS_VREDRAW; /* Class style(s). */
  279. wc.lpfnWndProc = (WNDPROC)MainWndProc;
  280. wc.cbClsExtra = 0; /* No per-class extra data.*/
  281. wc.cbWndExtra = DLGWINDOWEXTRA; /* No per-window extra data. */
  282. wc.hInstance = hInstance; /* Application that owns the class. */
  283. wc.hIcon = NULL; //LoadIcon(hInstance, MAKEINTRESOURCE(SCROLL32_ICON));
  284. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  285. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); //UGetStockObject(LTGRAY_BRUSH); //WHITE_BRUSH);
  286. wc.lpszMenuName = NULL; //g_szClass; /* Name of menu resource in .RC file. */
  287. wc.lpszClassName = g_szClass; /* Name used in call to CreateWindow. */
  288. wc.hIconSm = NULL;
  289. RegisterClassEx(&wc);
  290. hwnd = CreateDialog(hInstance,
  291. g_szClass,
  292. 0,
  293. NULL);
  294. UpdateWindow(hwnd);
  295. ShowWindow(hwnd, SW_SHOW);
  296. while (GetMessage(&msg, NULL, 0, 0)){
  297. TranslateMessage(&msg);
  298. DispatchMessage(&msg);
  299. }
  300. return 0;
  301. }