|
In an SDI app , I m trying to do the following :
My View creates a Wnd and I am trying to dynamically create some controls ( CStatics)
Something like this
Test Test status
test 1 Running ....
test 2 Untested
test 3 Untested
All text are within their CStatics . I was trying to Color Code the Test Status
Like blue while running
red for failed
green for passed
grey for untested .
So I create a Class that inherits from CStatics and according to the article
HOWTO: Change the Color of an MFC Child Control Class
ID: Q132080
I overrode the OnChildNotify method
Here is what I do .
<br />
int value = 0; <br />
#define BACKCOLOR RGB(190,190,190)<br />
<br />
<br />
const COLORREF colors [] = { <br />
RGB(255,0,0),<br />
RGB(0,255,0),<br />
RGB(0,0,255)<br />
};<br />
<br />
<br />
#define VALUECOLOR colors[value]<br />
<br />
BOOL CColoredStatic::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) <br />
{<br />
<br />
if (message != WM_CTLCOLORSTATIC)<br />
{<br />
return CStatic::OnChildNotify(message,wParam,lParam,pLResult);<br />
}<br />
<br />
HDC hdcChild = (HDC)wParam;<br />
COLORREF oldTextColor = GetTextColor(hdcChild);<br />
COLORREF oldBkColor = GetBkColor(hdcChild);<br />
SetTextColor(hdcChild, VALUECOLOR );<br />
<br />
SetBkColor(hdcChild, BACKCOLOR);<br />
<br />
*pLResult = (LRESULT)(m_brush.GetSafeHandle());<br />
<br />
<br />
<br />
return TRUE;<br />
<br />
}<br />
<br />
void CColoredStatic::ChangeValue(const int &newVal)<br />
{<br />
value = newVal;<br />
Invalidate();<br />
}<br />
What I find is that after changing the value of "value" externally for the first CColorStatic object , all the CStatics get painted with the same color . Where the desired effect is to just update that Object .
My questions
when i do this
SetTextColor(hdcChild, VALUECOLOR );<br />
<br />
SetBkColor(hdcChild, BACKCOLOR);
So I have to restore the Color setting for the remaining controls ?
If yes what is that Call ? Something like a restoreObject !!!!!!!!
|
|
|
|
|
If I am reading your code correctly: value is a global variable, which is the problem. The variable value should be a class member, so that it only applies to the current CColoredStatic derived control, instead of all of them.
INTP
|
|
|
|
|
I m sorry it is a private data member of the class .
|
|
|
|
|
i have an compiled HtmlHelp file I'm using with my application. When I call the following function from MainFrame.cpp
<br />
::HtmlHelp(GetSafeHwnd(), "GameOn.chm::/Welcome.html", HH_DISPLAY_TOC, 0);<br />
it works fine. Using the same code in a DLL for my application, I doesn't work. What's more weird is that if I call Help from MainFrame first, then call help from a DLL, it works. If I call help from the DLL first and then try to call help from the MainFrame.cpp it doesn't work.
Is there something I might be missing from my DLL call that should be included? The htmlhelp.lib is being imported and the htmlhelp.h is referenced.
Thanks!
|
|
|
|
|
HtmlHelp is more sensitive to the 'process' than the Window handle, like WinHelp used to be.
Try passing the top level window of your application as the first parameter.
Even from a DLL, we just use ::GetDesktopWindow() instead.
When your program quits, or if you want to programaticlaly dismiss help, use the HH_CLOSE_ALL command.
|
|
|
|
|
<br />
::HtmlHelp(::GetDesktopWindow(), "GameOn.chm::/Welcome.htm", HH_DISPLAY_TOC, 0);<br />
This didn't work.
|
|
|
|
|
Provide the FULLY QUALIFIED file path to your help file.
You might not be the current directory when help is invoked. HTMLHelp doe snot otherwise know where to find your help file.
For exmaple:
::HtmlHelp(::GetDesktopWindow(), "C:\\Program Files\\Common Files\\MyCompanyName\\MyProductName\\GameOn.chm::/Welcome.htm", HH_DISPLAY_TOC, 0);
See if that works.
|
|
|
|
|
|
In VC 6.0 there was a way to make a custom appwizard then base it off of an existing project. I can't find this option in the .net environment. Is this no longer supported, or am I just looking in the wrong place? Thanks in advance.
[insert witty comment here]
bdiamond
|
|
|
|
|
Hey all. I'm having a problem getting a connection to a SQL Server to timeout. What is happening is I am using CDatabase::OpenEx (code below). If the computer is disconnected from the network, or the database server is down, the program just hangs forever. It never even times out after five or ten minutes and I have to manually end the process.
Here's what I'm using to connect:
CString DBCONNECT = "Driver={SQL Server};Connection Timeout=10;Server=DSC\\DAVEINSTANCE;Database=Master;Uid=sasd; Pwd=blah;"
(I put a space between ; and Pwd because the smiley was showing up)
CDatabase myDB;
myDB.SetLoginTimeout(10);
TRY {
myDB.OpenEx(DBCONNECT,CDatabase::noOdbcDialog);
.... I've tried without "Connection Timeout=10;" in the connection string, and only using myDB.SetLoginTimeout ... and vice versa ... without SetLoginTimeOut. I've also tried "Connect Timeout=10" Neither of these are working. I saw in the MSDN that some connections do not allow SetLoginTimeout, but I'm guessing there has to be a way to time out the connection instead of having the program hang on myDB.OpenEx().
Any help would be appreciated.
|
|
|
|
|
I am running a server client based application using VC++. I am using DDEML to initialize the DDE and creating string handles. Using Excel as the client application. when i run the .exe created from VC++, after say 2 hours the system starts slowing down and the CPU usage reaches 100%. Could someone please let me know how to make sure that CPU doesn't go 100%.
|
|
|
|
|
swerajan wrote:
...and the CPU usage reaches 100%.
Of which process?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
when i run my application(ddemlsrv.exe) the csrss.exe process gradually uses upto 80% of the CPU along with the ddemlsrv.exe it reaches 100%. I don't understand what is wrong with the program.
|
|
|
|
|
I've been trying to write a MP3 ripper myself, because
I can't find any good one online. I have been searching
for this similar project for a while, all I can find is
encoder.
While I do need an encoder, the first step I need is to
know how do I read a .cda file from a CD? I've been wondering
if fread() would work in this case, because I don't even
know if .cda is a binary file or not? Is it a binary file?
Please help me, or if you know similar project elsewhere,
would you please share it?
-----------------------------
C++ without virtual functions is not OO. Programming with classes but without dynamic binding is called "object based", but not "object oriented".
|
|
|
|
|
I m facing a problem in my project. Actually i have drawn a line in VC++ using moveTo and lineTO function. now if user double clicks the line a dialog box should be open. What the problem is to check wheather the user clicks on the line or not. for this i have created the boundry rectangle of the line i.e if the statement is like
pDC->MoveTo(x1,y1);
pDc->LineTo(x2,y2);
then the boundry rect will be Rectangle(x1,y1x2,y2). in this case the tolerance level(clickedpoint+-value) is very high. if user click say 5-10 Points far from the line still the dialog box will be opened. i want to reduce the size of the boundary rect. keep in mind there should not be any effect on the orentation of line
Let me know plzzz if any one have solution to this problem
|
|
|
|
|
Once the rectangle has been defined, and you know the point at which the mouse was clicked, just use PtInRect() .
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
this will work very well in the case if line is at the angle of 90 or 180 but if the line is at the angle of 60 or 45 etc in such cases the rectangle size will be quite big... i want to reduce that size
|
|
|
|
|
I believe you simply should calculate the distance between your line and the point where the user has clicked. If the result is lower than a few pixels, then consider the user has clicked on the line.
As a reminder, the distance between a point M(x0,y0) and a line L with equation Ax+By+C=0 is given by the formula:
d = fabs(Ax0+By0+C) / sqrt(A^2 + B^2)
|
|
|
|
|
My bad. I don't work with graphics (e.g., line drawing) so I forget that lines can be more than just horizontal!
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Normaly I would try something simular to Bresenham's line-drawing algorithm to test if a given point falls on or close to the line.
You can try looking at the DRAWCLI sample program in MSDN or at any victor drawing program you can find (with source), since they all needed to do this.
* Another option you could try, would be to use Regions (regions [Win32]) instead of Rectangles to specify the bounding area. A Region can be any shape you want it to be; therefor, you could use the PtInRegion() function to check if line is selected.
Good Luck!
INTP
|
|
|
|
|
Hi all ,
I have just discovered this forum.Looks great !!
I am trying to use downloaded files for compiling a program to decode DRM short wave HI FI .Article from ELEKTOR april 2004.
After getting everythig ready including the visual studio service pack 5 and corresponding processor pack (all installed)
The C++ refuses to acknowledge the existance of the declarations in the header files
xmmintrin.h and mmintrin.h and display 4 errors per line of prototype function
(syntax errors)going to over 5000 errors .
I suspect that the processor pack is not enabled by the program or the processor is not selected ??? My system uses an AMD 2600 with DDR(500 K).
Am I doing anything wrong ??
I just downloaded the article on SSE
G Brennet
|
|
|
|
|
Does anyone know how to have a button on a toolbar which is of a different width than the other buttons?
I have tried using multiple toolbars, and that works, but does not give the result I want when the window is made resized small and then back large again.
Thanks
|
|
|
|
|
You will need to derive your own class from CToolBar and override some of the functionality.
Here are the notes from my code to fix the drop down arrow problem:
If you want I could zip up the code and send it to you. There is no garantee that it will solve your problem, but it would give you a good start.
INTP
|
|
|
|
|
Thanks for the information and your offer to zip and send me the code.
I will look into the Q article, as well as another possibility.
If I think the zipped code would be useful, I'll send you an email.
Thanks again for the offer.
|
|
|
|
|
Hi, i've got this class
template<class t=""> class pointer
{
private:
T *p;
};
and i get 4 if i do sizeof(pointer).
if i add a static member data, it doesn;t count. why is it that? is it because there's only one copy of that atribute for all the instances of the class?
then, if i add a virtual function (or 2, or 3), i get 8 if i do sizeof(pointer). why is that?
thanks for your help!
|
|
|
|