jacq Posted April 13, 2012 Share Posted April 13, 2012 (edited) Welcome. When I press: $Zamknij = GUICtrlCreateButton("Zamknij", 200, 200, 73, 33, $WS_GROUP) Window is closed but you can not turn it on again. You have to enable the program again to make this possible. Return does not work. Code: expandcollapse popup;Biblioteki #include <GDIPlus.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIListBox.au3> #include <ListViewConstants.au3> #include <IE.au3> #include <EditConstants.au3> #include <Process.au3> #include <String.au3> #include <GuiConstants.au3> #include <GuiImageList.au3> ;Własna grafika jako okno programu Global Const $AC_SRC_ALPHA = 1 $dll=DllOpen("user32.dll") _GDIPlus_Startup() $pngSrc = @ScriptDir & "\tlo_tivor.png" GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") $GUI = _GUICreate_Alpha("Tivor", $pngSrc) $myGuiHandle = WinGetHandle("Tivor") ;Miejsce deklaracji zawartości okna głównego GUISetState() $GuiElementy = GUICreate("Elementy", 900, 550, 20, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $myGuiHandle) GUISetBkColor(0xABCDEF) _WinAPI_SetLayeredWindowAttributes($GuiElementy, 0xABCDEF, 255) ;Przycisk ustawienia $hUstawienia = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\ustawienia.png") $hUstawienia2 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\02.png") $hUstawienia3 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\03.png") $gui2_Ustawienia = GUICreate("Ustawienia", 0, 0, 495,18,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$GuiElementy) SetBitmap($gui2_Ustawienia,$hUstawienia,255) GUISetState(@SW_SHOW) While 1 buttonpng($gui2_Ustawienia,$hUstawienia,$hUstawienia2,$hUstawienia3) $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd GUISetState() $i = 0 While 1 $i = $i + 1 If $i = 255 Then $i = 0 $msg = GUIGetMsg() $advMsg = GUIGetMsg(1) Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd _GDIPlus_Shutdown() Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hwnd = WinGetHandle("Tivor")) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndIf EndFunc Func _GUICreate_Alpha($sTitle, $sPath, $iX=-1, $iY=-1, $iOpacity=255) Local $hGUI, $hImage, $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hImage = _GDIPlus_ImageLoadFromFile($sPath) $width = _GDIPlus_ImageGetWidth($hImage) $height = _GDIPlus_ImageGetHeight($hImage) $hGUI = GUICreate($sTitle, $width, $height, $iX, $iY, $WS_POPUP, $WS_EX_LAYERED) $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", $width) DllStructSetData($tSize, "Y", $height) $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, 2) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hImage) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>_GUICreate_Alpha 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) EndFunc ;==>SetBitmap Func buttonpng($guicanset,$anh1,$anh2,$anh3) if hander()=$guicanset then SetBitmap($guicanset,$anh2,255) Do if event() then Do if hander()<>$guicanset then SetBitmap($guicanset,$anh1,255) Else SetBitmap($guicanset,$anh3,255) EndIf Until not event() if hander()=$guicanset then SetBitmap($guicanset,$anh2,255) _Login() EndIf EndIf Until hander()<>$guicanset SetBitmap($guicanset,$anh1,255) EndIf EndFunc Func buttonpng2($guicanset,$anh1,$anh2,$anh3) if hander()=$guicanset then SetBitmap($guicanset,$anh2,255) Do if event() then Do if hander()<>$guicanset then SetBitmap($guicanset,$anh1,255) Else SetBitmap($guicanset,$anh3,255) EndIf Until not event() if hander()=$guicanset then SetBitmap($guicanset,$anh2,255) Exit EndIf EndIf Until hander()<>$guicanset SetBitmap($guicanset,$anh1,255) EndIf EndFunc Func hander() Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) If IsArray($iRet) Then Return HWnd($iRet[0]) Return SetError(1, 0, 0) EndFunc Func event($sHexKey="01", $vDLL = $dll) ; $hexKey must be the value of one of the keys. ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is. Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey) If @error Then Return SetError(@error, @extended, False) Return BitAND($a_R[0], 0x8000) <> 0 EndFunc ;==>_IsPressed Func _Login() ;Własna grafika jako okno programu $dll=DllOpen("user32.dll") _GDIPlus_Startup() $pngSrc2 = @ScriptDir & "\tlo_dane.png" GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") $GUI2 = _GUICreate_Alpha("Dane logowania", $pngSrc2) $myGuiHandle2 = WinGetHandle("Dane logowania") ;Miejsce deklaracji zawartości okna głównego GUISetState() $GuiDane = GUICreate("Dane logowania", 900, 550, 20, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $myGuiHandle2) #region ### START Koda GUI section ### $Zapisz = GUICtrlCreateButton("Zatwierdzam", 170, 160, 73, 33, $WS_GROUP) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0) $Zamknij = GUICtrlCreateButton("Zamknij", 200, 200, 73, 33, $WS_GROUP) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0) $login = GUICtrlCreateInput("", 150, 50, 150, 25) $password = GUICtrlCreateInput("", 150, 85, 150, 25, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL)) $text = GUICtrlCreateLabel("Podaj dane logowania", 145, 20, 200) GUICtrlSetColor(-1, 0x00ffff) GUICtrlSetFont(-1, 14, 800, 2) $text2 = GUICtrlCreateLabel("Podaj login", 50, 53, 100) GUICtrlSetColor(-1, 0x00ff00) GUICtrlSetFont(-1, 12, 600, 2) $text3 = GUICtrlCreateLabel("Podaj hasło", 50, 87, 100) GUICtrlSetColor(-1, 0x00ff00) GUICtrlSetFont(-1, 12, 600, 2) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0) GUICtrlSetBkColor($text, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetBkColor($text2, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetBkColor($text3, $GUI_BKCOLOR_TRANSPARENT) GUISetState(@SW_SHOW) #endregion ### START Koda GUI section ### GUISetBkColor(0xABCDEF) _WinAPI_SetLayeredWindowAttributes($GuiDane, 0xABCDEF, 255) ;Przycisk ustawienia $hUstawienia = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\ustawienia.png") $hUstawienia2 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\02.png") $hUstawienia3 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\03.png") $gui2_Ustawienia = GUICreate("Ustawienia", 0, 0, 495,18,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$GuiDane) SetBitmap($gui2_Ustawienia,$hUstawienia,255) GUISetState(@SW_SHOW) While 1 buttonpng2($gui2_Ustawienia,$hUstawienia,$hUstawienia2,$hUstawienia3) $nMsg = GUIGetMsg() Switch $nMsg Case $Zapisz $a = FileOpen("dane.ini", 2) $b = GUICtrlRead($login) $c = GUICtrlRead($password) IniWrite("dane.ini", "Dane", "l", $b) IniWrite("dane.ini", "Dane", "p", $c) FileClose($a) $x = IniRead('dane.ini', 'Dane', 'l', 0) $y = IniRead('dane.ini', 'Dane', 'p', 0) $HashCheck = StringInStr($x, '*') $HashCheck2 = StringInStr($y, '*') If $HashCheck = 0 Then $q = _StringEncrypt(1, $x, 'test') $q2 = _StringEncrypt(1, $y, 'test') IniWrite('dane.ini', 'Dane', 'l', ' ' & $q & '*') IniWrite('dane.ini', 'Dane', 'p', ' ' & $q2 & '*') EndIf MsgBox(64, "Info", "Dane zostały zapisane prawidłowo") EndSwitch If $nMsg = $Zapisz Or $nMsg = $Zamknij Then GUIDelete($myGuiHandle2) Return EndIf WEnd _GDIPlus_Shutdown() EndFunc Instead of tlo_tivor.png and tlo_dane.png add your own graphics to make it work. Edited April 13, 2012 by jacq Link to comment Share on other sites More sharing options...
BrewManNH Posted April 13, 2012 Share Posted April 13, 2012 It's because your script deletes the GUI when you press the button. What are you expecting it to do? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jacq Posted April 13, 2012 Author Share Posted April 13, 2012 Maybe some other solution becouse wincloes does not work. Is it possible to restore the window after removal. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 13, 2012 Share Posted April 13, 2012 Maybe if you explained what it is you're trying to do when the GUI is deleted and then reopened it might make it a bit easier to figure out how to help. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Reg2Post Posted April 13, 2012 Share Posted April 13, 2012 (edited) To OP, Your button is on a child GUI that deletes the parent GUI when clicked. If you just want to hide the parent GUI or "window" as you said, you may want to look at the help file for GUISetState and try the flags to hide/minimize. As BrewManNH stated, in your example code you are deleting your GUI and not hiding or minimizing it. Edited April 13, 2012 by Reg2Post Link to comment Share on other sites More sharing options...
jacq Posted April 13, 2012 Author Share Posted April 13, 2012 Now I know why return does not work.Because of the button, which is in the $GuiDane.When the button is removed it works.But please help me how to do to work with this key.I added a new code.Instead of tlo_tivor.png and tlo_dane.png add your own graphics to make it work. Link to comment Share on other sites More sharing options...
Reg2Post Posted April 13, 2012 Share Posted April 13, 2012 jacq,I suggest for the future you do not change your code in your original post on this forum channel. It makes if very difficult for others to follow the thread and provide help. If you have a revision, just post new code in a new post.As for your latest request, did you try GUISetState(@SW_Hide, $yourgui) instead of GUIDelete?You can unhide (show) your GUI with GUISetState(@SW_Show, $yourgui).Below is the online documentation page for GUISetState:http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm Link to comment Share on other sites More sharing options...
BrewManNH Posted April 13, 2012 Share Posted April 13, 2012 Your main problem with this script is you have too many While loops, the first While loop will never exit. The only way for the script to exit it, is through the exit function, and then of course, your script ends. So if never gets to the second While loop, and will never show your second GUI. And your buttonpng() function is being called every time the loop restarts, which is approximately 100 times per second give or take. Is that what you're intending there? Plus, in your second While loop you have $i incrementing every time through the loop until it gets to 255, where you reset it to 0, but I don't see where you're using $i anywhere in that loop. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jacq Posted April 13, 2012 Author Share Posted April 13, 2012 I knew that inside of this code is a little mistake. It was enough just to change the button name. I always remember not to repeat the names, even in functions but now I do not even notice this error. Maybe fatigue. But I'm grateful for all the attempts to help. Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now