DLL中能有自己的消息循环结构吗?

tempblack 2012-07-24 09:07:52

DLL中能有自己的消息循环结构吗?
如果可以的话,加上调用程序的消息循环结构,整个程序就有两套消息循环结构了?那消息处理会不会混乱了?
...全文
552 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sivenyu 2012-08-23
  • 打赏
  • 举报
回复
跑是跑起来的,但因为用HWND_MESSAGE,受Message-Only Windows限制,改用正常方式创建窗口后我自己问题解决了,参考帖子:
http://topic.csdn.net/t/20030106/17/1332183.html

附:
Message-Only Windows
A message-only window enables you to send and receive messages. It is not visible, has no Z order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.

To create a message-only window, specify the HWND_MESSAGE constant or a handle to an existing message-only window in the hWndParent parameter of the CreateWindowEx function. You can also change an existing window to a message-only window by specifying HWND_MESSAGE in the hWndNewParent parameter of the SetParent function.

titer1 2012-08-23
  • 打赏
  • 举报
回复
上面代码有说服力 但是还不能跑起来,是不是
titer1 2012-08-23
  • 打赏
  • 举报
回复
上面代码有说服力 但是还不能跑起来,是不是
sivenyu 2012-08-22
  • 打赏
  • 举报
回复
下面代码,已经在DLL入口new一个线程,然后new窗口以及消息循环,但从TRACE看,MessageOnlyWinProc消息处理函数,只能响应开始几个消息, 后面就是在GetMessage死掉了!

LRESULT CALLBACK MessageOnlyWinProc(HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
TRACE(TEXT("MessageOnlyWinProc msg(%d)\n"), uMsg);

switch(uMsg)
{
case WM_MY_MSG:
TRACE(TEXT("WM_MY_MSG\n"));
break;

case WM_CLOSE:
glbExit = true;
TRACE(TEXT("WM_CLOSE\n"));
DestroyWindow(hwnd);
break;

case WM_DESTROY:
glbExit = true;
TRACE(TEXT("WM_CLOSE\n"));
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}

return 0;
}

BOOL InitMessageOnlyWindow()
{
HINSTANCE hInstance = NULL;
hInstance = GetModuleHandle(NULL);

if (hInstance == NULL)
{
return FALSE;
}

WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=MessageOnlyWinProc;
wndcls.lpszClassName=TEXT("Message-Only Window");
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);


m_hwnd = CreateWindowEx(0,
TEXT("Message-Only Window"),
TEXT("Message-Only Window"),
0,0,0,
0,0,
HWND_MESSAGE,
0,
hInstance,
0);
if (m_hwnd == NULL)
{
TRACE(TEXT("CreateWindowEx failed!\n"));
return FALSE;
}


MSG msg = {0};
while (::GetMessage(&msg,m_hwnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}


return TRUE;
}


DWORD WINAPI DllThreed(LPVOID lpParameter)
{
InitMessageOnlyWindow();
return 0;
}




BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
ghModule = hModule;
static HANDLE hThreed = NULL;
if(!hThreed)
hThreed = ::CreateThread(NULL, 0, DllThreed, NULL, 0, NULL);
}
break;
}

return TRUE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif
sivenyu 2012-08-22
  • 打赏
  • 举报
回复
同问,认为可以的给个代码好不!
shremie 2012-08-21
  • 打赏
  • 举报
回复
可以有的。
Dobzhansky 2012-07-26
  • 打赏
  • 举报
回复


如果这两个消息循环没有很严重的相互依赖, 为什么不这样做.

消息循环放到自己的线程里头.

消息循环边界不是 DLL, 而是线程.
tempblack 2012-07-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

只有dll的界面取得焦点才进入dll的消息循环结构
[/Quote]

我只是为了利用CFrameWnd的消息循环结构,才继承的它。别的没用到。所以没有界面。
csucdl 2012-07-24
  • 打赏
  • 举报
回复
这要是同一个线程中的话, 只会有一个消息循环起作用, 消息循环是阻塞的
淡定的飘着 2012-07-24
  • 打赏
  • 举报
回复
只有dll的界面取得焦点才进入dll的消息循环结构

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