为对话框添加工具栏_第1页
为对话框添加工具栏_第2页
为对话框添加工具栏_第3页
为对话框添加工具栏_第4页
为对话框添加工具栏_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、/ DlgUIDlg.h : header file/#if !defined(AFX_DLGUIDLG_H_9DA02C7E_F6AD_4DF5_9B66_FADFD42E8A00_INCLUDED_)#define AFX_DLGUIDLG_H_9DA02C7E_F6AD_4DF5_9B66_FADFD42E8A00_INCLUDED_#if _MSC_VER > 1000#pragma once#endif / _MSC_VER > 1000/ CDlgUIDlg dialogclass CDlgUIDlg : public CDialog/ Constructionpubl

2、ic:    CToolBar m_wndToolBar;    BOOL m_bMenu1;    CDlgUIDlg(CWnd* pParent = NULL);    / standard constructor/ Dialog Data    /AFX_DATA(CDlgUIDlg)    enum IDD = IDD_DLGUI_DIALOG ;&

3、#160;       / NOTE: the ClassWizard will add data members here    /AFX_DATA    / ClassWizard generated virtual function overrides    /AFX_VIRTUAL(CDlgUIDlg)    public:   

4、 virtual BOOL PreTranslateMessage(MSG* pMsg);    protected:    virtual void DoDataExchange(CDataExchange* pDX);    / DDX/DDV support    /AFX_VIRTUAL/ Implementationprotected:    HICON m_hIcon;

5、60;   / Generated message map functions    /AFX_MSG(CDlgUIDlg)    virtual BOOL OnInitDialog();    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);    afx_msg void OnPaint();    afx_m

6、sg HCURSOR OnQueryDragIcon();    afx_msg void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);    afx_msg void OnDlgMenu1();    afx_msg void OnUpdateDlgMenu1(CCmdUI* pCmdUI);    afx_msg void OnMenu1Sub1(); &

7、#160;  afx_msg void OnUpdateMenu1Sub1(CCmdUI* pCmdUI);    afx_msg void OnUpdateTbutton1(CCmdUI* pCmdUI);    /AFX_MSG    DECLARE_MESSAGE_MAP();/AFX_INSERT_LOCATION/ Microsoft Visual C+ will insert additional declarations immediatel

8、y before the previous line.#endif / !defined(AFX_DLGUIDLG_H_9DA02C7E_F6AD_4DF5_9B66_FADFD42E8A00_INCLUDED_)/ DlgUIDlg.cpp : implementation file/#include "stdafx.h"#include "DlgUI.h"#include "DlgUIDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_F

9、ILE = _FILE_;#endif/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic:    CAboutDlg();/ Dialog Data    /AFX_DATA(CAboutDlg)    enum IDD = IDD_ABOUTBOX ;    /AFX_DATA    / Clas

10、sWizard generated virtual function overrides    /AFX_VIRTUAL(CAboutDlg)    protected:    virtual void DoDataExchange(CDataExchange* pDX);    / DDX/DDV support    /AFX_VIRTUAL/ Implementationprotected:

11、    /AFX_MSG(CAboutDlg)    /AFX_MSG    DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD)    /AFX_DATA_INIT(CAboutDlg)    /AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* p

12、DX)    CDialog:DoDataExchange(pDX);    /AFX_DATA_MAP(CAboutDlg)    /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog)    /AFX_MSG_MAP(CAboutDlg)        / No message handlers &

13、#160;  /AFX_MSG_MAPEND_MESSAGE_MAP()/ CDlgUIDlg dialogCDlgUIDlg:CDlgUIDlg(CWnd* pParent /*=NULL*/)    : CDialog(CDlgUIDlg:IDD, pParent)    /AFX_DATA_INIT(CDlgUIDlg)        / NOTE: the ClassWizard will add membe

14、r initialization here    /AFX_DATA_INIT    / Note that LoadIcon does not require a subsequent DestroyIcon in Win32    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);    m_bMenu1 = TRUE;void CDlgUIDlg:DoDataExchange(CD

15、ataExchange* pDX)    CDialog:DoDataExchange(pDX);    /AFX_DATA_MAP(CDlgUIDlg)        / NOTE: the ClassWizard will add DDX and DDV calls here    /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CDlgUIDlg, CDialog) 

16、   /AFX_MSG_MAP(CDlgUIDlg)    ON_WM_SYSCOMMAND()    ON_WM_PAINT()    ON_WM_QUERYDRAGICON()    ON_WM_MENUSELECT()    ON_COMMAND(IDM_MENU1_SUB1, OnMenu1Sub1)    ON_UPD

