请问在delphi中的CNNotify事件是由什么激发的,有什么作用?在delphi中并无答案。(50分)

  • 主题发起人 主题发起人 ozj
  • 开始时间 开始时间
O

ozj

Unregistered / Unconfirmed
GUEST, unregistred user!
请问在delphi中的CNNotify事件是由什么激发的,有什么作用?在delphi中并无答案。
如在TMonthCalendar的原码中就此:procedure TMonthCalendar.CNNotify(var Message:TWMNotify);
 
看以下本人做的一个控件中的代码你也许能知道 CNNotify 的上些作用。


procedure TpnCustomListView.CNNotify( var Msg: TWMNotify );
var
Item: TListItem;
R: TRect;
P: TPoint;
begin
with Msg.NMHdr^ do
begin
Msg.Result := 0;

case code of
lvn_BeginLabelEdit: //编辑 Item
begin
if not FEditOnRowClick then
begin
// This notification message is received when the list view is about
// to put the main item into edit mode. Only go into edit mode if
// the mouse was clicked on the main item.
Item := TListItem( PLVDispInfo( Pointer( Msg.NMHdr ) )^.item.LParam );
R := Item.DisplayRect( drLabel );

GetCursorPos( P );
P := ScreenToClient( P );

if not PtInRect( R, P ) or not CanEdit( Item ) then
Msg.Result := 1;
end;
end;


else
inherited;
end; { case }
end;
end; {= TpnCustomListView.CNNotify =}
 
CN_NOTIFY其实就是WINDOWS的WM_NOTIFY
想知道出处的话, 查查form.pas就知道了. 某个class的DefaultHandler方法中应该有这
么一句:
case ....
....
WM_NOTIFY:
SendMessage(...., CN_NOTIFY, ...., ....);

....

具体的忘记了.
 
CN_Notify is one of the Control Notification Messages.

CN_Notify message is sent to a Windows common control in response to a WM_Notify
message. Windows send the WM_Notify message to the owner of a common control to
inform it of an event in the control. The NmHdr field points to a TNmHdr recourd,
which contains the notification code. Delphi handles the events that gave rise
to the common control notifications, so the default response to the CN_Notify
message is to do nothing, and there is little reason to handle this message your
self.

The message type is TWMNotify.

TWMNotify = packed record
Msg: Cardinal;
IDCtrl: Longint;
NMHdr: PNMHdr;
Result: Longint;
end;

PNMHdr = ^TNMHdr;
$EXTERNALSYM tagNMHDR}
tagNMHDR = packed record
hwndFrom: HWND;
idFrom: UINT;
code: Integer; { NM_ code }
end;
TNMHdr = tagNMHDR;
 
老屯的解悉,请问是哪里来的?
 
The about information is copied from a book called "The Secret of Delphi 2.0"
 
接受答案了.
 
后退
顶部