本帖最后由 298311657 于 2012-8-3 21:59 编辑
#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GDIPlus.au3>
Global $IconInfo[3][5]
Func IconInfo_Loading()
$IconInfo[0][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_mini_highlight.png")
$IconInfo[0][1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_mini_down.png")
$IconInfo[0][2] = False
$IconInfo[1][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_max_highlight.png")
$IconInfo[1][1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_max_down.png")
$IconInfo[1][2] = False
$IconInfo[2][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_close_highlight.png")
$IconInfo[2][1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_close_down.png")
$IconInfo[2][2] = False
EndFunc ;==>IconInfo_Loading
Global $hGUI
Global $Width = 480, $Height = 320
_GDIPlus_Startup()
$hGUI = GUICreate("CrossDoor", $Width, $Height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
$cmdMini = GUICtrlCreateButton("", 380, 0, 28, 20)
GUICtrlSetTip(-1, "最小化窗口")
$cmdMax = GUICtrlCreateButton("", 408, 0, 28, 20)
GUICtrlSetTip(-1, "最大化窗口")
$cmdClose = GUICtrlCreateButton("", 436, 0, 39, 20)
GUICtrlSetTip(-1, "关闭窗口")
Global $Buttoninfo[3] = [GUICtrlGetHandle($cmdMini), GUICtrlGetHandle($cmdMax), GUICtrlGetHandle($cmdClose)]
IconInfo_Loading()
$bg = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\ok.png")
$hGraphic = _GDIPlus_ImageGetGraphicsContext($bg)
$Bgbitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphic)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($Bgbitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $bg, 0, 0, $Width, $Height)
$Ban = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\logo.png")
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Ban, 1, 1, 478, 20)
For $i = 0 To UBound($Buttoninfo) - 1
$trect = _WinAPI_GetWindowRect($Buttoninfo[$i])
$x = DllStructGetData($trect, "left")
$y = DllStructGetData($trect, "top")
$w = DllStructGetData($trect, "right") - DllStructGetData($trect, "left")
$h = DllStructGetData($trect, "Bottom") - DllStructGetData($trect, "top")
$trect = _WinAPI_GetWindowRect($hGUI)
$x = $x - DllStructGetData($trect, "left")
$y = $y - DllStructGetData($trect, "top")
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $IconInfo[$i][0], $x, $y, $w, $h)
Next
SetBitmap($hGUI, $Bgbitmap)
GUISetState()
$ControlGUI = GUICreate("ControlGUI", 207, 23, 32, 40, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_MDICHILD, $hGUI)
GUISetFont(11, 400, -1, "Comic Sans MS")
GUISetBkColor(0x123456, $ControlGUI)
$hinput = GUICtrlCreateInput("", 0, 0, 207, 23)
_API_SetLayeredWindowAttributes($ControlGUI, 0x123456, 195)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
AdlibRegister("ReduceMem", 60000) ;定时清理内存
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($Bgbitmap)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local Const $BCN_HOTITEMCHANGE = -1249
Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
Local $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")
Switch $nNotifyCode
Case $BCN_HOTITEMCHANGE; Win XP 支持
If BitAND($dwFlags, 0x10) = 0x10 Then
FlashCtl($hCtrl, True)
ElseIf BitAND($dwFlags, 0x20) = 0x20 Then
FlashCtl($hCtrl, False)
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Dim $iIDFrom = BitAND($iwParam, 0xFFFF)
Dim $iCode = BitShift($iwParam, 16)
Switch $iIDFrom
Case $cmdMini
If $iCode = $BN_CLICKED Then WinSetState($hWnd,"",@SW_MINIMIZE)
Case $cmdMax
If $iCode = $BN_CLICKED Then WinSetState($hWnd,"",@SW_MAXIMIZE)
Case $cmdClose
If $iCode = $BN_CLICKED Then Exit
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func FlashCtl($hControl, $iFlag)
_GDIPlus_GraphicsClear($hGraphic2, 0x00FFFFFF)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $bg, 0, 0, $Width, $Height)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Ban, 1, 1, 478, 20)
For $i = 0 To UBound($Buttoninfo) - 1
$trect = _WinAPI_GetWindowRect($Buttoninfo[$i])
$x = DllStructGetData($trect, "left")
$y = DllStructGetData($trect, "top")
$w = DllStructGetData($trect, "right") - DllStructGetData($trect, "left")
$h = DllStructGetData($trect, "Bottom") - DllStructGetData($trect, "top")
$trect = _WinAPI_GetWindowRect($hGUI)
$x = $x - DllStructGetData($trect, "left")
$y = $y - DllStructGetData($trect, "top")
If $iFlag And $hControl = $Buttoninfo[$i] Then
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $IconInfo[$i][1], $x, $y, $w, $h)
Else
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $IconInfo[$i][0], $x, $y, $w, $h)
EndIf
Next
SetBitmap($hGUI, $Bgbitmap)
Sleep(30)
EndFunc
Func SetBitmap($hGUI, $hImage, $iOpacity = 255)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_DeleteObject($hBitmap)
EndFunc ;==>SetBitmap
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
Switch $hWnd
Case $hGUI
Switch $iMsg
Case $WM_NCHITTEST
Return $HTCAPTION
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NCHITTEST
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)
If @error Then
Return SetError(@error, 0, 0)
ElseIf $Ret[0] = 0 Then
Return SetError(4, 0, 0)
Else
Return 1
EndIf
EndFunc ;==>_API_SetLayeredWindowAttributes
Func _ReduceMemory($i_PID = -1);内存释放函数
If $i_PID <> -1 Then
Local $ai_Handle = DllCall("kernel32.dll", "int", "OpenProcess", "int", 0x1f0fff, "int", False, "int", $i_PID)
Local $ai_Return = DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", $ai_Handle[0])
DllCall("kernel32.dll", "int", "CloseHandle", "int", $ai_Handle[0])
Else
Local $ai_Return = DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)
EndIf
Return $ai_Return[0]
EndFunc ;==>_ReduceMemory
Func ReduceMem()
_ReduceMemory(@AutoItPID)
EndFunc ;==>ReduceMem
|