|
John Simmons / outlaw programmer wrote:
Well that doesn't answer my question...
It should have indicated to you that pCmdUI->Enable(FALSE) is the way to do this in MFC. For it not to work is a good indication that you are doing something wrong elsewhere. Trying to do this with that EnableMenuItem() and GetMenu() code is like sanding against the grain.
John Simmons / outlaw programmer wrote:
I seriously doubt that.
I don't. Unless you are messing around with colors, a menu item that is gray is synonomous with one that disabled. In other words, I've not seen an enabled menu item that was gray, nor have I seen a disabled menu item that was non-gray.
Have you considered creating a temporary SDI project that does nothing but alter menu items via the ON_UPDATE_COMMAND_UI() handler? That would help to eliminate other code that might be masking the real problem.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-- modified at 9:52 Friday 7th October, 2005
|
|
|
|
|
It already is a SDI app, and no, I'm not messing with colors. Like I've already said twice, it grays out only AFTER the user clicks it.
I've even tried simply doing this on the updateUI handler:
pCmdUI->Enable(FALSE);
...and that still doesn't gray it out. This is all MFC with no derived classes regarding the menus, and all handlers were added through the class wizard, so I'm not doing anything strange at all.
I think it's got something to do with the fact that the menu is the main menu and not a sub menu (again, something I've already mentioned). I saw something somwhere that said the state of a menu items is updated before the menu is drawn. I'm thinking that since it's the main menu, and only drawn once (or when the window is resized?), it doesn't know about the disabled state because that's not checked until after the menu is drawn.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Try this instead:
DWORD dwFlags = (bEnable) ? MF_BYPOSITION | MF_ENABLED
: MF_BYPOSITION | MF_DISABLED | MF_GRAYED;
pMenu->EnableMenuItem(1 or 2 or 3 or 4, dwFlags); Another idea would be to create a different menu hierarchy where Start, Stop, Pause, and Resume are all under a common menu item.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Deleted the menu items and created a toolbar. The updateUI stuff works on the buttons. I think it goes back to the fact that I'm playing with the mainmenu instead of a sub-menu...
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
|
Hello guys,
I have next strange situation :
I have a function
CString Add(CString var1,CString var2)
{
..
}
which i use for adding two huge integers.
then for example I declare two variables :
CString x = "457235872349857348957238945723894579234896234789563";
CString y = "573489573894573894579234852378456782345683475683746";
then add them , for example 1000 times
while()
{
..
Add(x,y);
..
}
It takes my computer aproximately 5 seconds to do these calculations.
But then i decided to modify the Add function like this :
CString Add(CString & var1,CString & var2)
{
..
}
I expected that the calculations would be faster as no copy objects would be created in this case inside Add function , as I was passing directly addresses.
But the result is opposite
Can anybody explain why ??
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
It sounds strange but to fine out the
reason
1)Study the function use to add the strings
2)Try passing integer value for experiment to chek the speed
3)Try to study passing the CSting memeber.
Send me the feed back
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
vikas amin wrote:
2)Try passing integer value for experiment to chek the speed
Can't do that this function is implemented only for adding string values.
vikas amin wrote:
1)Study the function use to add the strings
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
Giorgi Moniava wrote:
Can't do that this function is implemented only for adding string values.
and what about overloading (just a guess) ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
and what about overloading (just a guess) ?
I just do not need it. You see I wrote this function because I needed to add numbers , for example like this size: "32457345873428957394857394857389245792348578923457934827589345345346456456456456462"
and even bigger. As far as I know in none of the C++ standard types(__int64 ,double ,..) they would not place.
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
vikas just suggested it for a try of performance... now do what you want
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
whats wrong man whats that icon. What did not you like in my reply????
I explained you why I could not use int -s in my function.
And to tell you truth I don't understand why I should use int -s , I was just intersted why when using CString objects the result was faster rather then with CString & -s
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
Giorgi Moniava wrote:
What did not you like in my reply????
i am trying to help, so if what i and vikas suggested don't satisfy, ok, it our fault, but if you didn't ever try it, how can you say it is not the point, and why should i help you more on this thread ? (or you badly explained your problem otherwise).
Giorgi Moniava wrote:
I don't understand why I should use int-s ; I was just intersted why when using CString objects the result was faster rather then with CString & -s
i understood that point. vikas just suggested to try with int s (at least, here is how i understood it) to see if the performance loss was coming from your add() function. maybe you string addition is to be reviewed... of course, int s cannot store such long digited integers.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxx, I also tried on my side, the point that he's trying to figure out, is why passed 2 strings by reference takes more times than passing string by values to an EMPTY function.
see my other answer ...
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
toxcct wrote:
how can you say it is not the point
I did not say it. I said that using int -s was not my point as I has to add huge numbers.Even if with the ints -s case , happens so that int& - s are faster that will have no sense to me.
toxcct wrote:
to see if the performance loss was coming from your add() function.
You can try using empty Add() function , as Maximillien posted and you'll see that the result is same
toxcct wrote:
i am trying to help
thanks for that
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
indeed, I tried just with an empty Add function, and it take twice as much time calling 1000000 times the function when using references.
( edited : ok I tried again, with a bigger iteration count, this is the code I use ( CProfiler can be found here on CP ).
void CtestCloseView::OnTataToto()
{
CString x = "457235872349857348957238945723894579234896234789563";
CString y = "573489573894573894579234852378456782345683475683746";
CProfiler profiler;
__int64 ptime = 0;
profiler.ProfileStart(LOGNONE);
for ( int i = 0; i < 8000000; i++ )
{
AddMe( x, y );
}
ptime = profiler.ProfileEnd();
double dd = profiler.SecsFromTicks(ptime);
CString s1;
s1.Format( "CtestCloseView::OnTataToto(1) : %5.5f seconds\n", dd );
TRACE( s1 );
profiler.ProfileStart(LOGNONE);
for ( int i = 0; i < 8000000; i++ )
{
AddMe2( x, y );
}
ptime = profiler.ProfileEnd();
dd = profiler.SecsFromTicks(ptime);
s1;
s1.Format( "CtestCloseView::OnTataToto(2) : %5.5f seconds\n", dd );
TRACE( s1 );
}
void CtestCloseView::AddMe( CString s1, CString s2 )
{
}
void CtestCloseView::AddMe2( const CString& s1, const CString& s2 )
{
}
The result are ( with 8000000 iterations ) :
CtestCloseView::OnTataToto(1) : 6.39813 seconds
CtestCloseView::OnTataToto(2) : 1.27944 seconds
and with 20000000 iterations :
CtestCloseView::OnTataToto(1) : 15.96244 seconds
CtestCloseView::OnTataToto(2) : 3.19041 seconds
which shows that I was wrong in my first assesment, and passing by reference will take less time.
Maximilien Lincourt
Your Head A Splode - Strong Bad
-- modified at 9:21 Friday 7th October, 2005
|
|
|
|
|
Don't you find this strange ????
In every book I've read It is said that using references in some cases reduces some time.
As in functions no copy objects are created(moreover if the objects are big).
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
Yup , I did the same with my Add() function but incremented the iterations up to 900000
and CString& - s ended in 100 seconds while CString -s in 190
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
Maybe the extra level of indirection when you are using references overrides the performance cost of passing it by value?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
(Back in the old days...)
CString is reference counted object. This means that when you pass the CString to another routine by value, all it does is increment the ref count of the REAL data. This means that you don't allocate a new buffer for the CString.
As already shown, by using empty routines, const & is faster. But when you add back in all the other code, the extra dereference required to access the CString by reference might cost more than the cost of passing the string by value.
(Doh, what the previous post said.) :->
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
-- modified at 9:56 Friday 7th October, 2005
|
|
|
|
|
Hi,
I am having some problems with drawing a transparent bitmap into a CStatic derived object. I am drawing inside the OnPaint handler using Graphics ( GDI+ ) object. Since Its a transparent image, the first time when the control is drawn, I am getting the image properly. From next time onwards, when OnPaint in invoked, I am getting a black border for the image, which becomes thicker and thicker as the OnPaint in invoked ( I have to call Invalidate in Mouse over).
Graphic object is attached to a Bitmap object and thats Bitmap object is used to draw to the CDC using DrawImage function. when I saved that Bitmap to a file, the image looks alright. So I guess its the DC of the CStatic control which is crating the problem. Also this CStatic control is placed in CDialog, and whenever, the dialog is minimized and restored, the image will be rendered correctly.
I would appreciate any help on this behaviour.
Looking forward for an answer
Thanks
Jugs
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
Does any one know how to remove the menu border or at least create a flat one (without MFC)?
Thank veeeeeeeeeeery much !!!!!!!!
-- modified at 7:44 Friday 7th October, 2005
|
|
|
|
|
|
I did, but there are only mfc samples
|
|
|
|
|
yes, sorry, i didn't see the point. put know this : MFC are just wrappers for Win32 functions (as Roger Allen explains in his introduction to menus[^]). so if you can find back which functions are use, you've got it...
see here[^] for Win32 related functions...
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 8:00 Friday 7th October, 2005
|
|
|
|