MainFrm.cpp
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:24k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "GraphSoft.h"
  5. #include "MainFrm.h"
  6. #include "GraphSoftView.h"
  7. #include "ColorSetDlg.h"
  8. #include "FillSetDlg.h"
  9. #include "LineMenu.h"
  10. #include "FullScreenHandler.h"
  11. #include "FullViewBtn.h"
  12. #include "undodlg.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMainFrame
  20. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  21. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  22. //{{AFX_MSG_MAP(CMainFrame)
  23. ON_WM_CREATE()
  24. ON_NOTIFY(TBN_DROPDOWN, IDR_PROPERTY_BAR, OnToolbarDropDown)
  25. ON_WM_CLOSE()
  26. ON_MESSAGE(WM_SETCOLOR,OnSetColor)
  27. ON_MESSAGE(WM_SETFILLCOLOR,OnSetFillColor)
  28. ON_MESSAGE(WM_SETFILLSTYLE,OnSetFillStyle)
  29. ON_COMMAND(ID_PENWIDTH_FIVE, OnPenwidthFive)
  30. ON_COMMAND(ID_PENWIDTH_ONE, OnPenwidthOne)
  31. ON_COMMAND(ID_PENWIDTH_SEVEN, OnPenwidthSeven)
  32. ON_COMMAND(ID_PENWIDTH_THREE, OnPenwidthThree)
  33. ON_COMMAND(ID_PENWIDTH_TWO, OnPenwidthTwo)
  34. ON_COMMAND(ID_SET_FILLSTYLE, OnSetFillstyle)
  35. ON_WM_DRAWITEM()
  36. ON_WM_MEASUREITEM()
  37. ON_WM_INITMENU()
  38. ON_COMMAND(ID_FULLSCREEN, OnFullscreen)
  39. ON_COMMAND(ID_FULLWINDOW, OnFullwindow)
  40. ON_WM_GETMINMAXINFO()
  41. ON_COMMAND(ID_SELECT_COLOR, OnSelectColor)
  42. ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
  43. ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  44. ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
  45. ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
  46. ON_NOTIFY(TBN_DROPDOWN, IDR_MAINFRAME, OnToolbarDropDown)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. static UINT indicators[] =
  50. {
  51. ID_SEPARATOR,// status line indicator
  52. ID_SEPARATOR,        
  53. ID_INDICATOR_CAPS,
  54. ID_INDICATOR_NUM,
  55. ID_INDICATOR_SCRL,
  56. };
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMainFrame construction/destruction
  59. CMainFrame::CMainFrame()
  60. {
  61. // TODO: add member initialization code here
  62. m_pdlgSetColor=new CColorSetDlg(0,this);
  63. m_pdlgSetFillColor=new CColorSetDlg(1,this);
  64. m_pdlgFillStyle=new CFillSetDlg(this);
  65. m_pdlgSetColor->Create(CColorSetDlg::IDD, this);
  66. m_pdlgSetColor->ShowWindow(SW_SHOW);
  67. m_pdlgSetColor->PostMessage(WM_COMMAND,IDCANCEL);
  68. m_pdlgSetFillColor->Create(CColorSetDlg::IDD, this);
  69. m_pdlgSetFillColor->ShowWindow(SW_SHOW);
  70. m_pdlgSetFillColor->PostMessage(WM_COMMAND,IDCANCEL);
  71. m_pdlgFillStyle->Create(CFillSetDlg::IDD,this);
  72.    
  73. m_pUndoDlg=NULL;
  74. }
  75. CMainFrame::~CMainFrame()
  76. {
  77. m_pdlgSetColor->DestroyWindow();
  78. delete m_pdlgSetColor;
  79. m_pdlgSetFillColor->DestroyWindow();
  80. delete m_pdlgSetFillColor;
  81. m_pdlgFillStyle->DestroyWindow();
  82. delete m_pdlgFillStyle;
  83. delete this->m_wndFullView.m_pBtn ;
  84. delete m_pUndoDlg;
  85. }
  86. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  87. {
  88. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  89. return -1;
  90. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT| CCS_ADJUSTABLE, WS_CHILD | WS_VISIBLE | CBRS_TOP
  91. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED,CRect(0,0,0,0),IDR_MAINFRAME) ||
  92. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  93. {
  94. TRACE0("Failed to create toolbarn");
  95. return -1;      // fail to create
  96. }
  97.     
  98. if (!m_wndStatusBar.Create(this) ||
  99. !m_wndStatusBar.SetIndicators(indicators,
  100.   sizeof(indicators)/sizeof(UINT)))
  101. {
  102. TRACE0("Failed to create status barn");
  103. return -1;      // fail to create
  104. }
  105.     m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_STRETCH,200);
  106. m_wndStatusBar.SetPaneStyle(1,SBPS_STRETCH);
  107. //m_wndStatusBar.SetPaneInfo(1,ID_INDICATOR_MOUSEPOSITION,SBPS_NORMAL,100);
  108.     //GraphBar
  109. if (!m_wndTBarGraph.CreateEx(this, TBSTYLE_FLAT| CCS_ADJUSTABLE, WS_CHILD | WS_VISIBLE | CBRS_LEFT
  110. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY ) ||
  111. !m_wndTBarGraph.LoadToolBar(IDR_DRAW_GRAPH))
  112. {
  113. TRACE0("Failed to create toolbarn");
  114. return -1;      // fail to create
  115. }     
  116. //Graph Operation Bar
  117. if (!m_wndTBarGraphOp.CreateEx(this, TBSTYLE_FLAT| CCS_ADJUSTABLE, WS_CHILD | WS_VISIBLE | CBRS_LEFT
  118. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY) ||
  119. !m_wndTBarGraphOp.LoadToolBar(IDR_GRAPH_OPERATION))
  120. {
  121. TRACE0("Failed to create toolbarn");
  122. return -1;      // fail to create
  123. }    
  124.     //PropertyBar
  125. if (!m_wndPropertyBar.CreateEx(this, TBSTYLE_FLAT| CCS_ADJUSTABLE,  WS_CHILD | WS_VISIBLE | CBRS_TOP
  126. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY| CBRS_SIZE_FIXED,CRect(0,0,0,0),IDR_PROPERTY_BAR ) ||
  127. !m_wndPropertyBar.LoadToolBar(IDR_PROPERTY_BAR))
  128. {
  129. TRACE0("Failed to create toolbarn");
  130. return -1;      // fail to create
  131. //WindowBar
  132. if (!m_wndWindow.CreateEx(this, TBSTYLE_FLAT| CCS_ADJUSTABLE,  WS_CHILD | WS_VISIBLE | CBRS_TOP
  133. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY| CBRS_SIZE_FIXED,CRect(0,0,0,0),IDR_WINDOWS ) ||
  134. !m_wndWindow.LoadToolBar(IDR_WINDOWS))
  135. {
  136. TRACE0("Failed to create toolbarn");
  137. return -1;      // fail to create
  138. /////////////////////////////////////////////////
  139. CRect rect;
  140.     int index=0;
  141. //让工具栏具有处理下拉箭头的能力
  142. DWORD dwExStyle = TBSTYLE_EX_DRAWDDARROWS;
  143. m_wndPropertyBar.GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)dwExStyle);
  144.     m_wndToolBar.GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)dwExStyle);
  145. //用SetButtonStyle()方法在选定的地方添加下拉箭头按钮
  146. //笔宽
  147. DWORD dwStyle = m_wndPropertyBar.GetButtonStyle(m_wndPropertyBar.CommandToIndex(ID_SELECT_PENWIDTH));
  148. dwStyle |= TBSTYLE_DROPDOWN;
  149.     m_wndPropertyBar.SetButtonStyle(m_wndPropertyBar.CommandToIndex(ID_SELECT_PENWIDTH), dwStyle);  
  150.     
  151. //颜色
  152. dwStyle = m_wndPropertyBar.GetButtonStyle(m_wndPropertyBar.CommandToIndex(ID_SELECT_COLOR));
  153. dwStyle |= TBSTYLE_DROPDOWN;
  154.     m_wndPropertyBar.SetButtonStyle(m_wndPropertyBar.CommandToIndex(ID_SELECT_COLOR), dwStyle);  
  155. //填充颜色
  156. dwStyle = m_wndPropertyBar.GetButtonStyle(m_wndPropertyBar.CommandToIndex(ID_SELECT_FILL_COLOR));
  157. dwStyle |= TBSTYLE_DROPDOWN;
  158.     m_wndPropertyBar.SetButtonStyle(m_wndPropertyBar.CommandToIndex(ID_SELECT_FILL_COLOR), dwStyle);  
  159. //填充类型
  160. dwStyle = m_wndPropertyBar.GetButtonStyle(m_wndPropertyBar.CommandToIndex(ID_SET_FILLSTYLE));
  161. dwStyle |= TBSTYLE_DROPDOWN;
  162.     m_wndPropertyBar.SetButtonStyle(m_wndPropertyBar.CommandToIndex(ID_SET_FILLSTYLE), dwStyle);  
  163. //撤消
  164. dwStyle = m_wndToolBar.GetButtonStyle(m_wndToolBar.CommandToIndex(ID_EDIT_UNDO));
  165. dwStyle |= TBSTYLE_DROPDOWN;
  166.     m_wndToolBar.SetButtonStyle(m_wndToolBar.CommandToIndex(ID_EDIT_UNDO), dwStyle);  
  167. //恢复
  168. dwStyle = m_wndToolBar.GetButtonStyle(m_wndToolBar.CommandToIndex(ID_EDIT_REDO));
  169. dwStyle |= TBSTYLE_DROPDOWN;
  170.     m_wndToolBar.SetButtonStyle(m_wndToolBar.CommandToIndex(ID_EDIT_REDO), dwStyle);  
  171. /////////////////////////////////////////////////////
  172. // TODO: Delete these three lines if you don't want the toolbar to
  173. //  be dockable
  174. //设置工具拦的位置
  175. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  176. m_wndTBarGraph.EnableDocking(CBRS_ALIGN_ANY);
  177. m_wndTBarGraphOp.EnableDocking(CBRS_ALIGN_ANY);
  178. m_wndPropertyBar.EnableDocking(CBRS_ALIGN_ANY);
  179. m_wndWindow.EnableDocking(CBRS_ALIGN_ANY);
  180. EnableDocking(CBRS_ALIGN_ANY);
  181. DockControlBar(&m_wndToolBar);
  182. DockControlBar(&m_wndTBarGraph);
  183. DockControlBar(&m_wndTBarGraphOp);
  184. RecalcLayout(TRUE);
  185. m_wndToolBar.GetWindowRect(&rect);
  186. rect.left+=1;
  187. rect.right+=1;
  188. DockControlBar(&m_wndPropertyBar,AFX_IDW_DOCKBAR_TOP,&rect); 
  189.     m_wndPropertyBar.GetWindowRect(&rect);
  190. rect.left+=1;
  191. rect.right+=1;
  192. DockControlBar(&m_wndWindow,AFX_IDW_DOCKBAR_TOP,&rect); 
  193. //创建全景视图
  194. if (!m_wndFullView.Create(this,IDD_FULLVIEW,WS_CHILD | WS_VISIBLE  | CBRS_TOOLTIPS | CBRS_RIGHT|CBRS_FLYBY | CBRS_SIZE_DYNAMIC,IDD_FULLVIEW))
  195. {
  196. TRACE0("Failed to create DlgBarn");
  197. return -1;      
  198. }
  199. CRect rect2 ;
  200. m_wndFullView.GetWindowRect(&rect2) ;
  201.     m_wndFullView.MoveWindow(4,42,172,143,true);
  202. m_wndFullView.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT) ;
  203. CString title;
  204. title.LoadString(IDS_FULLVIEWTITLE);
  205. m_wndFullView.SetWindowText(title);
  206. DockControlBar(&m_wndFullView) ;
  207. m_wndFullView.m_pBtn = new CFullViewBtn();
  208. m_wndFullView.GetWindowRect(&rect) ;
  209. m_wndFullView.CalcViewSize() ;
  210. m_wndFullView.m_pBtn->Create("TEST",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,m_wndFullView.m_pBtn->m_size,&m_wndFullView,0) ;
  211. return 0;
  212. }
  213. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  214. {
  215. if( !CFrameWnd::PreCreateWindow(cs) )
  216. return FALSE;
  217. // TODO: Modify the Window class or styles here by modifying
  218. //  the CREATESTRUCT cs
  219.     
  220. return TRUE;
  221. }
  222. /////////////////////////////////////////////////////////////////////////////
  223. // CMainFrame diagnostics
  224. #ifdef _DEBUG
  225. void CMainFrame::AssertValid() const
  226. {
  227. CFrameWnd::AssertValid();
  228. }
  229. void CMainFrame::Dump(CDumpContext& dc) const
  230. {
  231. CFrameWnd::Dump(dc);
  232. }
  233. #endif //_DEBUG
  234. /////////////////////////////////////////////////////////////////////////////
  235. // CMainFrame message handlers
  236. void CMainFrame::OnClose() 
  237. {
  238. // TODO: Add your message handler code here and/or call default
  239. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  240. CGraphSoftDoc* pDoc=pView->GetDocument();
  241. CString strTitle,strDetail;
  242. strTitle.LoadString(IDS_FILE_SAVE_TITLE);
  243. strDetail.LoadString(IDS_FILE_SAVE_STRING);
  244. if(pDoc->m_pCore->IsAbleToUndo()||pDoc->m_pCore->IsAbleToRedo()){
  245. int nRtn=MessageBox(strDetail,strTitle,MB_YESNOCANCEL|MB_SYSTEMMODAL);
  246. if(nRtn==IDYES){
  247. SendMessage(WM_COMMAND,WPARAM(ID_FILE_SAVE));
  248. }else if(nRtn==IDCANCEL){
  249. return ;
  250. }
  251. }
  252. CFrameWnd::OnClose();
  253. }
  254. void CMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
  255. {
  256. CWnd *pWnd;
  257. CRect rect;
  258. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  259. CGraphSoftDoc* pDoc=pView->GetDocument();
  260. switch (pnmtb->iItem)
  261. {
  262. case ID_SELECT_PENWIDTH:
  263. {
  264. CLineMenu mnLine;
  265. pWnd = &m_wndPropertyBar;
  266. pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rect);
  267. pWnd->ClientToScreen(&rect);
  268. mnLine.CreatePopupMenu();
  269. mnLine.AppendMenu(MF_ENABLED,ID_PENWIDTH_ONE,"1 X");
  270. mnLine.AppendMenu(MF_ENABLED,ID_PENWIDTH_TWO,"2 X");
  271. mnLine.AppendMenu(MF_ENABLED,ID_PENWIDTH_THREE,"3 X");
  272. mnLine.AppendMenu(MF_ENABLED,ID_PENWIDTH_FIVE,"5 X");
  273. mnLine.AppendMenu(MF_ENABLED,ID_PENWIDTH_SEVEN,"7 X");
  274. mnLine.ChangeStyle(&mnLine);
  275. mnLine.TrackPopupMenu(TPM_LEFTALIGN ,rect.left, rect.bottom,this);
  276. mnLine.DestroyMenu();
  277. break;
  278. }
  279. case ID_SELECT_COLOR:
  280. {
  281. pWnd = &m_wndPropertyBar;
  282. pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rect);
  283. pWnd->ClientToScreen(&rect);
  284. m_pdlgSetColor->Init();
  285.     m_pdlgSetColor->InitColor(((CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView())->m_clrCurrentColor);
  286. m_pdlgSetColor->SetWindowPos(&wndTopMost, rect.left,rect.bottom, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  287. m_pdlgSetColor->ShowWindow(SW_SHOW);
  288. m_pdlgSetColor->SetFocus();
  289. break;
  290. }
  291. case ID_SELECT_FILL_COLOR:
  292. {
  293. pWnd = &m_wndPropertyBar;
  294. pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rect);
  295. pWnd->ClientToScreen(&rect);
  296. m_pdlgSetFillColor->Init();
  297. m_pdlgSetFillColor->InitColor(((CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView())->m_clrCurrentFill);
  298. m_pdlgSetFillColor->SetWindowPos(&wndTopMost, rect.left,rect.bottom, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  299. m_pdlgSetFillColor->ShowWindow(SW_SHOW);
  300. m_pdlgSetFillColor->SetFocus();
  301. break;
  302. }
  303. case ID_SET_FILLSTYLE:
  304. {
  305. pWnd = &m_wndPropertyBar;
  306. pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rect);
  307. pWnd->ClientToScreen(&rect);
  308. m_pdlgFillStyle->Init();
  309. m_pdlgFillStyle->SetWindowPos(&wndTopMost, rect.left,rect.bottom, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  310. m_pdlgFillStyle->ShowWindow(SW_SHOW);
  311. m_pdlgFillStyle->SetFocus();
  312. break;
  313. }
  314. case ID_EDIT_UNDO :
  315. case ID_EDIT_REDO :
  316. {
  317. CCore* pCore=pDoc->m_pCore;
  318. if (m_pUndoDlg == NULL) {
  319. m_pUndoDlg = new CUndoDlg;
  320. m_pUndoDlg->Create(IDD_UNDODLG);
  321. m_pUndoDlg->m_list.m_pParentDlg = m_pUndoDlg;
  322. }
  323. if (! m_pUndoDlg->IsWindowVisible()) {
  324. pWnd = &m_wndToolBar;
  325. pWnd->SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rect);
  326. pWnd->ClientToScreen(&rect);
  327. CPoint pos;
  328. pos.x = rect.left;
  329. pos.y = rect.bottom;
  330. CRect rcDlg;
  331. m_pUndoDlg->GetWindowRect(&rcDlg);
  332. if (pos.x + rcDlg.Width() > ::GetSystemMetrics(SM_CXSCREEN))
  333. pos.x = rect.right - rcDlg.Width();
  334. if (pos.y + rcDlg.Height() > ::GetSystemMetrics(SM_CYSCREEN))
  335. pos.y = rect.top - rcDlg.Height();
  336. m_pUndoDlg->SetWindowPos(NULL, pos.x, pos.y, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  337. m_pUndoDlg->m_list.m_pCore = pCore;
  338. m_pUndoDlg->m_list.m_nID = pnmtb->iItem;
  339. m_pUndoDlg->m_list.SetContents();
  340. switch (m_pUndoDlg->m_list.m_nID) {
  341. case ID_EDIT_UNDO:
  342. m_pUndoDlg->m_statusFormatString.LoadString(IDS_EDIT_UNDO_TIMES);
  343. break;
  344. case ID_EDIT_REDO:
  345. m_pUndoDlg->m_statusFormatString.LoadString(IDS_EDIT_REDO_TIMES);
  346. break;
  347. }
  348. m_pUndoDlg->SetStatus(0);
  349. m_pUndoDlg->ShowWindow(SW_SHOW);
  350. }
  351. break ;
  352. }
  353. default:
  354. return;
  355. }   
  356. return;
  357. }   
  358. void CMainFrame::ActivateFrame(int nCmdShow) 
  359. {
  360. // TODO: Add your specialized code here and/or call the base class
  361. nCmdShow=SW_MAXIMIZE;
  362. CFrameWnd::ActivateFrame(nCmdShow);
  363. }
  364. void CMainFrame::OnSetColor(WPARAM wParam,LPARAM lParam)
  365. {
  366. COLORREF color=(COLORREF)wParam;
  367. if(((CGraphSoftView*)GetActiveView())->m_clrCurrentColor==color){
  368. return;
  369. }
  370. ((CGraphSoftView*)GetActiveView())->m_clrCurrentColor=color;
  371. CToolBar& wndToolBar = m_wndPropertyBar;
  372. CToolBarCtrl& toolbar = wndToolBar.GetToolBarCtrl();
  373. UINT uID = ID_SELECT_COLOR;
  374. int nIndex = wndToolBar.CommandToIndex(uID);
  375. if (nIndex >= 0) {
  376. CBitmap& bitmap = m_colorbmp;
  377. if (bitmap.GetSafeHandle())
  378. bitmap.DeleteObject();
  379. bitmap.LoadBitmap(IDB_BITMAP_LINECOLOR_SET);
  380. {
  381. CClientDC dc(this);
  382. CDC dcMem;
  383. dcMem.CreateCompatibleDC(&dc);
  384. dcMem.SelectObject(&bitmap);
  385. COLORREF clrBk = dcMem.GetPixel(0,0);
  386. for (int j = 0; j < 12; j++) {
  387. for (int i = 0; i < 16; i++) {
  388. if (dcMem.GetPixel(i,j) == clrBk)
  389. dcMem.SetPixel(i,j,::GetSysColor(COLOR_3DFACE));
  390. }
  391. }
  392. CRect rect(0, 12, 16, 16);
  393. dcMem.FillRect(rect, &CBrush(color));
  394. }
  395. int no = toolbar.AddBitmap(1, &bitmap);
  396. UINT uStyle ;
  397. int iImage ;
  398. wndToolBar.GetButtonInfo ( nIndex, uID, uStyle, iImage );
  399. wndToolBar.SetButtonInfo ( nIndex, uID, uStyle, no );
  400. }
  401. }
  402. void CMainFrame::OnSetFillColor (WPARAM wParam,LPARAM lParam)
  403. {
  404. COLORREF color=(COLORREF)wParam;
  405. if(((CGraphSoftView*)GetActiveView())->m_clrCurrentFill==color){
  406. return;
  407. }
  408. ((CGraphSoftView*)GetActiveView())->m_clrCurrentFill=color;
  409. CToolBar& wndToolBar = m_wndPropertyBar;
  410. CToolBarCtrl& toolbar = wndToolBar.GetToolBarCtrl();
  411. UINT uID = ID_SELECT_FILL_COLOR;
  412. int nIndex = wndToolBar.CommandToIndex(uID);
  413. if (nIndex >= 0) {
  414. CBitmap& bitmap = m_colorbmp;
  415. if (bitmap.GetSafeHandle())
  416. bitmap.DeleteObject();
  417. bitmap.LoadBitmap(IDB_BITMAP_FILLCOLOR_SET);
  418. {
  419. CClientDC dc(this);
  420. CDC dcMem;
  421. dcMem.CreateCompatibleDC(&dc);
  422. dcMem.SelectObject(&bitmap);
  423. COLORREF clrBk = dcMem.GetPixel(0,0);
  424. for (int j = 0; j < 12; j++) {
  425. for (int i = 0; i < 16; i++) {
  426. if (dcMem.GetPixel(i,j) == clrBk)
  427. dcMem.SetPixel(i,j,::GetSysColor(COLOR_3DFACE));
  428. }
  429. }
  430. CRect rect(0, 12, 16, 16);
  431. dcMem.FillRect(rect, &CBrush(color));
  432. }
  433. int no = toolbar.AddBitmap(1, &bitmap);
  434. UINT uStyle ;
  435. int iImage ;
  436. wndToolBar.GetButtonInfo ( nIndex, uID, uStyle, iImage );
  437. wndToolBar.SetButtonInfo ( nIndex, uID, uStyle, no );
  438. }
  439. }
  440. void CMainFrame::OnSetFillStyle (WPARAM wParam,LPARAM lParam)
  441. {
  442. int nStyle=(int)wParam;
  443. if(((CGraphSoftView*)GetActiveView())->m_shapeCurFillStyle==(SHAPE_FILLSTYLE)nStyle){
  444. return;
  445. }
  446. ((CGraphSoftView*)GetActiveView())->m_shapeCurFillStyle=(SHAPE_FILLSTYLE)nStyle;
  447. CToolBar& wndToolBar = m_wndPropertyBar;
  448. CToolBarCtrl& toolbar = wndToolBar.GetToolBarCtrl();
  449. UINT uID = ID_SET_FILLSTYLE;
  450. int nIndex = wndToolBar.CommandToIndex(uID);
  451. if (nIndex >= 0) {
  452. CBitmap& bitmap = m_colorbmp;
  453. if (bitmap.GetSafeHandle())
  454. bitmap.DeleteObject();
  455. switch(nStyle){
  456. case 0:
  457. bitmap.LoadBitmap(IDB_GRAPH_NOTFILL);
  458. break;
  459. case 1:
  460. bitmap.LoadBitmap(IDB_GRAPH_SOLIDFILL);
  461. break;
  462. default:
  463. break;
  464. }
  465. CClientDC dc(this);
  466. dc.SelectObject(&bitmap);
  467. int no = toolbar.AddBitmap(1, &bitmap);
  468. UINT uStyle ;
  469. int iImage ;
  470. wndToolBar.GetButtonInfo ( nIndex, uID, uStyle, iImage );
  471. wndToolBar.SetButtonInfo ( nIndex, uID, uStyle, no );
  472. }
  473. }
  474. void CMainFrame::OnPenwidthFive() 
  475. {
  476. // TODO: Add your command handler code here
  477. if(((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth==5){
  478. return;
  479. }
  480. ((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth=5;
  481. CToolBar& wndToolBar = m_wndPropertyBar;
  482. CToolBarCtrl& toolbar = wndToolBar.GetToolBarCtrl();
  483. UINT uID = ID_SELECT_PENWIDTH;
  484. int nIndex = wndToolBar.CommandToIndex(uID);
  485. if (nIndex >= 0) {
  486. CBitmap& bitmap = m_colorbmp;
  487. if (bitmap.GetSafeHandle())
  488. bitmap.DeleteObject();
  489. bitmap.LoadBitmap(IDB_PENWIDTH_FIVE);
  490. CClientDC dc(this);
  491. dc.SelectObject(&bitmap);
  492. int no = toolbar.AddBitmap(1, &bitmap);
  493. UINT uStyle ;
  494. int iImage ;
  495. wndToolBar.GetButtonInfo ( nIndex, uID, uStyle, iImage );
  496. wndToolBar.SetButtonInfo ( nIndex, uID, uStyle, no );
  497. }
  498. }
  499. void CMainFrame::OnPenwidthOne() 
  500. {
  501. // TODO: Add your command handler code here
  502. if(((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth==1){
  503. return;
  504. }
  505. ((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth=1;
  506. CToolBar& wndToolBar = m_wndPropertyBar;
  507. CToolBarCtrl& toolbar = wndToolBar.GetToolBarCtrl();
  508. UINT uID = ID_SELECT_PENWIDTH;
  509. int nIndex = wndToolBar.CommandToIndex(uID);
  510. if (nIndex >= 0) {
  511. CBitmap& bitmap = m_colorbmp;
  512. if (bitmap.GetSafeHandle())
  513. bitmap.DeleteObject();
  514. bitmap.LoadBitmap(IDB_PENWIDTH_ONE);
  515. CClientDC dc(this);
  516. dc.SelectObject(&bitmap);
  517. int no = toolbar.AddBitmap(1, &bitmap);
  518. UINT uStyle ;
  519. int iImage ;
  520. wndToolBar.GetButtonInfo ( nIndex, uID, uStyle, iImage );
  521. wndToolBar.SetButtonInfo ( nIndex, uID, uStyle, no );
  522. }
  523. }
  524. void CMainFrame::OnPenwidthSeven() 
  525. {
  526. // TODO: Add your command handler code here
  527. if(((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth==7){
  528. return;
  529. }
  530. ((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth=7;
  531. CToolBar& wndToolBar = m_wndPropertyBar;
  532. CToolBarCtrl& toolbar = wndToolBar.GetToolBarCtrl();
  533. UINT uID = ID_SELECT_PENWIDTH;
  534. int nIndex = wndToolBar.CommandToIndex(uID);
  535. if (nIndex >= 0) {
  536. CBitmap& bitmap = m_colorbmp;
  537. if (bitmap.GetSafeHandle())
  538. bitmap.DeleteObject();
  539. bitmap.LoadBitmap(IDB_PENWIDTH_SEVEN);
  540. CClientDC dc(this);
  541. dc.SelectObject(&bitmap);
  542. int no = toolbar.AddBitmap(1, &bitmap);
  543. UINT uStyle ;
  544. int iImage ;
  545. wndToolBar.GetButtonInfo ( nIndex, uID, uStyle, iImage );
  546. wndToolBar.SetButtonInfo ( nIndex, uID, uStyle, no );
  547. }
  548. }
  549. void CMainFrame::OnPenwidthThree() 
  550. {
  551. // TODO: Add your command handler code here
  552. if(((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth==3){
  553. return;
  554. }
  555. ((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth=3;
  556. CToolBar& wndToolBar = m_wndPropertyBar;
  557. CToolBarCtrl& toolbar = wndToolBar.GetToolBarCtrl();
  558. UINT uID = ID_SELECT_PENWIDTH;
  559. int nIndex = wndToolBar.CommandToIndex(uID);
  560. if (nIndex >= 0) {
  561. CBitmap& bitmap = m_colorbmp;
  562. if (bitmap.GetSafeHandle())
  563. bitmap.DeleteObject();
  564. bitmap.LoadBitmap(IDB_PENWIDTH_THREE);
  565. CClientDC dc(this);
  566. dc.SelectObject(&bitmap);
  567. int no = toolbar.AddBitmap(1, &bitmap);
  568. UINT uStyle ;
  569. int iImage ;
  570. wndToolBar.GetButtonInfo ( nIndex, uID, uStyle, iImage );
  571. wndToolBar.SetButtonInfo ( nIndex, uID, uStyle, no );
  572. }
  573. }
  574. void CMainFrame::OnPenwidthTwo() 
  575. {
  576. // TODO: Add your command handler code here
  577. if(((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth==2){
  578. return;
  579. }
  580. ((CGraphSoftView*)GetActiveView())->m_nCurrentPenWidth=2;
  581. CToolBar& wndToolBar = m_wndPropertyBar;
  582. CToolBarCtrl& toolbar = wndToolBar.GetToolBarCtrl();
  583. UINT uID = ID_SELECT_PENWIDTH;
  584. int nIndex = wndToolBar.CommandToIndex(uID);
  585. if (nIndex >= 0) {
  586. CBitmap& bitmap = m_colorbmp;
  587. if (bitmap.GetSafeHandle())
  588. bitmap.DeleteObject();
  589. bitmap.LoadBitmap(IDB_PENWIDTH_TWO);
  590. CClientDC dc(this);
  591. dc.SelectObject(&bitmap);
  592. int no = toolbar.AddBitmap(1, &bitmap);
  593. UINT uStyle ;
  594. int iImage ;
  595. wndToolBar.GetButtonInfo ( nIndex, uID, uStyle, iImage );
  596. wndToolBar.SetButtonInfo ( nIndex, uID, uStyle, no );
  597. }
  598. }
  599. void CMainFrame::OnSetFillstyle() 
  600. {
  601. // TODO: Add your command handler code here
  602. }
  603. void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
  604. {
  605. // TODO: Add your message handler code here and/or call default
  606. if(!nIDCtl) m_menu.DrawItem(lpDrawItemStruct);
  607. CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
  608. }
  609. void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
  610. {
  611. // TODO: Add your message handler code here and/or call default
  612. if(!nIDCtl) m_menu.MeasureItem(lpMeasureItemStruct);
  613. CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
  614. }
  615. void CMainFrame::OnInitMenu(CMenu* pMenu) 
  616. {
  617. CFrameWnd::OnInitMenu(pMenu);
  618. // TODO: Add your message handler code here
  619. m_menu.InitMenu(pMenu,IDR_MAINFRAME,&m_wndToolBar);
  620. //m_menu.InitMenu(pMenu,IDR_GRAPH_OPERATION,&(((CMainFrame*)(AfxGetApp()->GetMainWnd()))->m_wndTBarGraphOp));
  621. }
  622. void CMainFrame::OnFullscreen() 
  623. {
  624. // TODO: Add your command handler code here
  625. if (FullScreenHandler.InFullScreenMode())
  626. {
  627. FullScreenHandler.Restore(this);
  628. }else{
  629. FullScreenHandler.Maximize(this,this->m_pViewActive);
  630. }
  631. }
  632. void CMainFrame::OnFullwindow() 
  633. {
  634. // TODO: Add your command handler code here
  635. BOOL bVisible = false ;
  636. if( m_wndFullView.IsWindowVisible()) bVisible = true ;
  637. if(bVisible) {
  638. ShowControlBar(&m_wndFullView,FALSE,FALSE) ;
  639. }
  640. else {
  641. ShowControlBar(&m_wndFullView ,true,FALSE) ;
  642. }
  643. }
  644. void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpmmi)
  645. {
  646. CSize sz = FullScreenHandler.GetMaxSize();
  647. lpmmi->ptMaxSize = CPoint(sz);
  648. lpmmi->ptMaxTrackSize = CPoint(sz);
  649. }     
  650. void CMainFrame::OnSelectColor() 
  651. {
  652. // TODO: Add your command handler code here
  653. }
  654. void CMainFrame::OnEditRedo() 
  655. {
  656. // TODO: Add your command handler code here
  657. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  658. CGraphSoftDoc* pDoc=pView->GetDocument();
  659. pDoc->m_pCore->OnEditRedo();
  660. }
  661. void CMainFrame::OnEditUndo() 
  662. {
  663. // TODO: Add your command handler code here
  664. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  665. CGraphSoftDoc* pDoc=pView->GetDocument();
  666. pDoc->m_pCore->OnEditUndo();
  667. }
  668. void CMainFrame::OnUpdateEditRedo(CCmdUI* pCmdUI) 
  669. {
  670. // TODO: Add your command update UI handler code here
  671. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  672. CGraphSoftDoc* pDoc=pView->GetDocument();
  673. pCmdUI->Enable(pDoc->m_pCore->IsAbleToRedo() && pView->m_graph_op!=_graph_edit);
  674. }
  675. void CMainFrame::OnUpdateEditUndo(CCmdUI* pCmdUI) 
  676. {
  677. // TODO: Add your command update UI handler code here
  678. CGraphSoftView* pView=(CGraphSoftView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveView();
  679. CGraphSoftDoc* pDoc=pView->GetDocument();
  680. pCmdUI->Enable(pDoc->m_pCore->IsAbleToUndo() && pView->m_graph_op!=_graph_edit);
  681. }