zoukankan      html  css  js  c++  java
  • delphi获取其他外部程序中TDBGridEh控件中的数据

    使用钩子原理+dll注入。首先使用FindwindowEx能获取到表格的句柄,再转化为表格,将表格的内容赋值给你的新表格。
    function MsgWndProc(hwnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
    var
    // SG: TStringGrid;
    SG:TDrawgrid;
    X, Y: Integer;
    begin
    case Msg of
    CM_QUERYROW:
    begin
    Result := -1;
    if P^.DestWnd <> 0 then
    begin
    SG := Pointer(FindControl(P^.DestWnd));
    if SG <> nil then Result := SG.RowCount;
    end;
    Exit;
    end;
    CM_QUERYCOL:
    begin
    Result := -1;
    if P^.DestWnd <> 0 then
    begin
    SG := Pointer(FindControl(P^.DestWnd));
    if SG <> nil then Result := SG.ColCount;
    end;
    Exit;
    end;
    CM_HOOKCELL:
    begin
    Result := -1;
    P^.Text[0] := #0;
    if P^.DestWnd <> 0 then
    begin
    SG := Pointer(FindControl(P^.DestWnd));
    if SG <> nil then
    begin
    X := WParam;
    Y := LParam;
    if (X >= 0) and (X < SG.ColCount) and (Y >= 0) and (Y < SG.RowCount) then
    begin
    Result := Length(SG.Cells[X, Y]);//就是这里 获取不到它的单元格值?
    if Result > 0 then
    begin
    StrPLCopy(P^.Text, SG.Cells[X, Y], 1024);
    end;
    end;
    end;
    end;
    Exit;
    end;
    end;
    Result := DefWindowProc(hwnd, Msg, WParam, LParam);
    end;
    这个我已经测试通过。
  • 相关阅读:
    第一篇:GCD的使用
    第一篇:线程的安全
    内存问题
    第一篇:多线程的概念
    第一篇:NSOperation的概念
    存储问题
    第一篇:NSTread线程的创建
    第一篇:多线程使用
    遍历所有表,取每个表的MAXID更新到ID控制表
    <转载>SQL查询数据库各表所占空间
  • 原文地址:https://www.cnblogs.com/neights/p/2909134.html
Copyright © 2011-2022 走看看