【发布时间】:2014-07-03 03:37:00
【问题描述】:
当我添加这个时:
GUI, Add, Text,, this is my Control in Window
到这些中的任何一行(在新 gui 之后):
#Include %A_ScriptDir%\Gdip.ahk
Gui popmain:New
Gui, +lastfound -resize +AlwaysOnTop -Border +E0x80000 -Caption +ToolWindow
Gui, Color, ffffff
sFile = %A_ScriptDir%\bg.png
mDC_Scr := Gdi_CreateCompatibleDC(0)
pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromFile(sFile)
nWidth := Gdip_GetImageWidth(pBitmap)
nHeight := Gdip_GetImageHeight(pBitmap)
hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
oBitmap := Gdi_SelectObject(mDC_Scr, hBitmap)
Gui, popmain:show, x0 y0 W%nWidth% H%nHeight% ;hide
Gui, popmain: +LastFound
DllCall("UpdateLayeredWindow", "Uint", WinExist(), "Uint", 0, "Uint", 0, "int64P", nWidth|nHeight<<32, "Uint", mDC_Scr, "int64P", 0, "Uint", 0, "UintP", 255<<16|1<<24, "Uint", 2)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Gdi_SelectObject(mDC_Scr, oBitmap)
Gdi_DeleteObject(hBitmap)
Gdi_DeleteDC(mDC_Scr)
return
我的文本控件和任何在窗口上不可见的 gui 控件。 (放置在窗口但不可见)
如何显示 gui 控件?
谢谢
包含 Gdip.ahk:
Gdi_CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "")
{
NumPut(VarSetCapacity(bi, 40, 0), bi)
NumPut(nW, bi, 4)
NumPut(nH, bi, 8)
NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
Return DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
}
Gdi_CreateCompatibleDC(hDC = 0)
{
Return DllCall("gdi32\CreateCompatibleDC", "Uint", hDC)
}
Gdi_SelectObject(hDC, hGdiObj)
{
Return DllCall("gdi32\SelectObject", "Uint", hDC, "Uint", hGdiObj)
}
Gdi_DeleteObject(hGdiObj)
{
Return DllCall("gdi32\DeleteObject", "Uint", hGdiObj)
}
Gdi_DeleteDC(hDC)
{
Return DllCall("gdi32\DeleteDC", "Uint", hDC)
}
Gdip_CreateBitmapFromFile(sFile)
{
VarSetCapacity(wFile, 1023)
DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sFile, "int", -1, "Uint", &wFile, "int", 512)
DllCall("gdiplus\GdipCreateBitmapFromFile", "Uint", &wFile, "UintP", pBitmap)
Return pBitmap
}
Gdip_CreateBitmapFromHICON(hIcon)
{
DllCall("gdiplus\GdipCreateBitmapFromHICON", "Uint", hIcon, "UintP", pBitmap)
Return pBitmap
}
Gdip_CreateHBITMAPFromBitmap(pBitmap, ARGB = 0)
{
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pBitmap, "UintP", hBitmap, "Uint", ARGB)
Return hBitmap
}
Gdip_DisposeImage(pImage)
{
Return DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)
}
Gdip_GetImageWidth(pImage)
{
DllCall("gdiplus\GdipGetImageWidth", "Uint", pImage, "UintP", nW)
Return nW
}
Gdip_GetImageHeight(pImage)
{
DllCall("gdiplus\GdipGetImageHeight", "Uint", pImage, "UintP", nH)
Return nH
}
Gdip_Startup()
{
If Not DllCall("GetModuleHandle", "str", "gdiplus")
DllCall("LoadLibrary" , "str", "gdiplus")
VarSetCapacity(si, 16, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)
Return pToken
}
Gdip_Shutdown(pToken)
{
DllCall("gdiplus\GdiplusShutdown", "Uint", pToken)
If hModule := DllCall("GetModuleHandle", "str", "gdiplus")
DllCall("FreeLibrary" , "Uint", hModule)
Return 0
}
它被包含在上面的代码中
【问题讨论】:
-
什么版本的 Autohotkey 以及你使用什么 gdi 库?
-
Autohotkey_L v1.1.14.03 来自
ahkscript.org并包含 gdip.ahk (DllCall gdiplus, gdi32)。 -
我的 windows 7 是 32 位
-
DllCall的Errorlevel和返回值是多少?
-
没有错误。上面的代码已完成并以最佳状态显示我的 gui 窗口(具有透明的 png 背景)。看似分层的 gui 不允许添加 gui 控件。