查看窗口名 调用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. ...
随机推荐
- [每日一题]ES6中为什么要使用Symbol?
关注「松宝写代码」,精选好文,每日面试题 加入我们一起学习,day day up 作者:saucxs | songEagle 来源:原创 一.前言 2020.12.23日刚立的flag,每日一题,题目 ...
- javaNio 通道和缓冲区
/** * 大多数操作系统可以利用虚拟内存将文件或文件一部分映射到内存中,然后这个文件就可以被当做内存数组一样被访问:避免底层IO的开销<p> * [通道]是一种用于磁盘文件的一种抽象:& ...
- JAVA编程能力提升学习图
阿里大神毕玄整理的关于进阶JAVA的学习体系,知道下...
- filebeat7.5.2 在 windows server 2008 R2 设置系统服务报错
今天在windows server 2008 R2 设置filebeat为系统服务报错(在 windows 10 .windows server 2012.windows server 2019下安装 ...
- LeapMotion控制器 java语言开发笔记--(Java开发环境的准备)
(1)官方文档说的是必须是JDK6,JDK7,我试了一下JDK8也是可以的 (2)我是在Windows系统下用的是Eclipse Java的开发环境这里不再多说.将下载的JDK里面的java.dll和 ...
- ES6 对象拓展方法
一,ES6 对象拓展方法 ES6为对象提供了一些拓展方法,下面列举几个比较常见的对象拓展方法.
- 如何写一个自己的组件库,打成NPM包,并上传到NPM远程
1.首先使用vue create my_project 构建一个自己的Vue项目 2.vue.config.js和package.json配置如下,做了些修改 const path = require ...
- 【JavaWeb】AJAX 请求
AJAX 请求 什么是 AJAX AJAX(Asynchronous JavaScript And XMl),即异步 JS 和 XML.是指一种创建交互式网页应用的网页开发技术. AJAX 是一种浏览 ...
- LeetCode237 删除链表中的节点
请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点. 现有一个链表 -- head = [4,5,1,9],它可以表示为: 4 -> 5 -> 1 - ...
- CAN总线采样点测试
采样点是什么? 采样点是接受节点判断信号逻辑的位置,CAN通讯属于异步通讯.需要通过不断的重新同步才能保证收发节点的采样准确. 若采样点太靠前,则因为线缆原因,DUT外发报文尚未稳定,容易发生采样错误 ...