views:

327

answers:

2

Hi..

i am using c# .net 3.5 compact framework to write code.. please can any one tell me how do i register a form for WM_DEVICECHANGE and how to handle that message in windowproc..

if i do this i get intimation of device hardware change.. i m not getting how to write please tell.

Thanks

A: 

The key is to create a class deriving from NativeWindow, give this the handle of your form to call AssignHandle with, and override the WndProc function (allowing you to do what you want with WM_DEVICECHANGE).

See the example on this MSDN page for more details: Overriding the NativeWindow.WndProc Method

[EDIT] Not completely sure if the NativeWindow class is available in the compactFramework yet. If not, Alex Yakhnin has the class and a sample application of how to catch messages available here. Hope this will help.

John Sibly
A: 

Actually WM_DEVICECHANGE is unlikely to be what you want. You probably want to hook into Windows CE's device notification queue by calling RequestDeviceNotifications and passing to it a handle to a queue created with CreateMsgQueue.

If you don't feel like writing all of this P/Invoke code, as usual the Smart Device Framework already has it already done and in a more logical object model.

ctacke