Hello,
Here is some code that may be of help … It may need a small amount of
tweaking since i deleted and added some blocks of code without
compilation, so please take it with a pinch of salt. It should help form
a basis for what you need to do.
#define hidden_win “hidden”
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_CREATE :
return 0;
case WM_DESTROY :
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
DWORD _RegisterHiddenWindowClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 16;
wndclass.cbWndExtra = 16;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = hidden_win;
if (RegisterClass (&wndclass) == 0)
return FALSE;
return TRUE;
}
DWORD WINAPI _Worker(PVOID pData)
{
MSG msg;
HWND hWnd;
// Create tool window with no caption so that it does not show
up in the task mgr or in the task bar
hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, hidden_win, NULL,
WS_POPUP,
0, 0, 0, 0, NULL,
NULL, GetModuleHandle(NULL), NULL);
if (hWnd == NULL)
ExitThread(0);
// Pass the hWnd back to the creator
(HWND *)*pData = hWnd;
// Go into a message loop …
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return 0;
}
// You could use the functions like so …
// Some other thread …
{
DWORD hThread, dwThreadId;
HWND hHiddenWindow;
_RegisterHiddenWindowClass(GetModuleHandle(NULL));
hThread = CreateThread(NULL, 0, _Worker, &hHiddenWindow, 0,
&dwThreadId);
if (hThread == NULL)
HANDLEREG(&rCode, ERR_INVALID_INIT);
// Want to close the window
if (hHiddenWindow != NULL)
SendMessage(hHiddenWindow, WM_QUIT, 0, 0);
// Continue …
}
Regards
-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Tuesday, July 31, 2001 11:50 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Handling PnP WM_DEVICECHANGE messages from a DLL
to register for PnP notification we need to supply a window handle or a
service handle, neither
of which weI have. My questions are:
Can our DLL create a thread, which creates a window to handle the
WD_DEVICECHANGE
Creating hidden windows is simple For instance, COM uses ones.
Since window is owned by the thread which must process its message loop,
creating a thread seems to be a good idea too.
Send WM_QUIT to the window during the shutdown procedure. The thread
will
call WndProc, which must destroy the window and then the thread itself.
Max
You are currently subscribed to ntdev as: xxxxx@greenborder.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com