64,546
社区成员
发帖
与我相关
我的任务
分享
#define WM_COMM_RXCHAR WM_USER+7
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
CSouthh* cs = (CSouthh*)lpParam;
HWND m_hwnd = getOsgHwnd(cs->getview());
while (m_hwnd)
{
MSG msg;
if (PeekMessage(&msg, m_hwnd, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break ;
if (msg.message == WM_COMM_RXCHAR)
{
int a = 1;
}
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return 0;
}
void main()
DWORD threadID;
HANDLE hThread;
hThread = CreateThread(NULL,0,ThreadProc,cs,0,&threadID); // 创建线程
::Sleep(1000);
string str("$000.0,0002,0.5\n");
char* a = (char*)str.data();
PostMessage(getOsgHwnd(viewer),WM_COMM_RXCHAR, (WPARAM)a, (LPARAM)5555);
viewer->setSceneData(root);
viewer->run();
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_COMM_RXCHAR:
{
//OnMmWimData(wParam,lParam);
int a = 1;
return ERROR_SUCCESS;
}
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
ding* cs = (ding*)lpParam;
while (cs->m_hwnd)
{
MSG msg;
if (PeekMessage(&msg, cs->m_hwnd, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break ;
if (msg.message == WM_COMM_RXCHAR)
{
int a = 1;
}
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return 0;
}
ding::ding()
{
da = new dddd;
m_hwnd = GetConsoleHwnd();
DWORD threadID = 0;
HANDLE hThread;
hThread = CreateThread(NULL,0,ThreadProc,this,0,&threadID); // 创建线程
}
void ding::startDll()
{
da->test(m_hwnd);
}
HWND ding::GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024
HWND hwndFound;
char pszNewWindowTitle[MY_BUFSIZE];
char pszOldWindowTitle[MY_BUFSIZE];
GetConsoleTitle((LPWSTR)pszOldWindowTitle, MY_BUFSIZE);
sprintf(pszNewWindowTitle, "%d/%d",
GetTickCount(),
GetCurrentProcessId());
SetConsoleTitle((LPCWSTR)pszNewWindowTitle);
Sleep(40);
hwndFound=FindWindowW(NULL, (LPCWSTR)pszNewWindowTitle);
SetConsoleTitle((LPCWSTR)pszOldWindowTitle);
return(hwndFound);
}
void main()
{
ding* d = new ding();
d->startDll();
char strTitle[255];
GetConsoleTitle((LPWSTR)strTitle, 255);
HWND hw = FindWindow(L"ConsoleWindowClass",(LPWSTR)strTitle);
int a =1;
Sleep(1000000);
}
Syntax C++ BOOL WINAPI PeekMessage( _Out_ LPMSG lpMsg, _In_opt_ HWND hWnd, _In_ UINT wMsgFilterMin, _In_ UINT wMsgFilterMax, _In_ UINT wRemoveMsg ); Parameters lpMsg [out] Type: LPMSG A pointer to an MSG structure that receives message information. hWnd [in, optional] Type: HWND A handle to the window whose messages are to be retrieved. The window must belong to the current thread. If hWnd is NULL, PeekMessage retrieves messages for any window that belongs to the current thread, and any messages on the current thread's message queue whose hwnd value is NULL (see the MSG structure). Therefore if hWnd is NULL, both window messages and thread messages are processed. If hWnd is -1, PeekMessage retrieves only messages on the current thread's message queue whose hwnd value is NULL, that is, thread messages as posted by PostMessage (when the hWnd parameter is NULL) or PostThreadMessage.