首页 > 其他分享 >delphi cxgrid 过滤列表增加右键

delphi cxgrid 过滤列表增加右键

时间:2023-12-20 09:24:04浏览次数:39  
标签:tmpItem begin end delphi cxgrid filter 右键 choose

首先弹出来的下拉过滤列表也是一个form

思路,在不改源代码的情况:hook,捕捉  WM_SHOWWINDOW  消息,通过源码得知窗口类名 为”TcxGridFilterPopup“ 
再通过句柄转得到实例,同时在本单元type 一下新的 TcxGridFilterPopup, TcxGridPopupListBox 才能访问保护起来的方法跟属性

 CallWndProcHook:HHOOK;
 CurrentcxGridFilterPopup: TcxGridFilterPopup;
 pm_cxgrid_filter_choose:TPopupMenu;

initialization
initcxgrid_filter_Menus;
CallWndProcHook := SetWindowsHookEx(WH_CALLWNDPROC, @HookCallWndProc, 0, GetCurrentThreadID);



finalization
if CallWndProcHook > 0 then
UnHookWindowsHookEx(CallWndProcHook);
pm_cxgrid_filter_choose.Free;

 

type
TMycxGridFilterPopup = class(TcxGridFilterPopup)
end;


TMycxGridPopupListBox = class(TcxGridPopupListBox)
end;

 

function GetInstanceFromhWnd(const hWnd: Cardinal): TWinControl;
type
 PObjectInstance = ^TObjectInstance;
 TObjectInstance = packed record
   Code: Byte;            { 短跳转 $E8 }
   Offset: Integer;       { CalcJmpOffset(Instance, @Block^.Code); }
   Next: PObjectInstance; { MainWndProc 地址 }
   Self: Pointer;         { 控件对象地址 }
 end;
var
 wc: PObjectInstance;
begin
 Result := nil;
 wc     := Pointer(GetWindowLong(hWnd, GWL_WNDPROC));
 if wc <> nil then
 begin
   Result := wc.Self;
 end;
end;

function HookCallWndProc(code: Integer; wParam: wParam; lParam: lParam): LRESULT; stdcall;
var
cwp : PCwpStruct;
lpClassName: array [0..MAX_PATH] of Char;
tmpobjct:TWinControl;
begin
if code = HC_Action then
begin
cwp := PCwpStruct(lParam);
case cwp^.message of
WM_SHOWWINDOW:
begin
try
GetClassName(cwp.hwnd, lpClassName, MAX_PATH);
if lpClassName= 'TcxGridFilterPopup' then
begin
tmpobjct := GetInstanceFromhWnd(cwp.hwnd);
if (tmpobjct <> nil) then
begin
if TcxGridFilterPopup(tmpobjct).PopupMenu = nil then
TcxGridFilterPopup(tmpobjct).PopupMenu := pm_cxgrid_filter_choose;
CurrentcxGridFilterPopup := TcxGridFilterPopup(tmpobjct);
end;
end;
except
on e:exception do
Error_File(DataModule1.qry1.FieldByName('xm').AsString+ ' 添加过滤右键错误: '+ e.Message );
end;
end;
end;
end;
Result := CallNextHookEx(CallWndProcHook, code, wParam, lParam);
end;

procedure initcxgrid_filter_Menus;
var
 tmpItem: TMenuItem;
begin
 pm_cxgrid_filter_choose := TPopupMenu.Create(nil);
 tmpItem := TMenuItem.Create(pm_cxgrid_filter_choose);
 tmpItem.Caption := '全选';
 tmpItem.Tag := 1;
 tmpItem.OnClick := MyEventClass.SetcxGridFilterListChecked;
 pm_cxgrid_filter_choose.Items.Add(tmpItem);

 tmpItem := TMenuItem.Create(pm_cxgrid_filter_choose);
 tmpItem.Caption := '反选';
 tmpItem.Tag := 2;
 tmpItem.OnClick := MyEventClass.SetcxGridFilterListChecked;
 pm_cxgrid_filter_choose.Items.Add(tmpItem);
end;

