通过spy++已经得到 TStringGrid 的句柄 用C# 如何能得到 TStringGrid 中的数据 谁有实例
4条回答 默认 最新
- WorldMobile 2015-07-06 08:31关注
参考一下这段代码
以前做个这个,不过是C++的,使用了hook方法。 你可以参考 下载完了,运行Exec这个程序,是TStringGrid的示例,运行EnumControls.exe, 点击【列举窗体中的控件】按钮,就获取了TStringGrid的句柄, 点击【复制SG中的数据】就可以把Exec这个程序中TStringGrid的数据复制到EnumControls.exe了。 核心代码是这个: HWND DLLHWND; void __stdcall (*InstallHook)(HWND, HWND); void __stdcall (*UninstallHook)(); char * __stdcall (*GetHookedCell)(); DLLHWND = LoadLibrary("HookSG.dll"); InstallHook = (void (__stdcall *)(HWND, HWND))GetProcAddress(DLLHWND, "InstallHook"); UninstallHook = (void (__stdcall *)())GetProcAddress(DLLHWND, "UninstallHook"); GetHookedCell = (char * (__stdcall *)())GetProcAddress(DLLHWND, "GetHookedCell"); //AnsiString StrHwnd = SG->Cells[2][SelectedRow]; //if (StrHwnd == "") return; //HWND hWnd = (void *)(StrHwnd.ToInt()); //HWND hParent = GetParent(hWnd); //HWND hParent = FindWindow("TForm1", "列举窗体中的控件"); //HWND hParent = FindWindow("TForm1", "Form1"); //HWND hParent = FindWindow("TFrmSGHooked", "StringGrid to be hooked"); char cText[MAX_PATH] = {0}; strcpy(cText, Edit1->Text.c_str()); if (strcmp(cText, "") == 0) return; HWND hParent = FindWindow(NULL, cText); HWND hWnd = FindWindowEx(hParent, 0, "TStringGrid", NULL); if (!hWnd) return; InstallHook(Handle, hWnd); SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0); PostMessage(hParent, WM_NULL, 0, 0); for (int i = 0; i < 20; i++) { Sleep(100); Application->ProcessMessages(); if (MsgWnd != 0) break; } if (MsgWnd == 0) goto Exit; int iRow, iCol, iLen; iRow = SendMessage(MsgWnd, CM_QUERYROW, 0, 0); iCol = SendMessage(MsgWnd, CM_QUERYCOL, 0, 0); if (iRow <= 0 || iCol <= 0) goto Exit; SGSub->RowCount = iRow; SGSub->ColCount = iCol; for (int i = 0; i < iRow; i++) { for (int j = 0; j < iCol; j++) { iLen = SendMessage(MsgWnd, CM_HOOKCELL, j, i); if (iLen < 0) goto Exit; SGSub->Cells[j][i] = GetHookedCell(); } } Exit: MsgWnd = 0; UninstallHook(); SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0); FreeLibrary(DLLHWND);
解决 无用评论 打赏 举报
悬赏问题
- ¥20 腾讯企业邮箱邮件可以恢复么
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号
- ¥50 安装pyaudiokits失败
- ¥15 计组这些题应该咋做呀
- ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
- ¥15 让node服务器有自动加载文件的功能
- ¥15 jmeter脚本回放有的是对的有的是错的
- ¥15 r语言蛋白组学相关问题
- ¥15 Python时间序列如何拟合疏系数模型