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.

543 lines
12 KiB

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "WIATest.h"
  5. #include "WIATestView.h"
  6. #include "Progressbar.h"
  7. #include "MainFrm.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMainFrame
  15. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  16. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  17. //{{AFX_MSG_MAP(CMainFrame)
  18. ON_WM_CREATE()
  19. ON_WM_SIZE()
  20. //}}AFX_MSG_MAP
  21. END_MESSAGE_MAP()
  22. static UINT indicators[] =
  23. {
  24. ID_SEPARATOR, // status line indicator
  25. ID_INDICATOR_CAPS,
  26. ID_INDICATOR_NUM,
  27. ID_INDICATOR_SCRL,
  28. };
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame construction/destruction
  31. /**************************************************************************\
  32. * CMainFrame::CMainFrame()
  33. *
  34. * Constructor for mainframe window class
  35. *
  36. *
  37. * Arguments:
  38. *
  39. * none
  40. *
  41. * Return Value:
  42. *
  43. * none
  44. *
  45. * History:
  46. *
  47. * 2/14/1999 Original Version
  48. *
  49. \**************************************************************************/
  50. CMainFrame::CMainFrame()
  51. {
  52. m_pProgressBar = NULL;
  53. m_bSizeON = FALSE;
  54. }
  55. /**************************************************************************\
  56. * CMainFrame::~MainFrame()
  57. *
  58. * Destructor for mainframe window class
  59. *
  60. *
  61. * Arguments:
  62. *
  63. * none
  64. *
  65. * Return Value:
  66. *
  67. * none
  68. *
  69. * History:
  70. *
  71. * 2/14/1999 Original Version
  72. *
  73. \**************************************************************************/
  74. CMainFrame::~CMainFrame()
  75. {
  76. if(m_pProgressBar != NULL)
  77. delete m_pProgressBar;
  78. m_pProgressBar = NULL;
  79. }
  80. /**************************************************************************\
  81. * CMainFrame::OnCreate()
  82. *
  83. * Creates the Main Frame window, adding toolbars, and controls
  84. *
  85. *
  86. * Arguments:
  87. *
  88. * lpCreateStruct - Creation struct containing window params
  89. *
  90. * Return Value:
  91. *
  92. * status
  93. *
  94. * History:
  95. *
  96. * 2/14/1999 Original Version
  97. *
  98. \**************************************************************************/
  99. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  100. {
  101. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  102. return -1;
  103. if (!m_wndToolBar.Create(this)) {
  104. TRACE0("Failed to create toolbar\n");
  105. return -1; // fail to create
  106. }
  107. if (!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) {
  108. TRACE0("Failed to create toolbar\n");
  109. return -1; // fail to create
  110. }
  111. if (!m_wndTransferToolBar.Create(this)) {
  112. TRACE0("Failed to create toolbar\n");
  113. return -1; // fail to create
  114. }
  115. if (!m_wndTransferToolBar.LoadToolBar(IDR_TRANSFER_TOOLBAR)) {
  116. TRACE0("Failed to create toolbar\n");
  117. return -1; // fail to create
  118. }
  119. if (!m_wndStatusBar.Create(this) ||
  120. !m_wndStatusBar.SetIndicators(indicators,
  121. sizeof(indicators)/sizeof(UINT))) {
  122. TRACE0("Failed to create status bar\n");
  123. return -1; // fail to create
  124. }
  125. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  126. // enable Toolbar docking
  127. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  128. m_wndTransferToolBar.SetBarStyle(m_wndTransferToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  129. // enable Toolbar docking
  130. m_wndTransferToolBar.EnableDocking(CBRS_ALIGN_ANY);
  131. // window Docking
  132. EnableDocking(CBRS_ALIGN_ANY);
  133. m_wndTransferToolBar.SetWindowText("TRANSFER");
  134. DockControlBar(&m_wndTransferToolBar,AFX_IDW_DOCKBAR_TOP);
  135. m_wndToolBar.SetWindowText("WIATEST TOOLS");
  136. DockControlBarLeftOf(&m_wndToolBar,&m_wndTransferToolBar);
  137. ShowToolBar(IDR_MAINFRAME,FALSE);
  138. return 0;
  139. }
  140. void CMainFrame::DockControlBarLeftOf(CToolBar* Bar, CToolBar* LeftOf)
  141. {
  142. CRect rect;
  143. DWORD dw;
  144. UINT n;
  145. // get MFC to adjust the dimensions of all docked ToolBars
  146. // so that GetWindowRect will be accurate
  147. RecalcLayout(TRUE);
  148. LeftOf->GetWindowRect(&rect);
  149. rect.OffsetRect(1,0);
  150. dw=LeftOf->GetBarStyle();
  151. n = 0;
  152. n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
  153. n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
  154. n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
  155. n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
  156. // When we take the default parameters on rect, DockControlBar will dock
  157. // each Toolbar on a seperate line. By calculating a rectangle, we
  158. // are simulating a Toolbar being dragged to that location and docked.
  159. DockControlBar(Bar,n,&rect);
  160. }
  161. /**************************************************************************\
  162. * CMainFrame::EnableToolBarButton()
  163. *
  164. * Enables/Disables a requested toolbar button
  165. *
  166. *
  167. * Arguments:
  168. *
  169. * ToolBarID - Tool bar ID to use
  170. * ButtonID - Button to enable/disable
  171. * bEnable - TRUE (Enable) FALSE (Disable)
  172. *
  173. * Return Value:
  174. *
  175. * status
  176. *
  177. * History:
  178. *
  179. * 4/23/1999 Original Version
  180. *
  181. \**************************************************************************/
  182. BOOL CMainFrame::HideToolBarButton(DWORD ToolBarID, DWORD ButtonID, BOOL bEnable)
  183. {
  184. BOOL bResult = FALSE;
  185. if(ToolBarID == IDR_MAINFRAME){
  186. bResult = (m_wndToolBar.GetToolBarCtrl()).HideButton(ButtonID,bEnable);
  187. (m_wndToolBar.GetToolBarCtrl()).AutoSize();
  188. ShowControlBar(&m_wndToolBar,TRUE,FALSE);
  189. return bResult;
  190. }
  191. else if(ToolBarID == IDR_TRANSFER_TOOLBAR){
  192. bResult = (m_wndTransferToolBar.GetToolBarCtrl()).HideButton(ButtonID,bEnable);
  193. (m_wndTransferToolBar.GetToolBarCtrl()).AutoSize();
  194. ShowControlBar(&m_wndTransferToolBar,TRUE,FALSE);
  195. return bResult;
  196. }
  197. else
  198. return FALSE;
  199. }
  200. /**************************************************************************\
  201. * CMainFrame::PreCreateWindow()
  202. *
  203. * Handles precreation initialization for the window
  204. *
  205. *
  206. * Arguments:
  207. *
  208. * cs - Create struct containing window param settings
  209. *
  210. * Return Value:
  211. *
  212. * none
  213. *
  214. * History:
  215. *
  216. * 2/14/1999 Original Version
  217. *
  218. \**************************************************************************/
  219. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  220. {
  221. if( !CFrameWnd::PreCreateWindow(cs) )
  222. return FALSE;
  223. return TRUE;
  224. }
  225. /**************************************************************************\
  226. * CMainFrame::InitializationProgressCtrl()
  227. *
  228. * Handles progress control initialization
  229. *
  230. *
  231. * Arguments:
  232. *
  233. * strMessage - Status display for the progress text
  234. *
  235. * Return Value:
  236. *
  237. * none
  238. *
  239. * History:
  240. *
  241. * 2/14/1999 Original Version
  242. *
  243. \**************************************************************************/
  244. void CMainFrame::InitializeProgressCtrl(LPCTSTR strMessage)
  245. {
  246. if(m_pProgressBar == NULL)
  247. m_pProgressBar = new CProgressBar("Processing..",40,100);
  248. if(m_pProgressBar != NULL)
  249. {
  250. m_pProgressBar->ShowWindow(SW_SHOW);
  251. m_pProgressBar->SetText(strMessage);
  252. m_pProgressBar->SetRange(0,100);
  253. m_pProgressBar->SetPos(0);
  254. m_pProgressBar->SetStep(100);
  255. //m_pProgressBar->SetBarColour(RGB(0,200,0));
  256. }
  257. }
  258. /**************************************************************************\
  259. * CMainFrame::UpdateProgress()
  260. *
  261. * updates the progress control status
  262. *
  263. *
  264. * Arguments:
  265. *
  266. * iProgress - Current Progress to move progress control
  267. *
  268. * Return Value:
  269. *
  270. * none
  271. *
  272. * History:
  273. *
  274. * 2/14/1999 Original Version
  275. *
  276. \**************************************************************************/
  277. void CMainFrame::UpdateProgress(int iProgress)
  278. {
  279. m_pProgressBar->SetPos(iProgress);
  280. }
  281. /**************************************************************************\
  282. * CMainFrame::SetProgressText()
  283. *
  284. * Sets the progress control's text status
  285. *
  286. *
  287. * Arguments:
  288. *
  289. * strText - Text to set in display for status output
  290. *
  291. * Return Value:
  292. *
  293. * none
  294. *
  295. * History:
  296. *
  297. * 2/14/1999 Original Version
  298. *
  299. \**************************************************************************/
  300. void CMainFrame::SetProgressText(LPCTSTR strText)
  301. {
  302. if(m_pProgressBar != NULL)
  303. {
  304. m_pProgressBar->SetText(strText);
  305. //m_wndStatusBar.Invalidate();
  306. }
  307. }
  308. /**************************************************************************\
  309. * CMainFrame::DestroyProgressCtrl()
  310. *
  311. * Hides the progress control in a simulated destruction
  312. *
  313. *
  314. * Arguments:
  315. *
  316. * none
  317. *
  318. * Return Value:
  319. *
  320. * none
  321. *
  322. * History:
  323. *
  324. * 2/14/1999 Original Version
  325. *
  326. \**************************************************************************/
  327. void CMainFrame::DestroyProgressCtrl()
  328. {
  329. m_pProgressBar->ShowWindow(SW_HIDE);
  330. }
  331. /**************************************************************************\
  332. * CMainFrame::DisplayImage()
  333. *
  334. * not used at this time
  335. *
  336. *
  337. * Arguments:
  338. *
  339. * pDIB - DIB to paint
  340. *
  341. * Return Value:
  342. *
  343. * none
  344. *
  345. * History:
  346. *
  347. * 2/14/1999 Original Version
  348. *
  349. \**************************************************************************/
  350. void CMainFrame::DisplayImage(PBYTE pDIB)
  351. {
  352. CWIATestView* pView = (CWIATestView*)GetActiveView();
  353. //pView->PaintThis(pDIB);
  354. }
  355. /////////////////////////////////////////////////////////////////////////////
  356. // CMainFrame diagnostics
  357. #ifdef _DEBUG
  358. void CMainFrame::AssertValid() const
  359. {
  360. CFrameWnd::AssertValid();
  361. }
  362. void CMainFrame::Dump(CDumpContext& dc) const
  363. {
  364. CFrameWnd::Dump(dc);
  365. }
  366. #endif //_DEBUG
  367. /////////////////////////////////////////////////////////////////////////////
  368. // CMainFrame message handlers
  369. /**************************************************************************\
  370. * CMainFrame::ShowToolBar()
  371. *
  372. * Show's a hidden toolbar..possible closed by the user
  373. *
  374. *
  375. * Arguments:
  376. *
  377. * ToolBarID - Toolbar Resource ID
  378. *
  379. * Return Value:
  380. *
  381. * none
  382. *
  383. * History:
  384. *
  385. * 2/14/1999 Original Version
  386. *
  387. \**************************************************************************/
  388. void CMainFrame::ShowToolBar(int ToolBarID,BOOL bShow)
  389. {
  390. switch(ToolBarID)
  391. {
  392. case IDR_TRANSFER_TOOLBAR:
  393. ShowControlBar(&m_wndTransferToolBar,bShow,FALSE);
  394. break;
  395. case IDR_MAINFRAME:
  396. ShowControlBar(&m_wndToolBar,bShow,FALSE);
  397. break;
  398. default:
  399. break;
  400. }
  401. }
  402. /**************************************************************************\
  403. * CMainFrame::IsToolBarVisible()
  404. *
  405. * Determine's if the requested Toolbar is visible
  406. *
  407. *
  408. * Arguments:
  409. *
  410. * ToolBarID - Toolbar Resource ID
  411. *
  412. * Return Value:
  413. *
  414. * status
  415. *
  416. * History:
  417. *
  418. * 2/14/1999 Original Version
  419. *
  420. \**************************************************************************/
  421. BOOL CMainFrame::IsToolBarVisible(DWORD ToolBarID)
  422. {
  423. switch(ToolBarID)
  424. {
  425. case IDR_TRANSFER_TOOLBAR:
  426. return m_wndTransferToolBar.IsWindowVisible();
  427. break;
  428. case IDR_MAINFRAME:
  429. return m_wndToolBar.IsWindowVisible();
  430. break;
  431. default:
  432. break;
  433. }
  434. return FALSE;
  435. }
  436. /**************************************************************************\
  437. * CMainFrame::OnSize()
  438. *
  439. * Handles windows message for Mainframe resizing
  440. *
  441. *
  442. * Arguments:
  443. *
  444. * cx - change in width of mainframe window
  445. * cy - change in height of the mainframe window
  446. *
  447. * Return Value:
  448. *
  449. * none
  450. *
  451. * History:
  452. *
  453. * 2/14/1999 Original Version
  454. *
  455. \**************************************************************************/
  456. void CMainFrame::OnSize(UINT nType, int cx, int cy)
  457. {
  458. CFrameWnd::OnSize(nType, cx, cy);
  459. if(m_bSizeON)
  460. {
  461. CWIATestView* pView = (CWIATestView*)GetActiveView();
  462. if(cx > m_MinWidth)
  463. {
  464. if(pView != NULL)
  465. pView->ResizeControls(cx - m_oldcx,cy - m_oldcy);
  466. m_oldcx = cx;
  467. m_oldcy = cy;
  468. }
  469. if(cy > m_MinHeight)
  470. {
  471. if(pView != NULL)
  472. pView->ResizeControls(cx - m_oldcx,cy - m_oldcy);
  473. m_oldcx = cx;
  474. m_oldcy = cy;
  475. }
  476. }
  477. }
  478. /**************************************************************************\
  479. * CMainFrame::ActivateSizing()
  480. *
  481. * Starts the sizing funtionality of the mainframe
  482. *
  483. *
  484. * Arguments:
  485. *
  486. * bSizeON - Sizing activated, ON/OFF
  487. *
  488. * Return Value:
  489. *
  490. * none
  491. *
  492. * History:
  493. *
  494. * 2/14/1999 Original Version
  495. *
  496. \**************************************************************************/
  497. void CMainFrame::ActivateSizing(BOOL bSizeON)
  498. {
  499. m_bSizeON = bSizeON;
  500. RECT MainFrmRect;
  501. GetClientRect(&MainFrmRect);
  502. m_MinWidth = MainFrmRect.right;
  503. m_MinHeight = MainFrmRect.bottom;
  504. m_oldcx = m_MinWidth;
  505. m_oldcy = m_MinHeight;
  506. }