怎么获取桌面的句柄

怎么获取桌面的句柄,第1张

启动定时器:

SetTimer();

OnTimer()

{}

取得桌面:

HWND hwnd=GetDesktopWindow();

呵呵,你用画图工具就能做到。

你将一幅画,你准备做成背景的,打开,然后你想怎么写就怎么写,画图里面有文字工具,或者你用手写也行。

写完了保存,然后把那个作为桌面背景。这样就能实现你的目的。

还有,Photoshop也能行,而且它能做更好看的图。

好奇心是你获取知识的动力,好好保持。

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

'这是定义获得窗口句柄的API函数

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long,lParam As Any) As Long '这句是定义向获得窗口句柄发送按键消息的API函数

例子:你先建一个工程

form1caption="12345

画一个command1 名字为 "确定1"

事件

Private Sub Command1_Click()

msgbox MeHwnd '显示确定按钮的句柄

End Sub

生成12345exe

关闭VB6

打开VB6

再建一个工程 代码如下:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Private Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_LBUTTONDOWN = &H201

Private Const WM_LBUTTONUP = &H202

Private Const MK_LBUTTON = &H1

Dim hpwnd As Long, hcwnd As Long

Dim iResult As Long

Private Sub Command1_Click()

hpwnd = FindWindow(vbNullString, "12345")

hcwnd = FindWindowEx(hpwnd, 0, vbNullString, "确定")

SetForegroundWindow hcwnd

iResult = SendMessage(hcwnd, WM_LBUTTONDOWN, 0, 0&)

iResult = SendMessage(hcwnd, WM_LBUTTONUP, 0, 0&)

End Sub

然后先运行 事先生成好的12345exe

再运行后建的那个

你单击确定 就会使12345exe的确定按钮被单击 返回它的hwnd

我的方法是先找到12345exe的主窗口 然后根据主窗口的句柄获得其确定按钮的句柄 再使用sendmessage 发送模拟鼠标左键单击

VB控件的句柄 一般可用mehwnd 方法获得

enumwindows()有两个参数,一个是指向回调函数的指针,一个是用户定义的

lparam

值,

针对每个桌面窗口(或者顶层窗口)它调用回调函数一次。然后回调函数用该窗口句柄做一些处理,比如将它添加到列表中。这个方法保证枚举结果不会被窗口复杂

的层次关系搞乱,因此,一旦有了窗口句柄,我们就可以通过

getwindowtext()

得到窗口标题。

以上就是关于怎么获取桌面的句柄全部的内容,包括:怎么获取桌面的句柄、如何在桌面上画图啊、VB怎样获得桌面指定程序的窗口句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: http://outofmemory.cn/web/9576105.html

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

发表评论

登录后才能评论

评论列表(0条)

保存