Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > How a non-windowed program can receive WM_DEVICECHANGE from Window

Reply
Thread Tools Display Modes

How a non-windowed program can receive WM_DEVICECHANGE from Window

 
 
Amanda Lin
Guest
Posts: n/a

 
      05-29-2006
How a non-windowed component can receive messages from Windows?

I'm writing and testing my USB device driver on windows 2000.

My appication need to handle the WM_DEVICECHANGE message.
RegisterDeviceNotification() can let a application with a top-level window
to register to receive device notifications. It needs the handle of the
top-level window.

But my application is a console program. How a non-windowed program can
receive WM_DEVICECHANGE from Windows?

I was suggested to create a hidden window in a separate thread.
But CreateThread() only return the thread hanle and there is no window
attributes I can set when calling CreateThread().

Are there any other APIs?
Who can give me some advice? Thank you!




 
Reply With Quote
 
 
 
 
Robert Marquardt
Guest
Posts: n/a

 
      05-29-2006
Amanda Lin wrote:

> I was suggested to create a hidden window in a separate thread.
> But CreateThread() only return the thread hanle and there is no window
> attributes I can set when calling CreateThread().


This is the correct way. You then have to create a window in the thread
and the thread implements a GetMessage/DispatchMessage loop for the window.
The window belongs to the thread if it is created inside the thread. The
GetMessage/DispatchMessage is needed because the console application has
no loop of its own.
 
Reply With Quote
 
Pavel A.
Guest
Posts: n/a

 
      05-29-2006
"Amanda Lin" wrote:
.....
> I was suggested to create a hidden window in a separate thread.


It is a very good advice, it works. Why not to follow it?

> But CreateThread() only return the thread hanle and there is no window
> attributes I can set when calling CreateThread().


Great, and then call CreateWindow...

> Are there any other APIs?


May be these events are available thru WMI, but this can be even harder
way than a window.

Regards,
--PA

 
Reply With Quote
 
Doron Holan [MS]
Guest
Posts: n/a

 
      05-29-2006
speicifically, when calling CreateWindow, do not specify WS_VISIBLE in the
3rd parameter (dwStyle). you will have to create your own window class and
implement your own WndProc.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Pavel A." <> wrote in message
news:FE68DE6F-26E2-4979-B041-...
> "Amanda Lin" wrote:
> ....
>> I was suggested to create a hidden window in a separate thread.

>
> It is a very good advice, it works. Why not to follow it?
>
>> But CreateThread() only return the thread hanle and there is no window
>> attributes I can set when calling CreateThread().

>
> Great, and then call CreateWindow...
>
>> Are there any other APIs?

>
> May be these events are available thru WMI, but this can be even harder
> way than a window.
>
> Regards,
> --PA
>



 
Reply With Quote
 
Alexander Grigoriev
Guest
Posts: n/a

 
      05-29-2006
Or create a "message only" window.

"Doron Holan [MS]" <> wrote in message
news:...
> speicifically, when calling CreateWindow, do not specify WS_VISIBLE in the
> 3rd parameter (dwStyle). you will have to create your own window class
> and implement your own WndProc.
>
> d
>
> --
> Please do not send e-mail directly to this alias. this alias is for
> newsgroup purposes only.
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
> "Pavel A." <> wrote in message
> news:FE68DE6F-26E2-4979-B041-...
>> "Amanda Lin" wrote:
>> ....
>>> I was suggested to create a hidden window in a separate thread.

>>
>> It is a very good advice, it works. Why not to follow it?
>>
>>> But CreateThread() only return the thread hanle and there is no window
>>> attributes I can set when calling CreateThread().

>>
>> Great, and then call CreateWindow...
>>
>>> Are there any other APIs?

>>
>> May be these events are available thru WMI, but this can be even harder
>> way than a window.
>>
>> Regards,
>> --PA
>>

>
>



 
Reply With Quote
 
Robert Marquardt
Guest
Posts: n/a

 
      05-30-2006
Why is this a console program?
I would make this specific functionality a DLL so it can be used by a
GUI program or console program.
 
Reply With Quote
 
Amanda Lin
Guest
Posts: n/a

 
      05-30-2006
Thank all of you so much.
I need this console program to do a test. Amd if it's ok, I'll plant it into
the cygwin environment.

Now I've got trouble to create the hidden window via CreateWindow(). I'm not
familiar with windows API.

Must I set "lpClassName" and "lpWindowName" to create a window?
It seems I must set "lpClassName".

I've tried like that
hWnd=CreateWindow(NULL, NULL,
WS_POPUP|WS_DISABLED, //don't receive user input
0,0,10,10,
0, 0,
INVALID_HANDLE_VALUE, 0);

But it fails and the error code is "ERROR_CANNOT_FIND_WND_CLASS"
Where can I find the predefined system class names?
Thanks a lot!

"Amanda Lin" wrote:

