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.

420 lines
10 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. // MainFrm.cpp : implementation of the CMainFrame class
  8. //
  9. #include "stdafx.h"
  10. #include "WMITest.h"
  11. #include "MainFrm.h"
  12. #include "OpView.h"
  13. #include "ObjVw.h"
  14. #include "WMITestDoc.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. static TCHAR szWindowPos[] = _T("WindowPos");
  21. static TCHAR szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
  22. BOOL ReadWindowPlacement(LPCTSTR szSection,
  23. LPCTSTR szValueName, LPWINDOWPLACEMENT pwp)
  24. {
  25. CString strBuffer = AfxGetApp()->GetProfileString(szSection, szValueName);
  26. if (strBuffer.IsEmpty())
  27. return FALSE;
  28. WINDOWPLACEMENT wp;
  29. int nRead = _stscanf(strBuffer, szFormat,
  30. &wp.flags, &wp.showCmd,
  31. &wp.ptMinPosition.x, &wp.ptMinPosition.y,
  32. &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
  33. &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
  34. &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
  35. if (nRead != 10)
  36. return FALSE;
  37. wp.length = sizeof wp;
  38. *pwp = wp;
  39. return TRUE;
  40. }
  41. void WriteWindowPlacement(LPCTSTR szSection,
  42. LPCTSTR szValueName, LPWINDOWPLACEMENT pwp)
  43. // write a window placement to settings section of app's ini file
  44. {
  45. TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
  46. wsprintf(szBuffer, szFormat,
  47. pwp->flags, pwp->showCmd,
  48. pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  49. pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  50. pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  51. pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  52. AfxGetApp()->WriteProfileString(szSection, szValueName, szBuffer);
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CMainFrame
  56. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  57. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  58. //{{AFX_MSG_MAP(CMainFrame)
  59. ON_WM_CREATE()
  60. ON_WM_CLOSE()
  61. ON_UPDATE_COMMAND_UI(ID_STATUS_NUM_OBJECTS, OnUpdateStatusNumberObjects)
  62. ON_WM_DESTROY()
  63. ON_WM_INITMENUPOPUP()
  64. //}}AFX_MSG_MAP
  65. //ON_WM_INITMENU()
  66. ON_MESSAGE(WM_ENTERMENULOOP, OnEnterMenuLoop)
  67. ON_MESSAGE(WM_EXITMENULOOP, OnExitMenuLoop)
  68. END_MESSAGE_MAP()
  69. /*
  70. static UINT indicators[] =
  71. {
  72. ID_SEPARATOR, // status line indicator
  73. ID_INDICATOR_CAPS,
  74. ID_INDICATOR_NUM,
  75. ID_INDICATOR_SCRL,
  76. };
  77. */
  78. static UINT indicatorsMenuActive[] =
  79. {
  80. ID_SEPARATOR, // status line indicator
  81. };
  82. static UINT indicatorsMenuGone[] =
  83. {
  84. ID_STATUS_NUM_OBJECTS,
  85. ID_STATUS1,
  86. };
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CMainFrame construction/destruction
  89. CMainFrame::CMainFrame()
  90. {
  91. // TODO: add member initialization code here
  92. }
  93. CMainFrame::~CMainFrame()
  94. {
  95. }
  96. #define STATUS_SIZE_NUM_OBJ 200
  97. #define STATUS_SIZE_PROGRESS 100
  98. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  99. {
  100. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  101. return -1;
  102. // Setup the image list.
  103. m_imageList.Create(16, 16, TRUE, 4, 1);
  104. AddImage(IDB_ROOT, RGB(0, 0, 255));
  105. AddImageAndBusyImage(IDB_QUERY, RGB(0, 255, 0));
  106. AddImageAndBusyImage(IDB_EVENT_QUERY, RGB(0, 255, 0));
  107. AddImageAndBusyImage(IDB_ENUM_OBJ, RGB(0, 255, 0));
  108. AddImageAndBusyImage(IDB_ENUM_CLASS, RGB(0, 255, 0));
  109. AddImageAndBusyImage(IDB_CLASS, RGB(0, 255, 0));
  110. AddOverlayedImage(IDB_CLASS, IDB_MODIFIED, RGB(0, 255, 0));
  111. AddImageAndBusyImage(IDB_OBJECT, RGB(0, 255, 0));
  112. AddOverlayedImage(IDB_OBJECT, IDB_MODIFIED, RGB(0, 255, 0));
  113. AddImageAndKeyImage(IDB_OBJECT, RGB(0, 255, 0));
  114. AddImageAndKeyImage(IDB_TEXT, RGB(0, 255, 0));
  115. AddImageAndKeyImage(IDB_BINARY, RGB(0, 255, 0));
  116. // Restore the window placement.
  117. WINDOWPLACEMENT wp;
  118. wp.length = sizeof wp;
  119. if (ReadWindowPlacement(_T("Settings"), _T("WindowPos"), &wp))
  120. {
  121. theApp.m_nCmdShow = wp.showCmd;
  122. //wp.showCmd = SW_SHOWNORMAL;
  123. // This makes it look better when it starts.
  124. wp.showCmd = SW_HIDE;
  125. SetWindowPlacement(&wp);
  126. }
  127. if (!m_wndToolBar.CreateEx(this) ||
  128. !m_wndToolBar.LoadToolBarEx(MAKEINTRESOURCE(IDR_MAINFRAME)))
  129. {
  130. TRACE0("Failed to create toolbar\n");
  131. return -1; // fail to create
  132. }
  133. if (!m_wndReBar.Create(this) ||
  134. !m_wndReBar.AddBar(&m_wndToolBar))
  135. //!m_wndReBar.AddBar(&m_wndDlgBar))
  136. {
  137. TRACE0("Failed to create rebar\n");
  138. return -1; // fail to create
  139. }
  140. if (!m_wndStatusBar.Create(this) ||
  141. !m_wndStatusBar.SetIndicators(indicatorsMenuGone,
  142. sizeof(indicatorsMenuGone)/sizeof(UINT)))
  143. {
  144. TRACE0("Failed to create status bar\n");
  145. return -1; // fail to create
  146. }
  147. // TODO: Remove this if you don't want tool tips
  148. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  149. CBRS_TOOLTIPS | CBRS_FLYBY);
  150. //LoadBarState(_T("Settings"));
  151. m_wndStatusBar.SetPaneInfo(0, indicatorsMenuGone[0], SBPS_STRETCH, 0);
  152. m_wndStatusBar.SetPaneInfo(1, indicatorsMenuGone[1], SBPS_NORMAL, STATUS_SIZE_PROGRESS);
  153. return 0;
  154. }
  155. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
  156. CCreateContext* pContext)
  157. {
  158. // create splitter window
  159. if (!m_wndSplitter.CreateStatic(this, 1, 2))
  160. return FALSE;
  161. int cxCur = AfxGetApp()->GetProfileInt(_T("Settings"),
  162. _T("Pane 0 cxCur"), 100);
  163. if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(COpView), CSize(cxCur, 100), pContext) ||
  164. !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CObjView), CSize(100, 100), pContext))
  165. {
  166. m_wndSplitter.DestroyWindow();
  167. return FALSE;
  168. }
  169. return TRUE;
  170. }
  171. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  172. {
  173. if( !CFrameWnd::PreCreateWindow(cs) )
  174. return FALSE;
  175. // TODO: Modify the Window class or styles here by modifying
  176. // the CREATESTRUCT cs
  177. return TRUE;
  178. }
  179. /////////////////////////////////////////////////////////////////////////////
  180. // CMainFrame diagnostics
  181. #ifdef _DEBUG
  182. void CMainFrame::AssertValid() const
  183. {
  184. CFrameWnd::AssertValid();
  185. }
  186. void CMainFrame::Dump(CDumpContext& dc) const
  187. {
  188. CFrameWnd::Dump(dc);
  189. }
  190. #endif //_DEBUG
  191. /////////////////////////////////////////////////////////////////////////////
  192. // CMainFrame message handlers
  193. CObjView* CMainFrame::GetRightPane()
  194. {
  195. CWnd* pWnd = m_wndSplitter.GetPane(0, 1);
  196. CObjView* pView = DYNAMIC_DOWNCAST(CObjView, pWnd);
  197. return pView;
  198. }
  199. void CMainFrame::OnClose()
  200. {
  201. //SaveBarState("Settings");
  202. // Main window placement
  203. WINDOWPLACEMENT wp;
  204. wp.length = sizeof wp;
  205. if (GetWindowPlacement(&wp))
  206. {
  207. wp.flags = 0;
  208. if (IsZoomed())
  209. wp.flags |= WPF_RESTORETOMAXIMIZED;
  210. // and write it to registry
  211. WriteWindowPlacement(_T("Settings"), _T("WindowPos"), &wp);
  212. }
  213. int cxCur,
  214. cxMin;
  215. m_wndSplitter.GetColumnInfo(0, cxCur, cxMin);
  216. AfxGetApp()->WriteProfileInt(_T("Settings"), _T("Pane 0 cxCur"), cxCur);
  217. /*
  218. CWMITestDoc *pDoc = (CWMITestDoc*) GetActiveDocument();
  219. pDoc->Disconnect();
  220. */
  221. CFrameWnd::OnClose();
  222. }
  223. void CMainFrame::AddImage(DWORD dwID, COLORREF cr)
  224. {
  225. CBitmap bmp;
  226. bmp.LoadBitmap(dwID);
  227. m_imageList.Add(&bmp, cr);
  228. bmp.DeleteObject();
  229. }
  230. void CMainFrame::AddOverlayedImage(int iImage, int iOverlay, COLORREF cr)
  231. {
  232. CBitmap bmpImage,
  233. bmpOverlay,
  234. *pbmpOld;
  235. CImageList listTemp;
  236. HDC hdcScreen = ::GetDC(NULL);
  237. CDC dc,
  238. *pdcScreen = CDC::FromHandle(hdcScreen);
  239. POINT pt = {0, 0};
  240. // Get our image list ready.
  241. dc.CreateCompatibleDC(NULL);
  242. listTemp.Create(16, 16, TRUE, 1, 1);
  243. // Paint the busy image onto the normal image.
  244. bmpOverlay.LoadBitmap(iOverlay);
  245. listTemp.Add(&bmpOverlay, RGB(0, 255, 0));
  246. bmpImage.LoadBitmap(iImage);
  247. pbmpOld = dc.SelectObject(&bmpImage);
  248. listTemp.Draw(&dc, 0, pt, ILD_TRANSPARENT);
  249. dc.SelectObject(pbmpOld);
  250. m_imageList.Add(&bmpImage, cr);
  251. dc.DeleteDC();
  252. ::ReleaseDC(NULL, hdcScreen);
  253. bmpImage.DeleteObject();
  254. bmpOverlay.DeleteObject();
  255. }
  256. void CMainFrame::AddImageAndBusyImage(int iImage, COLORREF cr)
  257. {
  258. AddImage(iImage, cr);
  259. AddOverlayedImage(iImage, IDB_BUSY, cr);
  260. AddOverlayedImage(iImage, IDB_ERROR, cr);
  261. }
  262. void CMainFrame::AddImageAndKeyImage(int iImage, COLORREF cr)
  263. {
  264. AddImage(iImage, cr);
  265. AddOverlayedImage(iImage, IDB_KEY, cr);
  266. }
  267. void CMainFrame::OnUpdateStatusNumberObjects(CCmdUI* pCmdUI)
  268. {
  269. pCmdUI->SetText(m_strStatus);
  270. }
  271. /*
  272. void CMainFrame::OnInitMenu(CMenu* pMenu)
  273. {
  274. CFrameWnd::OnInitMenu(pMenu);
  275. }
  276. BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
  277. {
  278. return CFrameWnd::OnCommand(wParam, lParam);
  279. }
  280. */
  281. LRESULT CMainFrame::OnEnterMenuLoop(WPARAM wParam, LPARAM lParam)
  282. {
  283. m_wndStatusBar.SetIndicators(indicatorsMenuActive, 1);
  284. return 0;
  285. }
  286. LRESULT CMainFrame::OnExitMenuLoop(WPARAM wParam, LPARAM lParam)
  287. {
  288. m_wndStatusBar.SetIndicators(indicatorsMenuGone, 2);
  289. m_wndStatusBar.SetPaneInfo(0, indicatorsMenuGone[0], SBPS_STRETCH, 0);
  290. m_wndStatusBar.SetPaneInfo(1, indicatorsMenuGone[1], SBPS_NORMAL, STATUS_SIZE_PROGRESS);
  291. return 0;
  292. }
  293. void CMainFrame::SetStatusText(LPCTSTR szText)
  294. {
  295. m_strStatus = szText;
  296. }
  297. void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
  298. {
  299. CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  300. DWORD dwID = pPopupMenu->GetMenuItemID(0);
  301. if (dwID == ID_NO_METHODS_FOUND || dwID == ID_NO_S_METHODS)
  302. {
  303. CWMITestDoc *pDoc = (CWMITestDoc*) GetActiveDocument();
  304. CObjInfo *pInfo = pDoc->GetCurrentObj();
  305. if (pInfo)
  306. {
  307. CPropInfoArray *pProps = pInfo->GetProps();
  308. BOOL bStatic = dwID == ID_NO_S_METHODS;
  309. if (pProps && (bStatic && pProps->GetStaticMethodCount()) ||
  310. (!bStatic && pProps->GetMethodCount()))
  311. {
  312. // Get rid of the first item since it's only a placeholder.
  313. pPopupMenu->DeleteMenu(0, MF_BYPOSITION);
  314. POSITION pos = pProps->m_listMethods.GetHeadPosition();
  315. DWORD dwID = IDC_EXECUTE_METHOD_FIRST;
  316. while (pos)
  317. {
  318. CMethodInfo &info = pProps->m_listMethods.GetNext(pos);
  319. // We only add it if we're not in static mode or if
  320. // the method is static anyway.
  321. if (!bStatic || info.m_bStatic)
  322. {
  323. pPopupMenu->AppendMenu(MF_STRING, dwID, info.m_strName);
  324. }
  325. dwID++;
  326. }
  327. }
  328. }
  329. }
  330. }