2 u011767785 u011767785 于 2013.12.31 09:49 提问

MFC自定义消息运行第二遍时获取窗口失败

//按钮事件
void CircleDialog::OnBnClickedOk()
{

UpdateData(TRUE);
MsgParam param;
param.radius=r;
param.colorref1=color1.GetColor();
param.colorref2=color2.GetColor();
CMainFrame *pMainFrm=(CMainFrame*)AfxGetMainWnd();
CView *pView=pMainFrm->GetActiveView();
pView->SendMessage(WM_MYMSG,(WPARAM)&param,NULL);
CDialogEx::OnOK();

}
//消息响应函数
LRESULT CSimplePaintView::OnMyMessage(WPARAM wParam,LPARAM lParam){
MsgParam myParam=(MsgParam)wParam;
cr=myParam->radius;
lineColor=myParam->colorref1;
bgColor=myParam->colorref2;
m_rect.left=100;
m_rect.top=100;
m_rect.right=100+2*cr;
m_rect.bottom=100+2*cr;
m_pen.CreatePen(PS_SOLID,5,lineColor);
m_brush.CreateSolidBrush(bgColor);
UpdateData(FALSE);
Invalidate();
return 0;
}
//声明消息响应函数
protected:
afx_msg void OnFilePrintPreview();
afx_msg void OnRBut
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
afx_msg LRESULT OnMyMessage(WPARAM wParam,LPARAM lParam);
DECLARE_MESSAGE_MAP()
//消息映射

BEGIN_MESSAGE_MAP(CSimplePaintView, CView)
// 标准打印命令

ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CSimplePaintView::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_CIRCLE, &CSimplePaintView::OnCircle)
ON_COMMAND(ID_RECT, &CSimplePaintView::OnRect)
 **ON_MESSAGE(WM_MYMSG,OnMyMessage)** 

END_MESSAGE_MAP()
//定义宏
#define WM_MYMSG WM_USER+100

// 运行到第二遍时,pView下的指针(m_hWnd之类的)无法读取内存,但是点忽略后能继续运行。。

Csdn user default icon
上传中...
上传图片
插入图片