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

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Friends i am new to autoit and i am stuck in middle of automation of flashing tool..
      my requirement is i have a window and i have to get the value present in that window (below is the picture)

      in the above window i need to get the value of the highlighted field.the value of this filed keeps on changing...ii need to get the current value present in the field..below are the details of the window and field..

       
      CAN it be done?
       
      thanks

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys i am working on automating a flashing tool..When flashing is started if there is any error in connection it pops's up a error window...(as shown below)

       whenever this popup appears i need a msgbox to appear saying "error occured" how can i do this?
      Thanks

    • 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!