查看窗口名 调用dll setForegroundWindow
package main import (
"fmt"
"log"
"syscall"
"unsafe"
) var (
user32 = syscall.MustLoadDLL("user32.dll")
procEnumWindows = user32.MustFindProc("EnumWindows")
procGetWindowTextW = user32.MustFindProc("GetWindowTextW")
) func EnumWindows(enumFunc uintptr, lparam uintptr) (err error) {
r1, _, e1 := syscall.Syscall(procEnumWindows.Addr(), 2, uintptr(enumFunc), uintptr(lparam), 0)
if r1 == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
} func GetWindowText(hwnd syscall.Handle, str *uint16, maxCount int32) (len int32, err error) {
r0, _, e1 := syscall.Syscall(procGetWindowTextW.Addr(), 3, uintptr(hwnd), uintptr(unsafe.Pointer(str)), uintptr(maxCount))
len = int32(r0)
if len == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
} func FindWindow(title string) (syscall.Handle, error) {
var hwnd syscall.Handle
cb := syscall.NewCallback(func(h syscall.Handle, p uintptr) uintptr {
b := make([]uint16, 200)
_, err := GetWindowText(h, &b[0], int32(len(b)))
if err != nil {
// ignore the error
return 1 // continue enumeration
}
fmt.Printf("%s\n", syscall.UTF16ToString(b)) if syscall.UTF16ToString(b) == title {
// note the window
hwnd = h
return 0 // stop enumeration
}
return 1 // continue enumeration
})
EnumWindows(cb, 0)
if hwnd == 0 {
return 0, fmt.Errorf("No window with title '%s' found", title)
}
return hwnd, nil
} func main() {
//const title = "OpenTTD"
//const title = "FileZilla FTP Client"
const title = "OpenTTD"
h, err := FindWindow(title)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found '%s' window: handle=0x%x\n", title, h)
}
Go/Golang Trying to get window information via syscall. (As in EnumWindows, etc.) - Stack Overflow - Google Chrome
任务管理器
OpenTTD 1.3.0
openttd.exe 属性
filezilla.exe 属性
OfficePowerManagerWindow
game_manager [Y:\dev\game_manager] - C:\Go\src\os\exec\exec.go - GoLand
CandidateWindow
Mode Indicator
Mode Indicator
电池指示器
Network Flyout
Mode Indicator
Mode Indicator
go_win_api [Y:\dev\go_win_api] - ...\m.go - GoLand
OpenTTD 1.3.0
Found 'OpenTTD 1.3.0' window: handle=0x610d6
CandidateWindow
Mode Indicator
Mode Indicator
电池指示器
Network Flyout
Mode Indicator
Mode Indicator
go_win_api [Y:\dev\go_win_api] - ...\m.go - GoLand
OpenTTD 1.3.0
Get Retrun Value Before setForegroundWindow Invoked: %!s(uintptr=1)
package main import (
"fmt"
"log"
"syscall"
"unsafe"
) var (
user32 = syscall.MustLoadDLL("user32.dll")
procEnumWindows = user32.MustFindProc("EnumWindows")
procGetWindowTextW = user32.MustFindProc("GetWindowTextW")
user32_b, _ = syscall.LoadLibrary("user32.dll")
setForegroundWindow, _ = syscall.GetProcAddress(user32_b, "SetForegroundWindow")
) func EnumWindows(enumFunc uintptr, lparam uintptr) (err error) {
r1, _, e1 := syscall.Syscall(procEnumWindows.Addr(), 2, uintptr(enumFunc), uintptr(lparam), 0)
if r1 == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
} func GetWindowText(hwnd syscall.Handle, str *uint16, maxCount int32) (len int32, err error) {
r0, _, e1 := syscall.Syscall(procGetWindowTextW.Addr(), 3, uintptr(hwnd), uintptr(unsafe.Pointer(str)), uintptr(maxCount))
len = int32(r0)
if len == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
} func FindWindow(title string) (syscall.Handle, error) {
var hwnd syscall.Handle
cb := syscall.NewCallback(func(h syscall.Handle, p uintptr) uintptr {
b := make([]uint16, 200)
_, err := GetWindowText(h, &b[0], int32(len(b)))
if err != nil {
// ignore the error
return 1 // continue enumeration
}
fmt.Printf("%s\n", syscall.UTF16ToString(b)) if syscall.UTF16ToString(b) == title {
// note the window
hwnd = h
return 0 // stop enumeration
}
return 1 // continue enumeration
})
EnumWindows(cb, 0)
if hwnd == 0 {
return 0, fmt.Errorf("No window with title '%s' found", title)
}
return hwnd, nil
} func IntPtr(n int) uintptr {
return uintptr(n)
} func abort(funcname string, err syscall.Errno) {
panic(funcname + " failed: " + err.Error())
} func main() {
//const title = "OpenTTD"
//const title = "FileZilla FTP Client"
const title = "OpenTTD 1.3.0"
h, err := FindWindow(title)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found '%s' window: handle=0x%x\n", title, h) h, err = FindWindow(title)
if err != nil {
log.Fatal(err)
} ret, _, callErr := syscall.Syscall(setForegroundWindow, 1, uintptr(h), IntPtr(0), IntPtr(0))
if callErr != 0 {
abort("Call setForegroundWindow", callErr)
}
fmt.Printf("Get Retrun Value Before setForegroundWindow Invoked: %s\n", ret)
}
https://github.com/golang/go/wiki/WindowsDLLs
查看窗口名 调用dll setForegroundWindow的更多相关文章
- php调用dll经验小结
最近做一个网站,需要频繁使用远程数据,数据接口已经做好.在做转换的时候遇到了性能上的问题:开始打算用php来实现转换,苦苦查了数天,都没有找到直接操作字节的方法.虽然可以使用 pack() 方法将各个 ...
- 摘: VS2010 C++ 调用 DLL (C++编写)
一.为什么需要dll 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有通用性,就可将它构造成相对独立的功能模块并在之后的项目中重复使用. 比较常见的例子是各种应用程序框架,如ATL. ...
- C#程序实现动态调用DLL的研究(转)
摘 要:在<csdn开发高手>2004年第03期中的<化功大法——将DLL嵌入EXE>一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在可执行文件运行时,自动从资 ...
- 在VC中创建并调用DLL
转自:http://express.ruanko.com/ruanko-express_45/technologyexchange6.html 一.DLL简介 1.什么是DLL? 动态链接库英文为DL ...
- 在 C++Builder 工程里调用 DLL 函数
调用 Visual C++ DLL 给 C++Builder 程序员提出了一些独特的挑战.在我们试图解决 Visual C++ 生成的 DLL 之前,回顾一下如何调用一个 C++Builder 创建的 ...
- VB6.0调用DLL
目录 第1章 VB6.0调用DLL 1 1 VC++编写DLL 1 1.1 使用__stdcall 1 1.2 使用 .DEF 文件 1 2 简单数据类型 2 2.1 传 ...
- 在VS2012中采用C++中调用DLL中的函数 (4)
这两天因为需要用到VS2012来生成一个DLL代码,但是之前并没有用过DLL相关的内容,从昨天开始尝试调试DLL的文件调用,起初笔者在网络上找到了3片采用VSXXX版本进行调试的例子,相关的内容见本人 ...
- 在C++中调用DLL中的函数 (3)
1.dll的优点 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有通用性,就可将它构造成相对独立的功能模块并在之后的项目中重复使用.比较常见的例子是各种应用程序框架,ATL.MFC等 ...
- 在C++中调用DLL中的函数 (2)
应用程序使用DLL可以采用两种方式: 一种是隐式链接,另一种是显式链接.在使用DLL之前首先要知道DLL中函数的结构信息. Visual C++6.0在VC\bin目录下提供了一个名为Dumpbin. ...
随机推荐
- 【基础】:Rsync数据同步工具
第二十一节 Rsync数据同步工具 1.1 Rsync介绍 1.1.1 什么是Rsync? 1.1.2 Rsync简介 1.3 Rsync的特性 1.1.4 Rsync的企业工作场景说明 1.2 Rs ...
- 【程序包管理】Linux软件管理之src源码安装编译
在很多时候我们需要自定义软件的特性,这时就需要用到源码安装.那么,网上有很多编译源码的工具,那么,我们怎么知道别人使用的是什么工具呢.其实我也不知道(*^▽^*). 那么本篇博客主要是写C代码的源码安 ...
- SpringBoot进阶教程(六十八)Sentinel实现限流降级
前面两篇文章nginx限流配置和SpringBoot进阶教程(六十七)RateLimiter限流,我们介绍了如何使用nginx和RateLimiter限流,这篇文章介绍另外一种限流方式---Senti ...
- 高并发redis分布式锁
1.方法一 2方法二
- json 与 ajax
json类似与js中的对象,但是json中不能有方法,json相当于python中的字典,但是json中的键值如果是字符串的话,需要加上双引号:ajax是一个前后台配合的技术,它可以让js发送http ...
- swap是干嘛的?
本文截取自:http://hbasefly.com/2017/05/24/hbase-linux/ swap是干嘛的? 在Linux下,SWAP的作用类似Windows系统下的"虚拟内存&q ...
- 智能BPOS小票模板字体的使用
关于伯俊智能BPOS零售小票模板的设置,常用字体"黑体"."宋体"."Arial"这几个字体,在设置的时候看似没有问题, 但是在正真使用打印 ...
- wdcp的一个安全漏洞 2015 9 月
wdcp的一个安全漏洞,非常严重,请大家及时升级和检查 在九月份的时候,wdcp出了一个很严重的安全漏洞,当时也出了补丁更新,具体可看http://www.wdlinux.cn/bbs/thread- ...
- 2018年第九届蓝桥杯B组(201803-----乘积尾零)
标题题目:乘积尾零 如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零? 5650 4542 3554 473 946 4114 3871 9073 90 4329 2758 79 ...
- Python使用urllib,urllib3,requests库+beautifulsoup爬取网页
Python使用urllib/urllib3/requests库+beautifulsoup爬取网页 urllib urllib3 requests 笔者在爬取时遇到的问题 1.结果不全 2.'抓取失 ...