// .h
#pragma once
#include "afxwin.h"const UINT IDD_LIST = 0x400006; // 问题一:它该如何定义?在哪定义比较好呢?
// CMainFrame frameclass CMainFrame : public CFrameWnd
{
DECLARE_DYNCREATE(CMainFrame)
//protected:
public:
CMainFrame(); // protected constructor used by dynamic creation
virtual ~CMainFrame();protected:
DECLARE_MESSAGE_MAP()
private:
CDC *m_pDC;
CBitmap *m_pBmp;
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
private:
CListBox *m_pListbox;
public:
afx_msg void OnPaint();
afx_msg void OnClkList();
};// .cpp
// MainFrame.cpp : implementation file
//#include "stdafx.h"
#include "MainFrame.h"// CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)CMainFrame::CMainFrame()
: m_pDC(NULL)
, m_pBmp(NULL)
, m_pListbox(NULL)
{
Create(NULL, L"Raster"); CPaintDC dc(this);
m_pDC = new CDC;
m_pDC->CreateCompatibleDC(&dc); m_pBmp = new CBitmap;
m_pBmp->m_hObject = (HBITMAP)::LoadImage(
NULL,
L"black.bmp",
IMAGE_BITMAP,
21,
21,
LR_LOADFROMFILE
); m_pDC->SelectObject(m_pBmp->m_hObject);
}CMainFrame::~CMainFrame()
{
if (m_pDC)
{
delete m_pDC;
}
if (m_pBmp)
{
delete m_pBmp;
}
}
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_LBN_SELCHANGE(IDD_LIST, OnClkList) // 问题二:这种定义会不会有问题?
END_MESSAGE_MAP()
// CMainFrame message handlersint CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1; // TODO: Add your specialized creation code here m_pListbox = new CListBox;
m_pListbox->CreateEx( // 问题三:CreateEx要如何才能让它具备ON_LBN_SELCHANGE功能?
WS_EX_CLIENTEDGE,
L"ListBox",
NULL,
WS_VISIBLE|WS_CHILD,
CRect(10,50,180,300),
this,
IDD_LIST
); CString item[] =
{
L"BLACKNESS", L"DSTINVERT", L"MERGECOPY",
L"MERGEPAINT", L"NOTSRCCOPY", L"NOTSRCERASE",
L"PATCOPY", L"PATINVERT", L"PATPAINT",
L"SRCAND", L"SRCCOPY", L"SRCERASE",
L"SRCINVERT", L"SRCPAINT", L"WHITENESS"
}; DWORD raster[] =
{
BLACKNESS, DSTINVERT, MERGECOPY,
MERGEPAINT, NOTSRCCOPY, NOTSRCERASE,
PATCOPY, PATINVERT, PATPAINT,
SRCAND, SRCCOPY, SRCERASE,
SRCINVERT, SRCPAINT, WHITENESS
}; int index = 0;
for (int i=0; i<15; i++)
{
index = m_pListbox->AddString(item[i]);
m_pListbox->SetItemData(index, raster[i]);
} m_pListbox->SelectString(0, L"SRCCOPY"); return 0;
}void CMainFrame::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CFrameWnd::OnPaint() for painting messages
dc.TextOut(10, 10, L"Raster 运算值:");
dc.TextOut(210, 10, L"来源位图:");
dc.TextOut(210, 173, L"经济Raster 运算后的位图:"); int index = m_pListbox->GetCurSel();
DWORD raster = m_pListbox->GetItemData(index);
dc.BitBlt(210, 50, 21, 21, m_pDC, 0, 0, SRCCOPY);
dc.BitBlt(210, 213, 21, 21, m_pDC, 0, 0, raster);
}void CMainFrame::OnClkList() // 问题四:实测选择不同的list项,根本不能执行.但不知为什么?
{
MessageBox( L"哈!你单击了动态按钮。" );
}
#pragma once
#include "afxwin.h"const UINT IDD_LIST = 0x400006; // 问题一:它该如何定义?在哪定义比较好呢?
// CMainFrame frameclass CMainFrame : public CFrameWnd
{
DECLARE_DYNCREATE(CMainFrame)
//protected:
public:
CMainFrame(); // protected constructor used by dynamic creation
virtual ~CMainFrame();protected:
DECLARE_MESSAGE_MAP()
private:
CDC *m_pDC;
CBitmap *m_pBmp;
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
private:
CListBox *m_pListbox;
public:
afx_msg void OnPaint();
afx_msg void OnClkList();
};// .cpp
// MainFrame.cpp : implementation file
//#include "stdafx.h"
#include "MainFrame.h"// CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)CMainFrame::CMainFrame()
: m_pDC(NULL)
, m_pBmp(NULL)
, m_pListbox(NULL)
{
Create(NULL, L"Raster"); CPaintDC dc(this);
m_pDC = new CDC;
m_pDC->CreateCompatibleDC(&dc); m_pBmp = new CBitmap;
m_pBmp->m_hObject = (HBITMAP)::LoadImage(
NULL,
L"black.bmp",
IMAGE_BITMAP,
21,
21,
LR_LOADFROMFILE
); m_pDC->SelectObject(m_pBmp->m_hObject);
}CMainFrame::~CMainFrame()
{
if (m_pDC)
{
delete m_pDC;
}
if (m_pBmp)
{
delete m_pBmp;
}
}
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_LBN_SELCHANGE(IDD_LIST, OnClkList) // 问题二:这种定义会不会有问题?
END_MESSAGE_MAP()
// CMainFrame message handlersint CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1; // TODO: Add your specialized creation code here m_pListbox = new CListBox;
m_pListbox->CreateEx( // 问题三:CreateEx要如何才能让它具备ON_LBN_SELCHANGE功能?
WS_EX_CLIENTEDGE,
L"ListBox",
NULL,
WS_VISIBLE|WS_CHILD,
CRect(10,50,180,300),
this,
IDD_LIST
); CString item[] =
{
L"BLACKNESS", L"DSTINVERT", L"MERGECOPY",
L"MERGEPAINT", L"NOTSRCCOPY", L"NOTSRCERASE",
L"PATCOPY", L"PATINVERT", L"PATPAINT",
L"SRCAND", L"SRCCOPY", L"SRCERASE",
L"SRCINVERT", L"SRCPAINT", L"WHITENESS"
}; DWORD raster[] =
{
BLACKNESS, DSTINVERT, MERGECOPY,
MERGEPAINT, NOTSRCCOPY, NOTSRCERASE,
PATCOPY, PATINVERT, PATPAINT,
SRCAND, SRCCOPY, SRCERASE,
SRCINVERT, SRCPAINT, WHITENESS
}; int index = 0;
for (int i=0; i<15; i++)
{
index = m_pListbox->AddString(item[i]);
m_pListbox->SetItemData(index, raster[i]);
} m_pListbox->SelectString(0, L"SRCCOPY"); return 0;
}void CMainFrame::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CFrameWnd::OnPaint() for painting messages
dc.TextOut(10, 10, L"Raster 运算值:");
dc.TextOut(210, 10, L"来源位图:");
dc.TextOut(210, 173, L"经济Raster 运算后的位图:"); int index = m_pListbox->GetCurSel();
DWORD raster = m_pListbox->GetItemData(index);
dc.BitBlt(210, 50, 21, 21, m_pDC, 0, 0, SRCCOPY);
dc.BitBlt(210, 213, 21, 21, m_pDC, 0, 0, raster);
}void CMainFrame::OnClkList() // 问题四:实测选择不同的list项,根本不能执行.但不知为什么?
{
MessageBox( L"哈!你单击了动态按钮。" );
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货