procedure TMyEventClass.SetcxGridFilterListChecked(Sender:Tobject);
var
Item: TcxCustomGridTableItem;
i,Len:integer;
FValueList: TcxGridFilterValueList;
AActiveValueIndexes: TcxGridIndexes;
MycxGridPopupListBox: TMycxGridPopupListBox;
Choose:Boolean;
begin
if CurrentcxGridFilterPopup = nil then
Exit;
Choose := TMenuItem(Sender).Tag = 1;
Item := CurrentcxGridFilterPopup.Item;
MycxGridPopupListBox := TMycxGridPopupListBox(TMycxGridFilterPopup(CurrentcxGridFilterPopup).ListBox);
case Choose of
False:
begin
Item.Filtered := False;
//要同步状态不然下拉的列表不会刷新
for i := 0 to MycxGridPopupListBox.Count -1 do
begin
if MycxGridPopupListBox.HasCheck(i) then
MycxGridPopupListBox.Checked[i] := False;
end;
end;
True:
begin
try
FValueList := Item.GridView.ViewData.CreateFilterValueList;
//获取下拉内容
Item.DataBinding.GetFilterValues(FValueList, False,True,True);
Len := 0;
for I := 0 to FValueList.Count -1 do
begin
if not (FValueList[i].Kind in [fviAll, fviCustom]) then
begin
inc(Len);
SetLength(AActiveValueIndexes, Len);
AActiveValueIndexes[Len-1] := i;
MycxGridPopupListBox.Checked[i] := False;
MycxGridPopupListBox.DoAction(i);
end;
end;
finally
FValueList.Free;
end;
end;
end;
end;

 

标签:tmpItem,begin,end,delphi,cxgrid,filter,右键,choose
From: https://www.cnblogs.com/BTag/p/17915370.html

相关文章

  • DELPHI模板编程
    DELPHI模板编程procedureTCRUD<T>.execsql(OnTableModel:TTableModel);//执行事务性SQLbeginifreq.Body=nilthenExit;varpool:TDBPool:=GetDBPool(dbid);//databasepooldb:=pool.Lock;trytrytable:=serialize.TSerial<TTab......
  • 保存/恢复cxGrid布局
    //恢复布局IniFileName:=ExtractFilePath(Application.ExeName)+'Layout/'+Self.Name+'.ini';ifFileExists(IniFileName)thenSelf.tvResult.RestoreFromIniFile(IniFileName)//从布局文件中恢复elsebeginSelf.tvResult.BeginUpdate;fori:=0toSelf.tvR......
  • delphi ADO通过ODBC连接MySQL
    ADO通过ODBC连接MySQL操作步骤下载32位MySQLODBC驱动(MySQLConnector/ODBC下载地址)选择ADO驱动程序MicrosoftOLEDBProviderforODBCDrivers设置连接字符串连接字符串使用数据源名称Provider=MSDASQL.1;PersistSecurityInfo=False;DataSource=ceshiDataS......
  • Delphi实现登录窗体与主窗体的过程
    登录窗体:typeTfrmLogin=class(TForm)btn1:TButton;procedurebtn1Click(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}end;varfrmLogin:TfrmLogin;implementation{$R*.dfm}procedureTfrm......
  • Delphi Android程序启动过程
    文章转载于不得闲大师的文章,源文链 https://www.cnblogs.com/DxSoft/p/4460236.html Delphi的Android程序是原生的程序,也就是NativeActivity。那么就需要先看一下NativeActivity的原理,在AndroidManifest.xml文件里面指定入口activity为nativeactivity,这样应用程序一启动,jav......
  • delphi 变体Variant数组常用操作
    变体Variant数组常用操作代码procedureTForm1.Button1Click(Sender:TObject);varArr1,Arr2,Arr3:Variant;I,J:Integer;begin//创建包含10个整数类型元素的变体数组Arr1:=VarArrayCreate([0,9],varInteger);//创建2维数组,其中第1维是3个元素,第2维是5......
  • VSCode插件开发:右键点击创建一个文件夹和相应名称的文件
    开发一个输入名称然后创建文件夹和相同文件名的文件那么首先是注册右键点击事件"contributes":{"commands":[{"command":"createuniappfile.createvuefile","title":"CreateUniappFile"}],&qu......
  • HHDESK右键管理简介
    在HHDESK管理文件,除了基本的打开、删除、复制、粘贴、重命名外,还有多种便捷编辑方式。可以分别以下列模式打开文档: 文本模式即是以文本编辑器打开文档。 1二进制模式可进行二进制编辑。 2JSON模式可对JSON文件进行直观的解析。左侧配有节点框,方便操作与浏览;树形......
  • delphi 提示 Access violation at address 014CA924 in module 'EBD.exe'. Read of ad
    通过类似Accessviolationataddress014CA924inmodule'EBD.exe'.Readofaddress0D1A0000提示查看代码出错的行。1、开启map project -> options -> Linker -> Map file 选择detailed2、查看ImageBase 3、计算地址崩溃行偏移 = 崩溃地址(Crash Addre......
  • 将任意程序添加到鼠标右键
    在文本里添加如下语句,将下面标红的位置修改为自己到程序相关内容,并且将文件后缀命名为.reg,修改完双击运行即可WindowsRegistryEditorVersion5.00[HKEY_CLASSES_ROOT\*\shell\IDA7.7_32]@="IDA7.7_32""Icon"="D:\\green_soft\\IDA_Pro_7.7\\ida.exe"[HKEY_CLASSES_ROOT\*\s......