Jump to content
Sign in to follow this  
OmYcroN

Annoying _WinAPI_GetDlgCtrlID()

Recommended Posts

PsaltyDS

I don't understand what's happening here :

$hTreeView = _GUICtrlTreeView_Create( ... no need for this ... )

; this returns the handle (something like 0x002a0428)

_WinAPI_GetDlgCtrlID(-1 or hTreeView)

; this results always 0x00000000

Why ?

From the help file:

Remarks

GetDlgCtrlID accepts child window handles as well as handles of controls in dialog boxes. An application sets

the identifier for a child window when it creates the window by assigning the identifier value to the hmenu

parameter when calling the CreateWindow or CreateWindowEx function. Although GetDlgCtrlID may return a value

if $hWnd identifies a top-level window, top-level windows cannot have identifiers and such a return value is

never valid.

Is this a pop up dialog or child window?

^_^


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
OmYcroN

From the help file:

Is this a pop up dialog or child window?

^_^

$hGUI = GUICreate("Title", 100, 100) ; thats all

Share this post


Link to post
Share on other sites
KaFu

MsgBox(0,"","Handle: " & $hTreeView & @crlf & "ControlID: " & number(_WinAPI_GetDlgCtrlID($hTreeView)) & @crlf)

returns ControlID for me if applied to _GUICtrlTreeView_Create() example in help-file.

Share this post


Link to post
Share on other sites
martin

From the help file:

Is this a pop up dialog or child window?

^_^

The $hWnd refers to the treeview control not the parent gui so it's not a top-level window.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
martin

I don't understand what's happening here :

$hTreeView = _GUICtrlTreeView_Create( ... no need for this ... )

; this returns the handle (something like 0x002a0428)

_WinAPI_GetDlgCtrlID(-1 or hTreeView)

; this results always 0x00000000

Why ?

I think the answer is, as Kafu implies, that you are simply wrong.

Try this

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_TV = False; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTreeView

_Main()

Func _Main()

    Local $GUI
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
    $GUI = GUICreate("(UDF Created) TreeView Create", 400, 300)

    $hTreeView = _GUICtrlTreeView_CreateB($GUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState()
  consolewrite(_WinAPI_GetDlgCtrlID($hTreeView) & @CR)
    
EndFunc  ;==>_Main


        


Func _GUICtrlTreeView_CreateB($hWnd, $iX, $iY, $iWidth = 150, $iHeight = 150, $iStyle = 0x00000037, $iExStyle = 0x00000000)
    If Not IsHWnd($hWnd) Then _WinAPI_ShowError("Invalid Window handle for _GUICtrlTreeView_Create 1st parameter")

    Local $hTree, $nCtrlID

    If $iWidth = -1 Then $iWidth = 150
    If $iHeight = -1 Then $iHeight = 150
    If $iStyle = -1 Then $iStyle = 0x00000037
    If $iExStyle = -1 Then $iExStyle = 0x00000000

    $iStyle = BitOR($iStyle, $__TREEVIEWCONSTANT_WS_CHILD, $__TREEVIEWCONSTANT_WS_VISIBLE)

    $nCtrlID = _UDF_GetNextGlobalID($hWnd)
    ConsoleWrite("id = " & Hex($nCtrlID) & @CRLF)
    If @error Then Return SetError(@error, @extended, 0)

    $hTree = _WinAPI_CreateWindowEx($iExStyle, $__TREEVIEWCONSTANT_ClassName, "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $nCtrlID)
    _WinAPI_SetFont($hTree, _WinAPI_GetStockObject($__TREEVIEWCONSTANT_DEFAULT_GUI_FONT))
    _GUICtrlTreeView_SetUnicodeFormat($hTree, False)
    Return $hTree
EndFunc  ;==>_GUICtrlTreeView_Create
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
OmYcroN

MsgBox(0,"","Handle: " & $hTreeView & @crlf & "ControlID: " & number(_WinAPI_GetDlgCtrlID($hTreeView)) & @crlf)

returns ControlID for me if applied to _GUICtrlTreeView_Create() example in help-file.

Im sorry ... i wanted to refer to $parent = _GUICtrlTreeView_Add($hTreeView, ... ). This one does return that 0x00000000 for _WinAPI_GetDlgCtrlID($parent)

Share this post


Link to post
Share on other sites
KaFu

This creates an item in the treeviews SysTreeView32 control, which as far as I know does not have a controlId of its own but is accessed via the returned handle only.

What operation do you want to perform, that you try to obtain a controlID? All operations can be performed using the handle.

Edited by KaFu

Share this post


Link to post
Share on other sites
OmYcroN

This creates an item in the treeviews SysTreeView32 control, which as far as I know does not have a controlId of its own but is accessed via the returned handle only.

What operation do you want to perform, that you try to obtain a controlID? All operations can be performed using the handle.

For example i have a treeview with 4 $parents each with 2 $childs and i want to know what $child was checked (i have that style for the tree)

$parent02

$child0101

$child0102

$parent02

$child0201

$child0202

How can i do that using GUIGetMsg() cause with id s is really simple but with handles i don't understand how.

Share this post


Link to post
Share on other sites
KaFu

Use _GUICtrlTreeView_GetFirstItem() amd _GUICtrlTreeView_GetNext() to loop through items and check state like you would do it with FileFindFirstFile() and FileFindNextFile() for files.

Edit:

Resp. _GUICtrlTreeView_GetFirstChild() _GUICtrlTreeView_GetNextChild() for child items.

Edited by KaFu

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.