|
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 />
|
|
|
|
|
Are you saying that WaitCommEvent() never returns? If so, you may need to add some additional EV_xxx events to SetCommMask() .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Sorry I think i was getting a bit confused with the operation of WaitCommEvent()
The WaitCommEvent() returns only when the first time a character is received.. then the program sits in the while loop.. and waits for stuff..
Thank you so much for your help..now I get the tag packets completely..
|
|
|
|
|
The ReadFile() function returns when one of the following is true: a write operation completes on the write end, the number of bytes requested has been read, or an error occurs. As a test, change ReadFile() to:
do
{
char buff;
DWORD dwRead;
ReadFile(h, &buff, 1, &dwRead, NULL);
} while (dwRead == 1);
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I tried the test code u mentioned.. with that the program crashes (windows ends the program, send report to microsoft blah blah..) the first time a character is received ?!
|
|
|
|
|
So does ReadFile() read anything before the program crashes? I'm just wondering if it's ReadFile() that is the culprit, or some other piece of code that is executing right after that.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I think its Readfile() coz all the other code was functioning fine without it ? I don understand why it would do that coz.. the first method u gave and this one are the same principle arent they ?
Thanks for your help..
|
|
|
|
|
Hello,
How to convert pixels to centimeters using the printer DC?
How to save and load the page settings?
Ivan Cachicatari Blog[^]
www.latindevelopers.com
|
|
|
|
|
How about we just don't use the metric system... Much easier. Oops, forgot this was a world-wide forum. That wasn't too helpful, was it?
Danny
|
|
|
|
|
can u tell me how to use inbuild printing function of MFC?
I mean printing is supported for CView (CScrollView), but
i am not able to call the privew & print dialobbox from
my view derived from CScrollView.
thank u
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hello,
I am VERY new to C++ programming however would like to create a program that opens a XML file that contains information on for example 10 different objects. eg
Obj 1
height 10
length 10
width 10
colour brown
Obj 2
height 20
length 12
width 15
colour yellow
I would like the program to be able to use each of the objects separately, so I could use h to represent all the heights but specify object 2 and it would display the height, length, width and colour only, then I could specify object 1 or whatever and it would display the details for that object.
Is there a SIMPLE tutorial that I can read that would tell me how to do this or can anyone else help me.
Thank you.
Slightly confused person
|
|
|
|
|
You can use the DOMDocument or IXMLDOMDocument2 interface for this.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Take a look to this sample[^]code.
Codeproject has also several articles that could help you. One might be this[^]
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
SpuddyMcFuddy wrote:
s there a SIMPLE tutorial that I can read that would tell me how to do this or can anyone else help me.
This nice sample class can help you out.....
http://www.codeproject.com/soap/markupclass.asp
"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
|
|
|
|
|
If you call SheelExecute api, it just executes an application as if somebody double clicked it in shell, that is the default open command. I want to execute an exe programatically, but i dint want to invoke Open, i want to invoke "Run As" option of the context menu. Can anybody help me.
Tariq
|
|
|
|
|
you have to call the program which is expected to open the file, and pass it the file as parameter as it wants you to.
lets take an easy example :
your default text editor is UltraEdit (of course, you have a license for it ), but you want to open you text file within Notepad...
just call ShellExecute making it call "notepad.exe textfile.txt"...
however, all program are not always waiting for same parameter, and not even in same orders, so check it out then...
understand ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
You can use the "runas" verb with ShellExecute() .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thanks alot David, this was what i was looking for.
Thanks.
|
|
|
|