> How a non-windowed component can receive messages from Windows?
>
> I'm writing and testing my USB device driver on windows 2000.
>
> My appication need to handle the WM_DEVICECHANGE message.
> RegisterDeviceNotification() can let a application with a top-level window
> to register to receive device notifications. It needs the handle of the
> top-level window.
>
> But my application is a console program. How a non-windowed program can
> receive WM_DEVICECHANGE from Windows?
>
> I was suggested to create a hidden window in a separate thread.
> But CreateThread() only return the thread hanle and there is no window
> attributes I can set when calling CreateThread().
>
> Are there any other APIs?
> Who can give me some advice? Thank you!
>
>
>
>

 
Reply With Quote
 
Amanda Lin
Guest
Posts: n/a

 
      05-30-2006
Sorry! I've asked a stupid question.
I created a hidden window of "static" class. I'll test whether it can
receive the DEVICE_CHANGE message.

But there is another question, I don't want this window to be the "focus"
to get all the user input. What shall I do?

"Amanda Lin" wrote:

> Thank all of you so much.
> I need this console program to do a test. Amd if it's ok, I'll plant it into
> the cygwin environment.
>
> Now I've got trouble to create the hidden window via CreateWindow(). I'm not
> familiar with windows API.
>
> Must I set "lpClassName" and "lpWindowName" to create a window?
> It seems I must set "lpClassName".
>
> I've tried like that
> hWnd=CreateWindow(NULL, NULL,
> WS_POPUP|WS_DISABLED, //don't receive user input
> 0,0,10,10,
> 0, 0,
> INVALID_HANDLE_VALUE, 0);
>
> But it fails and the error code is "ERROR_CANNOT_FIND_WND_CLASS"
> Where can I find the predefined system class names?
> Thanks a lot!
>
> "Amanda Lin" wrote:
>
> > How a non-windowed component can receive messages from Windows?
> >
> > I'm writing and testing my USB device driver on windows 2000.
> >
> > My appication need to handle the WM_DEVICECHANGE message.
> > RegisterDeviceNotification() can let a application with a top-level window
> > to register to receive device notifications. It needs the handle of the
> > top-level window.
> >
> > But my application is a console program. How a non-windowed program can
> > receive WM_DEVICECHANGE from Windows?
> >
> > I was suggested to create a hidden window in a separate thread.
> > But CreateThread() only return the thread hanle and there is no window
> > attributes I can set when calling CreateThread().
> >
> > Are there any other APIs?
> > Who can give me some advice? Thank you!
> >
> >
> >
> >

 
Reply With Quote
 
Robert Marquardt
Guest
Posts: n/a

 
      05-30-2006
Amanda Lin wrote:

> But there is another question, I don't want this window to be the "focus"
> to get all the user input. What shall I do?


Simply never call ShowWindow. As long as the window stays invisible it
cannot get focus.
 
Reply With Quote
 
Amanda Lin
Guest
Posts: n/a

 
      05-30-2006
Some problem make me confused.

After I created a new thread, I need to call
1. RegisterClassEx() to create my own windows class
2. CreateWindow() to create the window of this class
3. RegisterDeviceNotification()

In step 1.
For RegisterClassEx(), I need to provide "Handle to the instance that
contains the window procedure for the class".
Is it the handle of the thread I just created?
Or is it the handle of the application? If yes, where to get it ?

Where can I get the handle of the class icon, cursor,background brush...
How can a console application that start with "main" give such graphic
information?
Shall I create an appliction that start with "WinMain" ?

In step 2,
For CreateWindow(), I also need to set the "handle to application instance".
Where to get it?

Could anyone give me some addvice or example code? Thanks a lot!





"Doron Holan [MS]" wrote:

> speicifically, when calling CreateWindow, do not specify WS_VISIBLE in the
> 3rd parameter (dwStyle). you will have to create your own window class and
> implement your own WndProc.
>
> d
>
> --
> Please do not send e-mail directly to this alias. this alias is for
> newsgroup purposes only.
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
> "Pavel A." <> wrote in message
> news:FE68DE6F-26E2-4979-B041-...
> > "Amanda Lin" wrote:
> > ....
> >> I was suggested to create a hidden window in a separate thread.

> >
> > It is a very good advice, it works. Why not to follow it?
> >
> >> But CreateThread() only return the thread hanle and there is no window
> >> attributes I can set when calling CreateThread().

> >
> > Great, and then call CreateWindow...
> >
> >> Are there any other APIs?

> >
> > May be these events are available thru WMI, but this can be even harder
> > way than a window.
> >
> > Regards,
> > --PA
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FS9 Windowed Mode with Vista Aydee Windows Vista Games 3 10-25-2008 06:13 AM
Send and Receive Window in Windows Mail Mister Lank Windows Vista Mail 3 04-22-2008 10:21 PM
Send Receive window is a black screen Wendell Windows Vista Mail 3 09-15-2007 07:19 PM
Receive Window Auto-Tuning on Vista Sooner Al [MVP] Windows Vista Networking 0 07-09-2007 11:51 AM
Running media center in windowed mode ? Martin Vaupell Windows Vista Music, Pictures and Video 3 04-01-2007 08:45 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59