Results 1 to 2 of 2

Thread: Events and Delegate

  1. #1

    Thread Starter
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103

    Question Events and Delegate

    Ok, it's days I'm in trouble with this... it should be easy!

    Say we have to do a class (say Windows) wich wraps EnumWindows (DllImpors[(user32.dll)])

    This class have just to raise the event Enumerate for each call of EnumWindows to its callback.

    I've no idea about how to do it!


    PHP Code:
    public class Windows

            
    [DllImport("user32.dll")] private static extern 
                  int EnumWindows
    (EnumWindowsProc ewpint lParam); 

            
    //delegate used for EnumWindows() callback function
            
    public delegate bool EnumWindowsProc(int hWndint lParam);

            public 
    Windows()
            {
                
    //Declare a callback delegate for EnumWindows() API call
                
    EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
                
    //Enumerate all Windows
                
    EnumWindows(ewp0);
            }
            
    //EnumWindows CALLBACK function
            
    private bool EvalWindow(int hWndint lParam)
            {
             
    // RAISE THE EVENT!
             // HOW???
            
    }
            
        }

    How to fill the "raising of event"?

    Thanx
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    What parameters do you want the event to have? Here is something basic. You can change it according to your needs.
    Code:
    public class Windows
    
            [DllImport("user32.dll")] private static extern 
            int EnumWindows(EnumWindowsProc ewp, int lParam); 
    
            //delegate used for EnumWindows() callback function
            public delegate bool EnumWindowsProc(int hWnd, int lParam);
    	public delegate void EnumWindowsHandler(string msg);
    	public event EnumWindowsHandler Log;
    
            public Windows()
            {
                //Declare a callback delegate for EnumWindows() API call
                EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
                //Enumerate all Windows
                EnumWindows(ewp, 0);
            }
            //EnumWindows CALLBACK function
            private bool EvalWindow(int hWnd, int lParam)
            {
             // RAISE THE EVENT!
            	if(Log != null)
    		{
    			Log("Enumeration Complete");
    		}
            }
            
        }
    }
    Dont gain the world and lose your soul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width