📄 buttonsview.cpp
字号:
// buttonsView.cpp : implementation of the CButtonsView class
//
#include "stdafx.h"
#include "buttons.h"
#include "odcombo.h"
#include "selfmenu.h"
#include "buttonsDoc.h"
#include "buttonsView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CButtonsView
IMPLEMENT_DYNCREATE(CButtonsView, CFormView)
BEGIN_MESSAGE_MAP(CButtonsView, CFormView)
//{{AFX_MSG_MAP(CButtonsView)
ON_BN_CLICKED(IDC_STDBTN, OnStdbtn)
ON_COMMAND(ID_SELFDRAW, OnSelfdraw)
ON_COMMAND(ID_BITMAP, OnBitmap)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CButtonsView construction/destruction
CButtonsView::CButtonsView()
: CFormView(CButtonsView::IDD)
{
//{{AFX_DATA_INIT(CButtonsView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CButtonsView::~CButtonsView()
{
}
void CButtonsView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CButtonsView)
DDX_Control(pDX, IDC_ODCOMBO, m_odcombo);
DDX_Control(pDX, IDC_STDBTN, m_stdbtn);
//}}AFX_DATA_MAP
}
BOOL CButtonsView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CButtonsView diagnostics
#ifdef _DEBUG
void CButtonsView::AssertValid() const
{
CFormView::AssertValid();
}
void CButtonsView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CButtonsDoc* CButtonsView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CButtonsDoc)));
return (CButtonsDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CButtonsView message handlers
// Here's where all the work takes place
void CButtonsView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// load bitmap for button (if not already done)
if (bm.m_hObject==NULL)
bm.LoadBitmap(IDB_BOMB);
// Set standard bitmap button
m_stdbtn.SetBitmap(bm);
// Auto load MFC bitmap button
if (m_MFCBtn.m_hWnd==NULL)
m_MFCBtn.AutoLoad(IDC_MFCBTN,this);
// Real owner/self draw button attach (could have used DDX)
if (m_odbtn.m_hWnd==NULL)
m_odbtn.SubclassDlgItem(IDC_ODBTN,this);
// Owner/self draw static attach (could have used DDX)
if (m_odstatic.m_hWnd==NULL)
m_odstatic.SubclassDlgItem(IDC_ODSTATIC,this);
// Set style to OWNERDRAW
SetWindowLong(m_odstatic.m_hWnd,GWL_STYLE,
m_odstatic.GetStyle()|SS_OWNERDRAW);
// Used DDX to attach combo box; could have used SubclassDlgItem instead
// Since the box already exists, we have to compute the item height
// and set it now so we will...
MEASUREITEMSTRUCT mis;
m_odcombo.MeasureItem(&mis);
m_odcombo.SetItemHeight(0,mis.itemHeight);
// Add some items, the strings don't really matter as we use the
// item data in this case
m_odcombo.ResetContent();
int n=m_odcombo.AddString("0");
m_odcombo.SetItemData(n,0);
n=m_odcombo.AddString("1");
m_odcombo.SetItemData(n,1);
// Now for a menu
CMenu *mainmenu=AfxGetApp()->m_pMainWnd->GetMenu(); // Get main menu
CMenu *tempmenu=mainmenu->GetSubMenu(1); // find our sub menu
m_selfMenu.Attach(tempmenu->m_hMenu); // attach it to special class
// set owner draw flag
m_selfMenu.ModifyMenu(ID_SELFDRAW,MF_BYCOMMAND|MF_OWNERDRAW,
ID_SELFDRAW,(char *)1);
// Standard bitmap Menu
tempmenu=mainmenu->GetSubMenu(2);
tempmenu->ModifyMenu(ID_BITMAP,MF_BYCOMMAND|MFT_BITMAP,
ID_BITMAP,(char *)bm.m_hObject);
}
void CButtonsView::OnStdbtn()
{
m_MFCBtn.EnableWindow(!m_MFCBtn.IsWindowEnabled());
}
void CButtonsView::OnSelfdraw()
{
MessageBox("Unimplemented");
}
void CButtonsView::OnBitmap()
{
MessageBox("Unimplemented");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -