How to use this WndProc in Windows Forms application?

后端 未结 2 1645
慢半拍i
慢半拍i 2021-01-06 23:36

Please guide me how to use this WndProc in Windows Forms application:

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam,         


        
2条回答
  •  Happy的楠姐
    2021-01-07 00:35

    The prototype for WndProc in C# is:

    protected virtual void WndProc(ref Message m)
    

    So, you need to override this procedure in your class, assumed that it's derived from Control.

    protected override void WndProc(ref Message m)
    {
        Boolean handled = false; m.Result = IntPtr.Zero;
        if (m.Msg == NativeCalls.APIAttach && (uint)m.Param == NativeCalls.SKYPECONTROLAPI_ATTACH_SUCCESS)
        {
            // Get the current handle to the Skype window
            NativeCalls.HWND_BROADCAST = m.WParam;
            handled = true;
            m.Result = new IntPtr(1);
        }
    
        // Skype sends our program messages using WM_COPYDATA. the data is in lParam
        if (m.Msg == NativeCalls.WM_COPYDATA && m.WParam == NativeCalls.HWND_BROADCAST)
        {
            COPYDATASTRUCT data = (COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
            StatusTextBox.AppendText(data.lpData + Environment.NewLine);
    
            // Check for connection
            if (data.lpData.IndexOf("CONNSTATUS ONLINE") > -1)
                ConnectButton.IsEnabled = false;
    
            // Check for calls
            IsCallInProgress(data.lpData);
            handled = true;
            m.Result = new IntPtr(1);
        }
    
        if (handled) DefWndProc(ref m); else base.WndProc(ref m);
    }
    

提交回复
热议问题