vb中API函数findwindow的详细用法

 我来答
yfcp
2015-12-10 · 知道合伙人软件行家
yfcp
知道合伙人软件行家
采纳数:1748 获赞数:5545
有多年网站建设相关工作经验。熟悉ASP、ASP.net、VB、JavaScript、HTML等语言和CSS、Ajax等相关技术。

向TA提问 私信TA
展开全部
vb中FindWindow函数可以用来返回窗体的句柄。
1、VB6.0中的API声明:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
2、具体使用:
dim i as long
i=FindWindow(vbNullString,"窗体的标题")
注意:这里的vbNullString是空的,没有任何字符,即不传递。和""空字符串是不一样的!
3、例子:
有一个标题名字是计算器的窗体或软件,获取这个计算器的句柄
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim i As Long
i = FindWindow(vbNullString, "计算器")
msgbox& i '显示窗体句柄
End sub
joychen_
2014-08-08 · TA获得超过1747个赞
知道大有可为答主
回答量:1617
采纳率:100%
帮助的人:1841万
展开全部
就是按照窗口的类名和标题查找顶层窗口。

微软官方说法如下:

The FindWindow function retrieves a handle to the top-level window
whose class name and window name match the specified strings. This function does
not search child windows. This function does not perform a case-sensitive
search.

To search child windows, beginning with a specified child window, use the
FindWindowEx
function.

Syntax
HWND FindWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName
);

Parameters

lpClassName
[in] Pointer to a null-terminated string that specifies the class name or a
class atom created by a previous call to the RegisterClass or
RegisterClassEx
function. The atom must be in the low-order word of lpClassName; the
high-order word must be zero.
If lpClassName points to a string, it specifies the window class name.
The class name can be any name registered with RegisterClass or
RegisterClassEx, or any of the predefined control-class names.

If lpClassName is NULL, it finds any window whose title matches the
lpWindowName parameter.

lpWindowName
[in] Pointer to a null-terminated string that specifies the window name (the
window's title). If this parameter is NULL, all window names match.
更多追问追答
追问

这为什么不对?

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

a = FindWindow(0, "计算器")

api所要求的NULL值和空字符串不是一回事和,需要传一个0进去。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式