首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

新人 关于MFC 中SDI弹出的对话框 获取VIEW指针的有关问题

2012-09-14 
新人求助 关于MFC 中SDI弹出的对话框 获取VIEW指针的问题做这个程序的目的是:通过点击菜单的myyouku弹出对

新人求助 关于MFC 中SDI弹出的对话框 获取VIEW指针的问题
做这个程序的目的是:通过点击菜单的myyouku弹出对话框 在弹出的对话框中可以输入颜色的数值(为了简单我只弄了红色 其他都是0)最后点一下TRY 可以再单文档的客户区中改变我输入的颜色.但是现在的问题是我一点击就无法运行.

C/C++ code
// 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_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CYoukuViewmytry 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 _DEBUGvoid 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键发送一个消息
C/C++ code
void mytry::OnButton1() {    // TODO: Add your control notification handler code here    SendMessage(MY_MESSAGE);}
我在我新建的类中已经定义好了我的自定义消息 .
是不是只能在OnDraw函数中绘图?
我是刚学的啊,求各位高中指点.轻砸..

[解决办法]
粗略了看了下

MY_MESSAGE消息编号是什么
ON_COMMAND(ID_MENUITEM32771, Onyouku) 应该用ON_MESSAGE,MENUITEM32771消息编号要对应上

Onyouku函数的返回值LRESULT 带两个入参LPARAM WPARAM

热点排行