System Messaging puzzle.

This is a discussion on System Messaging puzzle. within the Windows Programming forums, part of the Platform Specific Boards category; I am investigating trapping messages by overriding wndproc but I'm now having some problems: Code: protected override void WndProc(ref Message ...

  1. #1
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271

    System Messaging puzzle.

    I am investigating trapping messages by overriding wndproc but I'm now having some problems:
    Code:
    protected override void WndProc(ref Message m) 
            {        
            // Listen for operating system messages.
                switch (m.Msg)
                {
    
                    case WM_DEVICECHANGE:
                        {                        
                            if (m.WParam.ToInt32() == DBT_DEVICEARRIVAL )//<== Put there to follow the control loop
                                MessageBox.Show("System Device List Changed");                           
    
                            switch ( dMsg )
                            {
                                case DBT_DEVICEARRIVAL:
                                    MessageBox.Show("A device has been docked");
                                    break;
    
                                case DBT_DEVICEREMOVECOMPLETE:
                                    MessageBox.Show("A device has been REMOVED");
                                    break;
    
                                default:
                                    MessageBox.Show("Unrequired system Message");
                                    break;
    
                            } //end of nested switch statement
    
                        }
                        break;                                  
    
                }
                base.WndProc(ref m);
            }//end wndProc
    I am trapping the WD_DEVICECHANGE message but not the wParam. I out put the WParam value in my modified code and was getting 7. Can someone tell me why I can't trap the correct wParam?
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by WDT View Post
    I am investigating trapping messages by overriding wndproc but I'm now having some problems:
    Code:
    protected override void WndProc(ref Message m) 
            {        
            // Listen for operating system messages.
                switch (m.Msg)
                {
    
                    case WM_DEVICECHANGE:
                        {                        
                            if (m.WParam.ToInt32() == DBT_DEVICEARRIVAL )//<== Put there to follow the control loop
                                MessageBox.Show("System Device List Changed");                           
    
                            switch ( dMsg )
                            {
                                case DBT_DEVICEARRIVAL:
                                    MessageBox.Show("A device has been docked");
                                    break;
    
                                case DBT_DEVICEREMOVECOMPLETE:
                                    MessageBox.Show("A device has been REMOVED");
                                    break;
    
                                default:
                                    MessageBox.Show("Unrequired system Message");
                                    break;
    
                            } //end of nested switch statement
    
                        }
                        break;                                  
    
                }
                base.WndProc(ref m);
            }//end wndProc
    I am trapping the WD_DEVICECHANGE message but not the wParam. I out put the WParam value in my modified code and was getting 7. Can someone tell me why I can't trap the correct wParam?
    First of all, the above code doesn't give anyone much to work with as far as solving your problem. There may be a couple of problems. The first is that the OS will only send the WM_DEVICECHANGE message to applications with a top level window. The second is that the OS will send WM_DEVICECHANGE messages on port and volume changes only. To receive notification of other types of device changes you must use RegisterDeviceNotification. This will provide notifications of any type of device interface changes.

    Also, you'll have to register a device interface class GUID for every device that you want to support.

    If this still does not make any sense, post again, requesting POC code.

  3. #3
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    Thanks. I was actually already on that path when I posted the message just didn't know how to implement the RegisterDeviceNotification() function properly. doing this allowed me to be able to capture the messages I wanted but I now need an explanation on something else.
    Everytime I dock/undock my windows phone I get my message but the default is also triggered twice.
    Code:
         protected override void WndProc(ref Message m) 
            {            
            
            // Listen for operating system messages.
                switch (m.Msg)
                {
    
                    case (int)DeviceEvents.deviceEvent:
                        {                        
                            
                            switch ( m.WParam.ToInt32() )
                            {
                                case (int)DeviceEvents.deviceAdded:
                                    MessageBox.Show("A device has been docked");
                                    break;
    
                                case (int)DeviceEvents.deviceRemoved:
                                    MessageBox.Show("A device has been REMOVED");
                                    break;
    
                                default:
                                    MessageBox.Show("unrequired system Message was:\n\t" + m.WParam.ToString());
                                    break;
    
                            } //end of nested switch statement
    
                        }
                        break;                                  
    
                }
                base.WndProc(ref m);
            }//end wndProc
    Last edited by WDT; 04-10-2009 at 04:06 AM.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    DBT_DEVNODES_CHANGED Event

    The system broadcasts the DBT_DEVNODES_CHANGED device event when a device has been added to or removed from the system.
    That also explains the wParam of 7, since that's its value. The docs list all the valid wParams so use that to explain which other notifications you're getting.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by WDT View Post
    Thanks. I was actually already on that path when I posted the message just didn't know how to implement the RegisterDeviceNotification() function properly. doing this allowed me to be able to capture the messages I wanted but I now need an explanation on something else.
    Everytime I dock/undock my windows phone I get my message but the default is also triggered twice.
    Code:
         protected override void WndProc(ref Message m) 
            {            
            
            // Listen for operating system messages.
                switch (m.Msg)
                {
    
                    case (int)DeviceEvents.deviceEvent:
                        {                        
                            
                            switch ( m.WParam.ToInt32() )
                            {
                                case (int)DeviceEvents.deviceAdded:
                                    MessageBox.Show("A device has been docked");
                                    break;
    
                                case (int)DeviceEvents.deviceRemoved:
                                    MessageBox.Show("A device has been REMOVED");
                                    break;
    
                                default:
                                    MessageBox.Show("unrequired system Message was:\n\t" + m.WParam.ToString());
                                    break;
    
                            } //end of nested switch statement
    
                        }
                        break;                                  
    
                }
                base.WndProc(ref m);
            }//end wndProc
    The default is capturing the DBT_DEVNODES_CHANGED message or the number 7 if you will. You should at least capture one DBT_DEVNODES_CHANGED message when your device is connected or unconnected. This is for the most part dependent on the GUIDs you have registered.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 04:35 PM
  2. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 06:12 AM
  3. Problem Reporting System. Need Advide!
    By brunomiranda in forum Tech Board
    Replies: 9
    Last Post: 09-25-2003, 09:21 PM
  4. Number system base M, print numbers N digits wide...
    By biterman in forum C Programming
    Replies: 12
    Last Post: 11-19-2001, 03:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21