做这个程序的目的是:通过点击菜单的myyouku弹出对话框 在弹出的对话框中可以输入颜色的数值(为了简单我只弄了红色 其他都是0)最后点一下TRY 可以再单文档的客户区中改变我输入的颜色.但是现在的问题是我一点击就无法运行.
// youkuView.cpp : implementation of the CYoukuView class
//#include "stdafx.h"#include "mytry.h"
#include "youkuDoc.h"
#include "youkuView.h"
#include "youku.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CYoukuView
mytry dig;
IMPLEMENT_DYNCREATE(CYoukuView, CView)BEGIN_MESSAGE_MAP(CYoukuView, CView)
//{{AFX_MSG_MAP(CYoukuView)
ON_COMMAND(ID_MENUITEM32771, Onyouku)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CYoukuView construction/destructionCYoukuView::CYoukuView()
{
// TODO: add construction code here}CYoukuView::~CYoukuView()
{
}BOOL CYoukuView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CYoukuView drawingvoid CYoukuView::OnDraw(CDC* pDC)
{
CYoukuDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here/* CBrush brush;
brush.CreateSolidBrush(RGB(dig.m_try,0,0));
pDC->SelectObject(brush);
CRect rect;
GetClientRect(&rect);
pDC->Rectangle(&rect);*/}/////////////////////////////////////////////////////////////////////////////
// CYoukuView printingBOOL CYoukuView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CYoukuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CYoukuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CYoukuView diagnostics#ifdef _DEBUG
void CYoukuView::AssertValid() const
{
CView::AssertValid();
}void CYoukuView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CYoukuDoc* CYoukuView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CYoukuDoc)));
return (CYoukuDoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CYoukuView message handlersvoid CYoukuView::Onyouku() 
{
// TODO: Add your command handler code here dig.DoModal();
Invalidate();
}
void mytry::onchange()
{
CFrameWnd* pmain = (CFrameWnd*)AfxGetApp()->m_pActiveWnd;//获得视图类指针
CYoukuView *pdc = (CYoukuView *)pmain->GetActiveView();
CBrush brush;
CClientDC dc(pdc);
brush.CreateSolidBrush(RGB(dig.m_try,0,0));
dc.SelectObject(brush);
CRect rect;
GetClientRect(&rect);
dc.Rectangle(&rect);
}我是想通过消息函数通过按一下TRY键发送一个消息void mytry::OnButton1() 
{
// TODO: Add your control notification handler code here
SendMessage(MY_MESSAGE);
}
我在我新建的类中已经定义好了我的自定义消息 .
是不是只能在OnDraw函数中绘图?
我是刚学的啊,求各位高中指点.轻砸..

解决方案 »

  1.   

    粗略了看了下MY_MESSAGE消息编号是什么
    ON_COMMAND(ID_MENUITEM32771, Onyouku) 应该用ON_MESSAGE,MENUITEM32771消息编号要对应上Onyouku函数的返回值LRESULT 带两个入参LPARAM WPARAM
      

  2.   

    谢谢您的回复,但是好像不是那里错了 我那个ON_COMMAND的功能是单文档菜单弹出对话框的 ,您说的那个我在后面有声明的BEGIN_MESSAGE_MAP(mytry, CDialog)
    //{{AFX_MSG_MAP(mytry)
    ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
    ON_MESSAGE(MY_MESSAGE,onchange)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
      

  3.   

    谢谢您的回复,但是好像不是那里错了 我那个ON_COMMAND的功能是单文档菜单弹出对话框的 ,您说的那个我在后面有声明的
    BEGIN_MESSAGE_MAP(mytry, CDialog)
        //{{AFX_MSG_MAP(mytry)
        ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
        ON_MESSAGE(MY_MESSAGE,onchange)
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()