package main
/*
#include <malloc.h>
#include <windows.h>
HDC *hdcArr
BOOL CALLBACK EnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
for (int i = 0; i < (_msize(hdcArr) / sizeof(HDC)); i++) {
if (hdcArr[i] == NULL) {
hdcArr[i] = hdcMonitor;
break;
}
}
return TRUE;
}
void Init() {
int count = GetSystemMetrics(SM_CMONITORS);
hdcArr = (HDC*)malloc(sizeof(HDC) * count);
memset(hdcArr, 0, sizeof(HDC) * count);
}
HDC* GetHDC() {
return *hdcArr;
}
*/
import "C"
import (
"fmt"
"reflect"
"unsafe"
".../w32"
)
func main() {
var hdc w32.HDC
hdc = w32.GetDC(0)
C.Init()
w32.EnumDisplayMonitors(hdc, nil, reflect.ValueOf(C.EnumProc).Pointer(), 0)
t := (*[]w32.HDC)(unsafe.Pointer(&C.hdcArr))
cx := w32.GetDeviceCaps((*t)[0], w32.HORZRES)
fmt.Println(cx)
}
我写了上面的源代码。
我想要的是将 cgo 的 HDC 数组导入到 w32.HDC 数组中,以了解每个监视器的宽度和高度值。
但是,如果您导入t: = (* [] w32.HDC) unsafe.Pointer (& C.hdcArr))并调用,则cx: = w32.GetDeviceCaps ((* t) [0], w32.HORZRES)仅返回 0。
如何使用 cgo 查找多个显示器的宽度和高度?
拉丁的传说
相关分类