Discussion:
GetWindowText
(too old to reply)
Mike Larson
2003-09-16 18:04:20 UTC
Hello,

I'm working in a plain DLL, not a driver.

I am trying to use the GetWindowText function to get the text in a TextBox
from a VB6 app.

The GetWindowText function in always returning an empty string. Here is the
code:
long _stdcall ReadText (HWND ReadControl, HWND WriteControl)
{
char ReceiveString [40];
GetWindowText(ReadControl, ReceiveString, 40);
SetWindowText(WriteControl, ReceiveString);
SendMessage(WriteControl, WM_KEYUP, 0, 0);

return ((long)ReceiveString [0]);
}

ReadControlis the hWnd value from the VB6 app of the TextBox to read,
WriteControl is the textbox to copy to.

Am I using it correctly? Is there another function I should be using.

I'm returning the first character just to see what if anything is being
read.

Thanks for any help.

Mike
Mike Larson
2003-09-16 18:40:22 UTC
Thanks for the reply.

It turns out that I forgot that I cleared the textbox in the VB app before
the call to ReadText. As it turns out both GetWindowText and the
SendMessage with WM_GETTEXT works as expected.

Thanks again.
Instead of using GetWindowText() use WM_GETTEXT message. Something
like
long _stdcall ReadText (HWND ReadControl, HWND WriteControl)
{
TCHAR ReceiveString [MAX_PATH+1] = {0};
SendMessage( ReadControl, WM_GETTEXT, MAX_PATH,
(LPARAM)(LPTSTR)ReceiveString );
..........
..........
}
--
Cheers
Check Abdoul [ VC++ MVP ]
-----------------------------------
Post by Mike Larson
Hello,
I'm working in a plain DLL, not a driver.
I am trying to use the GetWindowText function to get the text in a TextBox
from a VB6 app.
The GetWindowText function in always returning an empty string. Here is
the
Post by Mike Larson
long _stdcall ReadText (HWND ReadControl, HWND WriteControl)
{
char ReceiveString [40];
GetWindowText(ReadControl, ReceiveString, 40);
SetWindowText(WriteControl, ReceiveString);
SendMessage(WriteControl, WM_KEYUP, 0, 0);
return ((long)ReceiveString [0]);
}
ReadControlis the hWnd value from the VB6 app of the TextBox to read,
WriteControl is the textbox to copy to.
Am I using it correctly? Is there another function I should be using.
I'm returning the first character just to see what if anything is being
read.
Thanks for any help.
Mike
Alan Carre
2003-09-17 10:44:40 UTC
Actually... strangely enough, you don't need to send a message OR call GetWindowText.
You can simply use "DefWindowProc" with the 'messages' WM_GETTEXTLENGTH and
WM_GETTEXT to get the length first, and then the text. I know it sounds crazy, but it
works. DefWindowProc doesn't need to be called inside the WndProc, or even the
process associated with the HWND parameter.

- Alan

P.S. Also note that, sending the message can cause your application to hang if the
receving thread is blocked for some reason.
Post by Mike Larson
It turns out that I forgot that I cleared the textbox in the VB app before
the call to ReadText. As it turns out both GetWindowText and the
SendMessage with WM_GETTEXT works as expected.
Just by the way, note that GetWindowText() is guaranteed to work only when
the target window is owned by a thread in the same process as the calling
thread. Otherwise, you need to send the message.
Regards,
Will
William DePalo [MVP VC++ ]
2003-09-17 14:55:15 UTC
Post by Alan Carre
Actually... strangely enough, you don't need to send a
message OR call GetWindowText. You can simply use
"DefWindowProc" with the 'messages' WM_GETTEXTLENGTH
and WM_GETTEXT to get the length first, and then the text.
I know it sounds crazy, but it works.
Yes, it does sound crazy. :-) You have tried this on NT/2K/XP?
Post by Alan Carre
P.S. Also note that, sending the message can cause
your application to hang if the receving thread is blocked
for some reason.
Right. That's why there is a SendMessageTimeout() function.

