|
I am trying to get the text from a control in another process. I know the handle for the control and I know the afx class name. It is as follows:
Class Name : Afx:400000:20
This control is part of a chatbox in an external application. I have tried several different things but I have so far failed to get the text from it.
Any ideas or help would be greatly appreciated.
Thanks.
Dave
|
|
|
|
|
cats8199 wrote:
I have tried several different things...
Such as?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I have tried sending the messages EM_GETLINECOUNT and WM_GETTEXT. Both return zero. This is a multiline text box. I have tried treating it as a CListBox, a CComboBox and a CListCtrl. All to no avail.
Dave
|
|
|
|
|
cats8199 wrote:
This is a multiline text box. I have tried treating it as a CListBox, a CComboBox and a CListCtrl. All to no avail.
It's no surprise! Why haven't you tried CEdit instead? That, however, is not the problem here. If neither EM_GETLINECOUNT nor WM_GETTEXT worked, using an MFC class is just added complexity.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Send the WM_GETTEXT message to that control.
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
I have tried sending the messages EM_GETLINECOUNT and WM_GETTEXT. Both return zero. This is a multiline text box. I have tried treating it as a CListBox, a CComboBox and a CListCtrl. All to no avail.
Dave
|
|
|
|
|
Check out this article, it has code that does what you want.http://www.codeproject.com/tools/WindowScraper_Utility.asp[^]
If you tried sending a WM_SETTEXT message to the window and it doesn't work, it could because the authors of the control did not implement a WM_SETTEXT handler. I see this error quite often in custom controls. What a lot of people seem to do is override the GetWindowText() function, instead of adding a WM_GETTEXT message handler.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
I read MSDN whole day, but it didn't work. I need some example or good FAQ.
|
|
|
|
|
I mean TAPI for 2 modem connection (not internet).
|
|
|
|
|
have you tried this article[^] ?
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
this may help u.. Click
Regards,
V
|
|
|
|
|
|
Give me please an example of using Interbase in VC++. mailto:grey_s3@yandex.ru
|
|
|
|
|
|
|
how to change colour of static text at runtime.
|
|
|
|
|
Try using SetTextColor function of CDC by trapping the ON_WM_CTLCOLOR() message. In the message-handler OnCtlColor, use code like this:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(m_stText.m_hWnd == pWnd->m_hWnd)
{
pDC->SetTextColor(RGB(0,0,155));
}
return hbr;
}
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
|
|
|
|
|
hi,
thanks man it worked ,and for clearing the concept with that informative code
I added the following code to get the CWnd* handle to the static control from the IDC_
CWnd *m_stText=GetDlgItem(IDC_STATIC);and i guess it doesnt work with the button.
thanks
Farpointer
|
|
|
|
|
farpointer wrote:
guess it doesnt work with the button.
thanks
For Coloring the Button you either have to subclass it or make it owner drawn...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
The WM_CTLCOLORSTATIC message is sent to the parent during drawing of the control. The HDC and HWND are provided to change the foreground colors. The return value is a brush to set the background.
|
|
|
|
|
Hello..
I'm trying to read in data coming from the serial port.. the data can come in at any time (so the program has to monitor the serial port continuously, thats why i'm using a while loop in my code below). I'm reading Tag IDs (strings) which are formatted into packets.. each packet starts with the '&' character and ends with the '$' character..
Right now I read in the whats coming from the serial port (using a infinite while loop) into a string and then tokenize that string according to my packet delimiters.. the problem is that Readfile is returning after getting part of the tag ID packet and then the remaining part of the tag ID packet comes the next time the while loop is called.. I think its something to do with the way I use the readfile function in the while loop..my code is given below.. Please advice..
Thank you for your help..
<br />
<br />
char buffer[200000];<br />
<br />
while (true)<br />
{<br />
printf("In while\n"); <br />
<br />
memset(buffer, 0, sizeof(buffer));<br />
if (ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0))<br />
{<br />
printf("Read file has a result\n"); <br />
if (bytesRead != 0)<br />
{<br />
printf("Got some bytes\n"); <br />
printf ("%s", buffer);<br />
<br />
printf( "Tokens in buffer:\n" );<br />
<br />
token = strtok(buffer, "&$" );<br />
<br />
while( token != NULL )<br />
{<br />
<br />
printf( " %s\n", token );<br />
<br />
token = strtok( NULL, "&$" );<br />
}<br />
<br />
}<br />
<br />
else <br />
{<br />
printf("No bytes read\n"); <br />
}<br />
}<br />
<br />
else {<br />
printf("Readfile didnt give proper result \n"); <br />
}<br />
Sleep(200);<br />
}<br />
<br />
|
|
|
|
|
You have serveral solutions to this 'problem'. First, it is not a problem but a normal behavior: you are reading the serial buffer faster than the data is coming in, so depending on the timeout you specified for the serial port, you will probably have only a part of the data.
One solution is to read the string in several times: you keep a counter that says how much bytes needs still to be read and this counter will be also used as index to write the data in an array.
Second solution is to set timeout parameters of your serial port big enough to have the time to read the entire data. You can set timeouts by using the SetCommTimeouts function.
I prefer the first solution because it is more secure, even if you have some unexpected latency somewhere. And still, your device can send data not continuesly so you have to know when start reading then. Or you can use complete blocking reading but that's not a good solution neither: if your device stop, your program will hung.
Another thing: are you running this loop in a separate thread ? If no, I suggest to do so, like that it won't interfere with the user interface handling.
|
|
|
|
|
Thank you for your reply..
The things is.. I dono before hand how many tag packets will be coming in at a given time, as any number can come in, so cant use the first solution..
The Comm timeouts solution u mentioned.. say for instance suppose the tag ID packet comes in a little bit before the timeout and doesnt get read fully, then it would still get cut off like before wouldnt it..like u said i would know have to know when to start reading.. but in my case i dono coz i have to monitor the serial port continuously and get data whenever it comes..
I'm just using one thread as my program only has to add the tag ID packets to a database.. there is no user interaction with the program.
Could u pls elaborate on the Complete blocking reading or any other way i can go about this ?
Thank you for your help..
|
|
|
|
|
I would consider letting an event tell me that something was ready to be read rather than needlessly trying to read from a possibly empty port. Try something like:
SetCommMask(h, EV_RXCHAR);
DWORD dwEvent;
WaitCommEvent(h, &dwEvent, 0);
if ((dwEvent & EV_RXCHAR) == EV_RXCHAR)
{
do
{
ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0);
} while (bytesRead > 0);
}
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thank you for the reply..I tried the using the method u suggested above but the program just hangs and nothing at all is received.. this is the code what i'm using.. Pls advice.. Thank you..
<br />
SetCommMask(h, EV_RXCHAR);<br />
DWORD dwEvent;<br />
WaitCommEvent(h, &dwEvent, 0);<br />
<br />
while (true)<br />
{<br />
printf("In while\n"); <br />
<br />
memset(buffer, 0, sizeof(buffer));<br />
<br />
if ((dwEvent & EV_RXCHAR) == EV_RXCHAR)<br />
{ <br />
do <br />
{ <br />
ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0); <br />
} while (bytesRead > 0);<br />
}<br />
<br />
Sleep(200);<br />
}<br />
<br />
|
|
|
|