发送和将消息从一个类发送到另一堂课的问题.MFC程序
Problems with sending and getting messages from one class to another class. MFC program
这是我的代码:当我单击鼠标的左键并发送TE消息时,此功能是调用的:
#define WM_MYMESSAGE WM_USER+7
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
counter=0;
CWnd::OnLButtonDown(nFlags, point);
CRect wdRect;
GetClientRect(&wdRect);
HWND hwnd;
hwnd=::FindWindow(NULL,"Client");
if(wdRect.PtInRect(point))
{
counter++;
PostMessage(WM_MYMESSAGE,point.x,point.y);
}
}
在另一个文件mainfraim.cpp中,借助on_message(wm_mymessage,onnamemsg),我将消息发送到onnamemsg函数。此功能打开BMP文件。问题在于函数OnnameMSG对消息没有响应,并且此功能不起作用。我该怎么做才能使此函数在此消息中响应。你能帮我解决这个问题吗?这是代码。
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_MESSAGE(WM_MYMESSAGE, OnNameMsg)
ON_COMMAND(ID_EDIT_LINE, OnEditLine)
END_MESSAGE_MAP()
afx_msg LRESULT CMainFrame::OnNameMsg(WPARAM wParam,LPARAM IParam)
{
MSG msg;
char FileName[500];
char FileTitle[100];
FileName[0]=' ';
GetMessage(&msg,NULL,WM_MOUSEFIRST,0);
CFileDialog file(TRUE);
file.m_ofn.lpstrFilter=TEXT("Bitmap picture files *.bmp *.bmp All Files *.* *.* ");
file.m_ofn.lpstrFileTitle=FileTitle;
file.m_ofn.lpstrFile=FileName;
file.m_ofn.lpstrTitle="Open BMP File";
file.DoModal();
//if (FileName[0]==' ')return;
SetWindowText(FileTitle);
HANDLE hdibCurrent1 = OpenDIB(FileName);
hbm=0;
hbm=BitmapFromDib(hdibCurrent1,0);
GetObject(hbm,sizeof(BITMAP),(LPSTR)&bm);
CRect wdRect;
GetClientRect(&wdRect);
ClientToScreen(&wdRect);
int j=wdRect.Height();
int i=wdRect.Width();
//SetWindowPos(NULL,wdRect.left,wdRect.top, i,j,NULL);
if(hbm) { CClientDC dc(this);
HDC hdc=::GetDC(m_hWnd);
HDC hdcBits=::CreateCompatibleDC(hdc);
SelectObject(hdcBits,hbm);
//CRect wdRect;
GetClientRect(&wdRect);
CBrush brush;
brush.CreateSolidBrush(RGB(0,0,0));
dc.FillRect(&wdRect,&brush);
BitBlt(hdc, 0, 0, bm.bmWidth,bm.bmHeight,hdcBits,0,0, SRCCOPY);
DeleteDC(hdcBits);
::ReleaseDC(m_hWnd,hdc);
}
return 1;
}
您将消息发送给CChildView
,而不是将消息发送到CMainFrame
。由于您想将消息发送到主框架并在此处处理,因此必须将(PostMessage
)发送到主帧的窗口句柄。
您正在调用的PostMessage
是方法来自CWnd
,该方法与::PostMessage
API不同,因此将其发送到this
。您需要CMainFrame
的指针,然后致电该指针。假设您将主帧的指针纳入pMainFrame
,然后可以致电:
pMainFrame->PostMessage(WM_MYMESSAGE,point.x,point.y);
相关文章:
- 在 1 个服务器 n 客户端套接字 C++ MFC 应用程序中更新数据的客户端
- 如何在 MFC 应用程序中启动 ZeroMQ 线程?
- 视窗 10 :笔(手写笔)在 MFC 应用程序上不起作用
- 从 MFC C++ 6.0 应用程序迁移到 VS 2005
- C++ - 从 MFC 应用程序启动记事本,并将其默认标题从 "Untitled - Notepad" 更改为其他内容
- 由于选项卡顺序的原因,鼠标光标总是得到错误的hwnd-MFC应用程序
- 在网格视图中显示数据 - 基于 MFC c++ 对话框的应用程序
- MFC功能区主页按钮双击关闭应用程序
- 使用参数 + stdout + stderr 从命令行调用 MFC 应用程序
- 在 MFC 应用程序中实现 IServiceProvider
- 如何在MFC对话框应用程序中默认将复选框设置为选中?
- 基于 MFC 对话框的应用程序无法调用对话框两次
- 将数组/对象/结构列表从C#库中传递给C MFC应用程序
- 无论如何,是否可以确定MFC应用程序是通过PC重新启动或用户单击应用程序快捷方式开始的
- 如何在MFC多字节应用程序中显示西里尔文本?
- 如何仅从另一个 MFC 应用程序打开 MFC 应用程序
- 如何将子窗口(MFC 应用程序)的工作区保存到图像
- 儿童对话框 - setWindowTexta或sendmessagea崩溃程序-MFC
- 使用SDI应用程序(MFC)从文本文件读取数据并显示数据
- visual studio 2010 -查找dll在c++程序(MFC)中的加载位置