Jump to content
KemyKo

Problems with WinGetHandle() and GUIGetStyle()

Recommended Posts

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
#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
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

    • By ThePoro
      Hi everyone.
      I want to ask about this : 
      I want it runs from 1 to 100 and It opens 10 firefox profiles then access youtube. After I close a firefox window, the loop runs and wait for another window close until loop ends
      I have a loop like this.
      Func launch() Local $from = Int(GUICtrlRead($input1)) Local $to = Int(GUICtrlRead($input2)) If $to <> "" Then While $from <= $to Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") $to=$to+1 WEnd Else Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") EndIf EndFunc Is there any solution?
      Thank you!
    • By Rhidlor
      I was wondering if there was a library or something which provides the capability to Send() to inactive windows, and I know what you're thinking, I could just use ControlSend(); the reason I can't use that in this situation is because I need to hold down keys for specific prolonged periods of time. Also activating the window, Send()ing then de-activating the window isn't really an option here, I need the target window to always be in the background. I've looked around the forums for an adequate amount of time and didn't find anything useful, perhaps because the threads were all 10 years old, nevertheless, if anyone has any suggestions they would be greatly appreciated.
      Thanks!
    • By bbProg
      Hi,
       
      how can I wait activate for windows with information as in the photos attached?
      Class is not being recognized by the script.
       
      thanks in advanced.



    • By rcmaehl
      A UDF with Extended Functions for Window Management
       
      Notes:
      Fixes WinGetClassList'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.
    • By FrancescoDiMuro
      Good morning everyone

      I was playing a little bit with "Screen Capture" UDF, and I was trying to make a "Window" capture, but, since I made a GUI which through I fire the event "Capture", my GUI is captured as well, and I don't want to
      This is the line of code that makes the capture:
       
      _ScreenCapture_CaptureWnd($strScreenCaptureFileName, $objActiveWindow, 0, 0, -1, -1, False) And these are the lines of code which select the "active" window:
       
      Local $objCurrentWindow = 9999 If _IsPressed("01") Then $objCurrentWindow = WinGetHandle("[ACTIVE]") If $objCurrentWindow <> $objMyGUI Then $objActiveWindow = $objCurrentWindow EndIf EndIf Sorry If I made stupid mistakes
      Thanks in advance.

      Francesco
×
×
  • Create New...