Jump to content
Sign in to follow this  
pvee

mfc controls in a splitter view cannot be selected

Recommended Posts

pvee

hi All

Env: MFC visual studio6.0, win xp

I've been trying to autoit some of our legacy code written in MFC - an SDI app, which has got a number of tabs and some tabs got a splitter control

and has got a list view control in it. I can see its ids/handles autoit info or using UI spy tool but when I tried to get the handle of a list view

I get 0 return value (see the attached image for the tree structure of controls identified by the ui spy). I have tried a number of ways to get it, but no use

even tried _WINAPI_ function to enumerate the windows and I can see autoit returns the handle value. I used it in listview function to get the number of items

in the list views view - still no good. :blink: . This is the case of some of the controls in the AfxFrameOrView42 control. I can get automate some of the controls in

some other tabs like edit and button controls. only problem is in control sin frameorview . Any ideas gurus???? any help will be really appreciated ...

(sorry if u dont understand my problem, I'll explain it in detail, thanks in advance)

regards

pvee

post-58942-12788673977065_thumb.gif

Share this post


Link to post
Share on other sites
wolf9228

hi All

Env: MFC visual studio6.0, win xp

I've been trying to autoit some of our legacy code written in MFC - an SDI app, which has got a number of tabs and some tabs got a splitter control

and has got a list view control in it. I can see its ids/handles autoit info or using UI spy tool but when I tried to get the handle of a list view

I get 0 return value (see the attached image for the tree structure of controls identified by the ui spy). I have tried a number of ways to get it, but no use

even tried _WINAPI_ function to enumerate the windows and I can see autoit returns the handle value. I used it in listview function to get the number of items

in the list views view - still no good. :blink: . This is the case of some of the controls in the AfxFrameOrView42 control. I can get automate some of the controls in

some other tabs like edit and button controls. only problem is in control sin frameorview . Any ideas gurus???? any help will be really appreciated ...

(sorry if u dont understand my problem, I'll explain it in detail, thanks in advance)

regards

pvee

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>

Global $ChildArray  , $PTR_Chi


    GUICreate("My GUI with treeview", 350, 215)

    $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
    $compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
    $useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
    $resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
    $otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)

    $startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
    $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
    GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "aboutlabel"-text during initialization
    $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
    GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "compinfo"-text during initialization

    GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
    $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
    $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
    $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
    $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)

    GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "General"-item and paint in bold
    GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "Display"-item and paint in bold
    GUISetState()

$WinHandle = WinGetHandle("My GUI with treeview", "")
$RTArray = ChildWindows($WinHandle)
_ArrayDisplay($RTArray, "")
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

Func ChildWindows($WinHandle)
$WindowArray =  GetChildWindows($WinHandle)
Dim $RTArray[1][7]
For $i = 0 To  UBound($WindowArray) - 1
$RTArray[UBound($RTArray) - 1][0] = $WindowArray[$i]
$RTArray[UBound($RTArray) - 1][1] = ControlGetText ($WinHandle, "",$WindowArray[$i])
$pos = ControlGetPos($WinHandle, "",$WindowArray[$i])
$RTArray[UBound($RTArray) - 1][2] = _WinAPI_GetClassName($WindowArray[$i])
$RTArray[UBound($RTArray) - 1][3] = $pos[0]
$RTArray[UBound($RTArray) - 1][4] = $pos[1]
$RTArray[UBound($RTArray) - 1][5] = $pos[2]
$RTArray[UBound($RTArray) - 1][6] = $pos[3]
ReDim $RTArray[UBound($RTArray) + 1][7]
Next
ReDim $RTArray[UBound($RTArray) - 1][7]
Return $RTArray
EndFunc


Func  GetChildWindows($hWndParent)
If Not ($PTR_Chi) Then $PTR_Chi = RegisterEnumChildProc("CALLBACK_EnumChildProc")
EnumChildWindows($hWndParent , $PTR_Chi)
ReDim $ChildArray[UBound($ChildArray) - 1]
Return $ChildArray
EndFunc

