Call SendMessage WinAPI to get item_rect for tree control

Hi everyone!

I am trying to write lib for windows application GUI testing.The problem
that I see now it is how to call SendMessage WinAPI for tree control to
get tree item rect.Code Commctrl.h for this looks like:

#define TVM_GETITEMRECT (TV_FIRST + 4)
#define TreeView_GetItemRect(hwnd, hitem, prc, code)
(*(HTREEITEM *)prc = (hitem), (BOOL)SNDMSG((hwnd), TVM_GETITEMRECT,
(WPARAM)(code), (LPARAM)(RECT *)(prc)))

And I don’t know what is *(HTREEITEM *)prc = (hitem) and how to do this
on Ruby.

For example my Ruby code for GetRoot looks like:

def send_message(hwnd,msg,wParam,lParam )
send_message = user32 ‘SendMessage’ , [‘L’ , ‘L’ , ‘L’ , ‘P’ ], ‘L’
send_message.call hwnd, msg, wParam, lParam
end

def get_tree_root_item(htree)
send_message(htree,0x1100+10,TVGN_ROOT,0 )
end

and this works for me.

Commctrl.h for this looks:
#define TreeView_GetRoot(hwnd) TreeView_GetNextItem(hwnd, NULL,
TVGN_ROOT)

#define TVM_GETNEXTITEM (TV_FIRST + 10)
#define TreeView_GetNextItem(hwnd, hitem, code)
(HTREEITEM)SNDMSG((hwnd), TVM_GETNEXTITEM, (WPARAM)(code),
(LPARAM)(HTREEITEM)(hitem))

It would be greate if someone can explain what is *(HTREEITEM *)prc =
(hitem) and how to do this in Ruby.

Thanks,
Maxim

Did you ever figure this out? I am trying to do something similar

You need to pass a buffer to SendMessage to store the rectangle’s
information. You can pass the API a Ruby string, and Win32API will pass
the actual address of the string to the API. The API then mutate the
string content so that it stores the rectangle information. The string
itself is like a primitive structure containing different fields, and
later on you can use String#unpack to retrieve every single field.

Suppose you already have the handle to the controls and the message’s
internal integer representation defined:

buf = [handle_tree_item, 0, 0, 0].pack(‘l*’)
send_message = Win32API.new(‘user32’, ‘SendMessage’ , [‘L’ , ‘L’ , ‘L’ ,
‘P’ ], ‘L’)
sned_message.call(handle_tree_view, TVM_GETITEMRECT, 0, buf)
rect = buf.unpack(‘l*’)

rect[0] # left
rect[1] # top
rect[2] # right
rect[3] # bottom

And I don’t know what is *(HTREEITEM *)prc = (hitem) and how to do this
on Ruby.

This is basically a dereference operation on the pointer prc, which
cannot be done in Ruby in the language level. You can use RtlMoveMemory
supplied by kernel32.dll to achieve the same thing in an ugly manner.

Eric wrote in post #978925:

Did you ever figure this out? I am trying to do something similar

I found more flexible solution to work with Windows applications. I
integrate AutoIT.dll with Ruby.It works great and meet all my
requirements.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs