User interface 如何在Autohotkey中将gui控件添加到分层gui

User interface 如何在Autohotkey中将gui控件添加到分层gui,user-interface,autohotkey,User Interface,Autohotkey,当我添加以下内容时: 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.p

当我添加以下内容时:

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之后,您可以销毁它,然后创建一个新的GUI,添加动态添加的新控件。请记住,如果您不想销毁以前的Gui,可以给新Gui一个随机名称,然后在销毁以前的Gui时显示它


我希望这是有意义的。

您使用的是什么版本的Autohotkey和什么gdi库?Autohotkey_L v1.1.14.03来自
ahkscript.org
以及附带的gdip.ahk(DllCall-gdiplus,gdi32)。我的windows 7是32位。DllCall的错误级别和返回值是什么?无错误。以上代码已完成,并以最佳状态显示我的gui窗口(具有透明的png背景)。看似分层的gui不允许添加gui控件。
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
}