[VC(Visual C++) ]- 按鈕物件陣列

[VC(Visual C++) ]- 按鈕物件陣列

[VC(Visual C++) ]- 按鈕物件陣列

本篇分享按鈕物件陣列範例有興趣的(C/P)同好歡迎來http://filemarkets.com/file/jashliao/5a74a85a/索取因為我不會上傳檔案分享哈哈 ^ ^

主要程式碼

001    // computDlg.cpp : implementation file                
002    //                
003                    
004    #include "stdafx.h"                
005    #include "comput.h"                
006    #include "computDlg.h"                
007                    
008    #ifdef _DEBUG                
009    #definenew DEBUG_NEW                
010    #undef THIS_FILE                
011    staticchar THIS_FILE[] = __FILE__;                
012    #endif                
013                    
014    /////////////////////////////////////////////////////////////////////////////                
015    // CAboutDlg dialog used for App About                
016                    
017    class CAboutDlg : public CDialog                
018    {                
019    public:                
020        CAboutDlg();            
021                    
022    // Dialog Data                
023        //{{AFX_DATA(CAboutDlg)            
024        enum { IDD = IDD_ABOUTBOX };            
025        //}}AFX_DATA            
026                    
027        // ClassWizard generated virtual function overrides            
028        //{{AFX_VIRTUAL(CAboutDlg)            
029        protected:            
030        virtualvoid DoDataExchange(CDataExchange* pDX);    // DDX/DDV support            
031        //}}AFX_VIRTUAL            
032                    
033    // Implementation                
034    protected:                
035        //{{AFX_MSG(CAboutDlg)            
036        //}}AFX_MSG            
037        DECLARE_MESSAGE_MAP()            
038    };                
039                    
040    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)                
041    {                
042        //{{AFX_DATA_INIT(CAboutDlg)            
043        //}}AFX_DATA_INIT            
044    }                
045                    
046    void CAboutDlg::DoDataExchange(CDataExchange* pDX)                
047    {                
048        CDialog::DoDataExchange(pDX);            
049        //{{AFX_DATA_MAP(CAboutDlg)            
050        //}}AFX_DATA_MAP            
051    }                
052                    
053    BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)                
054        //{{AFX_MSG_MAP(CAboutDlg)            
055            // No message handlers        
056        //}}AFX_MSG_MAP            
057    END_MESSAGE_MAP()                
058                    
059    /////////////////////////////////////////////////////////////////////////////                
060    // CComputDlg dialog                
061                    
062    CComputDlg::CComputDlg(CWnd* pParent /*=NULL*/)                
063        : CDialog(CComputDlg::IDD, pParent)            
064    {                
065        //{{AFX_DATA_INIT(CComputDlg)            
066            // NOTE: the ClassWizard will add member initialization here        
067        //}}AFX_DATA_INIT            
068        // Note that LoadIcon does not require a subsequent DestroyIcon in Win32            
069        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);            
070    }                
071                    
072    void CComputDlg::DoDataExchange(CDataExchange* pDX)                
073    {                
074        CDialog::DoDataExchange(pDX);            
075        //{{AFX_DATA_MAP(CComputDlg)            
076            // NOTE: the ClassWizard will add DDX and DDV calls here        
077        //}}AFX_DATA_MAP            
078    }                
079                    
080    BEGIN_MESSAGE_MAP(CComputDlg, CDialog)                
081        //{{AFX_MSG_MAP(CComputDlg)            
082        ON_WM_SYSCOMMAND()            
083        ON_WM_PAINT()            
084        ON_WM_QUERYDRAGICON()            
085        //}}AFX_MSG_MAP            
086    END_MESSAGE_MAP()                
087                    
088    /////////////////////////////////////////////////////////////////////////////                
089    // CComputDlg message handlers                
090                    
091    BOOL CComputDlg::OnInitDialog()                
092    {                
093        CDialog::OnInitDialog();            
094                    
095        // Add "About..." menu item to system menu.            
096                    
097        // IDM_ABOUTBOX must be in the system command range.            
098        ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);            
099        ASSERT(IDM_ABOUTBOX < 0xF000);            
100                    
101        CMenu* pSysMenu = GetSystemMenu(FALSE);            
102        if (pSysMenu != NULL)            
103        {            
104            CString strAboutMenu;        
105            strAboutMenu.LoadString(IDS_ABOUTBOX);        
106            if (!strAboutMenu.IsEmpty())        
107            {        
108                pSysMenu->AppendMenu(MF_SEPARATOR);    
109                pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);    
110            }        
111        }            
112                    
113        // Set the icon for this dialog.  The framework does this automatically            
114        //  when the application's main window is not a dialog            
115        SetIcon(m_hIcon, TRUE);            // Set big icon
116        SetIcon(m_hIcon, FALSE);        // Set small icon    
117                    
118        // TODO: Add extra initialization here            
119                    
120        return TRUE;  // return TRUE  unless you set the focus to a control            
121    }                
122                    
123    void CComputDlg::OnSysCommand(UINT nID, LPARAM lParam)                
124    {                
125        if ((nID & 0xFFF0) == IDM_ABOUTBOX)            
126        {            
127            CAboutDlg dlgAbout;        
128            dlgAbout.DoModal();        
129        }            
130        else            
131        {            
132            CDialog::OnSysCommand(nID, lParam);        
133        }            
134    }                
135                    
136    // If you add a minimize button to your dialog, you will need the code below                
137    //  to draw the icon.  For MFC applications using the document/view model,                
138    //  this is automatically done for you by the framework.                
139                    
140    void CComputDlg::OnPaint()                 
141    {                
142        if (IsIconic())            
143        {            
144            CPaintDC dc(this); // device context for painting        
145                    
146            SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);        
147                    
148            // Center icon in client rectangle        
149            int cxIcon = GetSystemMetrics(SM_CXICON);        
150            int cyIcon = GetSystemMetrics(SM_CYICON);        
151            CRect rect;        
152            GetClientRect(&rect);        
153            int x = (rect.Width() - cxIcon + 1) / 2;        
154            int y = (rect.Height() - cyIcon + 1) / 2;        
155                    
156            // Draw the icon        
157            dc.DrawIcon(x, y, m_hIcon);        
158        }            
159        else            
160        {            
161            CDialog::OnPaint();        
162        }            
163    }                
164                    
165    // The system calls this to obtain the cursor to display while the user drags                
166    //  the minimized window.                
167    HCURSOR CComputDlg::OnQueryDragIcon()                
168    {                
169        return (HCURSOR) m_hIcon;            
170    }                
171                    
172    BOOL CComputDlg::OnCommand(WPARAM wParam, LPARAM lParam)                 
173    {                
174        // TODO: Add your specialized code here and/or call the base class            
175        switch(wParam)            
176        {            
177        case IDC_1:            
178            MessageBox("test1");        
179            break;        
180        case IDC_2:            
181            MessageBox("test2");        
182            break;        
183                    
184        }            
185        return CDialog::OnCommand(wParam, lParam);            
186    }                

 

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *