本帖最后由 xyold1 于 2015-10-10 20:12 编辑
我要在透明的子窗体上作图,显示一些信息,而在画半透明图的时候出现了一些问题
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
Local $hGUI, $hGraphic, $hPen,$hGUI2
; Create GUI
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
$hGUI2 = GUICreate("透明", 280, 220, 0,0, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$hGUI)
GUISetBkColor(0x00ff00)
_API_SetLayeredWindowAttributes($hGUI2, 0x00ff00)
GUISetState()
; Draw line
_GDIPlus_Startup ()
;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI2)
$hPen = _GDIPlus_PenCreate (0x55ff0000,10)
_GDIPlus_GraphicsDrawLine ($hGraphic, 10, 150, 390, 150, $hPen)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
_GDIPlus_PenDispose ($hPen)
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_Shutdown ()
EndFunc ;==>_Main
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)
Local Const $AC_SRC_ALPHA = 1
Local Const $ULW_ALPHA = 2
Local Const $LWA_ALPHA = 0x2
Local Const $LWA_COLORKEY = 0x1
If Not $isColorRef Then
$i_transcolor = Hex(String($i_transcolor), 6)
$i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
EndIf
Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
Select
Case @error
Return SetError(@error, 0, 0)
Case $Ret[0] = 0
Return SetError(4, 0, 0)
Case Else
Return 1
EndSelect
EndFunc ;==>_API_SetLayeredWindowAttributes
上面的代码$hGUI2是屏蔽了00ff00颜色的透明窗口,用红色半透明的画笔DrawLine,线不是红色的
如下图
不是下面的半透明红色
那么如何让半透明的颜色正确显示呢
是在别的控件上画图
还是更改窗体透明的方式呢 |