Author: Tomas Rutkauskas
By hooking into the WndProc I can listen to the messages generated for
TWinControls. I am looking for the WN_CUT, WM_PASTE and WM_CLEAR so that I can lock
a record before the cut, paste or clear change occurs. The TComboBox does not
generate these events when the Style is csDropDown. Any way to capture these events?
Answer:
Override the ComboWndProc method ín a class derived from TCombobox. Example:
1 unit Unit1;
2 3 interface4 5 uses6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls;
8 9 type10 TCombobox = class(stdctrls.TComboBox)
11 protected12 procedure ComboWndProc(varmessage: TMessage; ComboWnd: HWnd;
13 ComboProc: Pointer); override;
14 end;
15 TForm1 = class(TForm)
16 ComboBox1: TComboBox;
17 Memo1: TMemo;
18 private19 { Private declarations }20 public21 { Public declarations }22 end;
23 24 var25 Form1: TForm1;
26 27 implementation28 29 {$R *.dfm}30 31 { TCombobox }32 33 procedure Report(const S: string);
34 begin35 form1.memo1.lines.add(S);
36 end;
37 38 procedure TCombobox.ComboWndProc(varmessage: TMessage; ComboWnd: HWnd;
39 ComboProc: Pointer);
40 begin41 inherited;
42 casemessage.Msg of43 WM_CUT: Report('CUT');
44 WM_PASTE: Report('PASTE');
45 WM_CLEAR: Report('CLEAR');
46 end;
47 end;
48 49 end.