How to capture the WM_CUT, WM_CLEAR and WM_PASTE messages in a TComboBox (Views: 27)
Problem/Question/Abstract: 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: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TCombobox = class(stdctrls.TComboBox) protected procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override; end; TForm1 = class(TForm) ComboBox1: TComboBox; Memo1: TMemo; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} { TCombobox } procedure Report(const S: string); begin form1.memo1.lines.add(S); end; procedure TCombobox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); begin inherited; case message.Msg of WM_CUT: Report('CUT'); WM_PASTE: Report('PASTE'); WM_CLEAR: Report('CLEAR'); end; end; end. |