為什么獲取不到這個句柄的text資訊
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
BOOL CALLBACK EnumFunc(HWND hwnd,LPARAM lp);
BOOL CALLBACK EnumChildWinProc (HWND hwnd, LPARAM lParam);
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
BOOL CALLBACK EnumFunc(HWND hwnd,LPARAM lp)
{
return true;
}
BOOL CALLBACK EnumChildWinProc (HWND hwnd, LPARAM lParam)
{
String str;
char wndclassname [255];
char wndcaption [255];
str="WindowsForms10.EDIT.app.0.2c908d5";
GetWindowText(hwnd,wndcaption,255);
SendMessage(hwnd, WM_GETTEXT, 255, Integer(&wndcaption));
GetClassName(hwnd,wndclassname,255);
Form1->Memo1->Lines->Add(StrPas(wndclassname));
Form1->Memo1->Lines->Add(StrPas(wndcaption));
Form1->Memo1->Lines->Add(IntToStr((int)hwnd));
Form1->Memo1->Lines->Add("------------------------------------");
Form1->Memo2->Lines->Add(IntToStr((int)hwnd));
return true;
}
////////////////////////////////////////////////////////////////////////////////
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form1->Memo2->Lines->Clear();
HWND hwnd;
hwnd=FindWindow(NULL,"Form1");
if(!hwnd)
{
Label6->Caption="獲取資訊失敗";
return;
}
else
{
Label6->Caption="獲取資訊成功";
Memo1->Lines->Clear();
EnumChildWindows(hwnd, (int (__stdcall *)())EnumChildWinProc,0);
String xm=Form1->Memo2-> Lines-> Strings[28] ;
char xmtx [255];
hwnd=(HWND)StrToInt(xm);
GetWindowText(hwnd,xmtx,255);
int wndcaption;
SendMessage(hwnd, WM_GETTEXT, 255, Integer(&wndcaption));
String mstr=xmtx;
Memo3->Lines->Add(mstr);
}
}
//---------------------------------------------------------------------------
uj5u.com熱心網友回復:
我先遍歷視窗的所有句柄,然后把句柄,類名,TEXT資訊添加到MEMO1里,把句柄添加到memo2里,獲取memo2的句柄,然后根據這個句柄獲取text資訊,為什么獲取不到呢?謝謝各位大哥哈。uj5u.com熱心網友回復:
各位大俠 救命啊uj5u.com熱心網友回復:
首先,你要確定獲取到的句柄正確。其次,Memo組件的內容,用GetWindowText就可以獲取到。uj5u.com熱心網友回復:
我獲取到得句柄是正確的哈,填寫到Memo里面也是正確的,我對應過了,也是用getwindowtext獲取的可以米獲取到哈,代碼已經發了,請教各位大俠我錯哪里了。uj5u.com熱心網友回復:
WindowsForms10.EDIT.app.0.2c908d5 這個是啥控制元件uj5u.com熱心網友回復:
看起來是.NET生成的視窗。uj5u.com熱心網友回復:
我也遇到同樣的問題,求解!!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/148754.html
