100分请教高手问题:无法重载系统底层WndProc(ref Message m)函数

biduan 2006-05-11 03:43:25
前天自己写了一个自定义的控件,继承ListView,并且调用地层的WndProc(ref Message m)
来捕获系统的消息,然而无论如何我在测试时候程序始终无法运行到WndProc(ref Message m)内部的函数(设置断点):
[SecurityPermission(SecurityAction.LinkDemand, flags=SecurityPermissionFlag.UnmanagedCode)]
protected override void WndProc(ref Message m)
{
if (m.Msg ==(int) Win32.Consts.WM_NCPAINT)
_backgroundDirty = true;

if (m.Msg == (int)Win32.Consts.WM_ERASEBKGND)
{
if (ProcessBackground() == false)
{
return;
}
}

if (m.Msg == (int)Win32.Consts.OCM_NOTIFY)
{

Win32.NMHDR notifyHeader = (Win32.NMHDR)m.GetLParam(typeof(Win32.NMHDR));

if (notifyHeader.code == (int)Win32.Consts.LVN_ITEMCHANGED)
_paintBackground = false;

if (notifyHeader.hwndFrom.Equals(this.Handle) && notifyHeader.code == (int)Win32.Consts.NM_CUSTOMDRAW)
{
_paintBackground = true;

if (ProcessListCustomDraw(ref m))
return;
}
}
base.WndProc(ref m);
}
WndProc理解成一个死循环,不断的从消息队列里面获取消息,这里设下断点无论如何都会运行到的,然而现在却无法捕获任何消息(没有运行这段函数),究竟是怎么回事?
...全文
409 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangxf0022 2006-06-05
  • 打赏
  • 举报
回复
Release应该美关系的,应该是程序没有执行到base.WndProc(ref m);这句。消息应该保证循环,如果不循环的话会导致不执行的。

还有,那个Form.wndProc的例子是可以执行的。不知道是不是SDK的版本问题
kssys 2006-05-26
  • 打赏
  • 举报
回复
楼主检查一下,是否把程序调试模式设为Release
ilovejolly 2006-05-26
  • 打赏
  • 举报
回复
mark
kokubo_wing 2006-05-16
  • 打赏
  • 举报
回复
学习
yinweihong 2006-05-12
  • 打赏
  • 举报
回复
http://www.vbdotnetheaven.com/UploadFile/lubosh/EmptyListView11102005022530AM/EmptyListView.aspx?ArticleID=6da9eb6f-16a1-4bce-9fe8-e7ee20612a7d
参考一下这篇文章看看
「已注销」 2006-05-12
  • 打赏
  • 举报
回复
谢谢AlphaGroup
不过
[SecurityPermission(SecurityAction.LinkDemand, flags=SecurityPermissionFlag.UnmanagedCode)]
//这个特性去掉没有用
很奇怪的问题....
难道没有高手知道怎么解决吗?
AlphaGroup 2006-05-12
  • 打赏
  • 举报
回复
把这个[SecurityPermission(SecurityAction.LinkDemand, flags=SecurityPermissionFlag.UnmanagedCode)]去掉试试
「已注销」 2006-05-11
  • 打赏
  • 举报
回复

下面是从msdn示范的代码拷贝过来的,程序运行时候始终没有看见绘制
“Application is Inactive”
奇怪之中!

using System;
using System.Drawing;
using System.Windows.Forms;

namespace csTempWindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
// Constant value was found in the "windows.h" header file.
private const int WM_ACTIVATEAPP = 0x001C;
private bool appActive = true;

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

public Form1()
{
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
}

protected override void OnPaint(PaintEventArgs e)
{
// Paint a string in different styles depending on whether the
// application is active.
if (appActive)
{
e.Graphics.FillRectangle(SystemBrushes.ActiveCaption,20,20,260,50);
e.Graphics.DrawString("Application is active", this.Font, SystemBrushes.ActiveCaptionText, 20,20);
}
else
{
e.Graphics.FillRectangle(SystemBrushes.InactiveCaption,20,20,260,50);
e.Graphics.DrawString("Application is Inactive", this.Font, SystemBrushes.ActiveCaptionText, 20,20);
}
}

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
protected override void WndProc(ref Message m)
{
// Listen for operating system messages.
switch (m.Msg)
{
// The WM_ACTIVATEAPP message occurs when the application
// becomes the active application or becomes inactive.
case WM_ACTIVATEAPP:

// The WParam value identifies what is occurring.
appActive = (((int)m.WParam != 0));

// Invalidate to get new text painted.
this.Invalidate();

break;
}
base.WndProc(ref m);
}
}
}

17,741

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