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

时间:2014-07-03 03:37:01

标签: 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.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
}

它包含在上面的代码中

1 个答案:

答案 0 :(得分:1)

您无法显示在&#34; Gui,Show&#34;

之后添加的控件

这是我的方法,在显示GUI之后,你可以销毁它然后创建一个新的gui添加你动态添加的新控件。记住,如果你不想破坏以前的Gui,你可以给新Gui一个随机名称,然后在破坏前一个名字的同时显示它。

我希望这是有道理的。