qq342252004 发表于 2010-2-20 13:05:28

PNG图片做窗口,如何实现按钮功能?(已解决)

本帖最后由 qq342252004 于 2011-1-25 09:03 编辑

问题如题,代码和图片在附件。

lchl0588 发表于 2010-2-20 14:02:10

本帖最后由 lchl0588 于 2010-2-20 14:03 编辑

其它按钮请参照“GUICtrlCreateButton”函数,
比如偶在帮助的原基础只改了两处,请参照如下代码:#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $Button_1, $Button_2, $msg
    GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("", 10, 30, 100);这里我把内容去掉了!!!如何显示正确的按钮,未做深一步的测试!!!还有后面的坐标一定与背景坐标一致哦!!!
    $Button_2 = GUICtrlCreateButton("", 0, -1);同上

    GUISetState()      ; will display andialog box with 2 button

    ; Run the GUI until the dialog is closed   光有上面的坐标还是不行的!!!,如果你点了下,根本不起作用哦!!!所以要添加下面的命令....
    While 1
      $msg = GUIGetMsg()
      Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                Run('Notepad.exe')    ; Will Run/Open Notepad
            Case $msg = $Button_2
                MsgBox(0, 'Testing', 'Button 2 was pressed')    ; Will demonstrate Button 2 being pressed
      EndSelect
    WEnd
EndFunc   ;==>Example暂时只想到用这个函数来完成!!!其它未深一步的尝试!!!!

guland 发表于 2010-2-20 18:35:40

楼上的简直没看懂LZ问的问题。。。。。

guland 发表于 2010-2-20 19:07:15

回复 1# qq342252004


    搜索一下论坛里面有很多的
http://www.autoitx.com/forum.php?mod=viewthread&tid=326&highlight=%B0%B4%C5%A5
给你一个例子

lchl0588 发表于 2010-2-21 13:07:53

回复 4# guland
呵呵,的确很多,当时LZ在QQ群里说只搜索到一个相关的帖子.....同时也没有看LZ的标题而回答问题!!
下面是偶搜索的!!!
还不少呢,点此进入寻找答案

afan 发表于 2010-2-21 15:00:39

单纯只需要在按钮处能点击就建立个透明的Label

ljlwater 发表于 2010-2-21 15:19:00

学习ing!
学习ing!
学习ing!

qq342252004 发表于 2010-2-21 22:32:58

单纯只需要在按钮处能点击就建立个透明的Label
afan 发表于 2010-2-21 15:00 http://www.autoitx.com/images/common/back.gif#include <GDIPlus.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
Global Const $AC_SRC_ALPHA=1
$x=ObjCreate("WMPlayer.OCX")
#Region ### START Koda GUI section ### Form=
_GDIPlus_Startup()
$hImage=_GDIPlus_ImageLoadFromFile("a1.png")
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$Form=GUICreate("AU3-调用WMPlayer.OCX来播放MP3文件",$width,$height,200,200,$WS_POPUP,$WS_EX_LAYERED)
SetBitmap($Form,$hImage,240)
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=
$Form1=GUICreate("", $width, $height, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $Form)
GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)
$x.stretchToFit=GUICtrlCreateObj($x, 85, 60, 418, 270)
$Label1 = GUICtrlCreateLabel("", 25, 104, 19, 48)
$Label2 = GUICtrlCreateLabel("", 25, 160, 19, 48)
$Label3 = GUICtrlCreateLabel("", 25, 216, 19, 55)
$Label4 = GUICtrlCreateLabel("", 545, 104, 19, 48)
$Label5 = GUICtrlCreateLabel("", 545, 160, 19, 48)
$Label6 = GUICtrlCreateLabel("", 545, 216, 19, 55)
GUISetState()
AdlibEnable ("stretchToFit", 500)
$x.uimode="Full"
$x.url="d:\mp3.mp3"
$x.Controls.play

GUIRegisterMsg($WM_NCHITTEST,"WM_NCHITTEST")

While 1
        _ReduceMemory(@AutoItPID)
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Label1
                        Exit
        EndSwitch
WEnd

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)
                        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle)
      Else
                        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf
        Return $ai_Return
EndFunc

Func stretchToFit()
        $x.stretchToFit=GUICtrlCreateObj($x, 85, 60, 418, 270);非全屏状态时是否伸展到最佳大小
