gpt4 book ai didi

c# - 如何在 Windows 窗体应用程序中使用此 WndProc?

转载 作者:行者123 更新时间:2023-11-30 20:49:44 30 4
gpt4 key购买 nike

请指导我如何在 Windows 窗体应用程序中使用此 WndProc:

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == NativeCalls.APIAttach && (uint)lParam == NativeCalls.SKYPECONTROLAPI_ATTACH_SUCCESS)
{
// Get the current handle to the Skype window
NativeCalls.HWND_BROADCAST = wParam;
handled = true;
return new IntPtr(1);
}

// Skype sends our program messages using WM_COPYDATA. the data is in lParam
if (msg == NativeCalls.WM_COPYDATA && wParam == NativeCalls.HWND_BROADCAST)
{
COPYDATASTRUCT data = (COPYDATASTRUCT)Marshal.PtrToStructure(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;
return new IntPtr(1);
}

return IntPtr.Zero;
}

我见过有人在 WPF 中以这种方式使用上面的代码,例如

protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);

// Attach WndProc
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}

最佳答案

您可以使用 Application.AddMessageFilter方法。

[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public class TestMessageFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
// Blocks all the messages relating to the left mouse button.
if (m.Msg >= 513 && m.Msg <= 515)
{
Console.WriteLine("Processing the messages : " + m.Msg);
return true;
}
return false;
}
}

关于c# - 如何在 Windows 窗体应用程序中使用此 WndProc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23220111/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com