Показать полную графическую версию : png или ico вместо обычной кнопки,как реализовать?
Здраствуйте...
1.Как вместо кнопки закрыть , поставить свои 3 изображения, таким образом, что бы при наведении и нажатии изображение изменялось?
2.Как вместо кнопки запуск , установить свое изображение формата png , таким же образом как и в пункте 1 ?
#Include <WindowsConstants.au3>
#Include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>
#Include <GDIPlus.au3>
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\1660807-1.png')
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_Shutdown()
$hForm = GUICreate('Здраствуйте', 620, 460, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
_WinAPI_UpdateLayeredWindowEx($hForm, -1, -1, $hBitmap, 255)
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')
GUISetState()
$iPos = WinGetPos($hForm)
$hChild = GUICreate('', 620, 460, $iPos[0], $iPos[1], $WS_POPUP, $WS_EX_LAYERED, $hForm)
GUISetBkColor(0xFF00DC)
$iButton = GUICtrlCreateButton('Закрыть', 568, 2, 50, 20)
$iButton1 = GUICtrlCreateButton('Запуск', 40, 68, 50, 20)
_WinAPI_SetLayeredWindowAttributes($hChild, 0xFF00DC, 255)
GUIRegisterMsg($WM_MOVE, 'WM_MOVE')
GUISetState()
While 1
Switch GUIGetMsg()
Case -3, $iButton
Exit
EndSwitch
Switch GUIGetMsg()
Case $iButton1
ShellExecute('drv\Ex.exe')
EndSwitch
WEnd
Func WM_MOVE($hWnd, $iMsg, $wParam, $lParam)
Switch $hWnd
Case $hForm
$iPos = _WinAPI_GetPosFromRect(_WinAPI_GetWindowRect($hWnd))
WinMove($hChild, '', $iPos[0], $iPos[1])
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
Switch $hWnd
Case $hForm
Switch _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
Case $HTCLIENT
Return $HTCAPTION
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
изображение( фон)
http://savepic.su/1389277m.png (http://savepic.su/1389277.htm)
1660807-1.png
Спасибо за внимание
посмотрите в справке GUICtrlSetImage
Vsirf, вот, только у меня при активности кнопки картинка исчезает.
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
$Gui=GUICreate('пример', 300, 220, -1, -1, BitOr($WS_BORDER, $WS_POPUP, $WS_SYSMENU))
; GUICreate('пример', 300, 220)
; =====================================
$hImage1 = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 27)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 112)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 25)
$Button = GUICtrlCreateButton("", 300-27, 2, 25, 25)
_GUICtrlButton_SetImageList(-1, $hImage1, 1, 4)
; =====================================
$hImageList = _GUIImageList_Create(66, 91, 5)
_GDIPlus_Startup()
_Image(@ScriptDir & '\Image1.png')
_Image(@ScriptDir & '\Image2.png')
_Image(@ScriptDir & '\Image3.png')
_GDIPlus_Shutdown()
; =====================================
$Button1 = GUICtrlCreateButton("", 10, 50, 80, 100)
_GUICtrlButton_SetImageList(-1, $hImageList, 1)
GUISetState()
While 1
Switch GUIGetMsg()
Case $Button1
MsgBox(0, 'Сообщение', 'е')
Case $GUI_EVENT_CLOSE, $Button
ExitLoop
EndSwitch
WEnd
Func _Image($Path)
$h_Image = _GDIPlus_BitmapCreateFromFile($Path)
$h_Bitmap =_GDIPlus_BitmapCreateHBITMAPFromBitmap($h_Image)
_GUIImageList_Add($hImageList, $h_Bitmap)
_GDIPlus_ImageDispose($h_Image)
_WinAPI_DeleteObject($h_Bitmap)
EndFunc
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
$Gui=GUICreate("Тест", 300, 220, -1, -1, BitOr($WS_BORDER, $WS_POPUP, $WS_SYSMENU))
$btn1 = GUICtrlCreateButton("", 300-23, 2, 21, 21, $BS_ICON)
GUICtrlSetImage($btn1, "shell32.dll", -28, 0)
$btn2 = GUICtrlCreateButton("", 115, 66, 40, 40, $BS_ICON)
GUICtrlSetImage($btn2, "shell32.dll", -162)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
Switch GUIGetMsg()
Case $btn2
MsgBox(0, 'Сообщение', 'е')
Case $GUI_EVENT_CLOSE, $btn1
ExitLoop
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam
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 and Above
If BitAND($dwFlags, 0x10) = 0x10 Then
Switch $nID
Case $btn1
GUICtrlSetImage($btn1, "shell32.dll", -113, 0)
Case $btn2
GUICtrlSetImage($btn2, "shell32.dll", -195)
EndSwitch
ElseIf BitAND($dwFlags, 0x20) = 0x20 Then
Switch $nID
Case $btn1
GUICtrlSetImage($btn1, "shell32.dll", -28, 0)
Case $btn2
GUICtrlSetImage($btn2, "shell32.dll", -162)
EndSwitch
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
посмотрите в справке GUICtrlSetImage »
Все перечитал, но как сделать что бы картинка менялась при наведении и нажатии?
вот, только у меня при активности кнопки картинка исчезает. »
надо что бы возвращалась в начальное состояние
может попробовать с помощью GUICtrlOnHover ?
madmasles
25-02-2012, 02:26
только у меня при активности кнопки картинка исчезает. »Чтобы нормально работало, в ImageList должно быть не менее пяти иконок(картинок), а не три, как в Вашем примере.
Чтобы нормально работало, в ImageList должно быть не менее пяти иконок(картинок), а не три, как в Вашем примере. »
madmasles, сделал,но изображение только на одной кнопке,на второй не отображается :search:
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
GUICreate('Добро пожаловать', 600, 300)
GUICtrlCreatePic(@ScriptDir & '\Resources\gfxinstall.jpg', 0, 0, 600, 300)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()
$hImageList = _GUIImageList_Create(35, 22, 5)
_GDIPlus_Startup()
_Image(@ScriptDir & '\Resources\png\1.png')
_Image(@ScriptDir & '\Resources\png\2.png')
_Image(@ScriptDir & '\Resources\png\3.png')
_Image(@ScriptDir & '\Resources\png\4.png')
_Image(@ScriptDir & '\Resources\png\5.png')
_GDIPlus_Shutdown()
$Button1 = GUICtrlCreateButton("", 10, 50, 35, 22)
_GUICtrlButton_SetImageList(-1, $hImageList, 1)
; =====================================
$hImageList1 = _GUIImageList_Create(35, 22, 5)
_GDIPlus_Startup()
_Image(@ScriptDir & '\Resources\png\1.png')
_Image(@ScriptDir & '\Resources\png\2.png')
_Image(@ScriptDir & '\Resources\png\3.png')
_Image(@ScriptDir & '\Resources\png\4.png')
_Image(@ScriptDir & '\Resources\png\5.png')
_GDIPlus_Shutdown()
$Button2 = GUICtrlCreateButton("", 10, 150, 35, 22)
_GUICtrlButton_SetImageList(-1, $hImageList1, 1)
GUISetState()
While 1
Switch GUIGetMsg()
Case -3, $Button1
Exit
EndSwitch
Switch GUIGetMsg()
Case -3, $Button2
Exit
EndSwitch
WEnd
Func _Image($Path)
$h_Image = _GDIPlus_BitmapCreateFromFile($Path)
$h_Bitmap =_GDIPlus_BitmapCreateHBITMAPFromBitmap($h_Image)
_GUIImageList_Add($hImageList, $h_Bitmap)
_GDIPlus_ImageDispose($h_Image)
_WinAPI_DeleteObject($h_Bitmap)
EndFunc
и еще,как кнопку сделать прозрачной,что бы отображалась лиш картинка?
madmasles, AZJIO, ferget, Почти решил вопрос...
AZJIO, Вот таким образом кнопка не пропадает :
$hImageList = _GUIImageList_Create(35, 22, 5)
_GDIPlus_Startup()
_Image(@ScriptDir & '\Resources\png\1.png', $hImageList)
_Image(@ScriptDir & '\Resources\png\2.png', $hImageList)
_Image(@ScriptDir & '\Resources\png\3.png', $hImageList)
_Image(@ScriptDir & '\Resources\png\4.png', $hImageList)
_Image(@ScriptDir & '\Resources\png\5.png', $hImageList)
_GDIPlus_Shutdown()
Вот так изображение отображается на всех кнопках:
Func _Image($Path, ByRef $newImage)
$h_Image = _GDIPlus_BitmapCreateFromFile($Path)
$h_Bitmap =_GDIPlus_BitmapCreateHBITMAPFromBitmap($h_Image)
_GUIImageList_Add($newImage, $h_Bitmap)
_GDIPlus_ImageDispose($h_Image)
_WinAPI_DeleteObject($h_Bitmap)
EndFunc
Теперь следующий вопрос:
Это все хорошо работает если фон JPG изображение в обычном окне ,но, все же как сделать кнопку прозрачной( что бы отображалось лишь изображение ),и как это все сделать если фон - png изображение,и на нем кнопки с png изображениями ?
Код и изображение в шапке темы...
Если можно,наведите пример не с одной кнопкой,а с двумя, что бы для меня понятнее было,спасибо :)
madmasles
25-02-2012, 20:40
Vsirf,
Попробуйте, например, так.#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $aIcon[3][5] = [[0, -3, -2, -5],[0, -4, -2, -3],[0, -5, -2, -4]], _
$aText[3] = ['Minimize', 'MsgBox', 'Exit']
$hGui = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Test', 200, 100, -1, -1, $WS_POPUP, $WS_EX_DLGMODALFRAME)
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)('Таскать можно', 0, 0, 140, 22, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)('', 0, 22, 200, 2, -1, $WS_EX_STATICEDGE)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) 2
$aIcon[$i][0] = GUICtrlCreateIcon (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateIcon.htm)('', 0, 140 + $i * 20, 3, 16, 16)
GUICtrlSetCursor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetCursor.htm)(-1, 0)
GUICtrlSetTip (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetTip.htm)(-1, $aText[$i])
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
_ChangeImage()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE, $aIcon[2][0]
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $aIcon[0][0]
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_MINIMIZE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_minimize))
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $aIcon[1][0]
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, 'Info', '2 Icon click', 0, $hGui)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _ChangeImage()
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $s_IconFile = @SystemDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@systemdir) & '\user32.dll'
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $a_Cursor = GUIGetCursorInfo (http://www.autoitscript.com/autoit3/docs/functions/GUIGetCursorInfo.htm)()
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 0 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) 2
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $a_Cursor[4] = $aIcon[$i][0] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $a_Cursor[2] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aIcon[$i][4] <> 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetImage (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetImage.htm)($aIcon[$i][0], $s_IconFile, $aIcon[$i][1])
$aIcon[$i][4] = 1
ConsoleWrite (http://www.autoitscript.com/autoit3/docs/functions/ConsoleWrite.htm)($i + 1 & ' Icon click' & @LF (http://www.autoitscript.com/autoit3/docs/macros.htm#@lf))
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aIcon[$i][4] <> 2 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetImage (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetImage.htm)($aIcon[$i][0], $s_IconFile, $aIcon[$i][2])
$aIcon[$i][4] = 2
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aIcon[$i][4] <> 3 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetImage (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetImage.htm)($aIcon[$i][0], $s_IconFile, $aIcon[$i][3])
$aIcon[$i][4] = 3
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc) ;==>_ChangeImage
madmasles, мне надо с png изображениями , и фон png изображение :)
с иконками я неумею работать :)
madmasles
26-02-2012, 01:31
мне надо с png изображениями »
Посмотрите здесь: Поддержка иконок и изображений, содержащих прозрачность (Alpha канал) (http://autoit-script.ru/index.php/topic,49)
Vsirf, Я сделал ошибку, не передав в функцию дескриптор списка изображений, используя один список, теперь рисунки добавляются каждый в свой список изображений. И работает.
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
$Gui=GUICreate('пример', 300, 220, -1, -1, BitOr($WS_BORDER, $WS_POPUP, $WS_SYSMENU))
; GUICreate('пример', 300, 220)
; =====================================
$hImage1 = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 27)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 112)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 25)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 25)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 27)
$Button = GUICtrlCreateButton("", 300-27, 2, 25, 25)
_GUICtrlButton_SetImageList(-1, $hImage1, 1, 4)
; =====================================
$hImageList = _GUIImageList_Create(66, 91, 5)
_GDIPlus_Startup()
_Image($hImageList, @ScriptDir & '\Image1.png')
_Image($hImageList, @ScriptDir & '\Image2.png')
_Image($hImageList, @ScriptDir & '\Image3.png')
_Image($hImageList, @ScriptDir & '\Image1.png')
_Image($hImageList, @ScriptDir & '\Image1.png')
_GDIPlus_Shutdown()
; =====================================
$Button1 = GUICtrlCreateButton("", 10, 50, 80, 100)
_GUICtrlButton_SetImageList(-1, $hImageList, 1)
; =====================================
$hImageList1 = _GUIImageList_Create(66, 91, 5)
_GDIPlus_Startup()
_Image($hImageList1, @ScriptDir & '\Image1.png')
_Image($hImageList1, @ScriptDir & '\Image2.png')
_Image($hImageList1, @ScriptDir & '\Image3.png')
_Image($hImageList1, @ScriptDir & '\Image1.png')
_Image($hImageList1, @ScriptDir & '\Image1.png')
_GDIPlus_Shutdown()
; =====================================
$Button2 = GUICtrlCreateButton("", 100, 50, 80, 100)
_GUICtrlButton_SetImageList(-1, $hImageList1, 1)
GUISetState()
While 1
Switch GUIGetMsg()
Case $Button1
MsgBox(0, 'Сообщение', 'е')
Case $Button2
MsgBox(0, 'Сообщение', 'е')
Case $GUI_EVENT_CLOSE, $Button
ExitLoop
EndSwitch
WEnd
Func _Image($hImageList, $Path)
$h_Image = _GDIPlus_BitmapCreateFromFile($Path)
$h_Bitmap =_GDIPlus_BitmapCreateHBITMAPFromBitmap($h_Image)
_GUIImageList_Add($hImageList, $h_Bitmap)
_GDIPlus_ImageDispose($h_Image)
_WinAPI_DeleteObject($h_Bitmap)
EndFunc
Так как я не сразу догадался, об ошибке, то делал второй вариант, тоже не плохой, по принципу Filmstrip. Картинки вставляются в один рисунок, а при использовании указываются координаты нужного участка рисунка.
Вот готовый пример (http://rghost.ru/36712175) (9кб) с картинками в комплекте.
AZJIO, отлично, хорошо придумал, но картинка на кнопке мерцает после нажатия, пропадает,потом заново появляется )))
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.