EndFunc

Func WM_NCHITTEST($hwnd,$iMsg,$hPamare,$lPamare)
        if($hwnd=$Form) And ($iMsg=$WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

Func SetBitmap($hGUI, $hImage, $iOpacity)
        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", $AC_SRC_ALPHA)
        _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
        _WinAPI_ReleaseDC (0, $hScrDC)
        _WinAPI_SelectObject($hMemDC, $hOld)
        _WinAPI_DeleteObject($hBitmap)
        _WinAPI_DeleteDC($hMemDC)
        _GDIPlus_ShutDown ()
EndFunc不知道如何建立一个透明的Label,我现在的按钮是用Label。

afan 发表于 2010-2-21 23:08:47

回复 8# qq342252004 #include <GDIPlus.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
Global Const $AC_SRC_ALPHA=1
$x=ObjCreate("WMPlayer.OCX")
#Region ### START Koda GUI section ### Form=
_GDIPlus_Startup()
$hImage=_GDIPlus_ImageLoadFromFile("a1.png")
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$Form=GUICreate("AU3-调用WMPlayer.OCX来播放MP3文件",$width,$height,200,200,$WS_POPUP,$WS_EX_LAYERED)
SetBitmap($Form,$hImage,240)
$Label1 = GUICtrlCreateLabel("", 32, 110, 19, 48)
$Label2 = GUICtrlCreateLabel("", 32, 166, 19, 48)
$Label3 = GUICtrlCreateLabel("", 32, 222, 19, 55)
$Label4 = GUICtrlCreateLabel("", 550, 110, 19, 48)
$Label5 = GUICtrlCreateLabel("", 550, 166, 19, 48)
$Label6 = GUICtrlCreateLabel("", 550, 222, 19, 55)
GUISetState()
#EndRegion ### START Koda GUI section ### Form=
$Form1=GUICreate("", $width, $height, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $Form)
GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)
$x.stretchToFit=GUICtrlCreateObj($x, 85, 60, 418, 270)
GUISetState()
AdlibRegister ("stretchToFit", 500)
$x.uimode="Full"
$x.url="d:\mp3.mp3"
$x.Controls.play

GUIRegisterMsg($WM_NCHITTEST,"WM_NCHITTEST")

While 1
      _ReduceMemory(@AutoItPID)
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Label1
                        Msgbox(0,0,'$Label1')
                Case $Label2
                        Msgbox(0,0,'$Label2')
                Case $Label3
                        Msgbox(0,0,'$Label3')
                Case $Label4
                        Msgbox(0,0,'$Label4')
                Case $Label5
                        Msgbox(0,0,'$Label5')
                Case $Label6
                        Msgbox(0,0,'$Label6')
      EndSwitch
WEnd

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)
                        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle)
      Else
                        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
      EndIf
      Return $ai_Return
EndFunc

Func stretchToFit()
      $x.stretchToFit=GUICtrlCreateObj($x, 85, 60, 418, 270);非全屏状态时是否伸展到最佳大小
EndFunc

Func WM_NCHITTEST($hwnd,$iMsg,$hPamare,$lPamare)
      if($hwnd=$Form) And ($iMsg=$WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

Func SetBitmap($hGUI, $hImage, $iOpacity)
      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", $AC_SRC_ALPHA)
      _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
      _WinAPI_ReleaseDC (0, $hScrDC)
      _WinAPI_SelectObject($hMemDC, $hOld)
      _WinAPI_DeleteObject($hBitmap)
      _WinAPI_DeleteDC($hMemDC)
      _GDIPlus_ShutDown ()
EndFunc

qq342252004 发表于 2010-2-22 08:45:20

谢谢afan帮忙,问题已解决。

lxz 发表于 2010-2-23 08:35:29

学习学习......

nekin 发表于 2010-2-24 22:18:26

学习中……

qixinwb 发表于 2010-2-27 14:35:45

佩服佩服!!
api和dll的调用不知从哪儿学,有高人指点吗?

uxuuexqyxwk 发表于 2011-4-15 00:52:27

不错 值 得学习

smking0204 发表于 2011-4-15 16:08:49

我也是来学习我也是来学习
页: [1] 2
查看完整版本: PNG图片做窗口,如何实现按钮功能?(已解决)