怎么通过c语言 获得 浏览器句柄啊

怎么通过c语言 获得 浏览器句柄啊,第1张

给你个例子

HWND GetDlgItem( int nID ) const;

Retrieves the specified child window

GetDlgItem(ID)->GetWindowText(str)

CTestDlg 类中 声明 CTestA NewForm;

然后

void CTestDlg::OnButton1()

{

NewForm=new CTestA;

NewForm->Create(IDD_TestA_DIALOG,this);

NewForm->ShowWindow(SW_SHOW);

}

然后

void CTestDlg::OnButton2()

{

if(::IsWindow(NewForm->GetSafeHwnd()))

{

if(::IsWindowVisible(NewForm->GetSafeHwnd()))

{

AfxMessageBox("窗体存在");

}

else

{

AfxMessageBox("窗体不存在");

}

}

}

最后别忘了在新窗口中重载

void CTestADlg::PostNcDestroy()

{

delete this;

CDialog::PostNcDestroy();

}

using System;

using SystemRuntimeInteropServices;

using SystemText;

using SystemCollectionsGeneric;

class CSharpAPIsDemo

{

private delegate bool WNDENUMPROC(IntPtr hWnd, int lParam);

[DllImport("user32dll")]

private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, int lParam);

//[DllImport("user32dll")]

//private static extern IntPtr FindWindowW(string lpClassName, string lpWindowName);

[DllImport("user32dll")]

private static extern int GetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedTypeLPWStr)]StringBuilder lpString, int nMaxCount);

[DllImport("user32dll")]

private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedTypeLPWStr)]StringBuilder lpString, int nMaxCount);

public struct WindowInfo

{

public IntPtr hWnd;

public string szWindowName;

public string szClassName;

}

public WindowInfo[] GetAllDesktopWindows()

{

List<WindowInfo> wndList = new List<WindowInfo>();

//enum all desktop windows

EnumWindows(delegate(IntPtr hWnd, int lParam)

{

WindowInfo wnd = new WindowInfo();

StringBuilder sb = new StringBuilder(256);

//get hwnd

wndhWnd = hWnd;

//get window name

GetWindowTextW(hWnd, sb, sbCapacity);

wndszWindowName = sbToString();

//get window class

GetClassNameW(hWnd, sb, sbCapacity);

wndszClassName = sbToString();

//add it into list

wndListAdd(wnd);

return true;

}, 0);

return wndListToArray();

}

}

比较简单,如果有不明白可以消息我。

你这个程序是捕捉0到9的按键状态,按下再松开时才会记录,想要识别所有按键,把for循环范围扩大。

比如for(charch=32;ch<=127;ch++)这样就包含了特殊符号及大小写字母还有数字。

但是,这个代码是有问题的!

一、你这个代码需在键位已经按下后启动才能识别,否则启动时没有按下对应键位,程序就结束了。要嵌套死循环,让其一直检测。

二、直接扩大ASCII区间,像上面的那样32~127,识别字母区间会被防毒软件直接判断为病毒!!。

三、GetAsyncKeyState不是C语言库函数,是window的函数,换其它 *** 作系统就失效。

GetAsyncKeyState返回值最高位为1则说明对应ch的键被按下,所以这里用&0x8000来判断最高位。

四、想要捕获其它软件界面内容还有很多方法,比如:

1、通过windowAPI函数FindWindow来获取窗口句柄。

2、遍历窗口下控件句柄,找到输入框句柄。

3、通过窗口句柄找到进程id(GetWindowThreadProcessId函数),再通过id获取进程句柄(OpenProcess函数)。

4、向目标进程申请内存(VirtualAllocEx),再通过PostMessage函数异步发送消息获取目标控件内的内容(具体消息要结合控件类型,另外注意PostMessage是异步执行)。

具体自行查阅资料,一言两语说不清,上面步骤需先搞懂window消息机制。

注意:以上方法依然只限window系统,且有数据保护的控件无法获取。

五、或简单暴力的方法,直接写个定时截图,只要硬盘够不停桌面截图。

但不论写什么程序,和装摄像头一样,终究都会被发现。!!!!!!!!!!!!!

以上就是关于怎么通过c语言 获得 浏览器句柄啊全部的内容,包括:怎么通过c语言 获得 浏览器句柄啊、VC获取对话框句柄问题、C#用API如何遍历所有窗口句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10127597.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存