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.

498 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: mwclass.cxx
  7. //
  8. // Contents: implementation for the main window class
  9. //
  10. // Classes: CMainWindow
  11. //
  12. // Functions: Exists
  13. //
  14. // History: 9-30-94 stevebl Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "test.h"
  18. #include "mwclass.h"
  19. #include "about.h"
  20. #include <assert.h>
  21. #include <oledlg.h>
  22. #include "linkcntr.h"
  23. CMyOleUILinkContainer MyOleUILinkContainer;
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Member: CMainWindow::CMainWindow
  27. //
  28. // Synopsis: constructor
  29. //
  30. // History: 9-30-94 stevebl Created
  31. //
  32. //----------------------------------------------------------------------------
  33. CMainWindow::CMainWindow()
  34. {
  35. }
  36. //+---------------------------------------------------------------------------
  37. //
  38. // Member: CMainWindow::~CMainWindow
  39. //
  40. // Synopsis: destructor
  41. //
  42. // History: 9-30-94 stevebl Created
  43. //
  44. // Notes: Destruction of the main window indicates that the app should
  45. // quit.
  46. //
  47. //----------------------------------------------------------------------------
  48. CMainWindow::~CMainWindow()
  49. {
  50. PostQuitMessage(0);
  51. }
  52. //+---------------------------------------------------------------------------
  53. //
  54. // Member: CMainWindow::InitInstance
  55. //
  56. // Synopsis: Instantiates an instance of the Galactic War window.
  57. //
  58. // Arguments: [hInstance] - instance of the app
  59. // [nCmdShow] - command to pass to ShowWindow
  60. //
  61. // Returns: TRUE on success
  62. // FALSE on failure
  63. //
  64. // History: 9-30-94 stevebl Created
  65. //
  66. // Notes: This method must be called only once, immediately after
  67. // class construction.
  68. //
  69. //----------------------------------------------------------------------------
  70. BOOL CMainWindow::InitInstance(HINSTANCE hInstance, int nCmdShow)
  71. {
  72. // Note, the Create method sets the _hwnd member for me so I don't
  73. // need to set it myself.
  74. if (!Create(
  75. TEXT(MAIN_WINDOW_CLASS_NAME),
  76. TEXT(VER_INTERNALNAME_STR),
  77. WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
  78. | WS_MAXIMIZEBOX | WS_THICKFRAME,
  79. CW_USEDEFAULT,
  80. CW_USEDEFAULT,
  81. CW_USEDEFAULT,
  82. CW_USEDEFAULT,
  83. NULL,
  84. NULL,
  85. hInstance))
  86. {
  87. return(FALSE);
  88. }
  89. ShowWindow(_hwnd, nCmdShow);
  90. UpdateWindow(_hwnd);
  91. return(TRUE);
  92. }
  93. //+---------------------------------------------------------------------------
  94. //
  95. // Member: CMainWindow::WindowProc
  96. //
  97. // Synopsis: main window procedure
  98. //
  99. // Arguments: [uMsg] - Windows message
  100. // [wParam] - first message parameter
  101. // [lParam] - second message parameter
  102. //
  103. // History: 9-30-94 stevebl Created
  104. //
  105. // Notes: See CHlprWindow for a description of how this method gets
  106. // called by the global WinProc.
  107. //
  108. //----------------------------------------------------------------------------
  109. LRESULT CMainWindow::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  110. {
  111. switch (uMsg)
  112. {
  113. case WM_CREATE:
  114. return(TRUE);
  115. case WM_COMMAND:
  116. return DoMenu(wParam, lParam);
  117. case WM_QUIT:
  118. case WM_CLOSE:
  119. default:
  120. return(DefWindowProc(_hwnd, uMsg, wParam, lParam));
  121. }
  122. return(FALSE);
  123. }
  124. //+---------------------------------------------------------------------------
  125. //
  126. // Member: CMainWindow::DoMenu
  127. //
  128. // Synopsis: implements the main menu commands
  129. //
  130. // Arguments: [wParam] - first window parameter
  131. // [lParam] - second window parameter
  132. //
  133. // History: 9-30-94 stevebl Created
  134. //
  135. //----------------------------------------------------------------------------
  136. LRESULT CMainWindow::DoMenu(WPARAM wParam, LPARAM lParam)
  137. {
  138. switch (LOWORD(wParam))
  139. {
  140. case IDM_INSERTOBJECT:
  141. TestInsertObject();
  142. break;
  143. case IDM_PASTESPECIAL:
  144. TestPasteSpecial();
  145. break;
  146. case IDM_EDITLINKS:
  147. TestEditLinks();
  148. break;
  149. case IDM_CHANGEICON:
  150. TestChangeIcon();
  151. break;
  152. case IDM_CONVERT:
  153. TestConvert();
  154. break;
  155. case IDM_CANCONVERT:
  156. TestCanConvert();
  157. break;
  158. case IDM_BUSY:
  159. TestBusy();
  160. break;
  161. case IDM_CHANGESOURCE:
  162. TestChangeSource();
  163. break;
  164. case IDM_OBJECTPROPS:
  165. TestObjectProps();
  166. break;
  167. case IDD_LINKSOURCEUNAVAILABLE:
  168. case IDD_CANNOTUPDATELINK:
  169. case IDD_SERVERNOTREG:
  170. case IDD_LINKTYPECHANGED:
  171. case IDD_SERVERNOTFOUND:
  172. case IDD_OUTOFMEMORY:
  173. TestPromptUser((int)LOWORD(wParam));
  174. break;
  175. case IDM_UPDATELINKS:
  176. TestUpdateLinks();
  177. break;
  178. case IDM_EXIT:
  179. SendMessage(_hwnd, WM_CLOSE, 0, 0);
  180. break;
  181. case IDM_ABOUT:
  182. {
  183. CAbout dlgAbout;
  184. dlgAbout.ShowDialog(_hInstance, MAKEINTRESOURCE(IDM_ABOUT), _hwnd);
  185. }
  186. break;
  187. default:
  188. return(DefWindowProc(_hwnd, WM_COMMAND, wParam, lParam));
  189. }
  190. return(FALSE);
  191. }
  192. void CMainWindow::TestInsertObject()
  193. {
  194. TCHAR szFile[MAX_PATH];
  195. OLEUIINSERTOBJECT io;
  196. memset(&io, 0, sizeof(OLEUIINSERTOBJECT));
  197. io.cbStruct = sizeof(io);
  198. io.dwFlags = IOF_SELECTCREATECONTROL | IOF_SHOWINSERTCONTROL;
  199. // io.dwFlags = IOF_SHOWINSERTCONTROL;
  200. io.hWndOwner = _hwnd;
  201. io.lpszFile = szFile;
  202. io.cchFile = MAX_PATH;
  203. io.lpszCaption = TEXT("Testing OleUIInsertObject dialog");
  204. memset(szFile, 0, sizeof(szFile));
  205. UINT uReturn = OleUIInsertObject(&io);
  206. MessageBoxFromStringIdsAndArgs(
  207. _hwnd,
  208. _hInstance,
  209. IDS_INSERTOBJECT,
  210. IDS_RETURN,
  211. MB_OK,
  212. uReturn,
  213. io.dwFlags,
  214. io.lpszFile,
  215. io.sc);
  216. }
  217. void CMainWindow::TestPasteSpecial()
  218. {
  219. LPDATAOBJECT lpClipboardDataObj = NULL;
  220. HRESULT hr = OleGetClipboard(&lpClipboardDataObj);
  221. if (SUCCEEDED(NOERROR))
  222. {
  223. OLEUIPASTEENTRY rgPe[1];
  224. rgPe[0].fmtetc.cfFormat = CF_TEXT;
  225. rgPe[0].fmtetc.ptd = NULL;
  226. rgPe[0].fmtetc.dwAspect = DVASPECT_CONTENT;
  227. rgPe[0].fmtetc.tymed = TYMED_HGLOBAL;
  228. rgPe[0].fmtetc.lindex = -1;
  229. rgPe[0].lpstrFormatName = TEXT("Text");
  230. rgPe[0].lpstrResultText = TEXT("Text");
  231. rgPe[0].dwFlags = OLEUIPASTE_PASTEONLY;
  232. OLEUIPASTESPECIAL ps;
  233. memset(&ps, 0, sizeof(ps));
  234. ps.cbStruct = sizeof(ps);
  235. ps.dwFlags = IOF_SHOWHELP | PSF_SELECTPASTE;
  236. ps.hWndOwner = _hwnd;
  237. ps.lpszCaption = TEXT("Paste Special");
  238. ps.lpSrcDataObj = lpClipboardDataObj;
  239. ps.arrPasteEntries = rgPe;
  240. ps.cPasteEntries = 1;
  241. ps.lpszCaption = TEXT("Testing OleUIPasteSpecial dialog");
  242. UINT uReturn = OleUIPasteSpecial(&ps);
  243. MessageBoxFromStringIdsAndArgs(
  244. _hwnd,
  245. _hInstance,
  246. IDS_PASTESPECIAL,
  247. IDS_RETURN,
  248. MB_OK,
  249. uReturn,
  250. ps.dwFlags,
  251. ps.nSelectedIndex,
  252. ps.fLink,
  253. ps.sizel);
  254. if (lpClipboardDataObj)
  255. {
  256. lpClipboardDataObj->Release();
  257. }
  258. }
  259. else
  260. {
  261. MessageBoxFromStringIdsAndArgs(
  262. _hwnd,
  263. _hInstance,
  264. IDS_NOCLIPBOARD,
  265. IDS_ERROR,
  266. MB_OK,
  267. hr);
  268. // report failure getting clipboard object
  269. }
  270. }
  271. void CMainWindow::TestEditLinks()
  272. {
  273. OLEUIEDITLINKS el;
  274. memset(&el, 0, sizeof(el));
  275. el.cbStruct = sizeof(el);
  276. el.dwFlags = ELF_SHOWHELP;
  277. el.hWndOwner = _hwnd;
  278. el.lpOleUILinkContainer = &MyOleUILinkContainer;
  279. el.lpszCaption = TEXT("Testing OleUIEditLinks dialog");
  280. UINT uReturn = OleUIEditLinks(&el);
  281. MessageBoxFromStringIdsAndArgs(
  282. _hwnd,
  283. _hInstance,
  284. IDS_EDITLINKS,
  285. IDS_RETURN,
  286. MB_OK,
  287. uReturn,
  288. el.dwFlags);
  289. }
  290. void CMainWindow::TestChangeIcon()
  291. {
  292. OLEUICHANGEICON ci;
  293. memset(&ci, 0, sizeof(ci));
  294. ci.cbStruct = sizeof(ci);
  295. ci.dwFlags = CIF_SHOWHELP | CIF_SELECTCURRENT;
  296. ci.hWndOwner = _hwnd;
  297. ci.lpszCaption = TEXT("Testing OleUIChangeIcon dialog");
  298. UINT uReturn = OleUIChangeIcon(&ci);
  299. MessageBoxFromStringIdsAndArgs(
  300. _hwnd,
  301. _hInstance,
  302. IDS_CHANGEICON,
  303. IDS_RETURN,
  304. MB_OK,
  305. uReturn,
  306. ci.dwFlags);
  307. }
  308. void CMainWindow::TestConvert()
  309. {
  310. OLEUICONVERT cv;
  311. memset(&cv, 0, sizeof(cv));
  312. cv.cbStruct = sizeof(cv);
  313. cv.dwFlags = CF_SHOWHELPBUTTON;
  314. cv.hWndOwner = _hwnd;
  315. cv.lpszCaption = TEXT("Testing OleUIConvert dialog");
  316. UINT uReturn = OleUIConvert(&cv);
  317. MessageBoxFromStringIdsAndArgs(
  318. _hwnd,
  319. _hInstance,
  320. IDS_CONVERT,
  321. IDS_RETURN,
  322. MB_OK,
  323. uReturn,
  324. cv.dwFlags);
  325. }
  326. void CMainWindow::TestCanConvert()
  327. {
  328. CLSID cid = { /* 00030003-0000-0000-c000-000000000046 ("Word Document") */
  329. 0x00030003,
  330. 0x0000,
  331. 0x0000,
  332. {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}
  333. };
  334. BOOL fReturn = OleUICanConvertOrActivateAs(cid, FALSE, CF_TEXT);
  335. MessageBoxFromStringIdsAndArgs(
  336. _hwnd,
  337. _hInstance,
  338. IDS_CANCONVERT,
  339. IDS_RETURN,
  340. MB_OK,
  341. fReturn);
  342. }
  343. void CMainWindow::TestBusy()
  344. {
  345. OLEUIBUSY bz;
  346. memset(&bz, 0, sizeof(bz));
  347. bz.cbStruct = sizeof(bz);
  348. bz.hWndOwner = _hwnd;
  349. bz.lpszCaption = TEXT("Testing OleUIBusy dialog");
  350. UINT uReturn = OleUIBusy(&bz);
  351. MessageBoxFromStringIdsAndArgs(
  352. _hwnd,
  353. _hInstance,
  354. IDS_BUSY,
  355. IDS_RETURN,
  356. MB_OK,
  357. uReturn,
  358. bz.dwFlags);
  359. }
  360. void CMainWindow::TestChangeSource()
  361. {
  362. OLEUICHANGESOURCE cs;
  363. memset(&cs, 0, sizeof(cs));
  364. cs.cbStruct = sizeof(cs);
  365. cs.hWndOwner = _hwnd;
  366. cs.lpszCaption = TEXT("Testing OleUIChangeSource dialog");
  367. UINT uReturn = OleUIChangeSource(&cs);
  368. MessageBoxFromStringIdsAndArgs(
  369. _hwnd,
  370. _hInstance,
  371. IDS_CHANGESOURCE,
  372. IDS_RETURN,
  373. MB_OK,
  374. uReturn,
  375. cs.dwFlags);
  376. }
  377. void CMainWindow::TestObjectProps()
  378. {
  379. OLEUIOBJECTPROPS op;
  380. memset(&op, 0, sizeof(op));
  381. op.cbStruct = sizeof(op);
  382. UINT uReturn = OleUIObjectProperties(&op);
  383. MessageBoxFromStringIdsAndArgs(
  384. _hwnd,
  385. _hInstance,
  386. IDS_OBJECTPROPS,
  387. IDS_RETURN,
  388. MB_OK,
  389. uReturn,
  390. op.dwFlags);
  391. }
  392. void CMainWindow::TestPromptUser(int nTemplate)
  393. {
  394. UINT uReturn = OleUIPromptUser(
  395. nTemplate,
  396. _hwnd,
  397. // string arguments:
  398. TEXT("Testing OleUIPromptUser"),
  399. TEXT("BAR"),
  400. TEXT("FOO"));
  401. MessageBoxFromStringIdsAndArgs(
  402. _hwnd,
  403. _hInstance,
  404. IDS_PROMPTUSER,
  405. IDS_RETURN,
  406. MB_OK,
  407. uReturn);
  408. }
  409. void CMainWindow::TestUpdateLinks()
  410. {
  411. UINT cLinks = 0;
  412. BOOL fReturn = OleUIUpdateLinks(
  413. &MyOleUILinkContainer,
  414. _hwnd,
  415. TEXT("Testing OleUIUpdateLinks dialog"),
  416. cLinks);
  417. MessageBoxFromStringIdsAndArgs(
  418. _hwnd,
  419. _hInstance,
  420. IDS_UPDATELINKS,
  421. IDS_RETURN,
  422. MB_OK,
  423. fReturn);
  424. }
  425. //+---------------------------------------------------------------------------
  426. //
  427. // Function: Exists
  428. //
  429. // Synopsis: simple function to test for the existance of a file
  430. //
  431. // History: 6-16-93 stevebl Created
  432. //
  433. //----------------------------------------------------------------------------
  434. int Exists(TCHAR *sz)
  435. {
  436. HANDLE h;
  437. h = CreateFile(sz,
  438. GENERIC_READ,
  439. FILE_SHARE_READ | FILE_SHARE_WRITE,
  440. NULL,
  441. OPEN_EXISTING,
  442. 0,
  443. 0);
  444. if (h != INVALID_HANDLE_VALUE)
  445. {
  446. CloseHandle(h);
  447. return(1);
  448. }
  449. return (0);
  450. }