www.gusucode.com > 一个VC++ GUI测试程序-源码程序 > 一个VC++ GUI测试程序-源码程序/code/Test2Dlg.cpp
//Download by http://www.NewXing.com // Test2Dlg.cpp : implementation file // #include "stdafx.h" #include "GUITest.h" #include "Test2Dlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTest2Dlg dialog CTest2Dlg::CTest2Dlg(CWnd* pParent /*=NULL*/) : CDlgBaseClass(CTest2Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CTest2Dlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CTest2Dlg::DoDataExchange(CDataExchange* pDX) { CDlgBaseClass::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTest2Dlg) DDX_Control(pDX, IDC_COLOR_BUTTON, m_color); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTest2Dlg, CDlgBaseClass) //{{AFX_MSG_MAP(CTest2Dlg) ON_BN_CLICKED(ID_GO, OnGo) ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTest2Dlg message handlers BOOL CTest2Dlg::OnInitDialog() { CDlgBaseClass::OnInitDialog(); SetToolTipMap(IDOK,"确定"); SetToolTipMap(IDCANCEL,"取消"); SetToolTipMap(IDC_EDIT1,"大家好啊!"); UINT nIDs[]={IDOK,IDCANCEL,ID_GO}; CreateIconButtons(nIDs,sizeof(nIDs)/sizeof(UINT)); SetButtonIcon(IDOK,1); SetButtonIcon(IDCANCEL,0); SetButtonIcon(ID_GO,3); ((CIconButton *)GetDlgItem(IDOK))->SetFontColor(RGB(255,0,0)); ((CIconButton *)GetDlgItem(IDOK))->SetFontBold(TRUE); ((CIconButton *)GetDlgItem(ID_GO))->SetHasMenu(); m_output.Create(_T("SysHeader32"),"",WS_CHILD|WS_VISIBLE|WS_BORDER,CRect(5,5,300,80),this,10001); CString strLine = CONTROL_BYTE; strLine += _T("11,00HEY!"); m_output.AddLine( strLine ); CString tmpStr="a;lfja;sfdjas"; m_output.AddLine(tmpStr); tmpStr="大家好!"; m_output.AddLine(tmpStr); m_Pie.SubclassDlgItem(IDC_PIC, this); m_Pie.SetTitle("Chart Title"); m_Pie.Reset(); m_Pie.AddPiece(RGB(255,0,0), RGB(0,255,0), 120, "第一时间"); m_Pie.AddPiece(RGB(0,0,255), RGB(0,255,0), 240, "第二时间"); m_OCtrl.Create(WS_CHILD|WS_VISIBLE|WS_BORDER,CRect(0,100,300,200),this); m_OCtrl.SetRange(-10.0, 10.0, 1) ; m_OCtrl.SetYUnits("Volts") ; m_OCtrl.SetXUnits("Samples (Windows Timer: 100 msec)") ; m_OCtrl.SetBackgroundColor(RGB(0, 64, 0)) ; m_OCtrl.SetGridColor(RGB(192, 255, 192)) ; m_OCtrl.SetPlotColor(RGB(255, 255, 255)) ; SetTimer(101,100,NULL); m_bttWnd.Create(this); m_bttWnd.SetWidth(200); m_bttWnd.SetBkColor(RGB(213,253,224)); //RGB(210,210,255) violet m_bttWnd.SetFrameColor(RGB(0,106,53)); m_bttWnd.AddTool(GetDlgItem(IDC_EDIT1), "IDC_EDIT1"); m_bttWnd.AddTool(GetDlgItem(ID_GO), "ID_GO"); m_bttWnd.AddTool(GetDlgItem(IDC_SLIDER1), "IDC_SLIDER1"); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } #include "GfxPopupMenu.h" void CTest2Dlg::OnGo() { CGfxPopupMenu menu; CMenu tmp; tmp.LoadMenu(IDR_MENU1); menu.Attach(*tmp.GetSubMenu(0)); menu.modifyMenu(ID_MENU_1, IDB_BITMAP1); menu.modifyMenu(ID_MENU_2, IDB_BITMAP2); menu.modifyMenu(ID_MENU_3, IDB_BITMAP1); menu.setVertBitmap(IDB_VERT); CPoint pt; ::GetCursorPos(&pt); menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this); } void CTest2Dlg::OnTimer(UINT nIDEvent) { double nRandom; // generate a random number between -5 and 5 nRandom = -5.0 + 10.0*rand()/(double)RAND_MAX; // append the new value to the plot m_OCtrl.AppendPoint(nRandom); CDlgBaseClass::OnTimer(nIDEvent); } BOOL CTest2Dlg::PreTranslateMessage(MSG* pMsg) { m_bttWnd.RelayEvent(pMsg); return CDlgBaseClass::PreTranslateMessage(pMsg); }