17、ATE_COMMAND_UI(IDM_MENU1_SUB1, OnUpdateMenu1Sub1)    ON_UPDATE_COMMAND_UI(ID_TBUTTON1, OnUpdateTbutton1)    /AFX_MSG_MAPEND_MESSAGE_MAP()/ CDlgUIDlg message handlersBOOL CDlgUIDlg:OnInitDialog()    CDialog:OnInitDialog();   &

18、#160;/ Add "About." menu item to system menu.    / IDM_ABOUTBOX must be in the system command range.    ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);    ASSERT(IDM_ABOUTBOX < 0xF000);    CMenu* pSysMenu

19、 = GetSystemMenu(FALSE);    if (pSysMenu != NULL)            CString strAboutMenu;        strAboutMenu.LoadString(IDS_ABOUTBOX);        if (

20、!strAboutMenu.IsEmpty()                    pSysMenu->AppendMenu(MF_SEPARATOR);            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX

21、, strAboutMenu);                / Set the icon for this dialog.  The framework does this automatically    /  when the application's main window is not a dialog   

22、; SetIcon(m_hIcon, TRUE);            / Set big icon    SetIcon(m_hIcon, FALSE);        / Set small icon        / TODO: Add extra initia

23、lization here    if( !m_wndToolBar.CreateEx( this,TBSTYLE_FLAT,WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER,CRect( 4,4,0,0 ) ) |        !m_wndToolBar.LoadToolBar( IDR_TOOLBAR1 ) )         MessageBo

24、x( _T("Can not create ToolBar!"),_T("Error"),MB_ICONWARNING | MB_OK );        return FALSE;        m_wndToolBar.ShowWindow( SW_SHOW );    RepositionBars( AFX_IDW_CONTROLBAR_FIRST,A

25、FX_IDW_CONTROLBAR_LAST,0 );    return TRUE;  / return TRUE  unless you set the focus to a controlvoid CDlgUIDlg:OnSysCommand(UINT nID, LPARAM lParam)    if (nID & 0xFFF0) = IDM_ABOUTBOX)        &#

26、160;   CAboutDlg dlgAbout;        dlgAbout.DoModal();        else            CDialog:OnSysCommand(nID, lParam);    / If you a

27、dd a minimize button to your dialog, you will need the code below/  to draw the icon.  For MFC applications using the document/view model,/  this is automatically done for you by the framework.void CDlgUIDlg:OnPaint()     if (IsIconic()  &#

28、160;         CPaintDC dc(this); / device context for painting        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);        / Center icon in client rectangle 

29、;       int cxIcon = GetSystemMetrics(SM_CXICON);        int cyIcon = GetSystemMetrics(SM_CYICON);        CRect rect;        GetClientRect(&r

30、ect);        int x = (rect.Width() - cxIcon + 1) / 2;        int y = (rect.Height() - cyIcon + 1) / 2;        / Draw the icon        dc.Draw

31、Icon(x, y, m_hIcon);        else            CDialog:OnPaint();    / The system calls this to obtain the cursor to display while the user drags/  the minimized window.HCUR

32、SOR CDlgUIDlg:OnQueryDragIcon()    return (HCURSOR) m_hIcon;void CDlgUIDlg:OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)     /CDialog:OnMenuSelect(nItemID, nFlags, hSysMenu);    CCmdUI cmdUI;    UINT nCount,i;&

33、#160;   CMenu *pMainMenu = NULL;    CMenu *pSubMenu = NULL;    if( hSysMenu = NULL | !( nFlags & MF_POPUP ) ) return;    pMainMenu = CMenu:FromHandle( hSysMenu );    pSubMenu = pMainMenu->GetSubMenu

34、( nItemID );    if( IsMenu( pSubMenu->GetSafeHmenu() ) )         cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();        for( i = 0; i < cmdUI.m_nIndexMax; i+ )      

35、;       cmdUI.m_nIndex = i;            cmdUI.m_nID = pSubMenu->GetMenuItemID( i );            if( cmdUI.m_nID = ( UINT )-1 | cmdUI.m_nID = 0 )

36、 continue;            cmdUI.m_pMenu = pSubMenu;            cmdUI.DoUpdate( this,FALSE );            nCount = pSubMenu-&g

37、t;GetMenuItemCount();            if( nCount < cmdUI.m_nIndexMax )                 cmdUI.m_nIndex -= ( cmdUI.m_nIndexMax - nCount );    &#

38、160;           while( cmdUI.m_nIndex < nCount && pSubMenu->GetMenuItemID( cmdUI.m_nIndex ) = cmdUI.m_nID )                     cmdUI.m_nIndex +;                                        cmdUI.m_n

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论