|
I have tested my examples and work wery well.
However, if you read again more carefully my previous posts you'll see that I have made some particular presumptions like
- we have a DIALOGEX resource.
- the dialog has attached a menu with ID in the .rc file (not a name).
- a CLASS statement was inserted in .rc file, that we'll replace with a class name with the same length.
If one of them is not respected, most possible you can have troubles.
There are just particular-case EXAMPLES, intended to show you the IDEA.
If you want to deal with all the cases and write a general function, dig deeper in DLGTEMPLATEEX structure documentation, as I already said and modify the code accordingly.
I can do that for you "solving all your homework", but I have not enough time now. And note that it's not for free, although costs only a dozen of beers...
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks a lot, the second presumption is not met, because I do not need a menu, so do you mean I have to attach a menu that I do not need in my .rc file? I am so sorry to disturb you again and again, if you can solve my problem completely, I will pay for your beers. ;P
virtual
|
|
|
|
|
Beers first!
Well, no menu, then lesser to skip.
WCHAR* pClassName = ((WCHAR*)lpDialogTemplate
+ sizeof(DLGTEMPLATEEX) / sizeof(WCHAR)
+ sizeof(WORD) / sizeof(WCHAR));
And don't forget to take a look in the .rc file to asure you have something like
IDD_DIALOG1 DIALOGEX DISCARDABLE 0, 0, 186, 95
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
CLASS "Mama Leone"
However, this is just a patch. As I already said, sweat a little and write a serious function taking care of every case.
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
OK, Beers is here.
I have done many tests, and then I found that "wcscpy(pClassName, L"Lama Leone");" can not excuted once I try to change the class name, the other way round, if I did not try to change the class name, this function can be excuted correctly. I think there may be some properties of the resource need be changed, but I do not know what properties should be changed and how. Thanks.
virtual
|
|
|
|
|
Hi,
I have a menu on a dialog box. There is an option called Grid , which which can be toggled. I want it to be checked/un-checked.
This is what I have done. It looks right to me. But it is not working.
void COption2::OnChartoptionsGrid()
{
IsGrid = 1- IsGrid;
}
void COption2::OnUpdateChartoptionsGrid(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(IsGrid);
}
Please help.
Fortitudine Vincimus!
|
|
|
|
|
if you look at the value of IsGrid when OnUpdateChartoptionsGrid gets called is the value as you expect it to be?
cje
|
|
|
|
|
Yes. It come 1 .
Even if I do not put
pCmdUI->SetCheck(IsGrid);
instead if I put
pCmdUI->SetCheck(1);
nothing happens
Fortitudine Vincimus!
|
|
|
|
|
|
Viorel. wrote: Are you sure your OnUpdateChartoptionsGrid handler is called by MFC?
Yes. I used the usual class wizard to call it.
Fortitudine Vincimus!
|
|
|
|
|
While I agree that your recommendation is a better solution (and more readable), what he has will work for toggling:
isGrid = 0;
isGrid = 1 - isGrid;
isGrid = 1 - isGrid;
isGrid = 1;
isGrid = 1 - isGrid;
isGrid = 1 - isGrid;
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Are you sure this function is executed when you start the program, open the dialog and click on menu item?
In order to check it, put a breakpoint in OnUpdateChartoptionsGrid (or MessageBox("The function was called") if you are not familiar with debugging). I suppose the function is never executed, that's why it does not have any effect.
|
|
|
|
|
Viorel. wrote: Are you sure this function is executed when you start the program, open the dialog and click on menu item?
Yes! The function IS executed. I put a message box and checked for both. .Thats the terriple part. I added the code to make the grid appear/disappear. Every thing is working fine. Only the check is not appearing.
Fortitudine Vincimus!
|
|
|
|
|
TheinstruTara wrote: added the code to make the grid appear/disappear. Every thing is working fine. Only the check is not appearing.
but the code you would use to make the grid appear/disappear would be in
void COption2::OnChartoptionsGrid()
setting the check mark is supposed to be happening in
void COption2::OnUpdateChartoptionsGrid(CCmdUI* pCmdUI)
There is no default support for calling OnUpdate routines in dialog boxes, there are articles etc... on how to do it.
If you set a breakpoint on the line
pCmdUI->SetCheck(IsGrid);
do you break in to the debugger when your dialog loads?
cje
|
|
|
|
|
Yes. I does.
Fortitudine Vincimus!
|
|
|
|
|
then I guess that my only other suggestion would be to get a pointer to the CMenu object and call CheckMenuItem directly instead of going through the OnUpdate mechanism. Something is certainly strange here - my code uses pCmdUI->SetCheck without a problem. sorry I can't be more help
cje
|
|
|
|
|
then I guess that my only other suggestion would be to get a pointer to the CMenu object and call CheckMenuItem direclty instead of going through the OnUpdate mechanism. My code uses pCmdUI->SetCheck without problems so there is definately something not right going on. Sorry I can't be of more help
cje
|
|
|
|
|
Oh no. So MY VS wants to trouble me
Thanks a lot for the help, all the same.
Fortitudine Vincimus!
|
|
|
|
|
I just got an email requesting me to write code for you to help troubleshoot this (I do not see the item yet on the message board). I think the request is a little over the top and my answer is no, I will not write a dialog box based application with a menu showing a working version of SetCheck.
I did, however do a quick google search for "CDialog CMenu" and in less than 5 minutes found others with the same problem that have been helped and a link to a microsoft article explaining a possible solution
http://support.microsoft.com/default.aspx?scid=kb;en-us;242577[^]
did you do any research on this or are you just wanting other people to do your work?
cje
|
|
|
|
|
cje wrote: (I do not see the item yet on the message board).
You did not see it on the message board because I did email my request to you.
cje wrote: did you do any research on this or are you just wanting other people to do your work?
Oh no. Please dont mistake me. I have struggled with this since two days and only then did I come to codeproject. Because I was'nt getting any errors and debuging showed that the everything is fine I did not know what to do.
My VS does behave unusually sometimes. I have to repetedly delete the debug files and the .ncb files to make things work. I had tried all that but in vain.
Anyway, NOW I know. Thanks a billion for the help. Next time, I shall google first!
Fortitudine Vincimus!
|
|
|
|
|
I checked the IsGrid number too. It toggles propery between 0 and 1.
Fortitudine Vincimus!
|
|
|
|
|
Is there anyother way of doing it?
Fortitudine Vincimus!
|
|
|
|
|
Hai
Is there any way in vc++ to round a double value to two(for example) decimal places without using any string function i.e I need the rounded value as a double value but not as a string.
Thanks in advance.
Taruni
|
|
|
|
|
Would something like this suffice?
double d = 12.3456;
int n = d * 1000.0;
double r = (n + 5) / 1000.0;
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
double round(double x, unsigned short places)
{
double multiplier = pow(10, (double)places);
double x1 = x * multiplier;
long y = (long)x1;
return (double)y / multiplier;
}
This method will truncate the last decimal place instead of rounding it. That is, if you have 1.246, it will be rounded to 1.24 instead of 1.25.
There are also some methods in the standard library for setting the precision of doubles, floats, etc. You might want to check those out as well.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
First you have to decide how you want them rounded:
Round up:
-1.5 -> -1.0
+1.5 -> +2.0
Round down:
-1.5 -> -2.0
+1.5 -> +1.0
Round towards 0:
-1.5 -> -1.0
+1.5 -> +1.0
'Bankers' rounding (round to even):
1.45 -> 1.4 (rounded down)
1.55 -> 1.6 (rounded up)
idea being that some will round up, some down, evens out in the end
...
...cmk
Save the whales - collect the whole set
|
|
|
|