找回密码
 加入
搜索
查看: 12187|回复: 16

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

 火.. [复制链接]
发表于 2010-2-20 13:05:28 | 显示全部楼层 |阅读模式
本帖最后由 qq342252004 于 2011-1-25 09:03 编辑

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 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 an  dialog 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
暂时只想到用这个函数来完成!!!其它未深一步的尝试!!!!
发表于 2010-2-20 18:35:40 | 显示全部楼层
楼上的简直没看懂LZ问的问题  。。。。。

评分

参与人数 1金钱 +10 收起 理由
lchl0588 + 10 多谢纠正,当时只想到这个函数!

查看全部评分

发表于 2010-2-20 19:07:15 | 显示全部楼层
回复 1# qq342252004


    搜索一下论坛里面有很多的
http://www.autoitx.com/forum.php ... hlight=%B0%B4%C5%A5
给你一个例子
发表于 2010-2-21 13:07:53 | 显示全部楼层
回复 4# guland
呵呵,的确很多,当时LZ在QQ群里说只搜索到一个相关的帖子.....同时也没有看LZ的标题而回答问题!!
下面是偶搜索的!!!
还不少呢,点此进入寻找答案
发表于 2010-2-21 15:00:39 | 显示全部楼层
单纯只需要在按钮处能点击就建立个透明的Label
发表于 2010-2-21 15:19:00 | 显示全部楼层
学习ing!
学习ing!
学习ing!
 楼主| 发表于 2010-2-21 22:32:58 | 显示全部楼层
单纯只需要在按钮处能点击就建立个透明的Label
afan 发表于 2010-2-21 15:00
#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[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

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。
发表于 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[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

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

评分

参与人数 1金钱 +40 贡献 +10 收起 理由
qq342252004 + 40 + 10 谢谢帮忙问题已解决

查看全部评分

 楼主| 发表于 2010-2-22 08:45:20 | 显示全部楼层
谢谢afan帮忙,问题已解决。
发表于 2010-2-23 08:35:29 | 显示全部楼层
学习学习......
发表于 2010-2-24 22:18:26 | 显示全部楼层
学习中……
发表于 2010-2-27 14:35:45 | 显示全部楼层
佩服佩服!!
api和dll的调用不知从哪儿学,有高人指点吗?
发表于 2011-4-15 00:52:27 | 显示全部楼层
不错 值 得学习
发表于 2011-4-15 16:08:49 | 显示全部楼层
我也是来学习我也是来学习
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-16 15:16 , Processed in 0.089687 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表