From: Kevin M. <kej...@ho...> - 2010-05-28 01:28:02
|
Thanks Robert for your help with this matter. I'll admit that I am not that experienced with Windows programming. I changed my sample code as per Robert's suggestions, but still couldn't get it to work properly. I think it has something to do with how strings are stored in a toolbar. I'm sure with some persistence it could be made to work, but I'm out of my depth at this point. Selva, as I said in my previous email, you could try searching Windows programming websites for a solution. I am sorry that I can't be of more help. Kevin. > Windows will only marshal messages in the range 0..WM_USER across > processes. > > The messages you are trying to use here are above WM_USER. So you are > passing to the other process an address (in the lParam of the > SendMessage) in your memory space - you are lucky not to crash the > other process :-) > > See this thread: > http://groups.google.com/group/microsoft.public.vc.mfc/browse_frm/thread/40c00794fa444323/291326274362ef36?lnk=st&q=dcsoft+sendmessageremote&rnum=1#291326274362ef36 > <http://groups.google.com/group/microsoft.public.vc.mfc/browse_frm/thread/40c00794fa444323/291326274362ef36?lnk=st&q=dcsoft+sendmessageremote&rnum=1#291326274362ef36> > for information about how to use VirtualAllocEx() and > ReadProcessMemory() to achieve what you want. > > Summary: > (1) Use VirtualAllocEx() to allocate some memory in the remote > process, and then use the address of that memory as the lParam to the > SnedMessage() call. > (2) Use ReadProcessMemory() to read the remote process memory back > into local memory. > > HTH. > Rob. > > On 27 May 2010 11:03, Kevin Marshall <kej...@ho... > <mailto:kej...@ho...>> wrote: > > Selva, > > I created a C/C++ version of my script and it still doesn't work. > The problem, it seems, is with the underlying Win32 API function > calls. It may be that what you are looking to do isn't possible. > Perhaps you could search C/C++ Windows programming websites, etc. > for your problem. Other than that, I am sorry that I can't be of > more help. If you do manage to find a solution, I wouldn't mind > hearing about it. > > Here is my code if you are interested: > > #define WIN32_LEAN_AND_MEAN > > #include <windows.h> > #include <windowsx.h> > #include <commctrl.h> > #include <stdio.h> > > HWND g_hWnd; > HWND g_hButton; > HWND g_hTextfield; > > int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, > LPSTR lpCmdLine, int nCmdShow ); > LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, > LPARAM lParam ); > void Append( HWND handle, char * text ); > > int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE > hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){ > WNDCLASSEX winClass; > MSG Msg; > > ZeroMemory( &Msg, sizeof(MSG) ); > > winClass.lpszClassName = "MY_CLASS"; > winClass.cbSize = sizeof(WNDCLASSEX); > winClass.style = CS_HREDRAW | CS_VREDRAW; > winClass.lpfnWndProc = WindowProc; > winClass.hInstance = hInstance; > winClass.hIcon = LoadIcon( NULL, IDI_APPLICATION ); > winClass.hIconSm = LoadIcon( NULL, IDI_APPLICATION ); > winClass.hCursor = LoadCursor( NULL, IDC_ARROW ); > winClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); > winClass.lpszMenuName = NULL; > winClass.cbClsExtra = 0; > winClass.cbWndExtra = 0; > > if( !RegisterClassEx(&winClass) ) > return E_FAIL; > > g_hWnd = CreateWindowEx( > NULL, "MY_CLASS", "Window Finder", > WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, > CW_USEDEFAULT, CW_USEDEFAULT, 320, 240, NULL, NULL, > hInstance, NULL > ); > > if( g_hWnd == NULL ) > return E_FAIL; > > RECT hwndRect; > GetClientRect( g_hWnd, &hwndRect ); > g_hButton = CreateWindowEx( > NULL, "BUTTON", "Find Window", > WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, > hwndRect.right / 2 - 40, 5, 80, 25, > g_hWnd, NULL, hInstance, NULL > ); > if( g_hButton == NULL ) > return E_FAIL; > > g_hTextfield = CreateWindowEx( > WS_EX_CLIENTEDGE | WS_EX_NOPARENTNOTIFY , "EDIT", "", > WS_VISIBLE | WS_CHILD | WS_BORDER | WS_HSCROLL | > WS_VSCROLL | ES_LEFT | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE, > 5, 35, hwndRect.right - 10, hwndRect.bottom - 40, > g_hWnd, NULL, hInstance, NULL > ); > if( g_hTextfield == NULL ) > return E_FAIL; > > ShowWindow( g_hWnd, nCmdShow ); > UpdateWindow( g_hWnd ); > > while( Msg.message != WM_QUIT ){ > if( GetMessage( &Msg, NULL, 0, 0 ) ){ > TranslateMessage( &Msg ); > DispatchMessage( &Msg ); > } > } > > UnregisterClass( "MY_CLASS", winClass.hInstance ); > > return Msg.wParam; > } > > LRESULT CALLBACK WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, > LPARAM lParam ){ > static bool bMouseDown = false; > static HWND hFoundHandle = NULL; > static HPEN hPenHilight = CreatePen( PS_SOLID, 5, RGB(0,0,0) ); > switch( uMsg ){ > case WM_KEYDOWN: { > switch( wParam ){ > case VK_ESCAPE: { > PostQuitMessage(0); > break; > } > } > break; > } > case WM_PARENTNOTIFY: { > int x = LOWORD(lParam); > int y = HIWORD(lParam); > > switch( LOWORD(wParam) ){ > case WM_LBUTTONDOWN: { > bMouseDown = true; > ShowWindow( g_hWnd, SW_HIDE ); > SetCapture( g_hWnd ); > break; > } > } > return 0; > break; > } > case WM_LBUTTONUP: { > bMouseDown = false; > if(hFoundHandle){ > InvalidateRect( hFoundHandle, NULL, true ); > UpdateWindow( hFoundHandle); > RedrawWindow( hFoundHandle, NULL, NULL, 1 ); > ShowWindow( g_hWnd, SW_SHOW ); > ReleaseCapture(); > char ClassName[MAX_PATH]; > GetClassName( hFoundHandle, ClassName, MAX_PATH ); > if(strcmp( ClassName, "ToolbarWindow32" ) == 0){ > Append( g_hTextfield, "Found toolbar\r\n" ); > int count = SendMessage( hFoundHandle, > TB_BUTTONCOUNT, 0, 0 ); > char string[MAX_PATH]; > sprintf( string, "Button count: %d\r\n", count ); > Append( g_hTextfield, string ); > for(int i = 0; i < count; i++){ > TBBUTTON button; > TBBUTTONINFO buttoninfo; > char text[MAX_PATH]; > SendMessage( hFoundHandle, TB_GETBUTTON, > (WPARAM)i, (LPARAM)&button ); > //SendMessage( hFoundHandle, > TB_GETBUTTONINFO, (WPARAM)button.idCommand, (LPARAM)&buttoninfo ); > //Append( g_hTextfield, buttoninfo.pszText ); > } > } > } > return 0; > break; > } > case WM_MOUSEMOVE: { > if( bMouseDown ){ > POINT point; > GetCursorPos( &point ); > HWND found = WindowFromPoint( point ); > if(found){ > hFoundHandle = found; > InvalidateRect( found, NULL, true ); > UpdateWindow( found ); > RedrawWindow( found, NULL, NULL, 1 ); > HDC hdc = GetDC( found ); > if(hdc){ > RECT rect; > GetWindowRect( found, &rect ); > HGDIOBJ oldpen = SelectObject( hdc, > hPenHilight ); > HGDIOBJ oldbrush = SelectObject( hdc, > GetStockObject(HOLLOW_BRUSH) ); > Rectangle( hdc, 0, 0, rect.right - > rect.left, rect.bottom - rect.top ); > SelectObject( hdc, oldpen ); > SelectObject( hdc, oldbrush ); > ReleaseDC( found, hdc); > } > } > } > return 0; > break; > } > case WM_CLOSE: { > PostQuitMessage(0); > return 0; > break; > } > default: > break; > } > return DefWindowProc( hWnd, uMsg, wParam, lParam ); > } > > void Append( HWND handle, char * text ){ > int length; > length = GetWindowTextLength( handle ); > SendMessage( handle, EM_SETSEL, length, length ); > SendMessage( handle, EM_REPLACESEL, (WPARAM) TRUE, (LPARAM) > text ); > } > /* END */ > > Kevin. >> Thx Kevin. >> I am trying the same thro sendmesssage of c/c++ and pack/unpack >> of Perl. >> However I did not get a lead on this and I am getting issue with >> sendmessage for toolbar control itself. >> Any idea on this,ofcourse, it may be out of your focus. >> Thx >> Selva D >> >> --- On *Thu, 20/5/10, Kevin Marshall /<kej...@ho...> >> <mailto:kej...@ho...>/* wrote: >> >> >> From: Kevin Marshall <kej...@ho...> >> <mailto:kej...@ho...> >> Subject: Re: [perl-win32-gui-users] Is it possible to work on >> toolbar controls with win32::GUI >> To: "selva ganapathy" <gan...@ya...> >> <mailto:gan...@ya...> >> Cc: per...@li... >> <mailto:per...@li...> >> Date: Thursday, 20 May, 2010, 5:38 AM >> >> Selva, >> >> I have managed to throw together a quick script that can be >> used to find info on a toolbar of another application. To use >> it, run the script and click and hold the left mouse button >> on the 'Find Window' button. This will hide the window, then >> while still holding the mouse button down, move the mouse >> over the toolbar of the other application and release the >> mouse. The window of the script should reappear, and display >> the number of buttons in the toolbar in the text box. >> Unfortunately, if you try to get the text of the toolbar >> buttons, the script crashes. At least, that is what happens >> for me when I try it on an instance of Notepad2 >> <http://www.flos-freeware.ch/notepad2.html>. Not sure exactly >> what causes this. It may work for you. Try un-commenting the >> block of code in the onMouseMove event to see what happens. >> Anyway, here is my script: >> >> #!perl >> use strict; >> use warnings; >> >> use Data::Dump qw(dump); >> #use Win32::API; >> use Win32::GUI qw(); >> use Win32::GUI::Constants qw(CW_USEDEFAULT HOLLOW_BRUSH WM_USER); >> #use constant {TB_GETBUTTON => WM_USER+23}; >> >> my $MouseDown = 0; >> my $FoundHandle; >> my $penHilight = Win32::GUI::Pen->new(-width => 5, -color => >> 0x000000, -style => 0); >> my $winMain = Win32::GUI::Window->new( >> -name => 'winMain', >> -text => 'Window Finder', >> -size => [320,240], >> -left => CW_USEDEFAULT, >> -maximizebox => 0, >> -resizable => 0, >> ); >> >> $winMain->AddButton( >> -name => 'btnWinFind', >> -text => 'Find Window', >> -pos => [$winMain->ScaleWidth()/2-40,5], >> -size => [80,25], >> -onMouseDown => sub { >> my($self,$x,$y,$flags) = @_; >> $MouseDown = 1; >> $winMain->Hide(); >> $self->SetCapture(); >> return 1; >> }, >> -onMouseUp => sub { >> my($self,$x,$y,$flags) = @_; >> $MouseDown = 0; >> if($FoundHandle){ >> Win32::GUI::InvalidateRect($FoundHandle, 1); >> Win32::GUI::Update($FoundHandle); >> Win32::GUI::Redraw($FoundHandle, 1); >> $winMain->Show(); >> $self->ReleaseCapture(); >> if(Win32::GUI::GetClassName($FoundHandle) eq >> 'ToolbarWindow32'){ >> my $count = >> Win32::GUI::Toolbar::ButtonCount($FoundHandle); >> $winMain->txtInfo->Text("$count\r\n"); >> # foreach(0..$count-1){ >> # my $tbbutton = "\0" x 20; >> # Win32::GUI::SendMessage($FoundHandle, >> TB_GETBUTTON, $_, $tbbutton); >> # dump $tbbutton; >> # my @button = >> Win32::GUI::Toolbar::GetButton($FoundHandle, $_); >> # my @size = >> Win32::GUI::Toolbar::GetButtonSize($FoundHandle); >> # my $text = >> Win32::GUI::Toolbar::GetButtonText($FoundHandle, $_); >> # $winMain->txtInfo->Append(join "\r\n", >> @size); >> # } >> } >> } >> return 1; >> }, >> -onMouseMove => sub { >> my($self,$x,$y,$flags) = @_; >> if($MouseDown){ >> my $found = >> Win32::GUI::WindowFromPoint($self->ClientToScreen($x,$y)); >> if($found){ >> $FoundHandle = $found; >> Win32::GUI::InvalidateRect($found, 1); >> Win32::GUI::Update($found); >> Win32::GUI::Redraw($found, 1); >> my $dc = Win32::GUI::DC::GetDC($found); >> my %rect; >> @rect{qw(left top right bottom)} = >> Win32::GUI::GetWindowRect($found); >> if($dc){ >> my $oldpen = >> Win32::GUI::DC::SelectObject($dc, $penHilight); >> my $oldbrush = >> Win32::GUI::DC::SelectObject($dc, >> Win32::GUI::DC::GetStockObject(HOLLOW_BRUSH)); >> >> Win32::GUI::DC::Rectangle($dc,0,0,$rect{right}-$rect{left},$rect{bottom}-$rect{top}); >> Win32::GUI::DC::SelectObject($dc, >> $oldpen) if $oldpen; >> Win32::GUI::DC::SelectObject($dc, >> $oldbrush) if $oldbrush; >> Win32::GUI::DC::ReleaseDC($found, $dc); >> } >> else { >> warn "Can't get DC: $^E"; >> } >> } >> } >> return 1; >> }, >> ); >> >> $winMain->AddTextfield( >> -name => 'txtInfo', >> -size => >> [$winMain->ScaleWidth()-10,$winMain->ScaleHeight()-40], >> -pos => [5,35], >> -multiline => 1, >> ); >> >> $winMain->Show(); >> >> Win32::GUI::Dialog(); >> >> __END__ >> >> I based this code off of some C/C++ code that was posted here >> <http://www.codeproject.com/kb/dialog/windowfinder.aspx>. >> >> Hope this helps, >> >> Kevin. >>> Kevin, >>> Thanks for your response.This is not created with Win32::GUI >>> This is VC++ application and in that application, in the >>> toolbar (you could see save image etc - attachment- red >>> colored is the toolbar INeed to work), I have to get/do the >>> Toolbar count , >>> Button click based on indiex or test >>> Click on IMage >>> Size of Each Button >>> Individual Button State. >>> My perl script will not create these window application, I >>> have to to some activity on these tollbar icons such as >>> click and for this I need use of this module. >>> Thx >>> Selva D >>> >>> --- On *Wed, 19/5/10, Kevin Marshall /<kej...@ho...> >>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=kej...@ho...>/* >>> wrote: >>> >>> >>> From: Kevin Marshall <kej...@ho...> >>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=kej...@ho...> >>> Subject: Re: [perl-win32-gui-users] Is it possible to >>> work on toolbar controls with win32::GUI >>> To: "selva ganapathy" <gan...@ya...> >>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=gan...@ya...> >>> Cc: per...@li... >>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=per...@li...> >>> Date: Wednesday, 19 May, 2010, 5:07 AM >>> >>> Selva, >>> >>> How exactly is this other window with toolbar created? >>> Is it from a completely separate script or from a module >>> that your script loads? Is it created using Win32::GUI >>> in Perl? Could you provide a small example of your problem? >>> >>> Sorry for the confusion. >>> >>> Kevin. >>>> Kevin. >>>> Thanks for the update. The one you have referred will >>>> get the tool bar button count for which you create the >>>> window and add content to that window and you are >>>> getting the same. >>>> But I look for the situation, where I have to get the >>>> Toolbar button count on existing window which I will >>>> not create on run time. >>>> I am looking some solution on the same . Any further >>>> thoughts from you is very much helpful. >>>> Thx in advance and I hope that I have clarified my >>>> requirement. >>>> Selva D >>>> >>>> --- On *Mon, 10/5/10, Kevin Marshall >>>> /<kej...@ho...> >>>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=kej...@ho...>/* >>>> wrote: >>>> >>>> >>>> From: Kevin Marshall <kej...@ho...> >>>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=kej...@ho...> >>>> Subject: RE: [perl-win32-gui-users] Is it possible >>>> to work on toolbar controls with win32::GUI >>>> To: gan...@ya... >>>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=gan...@ya...> >>>> Cc: "Perl-Win32-GUI-Users List" >>>> <per...@li...> >>>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=per...@li...> >>>> Date: Monday, 10 May, 2010, 7:44 AM >>>> >>>> Selva, >>>> >>>> You can use the ButtonCount() method to retrieve >>>> the number of buttons in the toolbar and the >>>> GetButtonText() method to retrieve the text of the >>>> specified button. Here is some sample code: >>>> >>>> #!perl >>>> use strict; >>>> use warnings; >>>> >>>> use Data::Dump qw(dump); >>>> use Win32::GUI qw(); >>>> use Win32::GUI::Constants qw(TBSTATE_ENABLED >>>> BTNS_SHOWTEXT IDB_STD_SMALL_COLOR CW_USEDEFAULT); >>>> >>>> my $win = Win32::GUI::Window->new( >>>> -name => 'win', >>>> -text => 'Toolbar Sample', >>>> -size => [320,240], >>>> -left => CW_USEDEFAULT, >>>> ); >>>> >>>> $win->AddToolbar( >>>> -name => 'toolbar', >>>> -adjustable => 1, >>>> -flat => 1, >>>> -multiline => 1, >>>> -nodivider => 1, >>>> ); >>>> my @buttons = (qw(Cut Copy Paste Undo Redo Delete >>>> New Open Save Preview >>>> Properties Help Find Replace Print)); >>>> $win->toolbar->LoadImages(IDB_STD_SMALL_COLOR); >>>> $win->toolbar->AddString($_) foreach @buttons; >>>> $win->toolbar->AddButtons( >>>> scalar @buttons, >>>> map >>>> {($_,$_+1,TBSTATE_ENABLED,BTNS_SHOWTEXT,$_)} >>>> 0..$#buttons >>>> ); >>>> >>>> $win->Show(); >>>> >>>> Win32::GUI::Dialog(); >>>> >>>> sub win_Resize { >>>> $win->toolbar->Width($win->Width()); >>>> return 1; >>>> } >>>> >>>> sub toolbar_ButtonClick { >>>> my($index,$dropdown) = @_; >>>> printf "Button %02d of %02d text => %s\n", $index, >>>> $win->toolbar->ButtonCount(), >>>> $win->toolbar->GetButtonText($index); >>>> return 1; >>>> } >>>> __END__ >>>> >>>> Hope this helps, >>>> >>>> Kevin. >>>> >>>> > Date: Tue, 4 May 2010 05:38:04 -0700 >>>> > From: gan...@ya... >>>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=gan...@ya...> >>>> > To: per...@li... >>>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=per...@li...> >>>> > Subject: [perl-win32-gui-users] Is it possible to >>>> work on toolbar controls with win32::GUI >>>> > >>>> > Hi, >>>> > I exhaustively looked at win32::GUI and please >>>> clarify on the same. >>>> > I just want to get the toolbar item- count and >>>> also the text of the items in toolbar. I saw >>>> win32::GUI was creating an window and doing adding >>>> some control for the same. >>>> > Is there any way to test the toolbar controls for >>>> the existing toolbar by passing the window handler. >>>> > >>>> > I also tried with win32::GUItest..but not >>>> succeeded.(by using sendmessage ) Please any clue >>>> on this? >>>> > >>>> > Thanks >>>> > Selva D >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> ------------------------------------------------------------------------------ >>>> > _______________________________________________ >>>> > Perl-Win32-GUI-Users mailing list >>>> > Per...@li... >>>> <http://aa.mc561.mail.yahoo.com/mc/compose?to=Per...@li...> >>>> > >>>> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users >>>> > http://perl-win32-gui.sourceforge.net/ >>>> >>>> ------------------------------------------------------------------------ >>>> Looking for a hot date? View photos of singles in >>>> your area! >>>> <http://clk.atdmt.com/NMN/go/150855801/direct/01/> >>>> >>>> >>> >>> >> >> >> > > > ------------------------------------------------------------------------------ > > > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > <mailto:Per...@li...> > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > http://perl-win32-gui.sourceforge.net/ > > |