26.3.txt
来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 34 行
TXT
34 行
Listing 26.3 Overriding WndProc to Handle Window Messages
public void EnumWindows()
{
// call the native dll function
EnumerateDeviceWindows( this.Hwnd );
}
// Override the default WndProc behavior to monitor messages.
protected override void WndProc(ref Message msg)
{
switch(msg.Msg)
{
case WM_USER_ADDWINDOW:
{
// get the window title using GetWindowText
StringBuilder windowText = new StringBuilder(1024);
GetWindowText( msg.LParam.ToInt32(), windowText, 1024 );
if( windowText.ToString() == “” )
break;
// if wParam is 1 then window is a child of someone
if( msg.WParam.ToInt32() == 1 )
windowText.Insert( 0, “ “);
// add it to the listbox of the main form
mainForm.AddWindow( msg.LParam, windowText.ToString() );
break;
}
default:
{
break;
}
}
// Call the base class WndProc for default message handling.
base.WndProc(ref msg);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?