Func  EnumChildWindows($hWndParent , $lpEnumFunc)
Local $lParam = 0
Global $ChildArray = 0
Dim $ChildArray[1]
$BOOL = DllCall("user32.dll","int","EnumChildWindows","hwnd",$hWndParent,"ptr",$lpEnumFunc,"int",$lParam)
if Not @error Then Return SetError(@error,"",$BOOL[0])
Return SetError(@error,"",False)
EndFunc

Func RegisterEnumChildProc($lpEnumFunc)
$handle = DLLCallbackRegister ($lpEnumFunc, "int", "hwnd;int")
Return DllCallbackGetPtr($handle)
EndFunc


Func CALLBACK_EnumChildProc($hwnd,$lParam)
For $i = 0 To UBound($ChildArray) - 1
if $ChildArray[$i] == $hwnd Then Return False
Next
$ChildArray[UBound($ChildArray) - 1] = $hwnd
ReDim $ChildArray[UBound($ChildArray) + 1]
Return True
EndFunc

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
pvee

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>

Global $ChildArray  , $PTR_Chi


    GUICreate("My GUI with treeview", 350, 215)

    $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
    $compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
    $useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
    $resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
    $otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)

    $startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
    $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
    GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "aboutlabel"-text during initialization
    $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
    GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "compinfo"-text during initialization

    GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
    $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
    $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
    $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
    $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)

    GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "General"-item and paint in bold
    GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "Display"-item and paint in bold
    GUISetState()

$WinHandle = WinGetHandle("My GUI with treeview", "")
$RTArray = ChildWindows($WinHandle)
_ArrayDisplay($RTArray, "")
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

Func ChildWindows($WinHandle)
$WindowArray =  GetChildWindows($WinHandle)
Dim $RTArray[1][7]
For $i = 0 To  UBound($WindowArray) - 1
$RTArray[UBound($RTArray) - 1][0] = $WindowArray[$i]
$RTArray[UBound($RTArray) - 1][1] = ControlGetText ($WinHandle, "",$WindowArray[$i])
$pos = ControlGetPos($WinHandle, "",$WindowArray[$i])
$RTArray[UBound($RTArray) - 1][2] = _WinAPI_GetClassName($WindowArray[$i])
$RTArray[UBound($RTArray) - 1][3] = $pos[0]
$RTArray[UBound($RTArray) - 1][4] = $pos[1]
$RTArray[UBound($RTArray) - 1][5] = $pos[2]
$RTArray[UBound($RTArray) - 1][6] = $pos[3]
ReDim $RTArray[UBound($RTArray) + 1][7]
Next
ReDim $RTArray[UBound($RTArray) - 1][7]
Return $RTArray
EndFunc


Func  GetChildWindows($hWndParent)
If Not ($PTR_Chi) Then $PTR_Chi = RegisterEnumChildProc("CALLBACK_EnumChildProc")
EnumChildWindows($hWndParent , $PTR_Chi)
ReDim $ChildArray[UBound($ChildArray) - 1]
Return $ChildArray
EndFunc

Func  EnumChildWindows($hWndParent , $lpEnumFunc)
Local $lParam = 0
Global $ChildArray = 0
Dim $ChildArray[1]
$BOOL = DllCall("user32.dll","int","EnumChildWindows","hwnd",$hWndParent,"ptr",$lpEnumFunc,"int",$lParam)
if Not @error Then Return SetError(@error,"",$BOOL[0])
Return SetError(@error,"",False)
EndFunc

Func RegisterEnumChildProc($lpEnumFunc)
$handle = DLLCallbackRegister ($lpEnumFunc, "int", "hwnd;int")
Return DllCallbackGetPtr($handle)
EndFunc


Func CALLBACK_EnumChildProc($hwnd,$lParam)
For $i = 0 To UBound($ChildArray) - 1
if $ChildArray[$i] == $hwnd Then Return False
Next
$ChildArray[UBound($ChildArray) - 1] = $hwnd
ReDim $ChildArray[UBound($ChildArray) + 1]
Return True
EndFunc

Hi Sir,

Thanks very much for your reply....

I have managed to get the list view count by getting the handle of the control using _WinAPI_EnumWindows and thensending

a send message call to the control handle - your tips helped me to look into the win API calls and it workd.

cheerio all the best

pvee

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.