帮忙看看这个程序,改好的或是给出实质性建议的一定给分
我刚开始学用VC,写了一段程序,我的本意是创建一个窗口,建立自己的图标,再加进工具栏(没有菜单),然后对工具栏的消息做出响应,然后……这样一步步地下去。
现在的问题是我创建了窗口,但不知道怎么加进自己的图标;加了工具条,但在响应消息的时候就报错(现在消息响应部分已被注释掉了)
下面是程序的主要部分,恳请大家指正,谢谢!
#include <afxwin.h>
#include <afxext.h>
#include <afxdisp.h>
#include <afxdtctl.h>
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
#endif
#include "resource.h"
// 应用程序类
class CDemo1App : public CWinApp
{
public:
virtual BOOL InitInstance();
};
CDemo1App demo1app;
// 主窗口类
class CMainFrame : public CFrameWnd
{
protected:
HICON m_hIcon;
CToolBar m_wndToolBar;
CMenu m_hMenu;
public:
CMainFrame();
// afx_msg void toolbarrun();
// DECLARE_MESSAGE_MAP()
};
/*
CMainFrame::toolbarrun()
{
MessageBox("Yes, Right");
return;
}
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND(ID_RUN, toolbarrun)
END_MESSAGE_MAP()
*/
BOOL CDemo1App::InitInstance()
{
m_pMainWnd = new CMainFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CMainFrame::CMainFrame()
{
Create(NULL, "(demo)", WS_OVERLAPPEDWINDOW);
m_hIcon = demo1app.LoadIcon(IDI_ICON);
m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ;
m_wndToolBar.LoadToolBar(IDR_MAINFRAME);
}