資源描述:
《實(shí)驗(yàn)五菜單、工具欄、狀態(tài)欄程序設(shè)計(jì)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫(kù)。
1、實(shí)驗(yàn)五菜單、工具欄、狀態(tài)欄程序設(shè)計(jì)【實(shí)驗(yàn)?zāi)康摹?、掌握主菜單程序設(shè)計(jì)方法2、學(xué)會(huì)工具欄程序設(shè)計(jì)3、掌握快捷菜單程序設(shè)計(jì)方法4、學(xué)會(huì)增加狀態(tài)欄窗格【實(shí)驗(yàn)內(nèi)容】1、建立一個(gè)單文檔應(yīng)用程序,添加菜單顯示,其中包含“文本”和“圖形”2個(gè)菜單項(xiàng),分別輸出文本和圖形。參考代碼:voidCSDIDispView::OnText(){//TODO:AddyourcommandhandlercodehereCClientDCdc(this);dc.TextOut(20,20,"我已經(jīng)學(xué)會(huì)了如何設(shè)計(jì)菜單程序!");}voidCSDIDispView::OnPicture(){//TODO:Addyou
2、rcommandhandlercodehereCClientDCdc(this);CBrush*BrushOld,BrushNew;BrushNew.CreateSolidBrush(RGB(255,0,0));BrushOld=dc.SelectObject(&BrushNew);//選用畫刷dc.Rectangle(50,50,250,150);dc.SelectObject(BrushOld);//還原畫刷BrushNew.DeleteObject();//釋放畫刷}2、為上述應(yīng)用程序添加菜單控制功能,選中“文本”時(shí),“圖形”菜單項(xiàng)無(wú)效;當(dāng)選中“圖形”時(shí),“文本”菜單項(xiàng)無(wú)效。
3、參考代碼:voidCSDIDispView::OnText(){//TODO:AddyourcommandhandlercodehereCClientDCdc(this);dc.TextOut(20,20,"我已經(jīng)學(xué)會(huì)了如何設(shè)計(jì)菜單程序!");m_picture=false;}voidCSDIDispView::OnPicture(){//TODO:AddyourcommandhandlercodehereCClientDCdc(this);CBrush*BrushOld,BrushNew;BrushNew.CreateSolidBrush(RGB(255,0,0));BrushO
4、ld=dc.SelectObject(&BrushNew);//選用畫刷dc.Rectangle(50,50,250,150);dc.SelectObject(BrushOld);//還原畫刷BrushNew.DeleteObject();//釋放畫刷m_text=false;}voidCSDIDispView::OnUpdateText(CCmdUI*pCmdUI){//TODO:AddyourcommandupdateUIhandlercodeherepCmdUI->Enable(m_text);}voidCSDIDispView::OnUpdatePicture(CCmdUI
5、*pCmdUI){//TODO:AddyourcommandupdateUIhandlercodeherepCmdUI->Enable(m_picture);}3、為上述應(yīng)用程序工具欄添加兩個(gè)工具按鈕,單擊第一個(gè)按鈕,在視圖窗口中彈出“打開(kāi)文件”對(duì)話框,單擊第二個(gè)按鈕,在消息框中顯示文本信息。參考代碼:voidCXiTi4_3View::OnText(){//TODO:AddyourcommandhandlercodehereMessageBox("我已經(jīng)學(xué)會(huì)了使用默認(rèn)工具欄了!");}4、創(chuàng)建一個(gè)單文檔應(yīng)用程序,在狀態(tài)欄中顯示鼠標(biāo)光標(biāo)的坐標(biāo)。(1)在MainFrm.h中將狀態(tài)欄對(duì)
6、象修改為publicpublic:CStatusBarm_wndStatusBar;(2)在MainFrm.cpp中添加狀態(tài)欄窗格ID_INDICATOR_COR(3)在串表中設(shè)置添加窗格的字符串格式(4)添加WM_MOUSEMOVE消息及其相應(yīng)函數(shù)voidCXiTi4_4View::OnMouseMove(UINTnFlags,CPointpoint){//TODO:Addyourmessagehandlercodehereand/orcalldefaultCStringstr;CMainFrame*pFrame=(CMainFrame*)AfxGetApp()->m_pMain
7、Wnd;CStatusBar*pStatus=&pFrame->m_wndStatusBar;str.Format("%d,%d",point.x,point.y);pStatus->SetPaneText(pStatus->CommandToIndex(ID_INDICATOR_COR),str);CView::OnMouseMove(nFlags,point);}1、建立一個(gè)單文檔應(yīng)用程序,添加“時(shí)間”主菜單項(xiàng),包含時(shí)、分、秒三個(gè)菜單項(xiàng),分別在視圖窗口中顯示當(dāng)前系