|
|
|
i want to know how to set IPAddress control in status bar.
thanks
|
|
|
|
|
you have the ip address. Convert it to some string format and use
SetPaneText (/*params*/) API from CStatusBar class
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Your question ranges over a few subjects.
1/ Putting a status bar on a dialog - and the other reply points you at an article for that.
2/ Putting a control on a pane
3/ and putting it in the Nth pane.
http://www.codeproject.com/KB/miscctrl/progressbar.aspx[^]
Will help with (2) and (3). It uses a progress bar, but that will be easily adaptable to another control type.
Good luck!
Iain.
|
|
|
|
|
I am working on a Win32 based GUI, which has a menu with a static area defined as
CONTROL "",IDC_GRAPH,"Static",SS_GRAYFRAME,17,119,264,54
in the rc file.
In my OnPaint(), the following code gets executed
HWND hStatic = GetDlgItem(m_hWnd,IDC_GRAPH); //m_hWnd is CWnd handle
RECT pRect;
HDC hStaticDC= GetDC(hStatic );
GetClientRect(hStatic,&pRect);
iCX = (pRect->right - pRect->left)/2;
iCY = (pRect->bottom - pRect->top)/2;
COLORREF bkColor = GetBkColor(hStaticDC);
HPEN pen = CreatePen(PS_SOLID,8,bkColor);
MoveToEx(hStaticDC,iCX+4,iCY,NULL);
LineTo(hStaticDC,iCX1+4,iCY);
The code compiles correctly. But the bkColor gets CLR_INVALID and MoveToEx and LineTo returns a zero value. Where have I gone wrong?
modified on Thursday, December 11, 2008 4:20 AM
|
|
|
|
|
Are you using the static as a placeholder on your dialog where your drawing is suposed to go? If so, why don't you simply acquire its position and then draw into the dialog's DC? And make your static non-visible? I think it's a simpler method than trying to draw onto a static from another windows OnPaint... anyhows, are you sure you get a correct DC for that static? And why do you MoveToEx and LineTo the same coord? (*iCX+4,iCY), if you want to make a point use SetPixel or SetPixelV instead. Am not sure if 0 length lines are drawn as a point by GDI or not though.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Recently I came to know that MFC in VC++ 2008 has been enhanced to a great extent with tabbed MDI views, ribbons etc. to name a few. This means a fully dedicated book on VC++ 2008 is the need of the hour.
I have few books on VC++ 6 & 2003. But to fully utilize the potentials of the 2008 version these are not sufficient.
Can anybody suggest a good book on VC++ 2008?
Thanks in advance.
|
|
|
|
|
Sorry I don't have any good suggestions on Visual C++ 2008.
Hope you're into native programming. If you're already comfortable with the existing MFC, C++ Concepts (VC 6 Above), I think you can easily grasp the Changes in Visual C++ 2008[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hello
My application is a multithreaded MFC VC++ application and I would like to implement logging support so that the logging has the following features:
1. Log messages based different levels of logging
2. Log different data types like CStrings, dump custom classes, windows handles etc, numeric values.
3. Log thread id's and other info
Can somebody suggest me a good logging library with all this support which can be used? What about Pantheios logging library, would it suffice my requirements?
Thanx
|
|
|
|
|
|
Hai !
I have a device connected to a COM port, i send a command to the device, the device responds, this response is stored in the buffer of COM port.
I read part of the response from buffer, and send the next command, now if i read response from buffer, i get the old remaining response plus the new response.
so i want to clear the buffer before i send a new command!
so how to clear the buffer of a COM port !
thanks !
|
|
|
|
|
How do you read and write to the Buffer?
|
|
|
|
|
Using the handle of Port along with ReadFile () and WriteFile ()
|
|
|
|
|
When communicating directly with the serial driver through the ::WriteFile() and ::ReadFile() API, you cannot "flush" the read buffer.
The file API contains the ::FlushFileBuffers() function, but it only flushes the transmit buffer if the handle refers to a communications device such as a COM port.
You have to read the entire response from your first request before issuing a new request to the device.
Why does this present a problem for you? Is it due to the lack of transmission protocol that you don't know how much data to expect from your device?
Some way you have to know when you've received the complete response from your device, either by protocol or by a timeout.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Are you specifying the FILE_FLAG_OVERLAPPED flag in CreateFile()..?
|
|
|
|
|
Ummm, I guess you replied to the wrong guy...
However, specifying the flag for overlapped mode doesn't make a difference regarding "flushing" the receive buffer in the serial driver.
On the other hand, overlapped mode should be used in any case.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
To be more specific :
The context where i want to clear buffer is somewhat as follows :
The device which is attached to the COM port is sujected to a specific Baudrate, parity, databit and stopbit, whose values i do not know beforehand. so i send the command for all combinations of baudrate, parity, databit stopbits.
During the process i receive junk/unnecessary response for a wrong combination, and i get correct/ expected response only for correct combination of baudrate, parity, databibit and stopbit.
so i want only to read the correct response and ignore others !
I know correct value starts with a specific value, so when ever there is a response starting with the specific value, I read it else I ignore it.
Now for the responses which I get for wrong combination donot start with a specific value so I ignore them hence they get accumulated in the buffer, now when the correct combination is reached and I try to read the response it starts with previous junk values as this response doesnot start with my specific value so it gets ignored in way I lose my correct response also, so I want to clear the buffer befor I send my command.
Thanks !
|
|
|
|
|
kapardhi wrote: The device which is attached to the COM port is sujected to a specific Baudrate, parity, databit and stopbit, whose values i do not know beforehand. so i send the command for all combinations of baudrate, parity, databit stopbits.
You actually mean that you have no idea, and cannot predict, what settings the device uses on start up? I find that very hard to believe, because it means that the device is uninitialized and hence should not be able to communicate at all.
Usually a device that supports multiple communication settings starts off with a known configuration; e.g 300 baud, 1 stop bit, no parity. Then the host negotiates with the device about a new configuration through a known protocol.
If you don't know anything about this device, you would be better off using an oscilloscope to find out what configuration is used.
But even if you find out what configuration is being used, you still have to know the protocol, which I suspect can be found at the same place as where the communication settings are documented.
The alternative is to set a timeout using ::SetCommTimeouts() to let the timeout of the read operation expire when the hardware hasn't received a new byte within e.g. ten byte times. Then it's reasonable to assume that you've received all data the device wants to send and you can continue and try another configuration.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Sorry u are misunderstanding me !
Actually in my application i have an option to change the baudrate, parity, stopbit, databit of the device connected as well as to change the baudrate, parity, stopbit, databit of the COM port.
now lets assume one of the user have changed the device baud rate to 115200, with even parity, 6 databits 2 stopbits.
now i donot know the configuration of the connected device, so i have to change my COM port settings and send command for all combinations of baudrate, parity etc in order to communicate with the device.
when i get the correct/expected response i can conclude that this is the combination of the device!
i am also using CommTimeOuts !
Thanks !
|
|
|
|
|
kapardhi wrote: Actually in my application i have an option to change the baudrate, parity, stopbit, databit of the device connected as well as to change the baudrate, parity, stopbit, databit of the COM port.
Why is this option offered to the user?
Is it because the application communicates with different kind of devices with different communication settings?
IF the application connects to different devices, doesn't one particular device start up with the same settings as the last time, i.e. is it not predictable?
If it is predictable, why not let the user choose from a list of device types that corresponds to the communication settings instead of giving him the possibility to change all settings and thus create this problem for you, the application, the device and himself?
My point is that the settings in the device should be the same every time it starts. If the user knows what kind of device it is, the application should know what configuration to use in order to communicate with that kind of device. It's your responsability as developer to make this mapping and if you don't think it is, then the user could use HyperTerminal, PuTTY or similar.
kapardhi wrote: i am also using CommTimeOuts !
But probably the wrong way, or with the read timeout too short, since you clearly have not received the complete answer. Otherwise you would not have posted this thread in the first place.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I can see this being very fragile [*]
What if you see the first part of the response, act on that, clear the buffer, but the rest of the response is still coming in?
You could clear the buffer too early. What do you do with the junk data?
If you wait for it to be quiet, you will add long delays.
If you wait till the right amount of data has come in, you don't need to flush.
I really struggle to see you needing to do this, unless your protocol is broken. If it's designed by someone else, then it's probably fine and you need to change your code. If it's designed by you, then you may need to go back and change the protocol *then* your code.
I've had similar issues with Pipes and sockets with varying data-lump-sizes, and solved it by having a header value specifying how many further bytes are in this lump of data. Simple but works well. Whether you pay attention to the whole data-lump or not, it's wise to read it all in. Feel free to throw it away.
Good luck,
Iain.
[*] A euphemism meaning it will fail within 2 minutes of someone else using it.
|
|
|
|
|
To be more specific :
The context where i want to clear buffer is somewhat as follows :
The device which is attached to the COM port is sujected to a specific Baudrate, parity, databit and stopbit, whose values i do not know beforehand. so i send the command for all combinations of baudrate, parity, databit stopbits.
During the process i receive junk/unnecessary response for a wrong combination, and i get correct/ expected response only for correct combination of baudrate, parity, databibit and stopbit.
so i want only to read the correct response and ignore others !
I know correct value starts with a specific value, so when ever there is a response starting with the specific value, I read it else I ignore it.
Now for the responses which I get for wrong combination donot start with a specific value so I ignore them hence they get accumulated in the buffer, now when the correct combination is reached and I try to read the response it starts with previous junk values as this response doesnot start with my specific value so it gets ignored in way I lose my correct response also, so I want to clear the buffer befor I send my command.
Thanks !
|
|
|
|
|
Are you perchance in search of PurgeComm[^]?
Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
PurgeComm clears the buffer of the device's driver, i want to clear the buffer of the Serial COM port of my computer !!
|
|
|
|
|