|
Hi there,
I'm experiencing problems disabling/graying menu items in the default menu added to an MFC application.
The following code to to check an item works but when I try to disable/gray a menu item (also shown below) the item is still enabled and not grayed (it doesn't change state):
<br />
CMenu *pMenu = GetMenu();<br />
pMenu->GetSubMenu(0)->CheckMenuItem(ID_FILE_NEW, MF_CHECKED);<br />
<br />
pMenu->GetSubMenu(0)->EnableMenuItem(ID_FILE_NEW, MF_GRAYED);
EnableMenuItem() returns 0 which, according to MSDN, means the previous state was MF_ENABLED.
Do any of you guys have an idea what might be causing this problem?
Thanks in advance!
|
|
|
|
|
Your code is working correctly, but the state of the menu item is being changed back to enabled by how MFC works. When a menu is about to be displayed, MFC will fire of a ON_UPDATE_COMMAND_UI handler for every item in the menu. If you handle this and disable the specific menu item in that handler, it will work OK. If you do not handle it, MFC will enable the menu item by default if a ON_COMMAND handler exists in the call tree for that item (i.e app/mainframe, doc or view).
So, you really need to enable/gray the item in the ON_UPDATE_COMMAND_UI handler for that specific menu item
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
Thanks for your reply. It makes sense
Anyways, I saw the MSDN reference for the "CCmdUI* pCmdUI" parameter of the ON_UPDATE_COMMAND_UI handler function which looks like this:
<br />
void CFileDoc::OnUpdateFileSave(CCmdUI* pCmdUI) <br />
{<br />
pCmdUI->Enable(m_fModified);<br />
}<br />
In that code it looks like you need to keep track of whether to enable or disable the button.
Is that really so? I mean, would I really have to create new variables for each element I would like to be able to enable/disable later on to hold the current state?
|
|
|
|
|
I used profile tool in vc6 to ananlyse the performance of c/c++ code.
But I can't find it in vc7. How can we do profile in vc7? any other tools?
|
|
|
|
|
|
hy, im wondering, what in your opinion is best. or what are the differences?
i tryed to do something with the microsoft installer (the one from the studio.net) but it doesent work really. i cant configure launch conditions (i tryed 2hours..) and i cant run any c++ code or a .exe file BEFORE i run the setup. ist this possible at all with installer?
with installshield this is no problem!
|
|
|
|
|
The deployment project type in Visual Studio .NET is a pretty simple wrapper around the core Windows Installer technology. If you don't need anything complicated, it's great.
Otherwise, look at some other tool that wraps Windows Installer, such as a newer version of InstallShield or Wise for Windows Installer[^]. It's the same install engine, in the end, but these tools give you far more power than the VS.NET deployment project does. This power is at the expense of simplicity.
|
|
|
|
|
help for ina grid control
skpanda
|
|
|
|
|
Hi all..
How do i insert a slider control in the mainframe of an mfc application.
Bye
|
|
|
|
|
Put something like:
m_wndSlider.Create(TBS_HORZ | WS_VISIBLE, CRect(5, 100, 500, 150), this, 1234); in the OnCreate() method, where m_wndSlider is a CSliderCtrl object.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
How do i change the background color of the dialog and all the dialog items to different color as easyly as possible (programatically).
thank you,
Toughest Steel Comes From Hottest Furnance
|
|
|
|
|
SetSysColors() is the easiest way (but it will change the colors of all the dialogs on your system).
Otherwise, override CDialog::OnPaint() to paint the dialog background, and handle WM_CTLCOLOR for all the child controls.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Thanx i will go with the latter.
Toughest Steel Comes From Hottest Furnance
|
|
|
|
|
You'll need to override the OnCtlColor() virtual function of the dialog class and handle the returned brush color.
You can then change the background color of the dialog, edit controls, static text, except the Button controls.
Search for Q117778 on the MSDN website for further examples.
I Dream of Absolute Zero
|
|
|
|
|
I'm trying to pass my local variables of one function to another fuction, all within the main. I get errors saying that the variables score1-score5 are undeclared. Here is what I'm trying to do so far:
#include <iostream>
using namespace std;
void getvalues();
void findlowest();
void calcaverage();
int main()
{
getvalues();
return 0;
}
void getvalues()
{
static int score1, score2, score3, score4, score5=0;
cout << "What is score 1? ";
cin >> score1;
cout << "What is score 2? ";
cin >> score2;
cout << "What is score 3? ";
cin >> score3;
cout << "What is score 4? ";
cin >> score4;
cout << "What is score 5? ";
cin >> score5;
findlowest();
}
void findlowest()
{
if (score1 < score2 && score1 < score3 && score1 < score4 && score1 < score5)
{
return score1;
}
if (score2 < score1 && score2 < score3 && score2 < score4 && score2 < score5)
{
return score2;
}
if (score3 < score1 && score3 < score2 && score3 < score4 && score3 < score5)
{
return score3;
}
if (score4 < score1 && score4 < score2 && score4 < score3 && score4 < score5)
{
return score4;
}
if (score5 < score1 && score5 < score2 && score5 < score3 && score5 < score4)
{
return score5;
}
}
|
|
|
|
|
Hi!
first, you dont pass the local variables declared in main() to the findlowest() function.
you have to declare it like this
int findlowest(int score1,int score2 ... int score5);
and I think, the minimum search can be done better:
if(score2 < score1)
score1=score2;
if(score3 < score1)
score1=score3;
if(score4 < score1)
score1=score4;
if(score5 < score1)
score1=score5;
return score1;
|
|
|
|
|
Please check your grammar book.
Give your fun some parameters to need!
Hello World!
|
|
|
|
|
Isn't this some joke ?
Ok, first of all you shold study something about arrays and loops.
Like
int score[5];
...
min = GetMin(score,sizeof(score)/sizeof(score[0]));
....
int GetMin(int *score,int count)
{
int i,min = score[0];
for (i=1; i<count; i++)
if (min>score[i])
min = score[i];
return min;
}
rrrado
|
|
|
|
|
Dear all,
I want to copy a directory to other location by myself, is there any fast way to copy folder and all of its child contents?
I just think the stupid way is create main folder, and then copy its child folder and contents every time...
I hope there is a good way for doing that~, anyone can give me some ideas??
Thank you~`
|
|
|
|
|
SHFileOperation() should do the trick.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Is it possible to access a SQL Server database from a CHTMLView the same way you would in an asp script using IIS?
Thanks,
Frank
"Keyboard Error - Press F1 to Continue"
|
|
|
|
|
Hi,
We have an activex control thats viewed by our customers
through IE. The activex control communicates back to our
servers for its operation. Some of our customers are
behind ISA servers. To make it easy on our customers, we
would like to be able to seamlessly connect even if there
is a ISA server in between. Can someone give me some
pointers to get started on this - URLS/books/code samples -
any thing to get started.
TIA,
|
|
|
|
|
I'd like to know how to append a file with a string. For example, I have a CStdio file or CArchive file. How to add a string at the end? I tried the following code:
StdioFile file(fileName, CFile::modeCreate|CFile::modeReadWrite);
file.SeekToEnd();
file.WriteString("New String");
file.Flush();
but it will wipe the old content away. The only way I can think of is to store the content first and then write stored strings and new string in. But that is too stupid. Is there anything easy to solve this problem.
Thanks a lot in advance.
|
|
|
|
|
The reason for the failure is not in the way you write to the file; it is in the way you open it. The CFile::modeCreate flag instructs the constructor to create a new file. If there is an existing file with the same name, it is truncated to zero length, thus wiping it clean.
In order to accomplish the desired result, you must open the file with a combination (OR) of flags CFile::modeCreate and CFile::modeNoTruncate . This combination will, if the file exists, open the file normally, and if it doesn't, it will create a new file. Removing both flags causes the function to fail if the file doesn't exist.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|