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.

504 lines
12 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. cwcreate.cpp
  5. Abstract:
  6. This module contains the code for the new window architecture.
  7. --*/
  8. #include "precomp.hxx"
  9. #pragma hdrstop
  10. HWND
  11. New_CreateWindow(
  12. HWND hwndParent,
  13. WIN_TYPES Type,
  14. UINT uClassId,
  15. UINT uWinTitle,
  16. PRECT pRect
  17. )
  18. /*++
  19. Description
  20. Generic rotuine to create a child window.
  21. Arguments
  22. hwndParent - handle to parent window
  23. uClassId - resource string ID containing class name
  24. uWinTitle - resource string ID containing window title
  25. pRect - Rect describing the position of the window.
  26. If NULL, CW_USEDEFAULT is used to specify the
  27. location of the window.
  28. --*/
  29. {
  30. TCHAR szClassName[MAX_MSG_TXT];
  31. TCHAR szWinTitle[MAX_MSG_TXT];
  32. int nX = CW_USEDEFAULT;
  33. int nY = CW_USEDEFAULT;
  34. int nWidth = CW_USEDEFAULT;
  35. int nHeight = CW_USEDEFAULT;
  36. COMMONWIN_CREATE_DATA Data;
  37. if (pRect)
  38. {
  39. nX = pRect->left;
  40. nY = pRect->top;
  41. nWidth = pRect->right;
  42. nHeight = pRect->bottom;
  43. }
  44. // get class name and tile
  45. Dbg(LoadString(g_hInst, uClassId, szClassName, _tsizeof(szClassName)));
  46. Dbg(LoadString(g_hInst, uWinTitle, szWinTitle, _tsizeof(szWinTitle)));
  47. Data.Type = Type;
  48. BOOL TopMax;
  49. MDIGetActive(g_hwndMDIClient, &TopMax);
  50. HWND Win = CreateWindowEx(
  51. WS_EX_MDICHILD | WS_EX_CONTROLPARENT, // Extended style
  52. szClassName, // class name
  53. szWinTitle, // title
  54. WS_CLIPCHILDREN | WS_CLIPSIBLINGS
  55. | WS_OVERLAPPEDWINDOW | WS_VISIBLE |
  56. (TopMax ? WS_MAXIMIZE : 0), // style
  57. nX, // x
  58. nY, // y
  59. nWidth, // width
  60. nHeight, // height
  61. hwndParent, // parent
  62. NULL, // menu
  63. g_hInst, // hInstance
  64. &Data // user defined data
  65. );
  66. // Creation is considered an automatic operation in
  67. // order to distinguish things occuring during creation
  68. // from normal user operations. Now that create is
  69. // finished, decrement to indicate the create op is over.
  70. if (Win != NULL)
  71. {
  72. COMMONWIN_DATA* CmnWin = GetCommonWinData(Win);
  73. if (CmnWin != NULL)
  74. {
  75. CmnWin->m_InAutoOp--;
  76. }
  77. }
  78. return Win;
  79. }
  80. HWND
  81. NewWatch_CreateWindow(
  82. HWND hwndParent
  83. )
  84. {
  85. return New_CreateWindow(hwndParent,
  86. WATCH_WINDOW,
  87. SYS_CommonWin_wClass,
  88. SYS_WatchWin_Title,
  89. NULL
  90. );
  91. }
  92. HWND
  93. NewLocals_CreateWindow(
  94. HWND hwndParent
  95. )
  96. {
  97. return New_CreateWindow(hwndParent,
  98. LOCALS_WINDOW,
  99. SYS_CommonWin_wClass,
  100. SYS_LocalsWin_Title,
  101. NULL
  102. );
  103. }
  104. HWND
  105. NewDisasm_CreateWindow(
  106. HWND hwndParent
  107. )
  108. {
  109. RECT Rect;
  110. SetRect(&Rect, CW_USEDEFAULT, CW_USEDEFAULT,
  111. DISASM_WIDTH, DISASM_HEIGHT);
  112. return New_CreateWindow(hwndParent,
  113. DISASM_WINDOW,
  114. SYS_CommonWin_wClass,
  115. SYS_DisasmWin_Title,
  116. &Rect
  117. );
  118. }
  119. HWND
  120. NewQuickWatch_CreateWindow(
  121. HWND hwndParent
  122. )
  123. {
  124. return New_CreateWindow(hwndParent,
  125. QUICKW_WINDOW,
  126. SYS_CommonWin_wClass,
  127. SYS_QuickWatchWin_Title,
  128. NULL
  129. );
  130. }
  131. HWND
  132. NewMemory_CreateWindow(
  133. HWND hwndParent
  134. )
  135. {
  136. return New_CreateWindow(hwndParent,
  137. MEM_WINDOW,
  138. SYS_CommonWin_wClass,
  139. SYS_MemoryWin_Title,
  140. NULL
  141. );
  142. }
  143. HWND
  144. NewCalls_CreateWindow(
  145. HWND hwndParent
  146. )
  147. {
  148. RECT Rect;
  149. SetRect(&Rect, CW_USEDEFAULT, CW_USEDEFAULT,
  150. CALLS_WIDTH, CALLS_HEIGHT);
  151. return New_CreateWindow(hwndParent,
  152. CALLS_WINDOW,
  153. SYS_CommonWin_wClass,
  154. SYS_CallsWin_Title,
  155. &Rect
  156. );
  157. }
  158. HWND
  159. NewCmd_CreateWindow(
  160. HWND hwndParent
  161. )
  162. {
  163. RECT Rect;
  164. SetRect(&Rect, CW_USEDEFAULT, CW_USEDEFAULT, CMD_WIDTH, CMD_HEIGHT);
  165. return New_CreateWindow(hwndParent,
  166. CMD_WINDOW,
  167. SYS_CommonWin_wClass,
  168. SYS_CmdWin_Title,
  169. &Rect
  170. );
  171. }
  172. HWND
  173. NewCpu_CreateWindow(
  174. HWND hwndParent
  175. )
  176. {
  177. RECT Rect;
  178. SetRect(&Rect, CW_USEDEFAULT, CW_USEDEFAULT,
  179. g_Ptr64 ? CPU_WIDTH_64 : CPU_WIDTH_32, CPU_HEIGHT);
  180. return New_CreateWindow(hwndParent,
  181. CPU_WINDOW,
  182. SYS_CommonWin_wClass,
  183. SYS_CpuWin_Title,
  184. &Rect
  185. );
  186. }
  187. HWND
  188. NewDoc_CreateWindow(
  189. HWND hwndParent
  190. )
  191. /*++
  192. Routine Description:
  193. Create the command window.
  194. Arguments:
  195. hwndParent - The parent window to the command window. In an MDI document,
  196. this is usually the handle to the MDI client window: g_hwndMDIClient
  197. Return Value:
  198. If successful, creates a valid window handle to the new command window.
  199. NULL if the window was not created.
  200. --*/
  201. {
  202. RECT Rect;
  203. // Set default geometry.
  204. SetRect(&Rect, CW_USEDEFAULT, CW_USEDEFAULT,
  205. DOC_WIDTH, DOC_HEIGHT);
  206. if (g_WinOptions & WOPT_OVERLAY_SOURCE)
  207. {
  208. PLIST_ENTRY Entry;
  209. PCOMMONWIN_DATA WinData;
  210. // If we're stacking up document windows go
  211. // find the first one and use it as a template.
  212. for (Entry = g_ActiveWin.Flink;
  213. Entry != &g_ActiveWin;
  214. Entry = Entry->Flink)
  215. {
  216. WinData = ACTIVE_WIN_ENTRY(Entry);
  217. if (WinData->m_enumType == DOC_WINDOW &&
  218. !IsIconic(WinData->m_Win))
  219. {
  220. GetWindowRect(WinData->m_Win, &Rect);
  221. MapWindowPoints(GetDesktopWindow(), g_hwndMDIClient,
  222. (LPPOINT)&Rect, 2);
  223. Rect.right -= Rect.left;
  224. Rect.bottom -= Rect.top;
  225. }
  226. }
  227. }
  228. return New_CreateWindow(hwndParent,
  229. DOC_WINDOW,
  230. SYS_CommonWin_wClass,
  231. SYS_DocWin_Title,
  232. &Rect
  233. );
  234. }
  235. HWND
  236. NewScratch_CreateWindow(
  237. HWND hwndParent
  238. )
  239. {
  240. return New_CreateWindow(hwndParent,
  241. SCRATCH_PAD_WINDOW,
  242. SYS_CommonWin_wClass,
  243. SYS_Scratch_Pad_Title,
  244. NULL
  245. );
  246. }
  247. HWND
  248. NewProcessThread_CreateWindow(
  249. HWND hwndParent
  250. )
  251. {
  252. return New_CreateWindow(hwndParent,
  253. PROCESS_THREAD_WINDOW,
  254. SYS_CommonWin_wClass,
  255. SYS_Process_Thread_Title,
  256. NULL
  257. );
  258. }
  259. HWND
  260. New_OpenDebugWindow(
  261. WIN_TYPES winType,
  262. BOOL bUserActivated,
  263. ULONG Nth
  264. )
  265. /*++
  266. Routine Description:
  267. Opens Cpu, Watch, Locals, Calls, or Memory Window under MDI
  268. Handles special case for memory win's
  269. Arguments:
  270. winType - Supplies Type of debug window to be openned
  271. bUserActivated - Indicates whether this action was initiated by the
  272. user or by windbg. The value is to determine the Z order of
  273. any windows that are opened.
  274. Return Value:
  275. Window handle.
  276. NULL if an error occurs.
  277. --*/
  278. {
  279. HWND hwndActivate = NULL;
  280. PCOMMONWIN_DATA CmnWin;
  281. switch (winType)
  282. {
  283. default:
  284. Assert(!_T("Invalid window type. Ignorable error."));
  285. break;
  286. case CMD_WINDOW:
  287. if (GetCmdHwnd())
  288. {
  289. hwndActivate = GetCmdHwnd();
  290. }
  291. else
  292. {
  293. return NewCmd_CreateWindow(g_hwndMDIClient);
  294. }
  295. break;
  296. case WATCH_WINDOW:
  297. if (GetWatchHwnd())
  298. {
  299. hwndActivate = GetWatchHwnd();
  300. }
  301. else
  302. {
  303. return NewWatch_CreateWindow(g_hwndMDIClient);
  304. }
  305. break;
  306. case LOCALS_WINDOW:
  307. if (GetLocalsHwnd())
  308. {
  309. hwndActivate = GetLocalsHwnd();
  310. }
  311. else
  312. {
  313. return NewLocals_CreateWindow(g_hwndMDIClient);
  314. }
  315. break;
  316. case CPU_WINDOW:
  317. if (GetCpuHwnd())
  318. {
  319. hwndActivate = GetCpuHwnd();
  320. }
  321. else
  322. {
  323. return NewCpu_CreateWindow(g_hwndMDIClient);
  324. }
  325. break;
  326. case SCRATCH_PAD_WINDOW:
  327. if (GetScratchHwnd())
  328. {
  329. hwndActivate = GetScratchHwnd();
  330. }
  331. else
  332. {
  333. return NewScratch_CreateWindow(g_hwndMDIClient);
  334. }
  335. break;
  336. case DISASM_WINDOW:
  337. if (!bUserActivated && GetSrcMode_StatusBar() &&
  338. NULL == GetDisasmHwnd() &&
  339. (g_WinOptions & WOPT_AUTO_DISASM) == 0)
  340. {
  341. return NULL;
  342. }
  343. if (GetDisasmHwnd())
  344. {
  345. hwndActivate = GetDisasmHwnd();
  346. }
  347. else
  348. {
  349. return NewDisasm_CreateWindow(g_hwndMDIClient);
  350. }
  351. break;
  352. case MEM_WINDOW:
  353. // Memory windows normally open a fresh window
  354. // whenever an open request occurs, but when applying
  355. // workspaces we don't want to continually add
  356. // new memory windows. In the workspace case we
  357. // reuse existing memory windows as much as possible.
  358. if (Nth != NTH_OPEN_ALWAYS &&
  359. (CmnWin = FindNthWindow(Nth, 1 << winType)) != NULL)
  360. {
  361. hwndActivate = CmnWin->m_Win;
  362. break;
  363. }
  364. hwndActivate = NewMemory_CreateWindow(g_hwndMDIClient);
  365. if (hwndActivate)
  366. {
  367. MEMWIN_DATA * pMemWinData = GetMemWinData(hwndActivate);
  368. Assert(pMemWinData);
  369. // If this window is being created from a workspace
  370. // don't pop up the properties dialog.
  371. if ( Nth == NTH_OPEN_ALWAYS &&
  372. pMemWinData->HasEditableProperties() )
  373. {
  374. pMemWinData->EditProperties();
  375. pMemWinData->UiRequestRead();
  376. }
  377. }
  378. break;
  379. case DOC_WINDOW:
  380. return NewDoc_CreateWindow(g_hwndMDIClient);
  381. case QUICKW_WINDOW:
  382. if (GetQuickWatchHwnd())
  383. {
  384. hwndActivate = GetQuickWatchHwnd();
  385. }
  386. else
  387. {
  388. return NewQuickWatch_CreateWindow(g_hwndMDIClient);
  389. }
  390. break;
  391. case CALLS_WINDOW:
  392. if (GetCallsHwnd())
  393. {
  394. hwndActivate = GetCallsHwnd();
  395. }
  396. else
  397. {
  398. return NewCalls_CreateWindow(g_hwndMDIClient);
  399. }
  400. break;
  401. case PROCESS_THREAD_WINDOW:
  402. if (GetProcessThreadHwnd())
  403. {
  404. hwndActivate = GetProcessThreadHwnd();
  405. }
  406. else
  407. {
  408. return NewProcessThread_CreateWindow(g_hwndMDIClient);
  409. }
  410. break;
  411. }
  412. if (hwndActivate)
  413. {
  414. if (GetKeyState(VK_SHIFT) < 0 &&
  415. GetKeyState(VK_CONTROL) >= 0)
  416. {
  417. SendMessage(g_hwndMDIClient, WM_MDIDESTROY,
  418. (WPARAM)hwndActivate, 0);
  419. }
  420. else
  421. {
  422. if (IsIconic(hwndActivate))
  423. {
  424. OpenIcon(hwndActivate);
  425. }
  426. ActivateMDIChild(hwndActivate, bUserActivated);
  427. }
  428. }
  429. return hwndActivate;
  430. }