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.

452 lines
16 KiB

  1. //**********************************************************************
  2. // File name: Simple.cpp
  3. //
  4. // Main source file for the Simple OLE 2.0 object container
  5. //
  6. // Functions:
  7. //
  8. // WinMain - Program entry point
  9. // MainWndProc - Processes messages for the frame window
  10. // About - Processes messages for the about dialog
  11. // DocWndProc - Processes messages for the doc window
  12. //
  13. // Copyright (c) 1992 - 1993 Microsoft Corporation. All rights reserved.
  14. //**********************************************************************
  15. #include "pre.h"
  16. #include "iocs.h"
  17. #include "ias.h"
  18. #include "app.h"
  19. #include "site.h"
  20. #include "doc.h"
  21. #include <testmess.h>
  22. #include <stdlib.h>
  23. #include "tests.h"
  24. // This line is needed for the debug utilities in OLE2UI
  25. extern "C" {
  26. OLEDBGDATA_MAIN("SIMPDND")
  27. }
  28. CSimpleApp FAR * lpCSimpleApp;
  29. BOOL fBeVerbose = FALSE;
  30. extern "C"
  31. void TestDebugOut(LPSTR psz)
  32. {
  33. if (fBeVerbose)
  34. {
  35. OutputDebugString(psz);
  36. }
  37. }
  38. //**********************************************************************
  39. //
  40. // WinMain
  41. //
  42. // Purpose:
  43. //
  44. // Program entry point
  45. //
  46. // Parameters:
  47. //
  48. // HANDLE hInstance - Instance handle for this instance
  49. //
  50. // HANDLE hPrevInstance - Instance handle for the last instance
  51. //
  52. // LPSTR lpCmdLine - Pointer to the command line
  53. //
  54. // int nCmdShow - Window State
  55. //
  56. // Return Value:
  57. //
  58. // msg.wParam
  59. //
  60. // Function Calls:
  61. // Function Location
  62. //
  63. // CSimpleApp::CSimpleApp APP.CPP
  64. // CSimpleApp::fInitApplication APP.CPP
  65. // CSimpleApp::fInitInstance APP.CPP
  66. // CSimpleApp::HandleAccelerators APP.CPP
  67. // CSimpleApp::~CSimpleApp APP.CPP
  68. // OleUIInitialize OLE2UI
  69. // OleUIUninitialize OLE2UI
  70. // GetMessage Windows API
  71. // TranslateMessage Windows API
  72. // DispatchMessage Windows API
  73. //
  74. // Comments:
  75. //
  76. //********************************************************************
  77. int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  78. {
  79. LPSTR pszTemp;
  80. MSG msg;
  81. fBeVerbose = GetProfileInt("OLEUTEST","BeVerbose",0);
  82. if(fBeVerbose == 0)
  83. {
  84. fBeVerbose = GetProfileInt("OLEUTEST","spdnd16",0);
  85. }
  86. // needed for LRPC to work properly...
  87. SetMessageQueue(96);
  88. lpCSimpleApp = new CSimpleApp;
  89. // we will add one ref count on our App. later when we want to destroy
  90. // the App object we will release this ref count. when the App's ref
  91. // count goes to 0, it will be deleted.
  92. lpCSimpleApp->AddRef();
  93. // process the command line
  94. if( (pszTemp = strstr(lpCmdLine, "-driver")) )
  95. {
  96. //we were launched by the test driver
  97. lpCSimpleApp->m_hDriverWnd = (HWND)strtoul(pszTemp+8, NULL, 10);
  98. }
  99. // app initialization
  100. if (!hPrevInstance)
  101. if (!lpCSimpleApp->fInitApplication(hInstance))
  102. return (FALSE);
  103. // instance initialization
  104. if (!lpCSimpleApp->fInitInstance(hInstance, nCmdShow))
  105. return (FALSE);
  106. /* Initialization required for OLE 2 UI library. This call is
  107. ** needed ONLY if we are using the static link version of the UI
  108. ** library. If we are using the DLL version, we should NOT call
  109. ** this function in our application.
  110. */
  111. if (!OleUIInitialize(hInstance, hPrevInstance))
  112. {
  113. OleDbgOut("Could not initialize OLEUI library\n");
  114. return FALSE;
  115. }
  116. // message loop
  117. while (GetMessage(&msg, NULL, NULL, NULL))
  118. if (!lpCSimpleApp->HandleAccelerators(&msg))
  119. {
  120. TranslateMessage(&msg); /* Translates virtual key codes */
  121. DispatchMessage(&msg); /* Dispatches message to window */
  122. }
  123. // De-initialization for UI libraries. Just like OleUIInitialize, this
  124. // funciton is needed ONLY if we are using the static link version of the
  125. // OLE UI library.
  126. OleUIUninitialize();
  127. // Release the ref count added on the App above. this will make
  128. // the App's ref count go to 0, and the App object will be deleted.
  129. lpCSimpleApp->Release();
  130. return (msg.wParam); /* Returns the value from PostQuitMessage */
  131. }
  132. //**********************************************************************
  133. //
  134. // MainWndProc
  135. //
  136. // Purpose:
  137. //
  138. // Processes messages for the frame window
  139. //
  140. // Parameters:
  141. //
  142. // HWND hWnd - Window handle for frame window
  143. //
  144. // UINT message - Message value
  145. //
  146. // WPARAM wParam - Message info
  147. //
  148. // LPARAM lParam - Message info
  149. //
  150. // Return Value:
  151. //
  152. // long
  153. //
  154. // Function Calls:
  155. // Function Location
  156. //
  157. // CSimpleApp::lCommandHandler APP.CPP
  158. // CSimpleApp::DestroyDocs APP.CPP
  159. // CSimpleApp::lCreateDoc APP.CPP
  160. // CSimpleApp::lSizeHandler APP.CPP
  161. // CSimpleDoc::lAddVerbs DOC.CPP
  162. // PostQuitMessage Windows API
  163. // DefWindowProc Windows API
  164. //
  165. // Comments:
  166. //
  167. //********************************************************************
  168. long FAR PASCAL _export MainWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  169. {
  170. switch (message)
  171. {
  172. case WM_TEST2:
  173. StartTest2(lpCSimpleApp);
  174. break;
  175. case WM_TEST1:
  176. StartTest1(lpCSimpleApp);
  177. break;
  178. case WM_CLOSE:
  179. DestroyWindow(lpCSimpleApp->m_hAppWnd);
  180. break;
  181. case WM_COMMAND: // message: command from application menu
  182. return lpCSimpleApp->lCommandHandler(hWnd, message, wParam, lParam);
  183. break;
  184. case WM_CREATE:
  185. return lpCSimpleApp->lCreateDoc(hWnd, message, wParam, lParam);
  186. break;
  187. case WM_DESTROY: // message: window being destroyed
  188. lpCSimpleApp->DestroyDocs(); // need to destroy the doc...
  189. PostQuitMessage(0);
  190. break;
  191. case WM_INITMENUPOPUP:
  192. // is this the edit menu?
  193. if ( LOWORD(lParam) == 1)
  194. return lpCSimpleApp->m_lpDoc->lAddVerbs();
  195. break;
  196. case WM_SIZE:
  197. return lpCSimpleApp->lSizeHandler(hWnd, message, wParam, lParam);
  198. default: // Passes it on if unproccessed
  199. return (DefWindowProc(hWnd, message, wParam, lParam));
  200. }
  201. return (NULL);
  202. }
  203. //**********************************************************************
  204. //
  205. // About
  206. //
  207. // Purpose:
  208. //
  209. // Processes dialog box messages
  210. //
  211. // Parameters:
  212. //
  213. // HWND hWnd - Window handle for dialog box
  214. //
  215. // UINT message - Message value
  216. //
  217. // WPARAM wParam - Message info
  218. //
  219. // LPARAM lParam - Message info
  220. //
  221. // Return Value:
  222. //
  223. // Function Calls:
  224. // Function Location
  225. //
  226. // EndDialog Windows API
  227. //
  228. // Comments:
  229. //
  230. //********************************************************************
  231. BOOL FAR PASCAL _export About(HWND hDlg,unsigned message,WORD wParam,LONG lParam)
  232. {
  233. switch (message) {
  234. case WM_INITDIALOG: /* message: initialize dialog box */
  235. return (TRUE);
  236. case WM_COMMAND: /* message: received a command */
  237. if (wParam == IDOK /* "OK" box selected? */
  238. || wParam == IDCANCEL) { /* System menu close command? */
  239. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  240. return (TRUE);
  241. }
  242. break;
  243. }
  244. return (FALSE); /* Didn't process a message */
  245. }
  246. //**********************************************************************
  247. //
  248. // DocWndProc
  249. //
  250. // Purpose:
  251. //
  252. // Processes dialog box messages
  253. //
  254. // Parameters:
  255. //
  256. // HWND hWnd - Window handle for doc window
  257. //
  258. // UINT message - Message value
  259. //
  260. // WPARAM wParam - Message info
  261. //
  262. // LPARAM lParam - Message info
  263. //
  264. // Return Value:
  265. //
  266. // Function Calls:
  267. // Function Location
  268. //
  269. // CSimpleApp::PaintApp APP.CPP
  270. // BeginPaint Windows API
  271. // EndPaint Windows API
  272. // DefWindowProc Windows API
  273. // IOleObject::QueryInterface Object
  274. // IOleObject::DoVerb Object
  275. // CSimpleSite::GetObjRect SITE.CPP
  276. // CSimpleDoc::QueryDrag DOC.CPP
  277. // CSimpleDoc::DoDragDrop DOC.CPP
  278. // SetTimer Windows API
  279. // KillTimer Windows API
  280. // SetCapture Windows API
  281. // ReleaseCapture Windows API
  282. //
  283. // Comments:
  284. //
  285. //********************************************************************
  286. long FAR PASCAL _export DocWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
  287. {
  288. HDC hDC;
  289. PAINTSTRUCT ps;
  290. switch (message) {
  291. case WM_PAINT:
  292. hDC = BeginPaint(hWnd, &ps);
  293. if (lpCSimpleApp)
  294. lpCSimpleApp->PaintApp (hDC);
  295. EndPaint(hWnd, &ps);
  296. break;
  297. case WM_LBUTTONDBLCLK:
  298. {
  299. POINT pt;
  300. pt.x = (int)(short)LOWORD (lParam );
  301. pt.y = (int)(short)HIWORD (lParam );
  302. if (lpCSimpleApp->m_lpDoc->m_lpSite &&
  303. lpCSimpleApp->m_lpDoc->m_lpSite->m_lpOleObject)
  304. {
  305. RECT rect;
  306. lpCSimpleApp->m_lpDoc->m_lpSite->GetObjRect(&rect);
  307. if ( PtInRect(&rect, pt) )
  308. {
  309. // Execute object's default verb
  310. lpCSimpleApp->m_lpDoc->m_lpSite->m_lpOleObject->DoVerb(
  311. OLEIVERB_PRIMARY, (LPMSG)&message,
  312. &lpCSimpleApp->m_lpDoc->m_lpSite->m_OleClientSite,
  313. -1, hWnd, &rect);
  314. }
  315. }
  316. }
  317. break;
  318. case WM_LBUTTONDOWN:
  319. {
  320. POINT pt;
  321. pt.x = (int)(short)LOWORD (lParam );
  322. pt.y = (int)(short)HIWORD (lParam );
  323. /* OLE2NOTE: check if this is a button down on the region
  324. ** that is a handle to start a drag operation. for us,
  325. ** this this is any where in the window. we
  326. ** do NOT want to start a drag immediately; we want to
  327. ** wait until the mouse moves a certain threshold. or a
  328. ** certain amount of time has elapsed. if
  329. ** LButtonUp comes before the drag is started, then
  330. ** the fPendingDrag state is cleared. we must capture
  331. ** the mouse to ensure the modal state is handled
  332. ** properly.
  333. */
  334. if (lpCSimpleApp->m_lpDoc->QueryDrag(pt) )
  335. {
  336. lpCSimpleApp->m_lpDoc->m_fPendingDrag = TRUE;
  337. lpCSimpleApp->m_lpDoc->m_ptButDown = pt;
  338. SetTimer(hWnd, 1, lpCSimpleApp->m_nDragDelay, NULL);
  339. SetCapture(hWnd);
  340. }
  341. break;
  342. }
  343. case WM_LBUTTONUP:
  344. if (lpCSimpleApp->m_lpDoc->m_fPendingDrag)
  345. {
  346. /* ButtonUP came BEFORE distance/time threshholds were
  347. ** exceeded. clear fPendingDrag state.
  348. */
  349. ReleaseCapture();
  350. KillTimer(hWnd, 1);
  351. lpCSimpleApp->m_lpDoc->m_fPendingDrag = FALSE;
  352. }
  353. break;
  354. case WM_MOUSEMOVE:
  355. {
  356. if (lpCSimpleApp->m_lpDoc->m_fPendingDrag)
  357. {
  358. int x = (int)(short)LOWORD (lParam );
  359. int y = (int)(short)HIWORD (lParam );
  360. POINT pt = lpCSimpleApp->m_lpDoc->m_ptButDown;
  361. int nDragMinDist = lpCSimpleApp->m_nDragMinDist;
  362. if (! ( ((pt.x - nDragMinDist) <= x)
  363. && (x <= (pt.x + nDragMinDist))
  364. && ((pt.y - nDragMinDist) <= y)
  365. && (y <= (pt.y + nDragMinDist)) ) )
  366. {
  367. // mouse moved beyond threshhold to start drag
  368. ReleaseCapture();
  369. KillTimer(hWnd, 1);
  370. lpCSimpleApp->m_lpDoc->m_fPendingDrag = FALSE;
  371. // perform the modal drag/drop operation.
  372. lpCSimpleApp->m_lpDoc->DoDragDrop( );
  373. }
  374. }
  375. break;
  376. }
  377. case WM_TIMER:
  378. {
  379. // drag time delay threshhold exceeded -- start drag
  380. ReleaseCapture();
  381. KillTimer(hWnd, 1);
  382. lpCSimpleApp->m_lpDoc->m_fPendingDrag = FALSE;
  383. // perform the modal drag/drop operation.
  384. lpCSimpleApp->m_lpDoc->DoDragDrop( );
  385. break;
  386. }
  387. default: /* Passes it on if unproccessed */
  388. return (DefWindowProc(hWnd, message, wParam, lParam));
  389. }
  390. return (NULL);
  391. }