|
After some sloppy refactoring I found something like this in my code:
<br />
class FooBar;<br />
<br />
void foo(const FooBar* const pBar)<br />
{<br />
<br />
delete pBar;<br />
} <br />
So far, so bad. What surprised me, was the fact that this code compiled without any error or warning. I was told, that this compiles also in GCC.
This also compiles though a non-const member function is called:
<br />
void foo(const FooBar* const pBar)<br />
{<br />
pBar->~FooBar();<br />
} <br />
Can you tell me why these snippets work (or at least compile)?
thanks,
Norbert
|
|
|
|
|
You're not changing pBar or what it points to, are you?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I'm surprised too about that behavior: technically the method doesn't change neither the pointer value nor the object itself, but substantially it makes a big change to both. I think it may be a good candidate to subtle bugs.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
|
Thanks for your replies and especially for the links.
Norbert
|
|
|
|
|
Is it possible to parse/send input data from a dialog form editctrl to an existing excel sheet/form (xls) cell?
Maybe this can be done through storing the formdata like in an csv-file or something that later can be imported to the right cells and rows in an excel (xls) sheet?
I've searched the net for solutions, but it seems like this is hard to do.. but it must be possible in some way. (VC++ 6.0)
anyone?
|
|
|
|
|
Yes, you can do this quite easly using Excel Automation.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I am aware of how to change the background color of the entire dialog in VS 6.0 (SetDialogBkColor(RGB(192,202,202) in InitInstance), but this does not seem to work in a dialog based project created in .NET
Any help on how to accomplish this in .NET would be apperciated.
Thanks!
|
|
|
|
|
overload OnEraseBkground()
|
|
|
|
|
do I just do a 'SetDialogBkColor(RGB(192,202,202),RGB(0,0,0))' inside 'OnEraseBkgnd'?
|
|
|
|
|
You can set the background brush in the window class or handle WM_ERASEBKGND. For the latter,
you need to draw the background yourself, using whatever method you want.
SetDialogBkColor is an obsolete method.
|
|
|
|
|
Ok, I handle the OnEraseBkgnd(CDC* pDC) and put the following in there:
CRect Rect;
GetClientRect(&Rect);
CBrush Bursh(RGB(192,202,202));
pDC->FillRect(&Rect,&Bursh);
return TRUE;
This seems to change the background, but my static text and edit boxes are still grey? Am I missing something?
Thanks
|
|
|
|
|
if you want the static controls backgrounds to be transparent, overload WM_CTLCOLOR. here a cool effect :
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC) {
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(192, 192, 192));
hbr = static_cast<HBRUSH>(GetStockObject(NULL_BRUSH));
}
return hbr;
}
BOOL CMyDlg::OnEraseBkgnd(CDC* pDC) {
CRect rect;
GetClientRect(&rect);
COLORREF c1 = RGB(64, 0, 64);
COLORREF c2 = RGB(0, 128, 128);
for(int i = 0; i < rect.Height(); i++) {
int r, g, b;
r = GetRValue(c1) + (GetRValue(c2) - GetRValue(c1)) * i / rect.Height();
g = GetGValue(c1) + (GetGValue(c2) - GetGValue(c1)) * i / rect.Height();
b = GetBValue(c1) + (GetBValue(c2) - GetBValue(c1)) * i / rect.Height();
pDC->FillSolidRect(0, i, rect.Width(), 1, RGB(r, g, b));
}
return TRUE;
}
|
|
|
|
|
Thanks all for the help, it worked
toxcct, thanks for the cool sample
|
|
|
|
|
I like your OnEraseBkgnd() implementation!
It has now become the background to my little MFCTester project I keep around for testing code
before I post it here.
I hope there's no royalties
Mark
|
|
|
|
|
hehe, :-> i know some would have liked it...
enjoy, it's perfectly free
BTW, i borrowed the shading effect to Nish on his personal blog
|
|
|
|
|
arunkk1 wrote: but my static text and edit boxes are still grey? Am I missing something?
Yes.
To extend toxcct's reply for the edit boxes
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(192, 192, 192));
hbr = static_cast(GetStockObject(NULL_BRUSH));
}
else if (nCtlColor == CTLCOLOR_EDIT)
{
pDC->SetTextColor(RGB(...,...,...));
pDC->SetBkColor(RGB(...,...,...));
hbr = (...some brush...);
}
return hbr;
}
|
|
|
|
|
You can use of WM_ERASEBKGND or WM_CTLCOLOR
|
|
|
|
|
dear you have to tell me...
Why on earth do you keep posting something that has already been suggested way better many hours after ?!
|
|
|
|
|
On the earth
|
|
|
|
|
you are gold medal man, you quite have ne excuse.
and wht can't you explain yourself ?
i know english is far from being your mother tongue, but please try and use simple words and short sentences, so that we can understand together...
|
|
|
|
|
Well I can read english but for write not very well and you said explain yourself but what ?
|
|
|
|
|
WhiteSky wrote: explain yourself but what ?
well, explain yourself on the fact that you know copeproject well enough to know that you replied something that was already answered, particularly when your answer if perfectly naked...
have you seen this[^] before posting ?
so ?
|
|
|
|
|
Its interesting for me that does in this period I was useful when I answer to question or my answer was itself problem
|
|
|
|
|
don't you understand ?
yes, answering a question in general well, and yes, your answer was exact and good.
but what i want you to understand, is that it's useless to tell something that has been submitted. it's as if you look on all the answers given there, and make a poor compilation af them. THIS is what i don't like ; and you know it, because we already had words on this some months ago.
if only you were replying within the same hour than someone else, but you come after 5 long hours and don't even provide much informations than what was already on the board.
i was feeling exactly the same way when i notified you here[^]
get me more now ?
|
|
|
|