|
Since i am trying to put text (CDC) on a Cstatic (which looks bluish on my screen) I would like to set the background color of CDC for the TextOut to be the same as the label color. I tried doing the following in the label class but of course its incorrect. HOw do I get the color of the label so I can SetBkColor of the CDC?
COLORREF cl = GetBkColor(GetDC());
GetBkColor' : cannot convert parameter 1 from 'class CDC *' to 'struct HDC__ *'
thanks,
sb
|
|
|
|
|
If this does not help:
COLORREF cl = GetDC()->GetBkColor();
nor
COLORREF cl = m_cMyLabel.GetDC()->GetBkColor();
then you can try this:
COLORREF cl = (COLORREF)GetSysColor(COLOR_3DFACE);
|
|
|
|
|
|
Michael Dunn wrote: Those calls to GetDC() are bad - you need to release every DC you get.
You are right -- explicit releasing should be preferable.
Actually MFC is able to release various handles at idle time. Values returned by GetDC and other functions are temporary objects which are stored in a collection. They a released between message processing.
|
|
|
|
|
Greetings:
I have this application that I'm writing under VS 2003 using C++ and MFC. This one dialog box contains a fixed segment, located in the left-hand part of the dialog, where all of the controls inside will not change. One of the controls is a list box and as the user selects a single item from the list box, the controls on the right automatically change to correspond with the selection. One selection may cause the controls on the right to become a couple of input boxes. Another selection may cause the controls on the right to become a combobox and some check-boxes. Get the picture?
The problem is that I am unsure about how to do this. I thought at first that just using property pages would be the way to go but I am rather sicked by the fact that the property sheet that "holds" the property pages is so inflexable. It is very difficult to resize the property sheet and then place the page part of the sheet into the area that you want. Furthermore, I noticed that the controls that are positioned in the sheet must be placed there programmatically. I hate that idea.
I would prefer to NOT have to paint and repaint my controls programmatically. I would like to draw each of the control sets in the resource editor and then come up with some easy way to just swap them in and out.
Has anybody out there done something like this? Any advice?
Thanks in advance,
Mark
|
|
|
|
|
Jethro63 wrote: This one dialog box contains a fixed segment, located in the left-hand part of the dialog, where all of the controls inside will not change. One of the controls is a list box and as the user selects a single item from the list box, the controls on the right automatically change to correspond with the selection. One selection may cause the controls on the right to become a couple of input boxes. Another selection may cause the controls on the right to become a combobox and some check-boxes. Get the picture?
The application that I am currently working on does the exact same thing.
Jethro63 wrote:
I would prefer to NOT have to paint and repaint my controls programmatically. I would like to draw each of the control sets in the resource editor and then come up with some easy way to just swap them in and out.
Has anybody out there done something like this? Any advice?
Just add all of the controls to the dialog template, end then use EnableWndow() accordingly.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
One of the ways is to dump all possible controls onto the dialog template (as suggested). To make this easier, create several arrays that contain the control IDs for each specific collection/selection, and then loop through them to show/hide/enable/disable as required. (Tip: use CWnd::SetRedraw( FALSE ) to disable drawing while you do this and CWnd::SetRedraw( TRUE ) followed by CWnd::RedrawWindow() to enable it after to prevent flickering.)
Another thing to do which is easier especially if you have lots of controls and you have to make sure they all have the correct tab order is to create several dialog templates, one for each collection/selection, and dynamically show/hide them as "floating" modeless dialogs.
This also makes it easier to place a collection/selection's specific functionality into its own file (one per dialog template).
You have to be careful of placement so things like moving the parent automatically moves the floating dialogs, and have to do a little work to make sure users can tab into and out of the active floating dialog correctly, but it might be easier and/or cleaner depending on your situation.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
|
Thanks for the help on this everybody. I guess I'm a bit perplexed at the prospect of designing a dialog by positioning ALL of the possible controls on the dialog and then turning them ON and OFF in context with the users selection. In my application, there are, I think, 6 different formats. Some are simple and some not so simple. In the resource editor, this is going to look like a dog's breakfast! If there are too many different formats you wish to support, this approach would surely become unfeasible.
I am surprised that VS does not offer an easier way of doing this...
Thanks again!
Mark
|
|
|
|
|
Is there an easy way for a server, implemented with CSockets, to know when one or more clients have disconnected antisocially e.g. network unplugged, powered off etc? I want to prevent a build up of 'obsolete' CSockets in my servers client list.
TIA
|
|
|
|
|
Use CAsyncSocket instead of CSocket and handler OnClose() event.
|
|
|
|
|
Great thanks!
Can't I can still use CSocket as this is subclassed from CAsyncSocket?
Thanks again!
Tony
|
|
|
|
|
He's right, but it doesn't work in all cases:
client --- router ---- router -- server
^ break connection here
If the network connection is broken between the client and server here, neither receives an error until they try to send data. Depending on how things are setup in your app, you might want to consider doing a ping message.
|
|
|
|
|
Hi all,
i want to execute a programm (f.e. ipconfig.exe) with CreateProcess and redirect the output to a char* if possible. The question is: How could this be done? As i am new to CPP, i haven't got a clue...
Can anybody give me a hint please?
Thanks in advance!
-- modified at 10:08 Wednesday 14th June, 2006
|
|
|
|
|
nmx_de wrote: i want to execute a programm (f.e. ipconfig.exe) with CreateProcess
ok
nmx_de wrote: redirect the output to a char* if possible
Do you want to redirect the settings done in ipconfig.exe ???
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
A_LaxmanDo you want to redirect the settings done in ipconfig.exe ???
The problem has nothing to do with ipconfig.exe itself. It was only an example.
I want to be able to call any program (like ipconfig.exe or anything else that returns text) from my program and receive the result.
Thanks for the fast reply
|
|
|
|
|
|
I think it's not what is looking for. He start a console program (like ipconfig.exe) and would like to retrieve the text outputted in the console (so it has nothing to do with returning data).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Cedric Moonen wrote: He start a console program (like ipconfig.exe) and would like to retrieve the text outputted in the console
Jep! This is exactly what i want...
|
|
|
|
|
nmx_de wrote: He start a console program (like ipconfig.exe) and would like to retrieve the text outputted in the console
Try myexe.exe > filename.txt in the ShellExecute which gives the output generated by the myexe.exe into filename.txt .
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
nmx_de wrote: Can anybody give me a hint please?
Hint 1
Hint 2
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
In the first line i want to thank you all for your help.
I managed to get it done like this, but i have some problems using it in another application.
When i put this code to my class and try to run a command from another function, the whole application freezes. Ok, i know that the code looks horrible, but it works a a single application.
Anybody out there with some tipps & tricks regarding this problem?
How could it be done as a class member without freezing the whole app?
Thanks, n.
<br />
#include "stdafx.h"<br />
#include <windows.h><br />
<br />
char* cmd(char *cmd);<br />
<br />
int main()<br />
{<br />
char* output = cmd("ipconfig.exe");<br />
MessageBox(0,output,"Test",0);<br />
return 0;<br />
}<br />
<br />
char* cmd(char *cmd)<br />
{<br />
HANDLE readHandle;<br />
HANDLE writeHandle;<br />
HANDLE stdHandle;<br />
DWORD bytesRead;<br />
char maxbuffer[1024];<br />
<br />
static char output[50000];<br />
SECURITY_ATTRIBUTES sa;<br />
PROCESS_INFORMATION pi;<br />
STARTUPINFO si;<br />
<br />
ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES));<br />
ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));<br />
ZeroMemory(&si,sizeof(STARTUPINFO));<br />
<br />
ZeroMemory(maxbuffer, 1024);<br />
<br />
sa.bInheritHandle = true;<br />
sa.lpSecurityDescriptor = NULL;<br />
sa.nLength = sizeof(SECURITY_ATTRIBUTES);<br />
si.cb = sizeof(STARTUPINFO);<br />
si.dwFlags = STARTF_USESHOWWINDOW;<br />
si.wShowWindow=SW_HIDE;<br />
<br />
if (!CreatePipe(&readHandle,&writeHandle,&sa,NULL))<br />
return "Error";<br />
<br />
stdHandle=GetStdHandle(STD_OUTPUT_HANDLE);<br />
<br />
if (!SetStdHandle(STD_OUTPUT_HANDLE,writeHandle))<br />
return "Error";<br />
if (!CreateProcess(NULL,cmd,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi))<br />
return "Error";<br />
if (!ReadFile(readHandle,output,1023,&bytesRead,NULL))<br />
return "Error";<br />
<br />
output[bytesRead]='\0';<br />
<br />
if (!SetStdHandle(STD_OUTPUT_HANDLE,stdHandle))<br />
return "Error: SetStdHandle(stdHandle) failed";<br />
if (!CloseHandle(readHandle))<br />
return "Error: CloseHandle(stdHandle) failed";<br />
if (!CloseHandle(writeHandle))<br />
return "Error: CloseHandle(stdHandle) failed";<br />
<br />
return output;<br />
}<br />
|
|
|
|
|
I am trying to write on a label.
In the OnEraseBackground function I have
pDC->TextOut(50,42,"aaaa",30);
At this location I get a black rectangle.
What do I need to do to see the text?
thanks,
sb
|
|
|
|
|
I do not know what foreground color, background color, drawing mode you are using, or if you are drawing at the right time because the code sample is missing detail.
But the last parameter you have specified in your example is incorrect - it is supposed to be the character count of the specified string (note that the documentation may be incorrect when it says "byte count"). As such, you should be specifying 4 .
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|