-----Original Message-----
From: Mike Blazer <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Sunday, January 23, 2000 5:26 AM
Subject: [perl-win32-gui] Can't read/write Edit control from the other
process
>Hello guys,
>I've got some very special problem and damn, had broken my head but without
any success.
>I have widget.pl that creates a dialog box with an Edit control (TextField)
inside.
>Then I need to read/write from/to this control in the other process.
>
>I tried *any* possible way I could imagine, but the second process does not
see the changes in the textfield and can't make any changes. I tried plain
GetWindowText/SetWindowText via Win32::API, the same functions from
Win32::Setupsup, Win32::GUI::Text and direct WM_GETTEXT/WM_SETTEXT mesages.
>The same example with the Label (Static) instead of Edit works perfect and
shows changes after InvalidateRect(1).
>
>Could somebody get me any point?
>
>Here is the widget.pl:
>#!/usr/bin/perl -w
>$|=1;
>
>use Win32::GUI;
>
>my $maxX = Win32::GUI::GetSystemMetrics(0);
>
>my $W = new Win32::GUI::DialogBox(
> -left => $maxX-170,
> -top => 0,
> -width => 170,
> -height => 70,
> -title => "IP monitor",
> -name => "IPmonitor",
> -style => WS_BORDER | DS_MODALFRAME | WS_POPUP |
> WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
> -exstyle => WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE |
> WS_EX_CONTROLPARENT | WS_EX_TOPMOST,
>);
>
>my $IPaddr = $W->AddTextfield(
> -left => 10,
> -top => 10,
> -width => 100,
> -height => 20,
> -name => "IPaddr",
> -tabstop => 1,
> -style => WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
> -exstyle => 0,
># -readonly => 1,
># -multiline => 1,
>);
>
>my $Stop = $W->AddButton(
> -left => 115,
> -top => 10,
> -width => 40,
> -height => 20,
> -text => "Stop",
> -name => "Stop",
> -default => 1,
> -ok => 1,
> -tabstop => 1,
>);
>
>
>#require Win32::API;
>#my $FindWindowEx ||= new Win32::API("user32", "FindWindowEx", [N,N,P,P],
N);
>#
>#my ($monitorHWND, $childHWND);
>#
># if (($monitorHWND = $FindWindowEx->Call(0, 0, 0, "IP monitor")) &&
># ($childHWND = $FindWindowEx->Call($monitorHWND, 0, "Edit", 0))) {
># print "$monitorHWND, $childHWND, $IPaddr->{handle}\n";
># }
>
>$IPaddr->Text("123.123.123.123");
>print "Edit control HWND: ".
> ($Win32::GUI::VERSION eq "Beta" ? $IPaddr->{handle} :
$IPaddr->{-handle})."\n";
>
>$W->Show();
>$W->Dialog();
>
>sub Stop_Click {
> return -1;
>}
>
>#sub IPaddr_Anonymous {
>#print "here".$IPaddr->Text."\n";
># 0;
>#}
>
>#sub IPaddr_Change {
>#print "here1".$IPaddr->Text."\n"; $IPaddr->Text("XXXXX") unless
$IPaddr->Text eq "XXXXX";
># 1;
>#}
>
>
>And here is the dirty second script (so that you can see almost all ways I
tried).
>
>
>#!/usr/bin/perl -w
>$|=1;
>
>use Win32::Setupsup;
>
>require Win32::API;
> $FindWindowEx = new Win32::API("user32", "FindWindowEx", [N,N,P,P], N);
> if (($monitorHWND = $FindWindowEx->Call(0, 0, 0, "IP monitor")) &&
> ($childHWND = $FindWindowEx->Call($monitorHWND, 0, "EDIT", 0))) {
># print "$childHWND:".GetWindowText($childHWND)."\n"; $res =
"aaaaaaaaaaa";
> Win32::Setupsup::SetFocus($childHWND);
>Win32::Setupsup::SendKeys($childHWND,
"\\BEG\\\\SHIFTL+\\\\END\\\\SHIFTL-\\255.255.255.255", 1);
>#Win32::Setupsup::SetWindowText($childHWND, "aaaa");
> Win32::Setupsup::SetFocus($monitorHWND);
># $SetWindowText = new Win32::API("user32", "SetWindowText", [N,P], N);
># $PostMessage ||= new Win32::API("user32", "PostMessage", [N,N,N,N], N);
># my $r = $PostMessage->Call($childHWND, 11, 1, 0);
># $r=$SetWindowText->Call($childHWND, "aaaa");print "$r\n";
>##SetWindowText1($childHWND);
># # 11 == WM_SETREDRAW
># $r = $PostMessage->Call($childHWND, 11, 1, 0);
>#print "wait...\n";sleep 5;
>use Win32::GUI;
>#Win32::GUI::PostMessage($childHWND, 11, 1, 0);
>#Win32::GUI::Text($childHWND, "888.888.888.888");
>#$a = "abcdefghijklmnop";$buf ="\0"x100;
>#$b = pack "p*", $a; $addr = unpack "L",pack "P*",$buf;
>
>#Win32::GUI::PostMessage($childHWND, 0x000C, 0, unpack "L",$b);
>#$PostMessage = new Win32::API("user32", "PostMessage", [N,N,N,P], N);
># my $e = $PostMessage->Call($monitorHWND, 0x000D, 100, $buf);
>#$e = Win32::GUI::PostMessage($childHWND, 0x000D, 1024, $addr);
>#print "$e = buf:$buf\n";
>#Win32::GUI::InvalidateRect($childHWND, 1);sleep 3;
>#Win32::GUI::PostMessage($monitorHWND, 0x0111, 0x03000002, $childHWND);
>$tt = Win32::GUI::Text($childHWND); #bless{-handle =>
$childHWND},"Win32::GUI::TextField");
>print "main:$childHWND:$tt\n".GetWindowText($childHWND)."\n";
>
># $UpdateWindow ||= new Win32::API("user32", "UpdateWindow", [N], N);
># my $s = $UpdateWindow->Call($childHWND);print "s:$s\n";
>
> }
>#=============
>sub GetWindowText ($) {
># arg - hwnd
> my $buf = "\0"x1024;
> $GetWindowText ||= new Win32::API("user32", "GetWindowText", [N,P,N], N);
>
> my $ret = $GetWindowText->Call(shift, $buf, 1024);
> $ret ? substr($buf, 0, $ret) : undef;
>}
>
>Sorry for the mess, just to show what was tried. And finally the only
working way I've found was to send keys to the Edit control with the use of
Win32::Setupsup - but that's stupid, isn't it?
>
>After I've found $childHWND this
>Win32::GUI::Text($childHWND, "255.255.255.255");
>Win32::GUI::InvalidateRect($childHWND, 1);
>
>should work as it works in that first process - but it does not.
>
>Thanks for any advise.
>
>--
>==================================
>Mike Blazer
>[EMAIL PROTECTED]
>http://base.dux.ru/guest/fno/perl/
>==================================
>
Does your edit control have a password style? If so, you just can't use use
plain GetWindowText/SetWindowText to read/write from/to edit controls that
are in another process. This is some form of security in in the Windows OS.
The only way that I have been able to do it is as follows:
For reading:
Save the clipboard contents.
Save the edit controls selection.
Send message to the edt control to select all the text and a message to post
it to the clipboard
Copy the clipboard contents, this is the text you want.
Restore the clipboard and selection.
For writing:
Post keyboard message to the edit control.
Indy Singh
DynamicSTATE Software
[EMAIL PROTECTED]
www.dynamicstate.com