Regards,
Will



Database (slave) 0.003973 s
44.2813 kB
Benchmark Min Max Average Total
SELECT `lang` FROM `newsgroup` WHERE `newsgroup_url` = 'microsoft.public.vc.language' (4)
0.000167 s
0.000527 s
0.000318 s
0.001273 s
2.2344 kB
2.3672 kB
2.2676 kB
9.0703 kB
SELECT `code`, `name` FROM `lang` WHERE `code` = 'en' (3)
0.000134 s
0.000186 s
0.000167 s
0.000500 s
2.4141 kB
2.4141 kB
2.4141 kB
7.2422 kB
SELECT * FROM `lang` WHERE `code` = 'en' (1)
0.000188 s
0.000188 s
0.000188 s
0.000188 s
12.5313 kB
12.5313 kB
12.5313 kB
12.5313 kB
SELECT * FROM `thread` WHERE `hash` = 'hbPUFpa7' (1)
0.000447 s
0.000447 s
0.000447 s
0.000447 s
4.2500 kB
4.2500 kB
4.2500 kB
4.2500 kB
SELECT * FROM `newsgroup` WHERE `newsgroup_id` = '21643' (1)
0.000476 s
0.000476 s
0.000476 s
0.000476 s
5.8047 kB
5.8047 kB
5.8047 kB
5.8047 kB
SELECT * FROM `temp_simthread` WHERE `hash` = 'hbPUFpa7' (1)
0.000684 s
0.000684 s
0.000684 s
0.000684 s
2.6953 kB
2.6953 kB
2.6953 kB
2.6953 kB
SELECT text_res, img_res, manual FROM porndetect WHERE hash = 'hbPUFpa7' AND page = 1 (1)
0.000405 s
0.000405 s
0.000405 s
0.000405 s
2.6875 kB
2.6875 kB
2.6875 kB
2.6875 kB
Kohana 0.013625 s
46.5469 kB
Benchmark Min Max Average Total
find_file (69)
0.000017 s
0.000413 s
0.000197 s
0.013625 s
0.5234 kB
2.1563 kB
0.6746 kB
46.5469 kB
Requests 0.083842 s
437.2656 kB
Benchmark Min Max Average Total
"hbPUFpa7/getwindowtext" (1)
0.087172 s
0.087172 s
0.087172 s
0.087172 s
465.2578 kB
465.2578 kB
465.2578 kB
465.2578 kB
Thread controller 0.001735 s
27.7188 kB
Benchmark Min Max Average Total
Init (1)
0.001735 s
0.001735 s
0.001735 s
0.001735 s
27.7188 kB
27.7188 kB
27.7188 kB
27.7188 kB
Thread parsing 0.054532 s
61.7422 kB
Benchmark Min Max Average Total
Other (2)
0.006691 s
0.013320 s
0.010005 s
0.020011 s
10.7656 kB
14.1641 kB
12.4648 kB
24.9297 kB
PHP Post Parsing (1)
0.003842 s
0.003842 s
0.003842 s
0.003842 s
23.0156 kB
23.0156 kB
23.0156 kB
23.0156 kB
C++ Post Parsing (1)
0.030278 s
0.030278 s
0.030278 s
0.030278 s
7.4766 kB
7.4766 kB
7.4766 kB
7.4766 kB
Three (1)
0.000401 s
0.000401 s
0.000401 s
0.000401 s
6.3203 kB
6.3203 kB
6.3203 kB
6.3203 kB
Load & uncompress 0.013219 s
8.6016 kB
Benchmark Min Max Average Total
load_thread (1)
0.013219 s
0.013219 s
0.013219 s
0.013219 s
8.6016 kB
8.6016 kB
8.6016 kB
8.6016 kB
Application Execution (507) 0.020666 s 33.418700 s 0.197975 s 0.113743 s
749.6172 kB 4,534.3750 kB 1,358.3563 kB 1,087.4688 kB