KemyKo

Problems with WinGetHandle() and GUIGetStyle()

3 posts in this topic

#1 ·  Posted

I want to create a program that resizes and changes style/exstyles of other windows. ^_^

The problem is that i don`t know why my script doesn`t work.:sweating:

Here is an example:

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $setStyle, $getStyle, $outputString='', $getHandle, $setState

$getHandle = WinGetHandle("[CLASS:Notepad]")
$outputString &= $getHandle & @LF

$setState = GUISetState(@SW_SHOWNORMAL, $getHandle)
$outputString &= $setState & @LF

$getStyle = GUIGetStyle($getHandle)
If IsArray($getStyle) = 1 Then
    $outputString &= $getStyle[0]& ' ' &$getStyle[1]& @LF
Else
    $outputString &= "NOTHING" & @LF
EndIf

$setStyle = GUISetStyle($WS_POPUPWINDOW, -1, $getHandle)
$outputString &= $setStyle & @LF

MsgBox(0,"OUTPUT", $outputString)

It doesn`t work... At least not for me :blink:

I noticed that $getHandle is "0x0021023A" and AutoIt Window Info shows : "0x000000000021023A"

I don`t know if that`s a problem :(. If it is, idk how to fix it :sweating:

Share this post


Link to post
Share on other sites



#2 ·  Posted

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>



Global $hNotepad = WinGetHandle("[Class:Notepad]")
If (@error) Then Exit ConsoleWrite("Failed to get Notepad handle" & @LF)

Global $iStyle = _WinAPI_GetWindowLong($hNotepad, $GWL_STYLE)

ConsoleWrite("Current Style List: " & StyleVariablesFromStyle($iStyle) & @LF)

$iStyle = BitXOR($iStyle, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)

ConsoleWrite("New Style List: " & StyleVariablesFromStyle($iStyle) & @LF)

_WinAPI_SetWindowLong($hNotepad, $GWL_STYLE, $iStyle)

Func StyleVariablesFromStyle(Const $iStyles)
    Local Static $aStyles[][] = [["$WS_BORDER", 0x00800000], _
            ["$WS_POPUP", 0x80000000], _
            ["$WS_CAPTION", 0x00C00000], _
            ["$WS_CLIPCHILDREN", 0x02000000], _
            ["$WS_CLIPSIBLINGS", 0x04000000], _
            ["$WS_DISABLED", 0x08000000], _
            ["$WS_DLGFRAME", 0x00400000], _
            ["$WS_HSCROLL", 0x00100000], _
            ["$WS_MAXIMIZE", 0x01000000], _
            ["$WS_MAXIMIZEBOX", 0x00010000], _
            ["$WS_MINIMIZE", 0x20000000], _
            ["$WS_MINIMIZEBOX", 0x00020000], _
            ["$WS_OVERLAPPED", 0x00000000], _
            ["$WS_OVERLAPPEDWINDOW", 0x00CF0000], _
            ["$WS_POPUPWINDOW", 0x80880000], _
            ["$WS_SIZEBOX", 0x00040000], _
            ["$WS_SYSMENU", 0x00080000], _
            ["$WS_THICKFRAME", 0x00040000], _
            ["$WS_VSCROLL", 0x00200000], _
            ["$WS_VISIBLE", 0x10000000], _
            ["$WS_CHILD", 0x40000000], _
            ["$WS_GROUP", 0x00020000], _
            ["$WS_TABSTOP", 0x00010000], _
            ["$DS_MODALFRAME", 0x00000080], _
            ["$DS_SETFOREGROUND", 0x00000200], _
            ["$DS_CONTEXTHELP", 0x00002000]]
    Local $sStyles = ""
    For $i = 0 To UBound($aStyles) - 1
        If (BitAND($iStyles, $aStyles[$i][1]) = $aStyles[$i][1]) Then $sStyles &= $aStyles[$i][0] & ", "
    Next
    Return StringTrimRight($sStyles, 2)
EndFunc   ;==>StyleVariablesFromStyle

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

6 minutes ago, InunoTaishou said:
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>



Global $hNotepad = WinGetHandle("[Class:Notepad]")
If (@error) Then Exit ConsoleWrite("Failed to get Notepad handle" & @LF)

Global $iStyle = _WinAPI_GetWindowLong($hNotepad, $GWL_STYLE)

ConsoleWrite("Current Style List: " & StyleVariablesFromStyle($iStyle) & @LF)

$iStyle = BitXOR($iStyle, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)

ConsoleWrite("New Style List: " & StyleVariablesFromStyle($iStyle) & @LF)

_WinAPI_SetWindowLong($hNotepad, $GWL_STYLE, $iStyle)

Func StyleVariablesFromStyle(Const $iStyles)
    Local Static $aStyles[][] = [["$WS_BORDER", 0x00800000], _
            ["$WS_POPUP", 0x80000000], _
            ["$WS_CAPTION", 0x00C00000], _
            ["$WS_CLIPCHILDREN", 0x02000000], _
            ["$WS_CLIPSIBLINGS", 0x04000000], _
            ["$WS_DISABLED", 0x08000000], _
            ["$WS_DLGFRAME", 0x00400000], _
            ["$WS_HSCROLL", 0x00100000], _
            ["$WS_MAXIMIZE", 0x01000000], _
            ["$WS_MAXIMIZEBOX", 0x00010000], _
            ["$WS_MINIMIZE", 0x20000000], _
            ["$WS_MINIMIZEBOX", 0x00020000], _
            ["$WS_OVERLAPPED", 0x00000000], _
            ["$WS_OVERLAPPEDWINDOW", 0x00CF0000], _
            ["$WS_POPUPWINDOW", 0x80880000], _
            ["$WS_SIZEBOX", 0x00040000], _
            ["$WS_SYSMENU", 0x00080000], _
            ["$WS_THICKFRAME", 0x00040000], _
            ["$WS_VSCROLL", 0x00200000], _
            ["$WS_VISIBLE", 0x10000000], _
            ["$WS_CHILD", 0x40000000], _
            ["$WS_GROUP", 0x00020000], _
            ["$WS_TABSTOP", 0x00010000], _
            ["$DS_MODALFRAME", 0x00000080], _
            ["$DS_SETFOREGROUND", 0x00000200], _
            ["$DS_CONTEXTHELP", 0x00002000]]
    Local $sStyles = ""
    For $i = 0 To UBound($aStyles) - 1
        If (BitAND($iStyles, $aStyles[$i][1]) = $aStyles[$i][1]) Then $sStyles &= $aStyles[$i][0] & ", "
    Next
    Return StringTrimRight($sStyles, 2)
EndFunc   ;==>StyleVariablesFromStyle

 

Thx a lot. This solved my problem :D

Edited by KemyKo

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Jibberish
      By Jibberish
      Hi,
      I am maybe an intermediate AutoIt script writer, but have no experience creating GUIs.
      I have a script with two functions. One for Checkboxes and another with radio buttons. Each function creates it's own window.
      I'd like to use one window with both checkboxes and radio buttons.
      I pulled samples from AutoIt Help and other places and worked it into this: (RadioCheck still uses the example Case and MsgBoxes. I will clean this up soon)
      Func CheckOptions() ; Create a GUI with various controls. Local $hGUI = GUICreate("SGX4CP Options", 275, 250) ; Create a checkbox control. Local $iLoopCheckbox = GUICtrlCreateCheckbox("Loop", 10, 10, 185, 25) Local $iFullScreenCheckbox = GUICtrlCreateCheckbox("Fullscreen", 10, 40, 185, 25) Local $iRestartPlaybackCheckbox = GUICtrlCreateCheckbox("Restart Playback from Sleep", 10, 70, 185, 25) GUICtrlSetState($iRestartPlaybackCheckbox, $GUI_CHECKED) Local $iDisableSleepCheckbox = GUICtrlCreateCheckbox("Disable Sleep", 10, 100, 185, 25) Local $iLogCheckbox = GUICtrlCreateCheckbox("Show Log", 10, 130, 185, 25) GUICtrlSetState($iLogCheckbox, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Next", 110, 220, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $iLoopCheckbox If _IsChecked($iLoopCheckbox) Then $bLoopChecked = True Else $bLoopChecked = False EndIf Case $iFullScreenCheckbox if _IsChecked($iFullScreenCheckbox) Then $bFullScreenChecked = True Else $bFullScreenChecked = False EndIf Case $iRestartPlaybackCheckbox if _IsChecked($iRestartPlaybackCheckbox) Then $bRestartPlaybackChecked = True Else $bRestartPlaybackChecked = False EndIf Case $iDisableSleepCheckbox if _IsChecked($iDisableSleepCheckbox) Then $bDisableSleepChecked = True Else $bDisableSleepChecked = False EndIf Case $iLogCheckbox if _IsChecked($iLogCheckbox) Then $bLogChecked = True Else $bLogChecked = False EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc Func RadioCheck() GUICreate("Select Test",300,180) ; will create a dialog box that when displayed is centered Local $idRadio1 = GUICtrlCreateRadio("Loop Forever", 10, 10) Local $idRadio2 = GUICtrlCreateRadio("Play each video 3 times", 10, 40) Local $idRadio3 = GUICtrlCreateRadio("Play each video separately", 10, 70) GUICtrlSetState($idRadio1, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Start Test", 120,100) GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE ExitLoop Case $idMsg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'The app will run forever, playing each video once, then looping back to the first video.') $bTestSelectForever = True Case $idMsg = $idRadio2 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Each video will loop 3 times then move to the next video.') $bTestSelect3Times = True Case $idMsg = $idRadio3 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Player opens, first video plays, player closes. Player opens, second video plays, player closes, etc.') $bTestSelectSingleVideo = True EndSelect WEnd EndFunc I would like to combine the checkbox "Loop" and the radio button $idRadio2. Radio2 requires Loop to be checked.
      I planned to remove the Loop checkbox and only enable it if Radio2 is selected.
      Can I combine these two functions into one with one window with both Checkboxes and Radio Buttons?
      Thanks
      Jibberish
    • nacerbaaziz
      By nacerbaaziz
      Hi friends, I have a question, please.
      I have created a window containing a edit box
      I need to know how to change the keyboard language,
      e.g :
      if a user open the  script  it will be change the keyBord language   in window automatically into English
      I found more examples but didn't work with me .
      Note:  
       I use the windows 10 os
      Please help me .
      thanks in advance to all
      with my Greetings and my appreciation for all users and admins
    • WoodGrain
      By WoodGrain
      Hi guys,
      I'm trying to move and resize a program call CPUID HWMonitor (http://www.cpuid.com/softwares/hwmonitor.html) but WinMove() doesn't work. Can someone tell me how to get this to work for this program? I've successfully moved other programs using WinMove(), and I've used WinGetTitle ("[ACTIVE]") to confirm the title is correct. WinActivate("CPUID HWMonitor") does work.
      If I run the following code nothing happens, doesn't move or resize, but AutoIt doesn't complain about the code either:
      WinMove("CPUID HWMonitor", 0, 0, 475, 715) The class changes every time the program opens (and I've nevery had a lot of success with classes tbh, bit hit and miss for me).
      Thanks all!
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I would like to know if I can use the Excel UDF to manipulating a .csv file without having Office installed on the PC I'm going to work...
      I read somewhere that it could be done, but I'm here to ask and be sure of what I remember... 
      I'd like to post another question...
      How can I retrieve the handle of a windows from a PID of an .exe?
      I have my script that does a ShellExecute ( which returns the PID of the .exe ), and then, switching a parameter read from a .ini file, adapt the Window on the screen ( Maximize, Minimize, On Top )...
      I tried, but without having success with this:
       
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=prova.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <WinAPIEx.au3> #include <Array.au3> Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini" If(FileExists($sFileConfigurazione)) Then Local $aSezioniIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error) Else ; Lancio dell'applicativo indicato nel file di configurazione Local $iPID = ShellExecute($aSezioniIni[1][1]) Local $hWnd If($iPID <> 0) Then Local $aWinList = WinList() For $i = 1 To $aWinList[0][0] If(WinGetProcess($aWinList[$i][1] = $iPID)) Then $hWnd = $aWinList[$i][1] EndIf Next Switch($aSezioniIni[2][1]) Case $aSezioniIni[2][1] = "MIN" WinSetState($hWnd, "", @SW_MINIMIZE) Case $aSezioniIni[2][1] = "MAX" WinSetState($hWnd, "", @SW_MAXIMIZE) Case $aSezioniIni[2][1] = "TOP" WinSetOnTop($hWnd, "", $WINDOWS_ONTOP) EndSwitch EndIf EndIf EndIf It just set on top the .exe I'm launching...
      Thanks
    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management

      DISCLAIMER:
      This UDF is still in the development phase. All code works and should be generally bug free, however function names and parameters are subject to change.
       
      Notes:
      Fixes _WindowGetClassList's barbaric returning of a @LF separated string instead of an array.
       
      Potential Uses:
      Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs)
       
      Functions:
      _WinGetClassList
      _WinGetClassNNList
      _WindowGetHandleList
      _WindowGetHandleListFromPos
       
      Download: 
      WindowEx.zip  (v0.4)
       
      Changelog:
      10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs:
      None reported To Do:
      To Be Decided. Opinions welcome! Upcoming Changes:
      To Be Decided.