|
Hello
I have a pop up context menu for a treeview where one item displays further sub items when selected. The exact items displayed depends on the current program state and what items are in the tree view.
I am able to achieve this quite simply by checking the program state and then using RemoveMenu() or EnableMenuItem().
However, there are some circumstances where I want to disable or remove the parent item. checking the properties page in the visual studio resource editor shows that this menu item has not been assigned an ID and in fact it prevents me from doing so.
I've tried using GetMenuItemID() as I know the items position but this returns NULL.
E.g Menu is:
View Properties
Move To Segment
When user selects Move To Segment further menu options appear,
how many appear is dependent on the number of segments:
Move To Segment One
Move To Segment Two
Move To Segment Three
However in some circumstances (when there are no segments) I want to remove the parent item Move To Segment from the menu.
Any suggestions?
Cheers
Rich
|
|
|
|
|
GetMenuItemId return a valid ID only for simple menu items and for pop-up menus it returns -1. I am not 100% sure but you should use GetSubMenu for the popup menus. See MSDN[^].
-Saurabh
|
|
|
|
|
One sugesstion:
Instead of creating main menu and removing menus depending on program state
Why not create menus based on program stateso no need to remove anything.
I hope it makes sense.
Regards,
Sandip.
|
|
|
|
|
This is only possible if states of the program is static and do not change at run-time.
-Saurabh
|
|
|
|
|
Thanks Sandip
I think that's exactly what i'll do. In fact I already do this and have several menus for different situations. However I think I got so focused on trying to correct the problem that I did not think to apply this practice again!
|
|
|
|
|
Hi,
I`m somewhat new to programming and I just have a question about strings.
Say I have a string that is read from a .csv file and looks like
word1,word2,word3,word4
how would I isolate, say, word3, and have the value in a seperate variable.
Any help in working with .csv in C++ would be great as well. I`ve only figured out how to extract rows from the file using streams. However, as my question states, I still have trouble with columns being seperated by commas and how to perform operations on them. Any help would be appreciated, thanks.
-Alex
|
|
|
|
|
You can use CString::Tokenize() method to get values separated by any separater like comma, space etc.
See the example from MSDN:
Example
The following example demonstrates the use of CStringT::Tokenize.
CAtlString str( "%First Second#Third" );
CAtlString resToken;
int curPos= 0;
resToken= str.Tokenize("% #",curPos);
while (resToken != "")
{
printf("Resulting token: %s\n", resToken);
resToken= str.Tokenize("% #",curPos);
};
Output
Resulting Token: First
Resulting Token: Second
Resulting Token: Third
--
"Programming is an art that fights back!"
modified on Thursday, June 12, 2008 3:52 AM
|
|
|
|
|
toasttime wrote: Say I have a string that is read from a .csv file and looks like
word1,word2,word3,word4
how would I isolate, say, word3, and have the value in a seperate variable.
You need to tokenize this string based on a separator char (for you it will be ',').
You can use either Tokenize function of CString or _tcstok_s . Then you can do additional operations based on the tokens, like compare and decide whether it's the string that you were looking for.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
CString's Tokenize method helps
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
I want to get System login detail.
Such as i want to get Which user(administrator or user),user type etc
How to get this in VC++
|
|
|
|
|
pooja_friends wrote: Which user(administrator or user
IsUserAnAdmin()[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
can you give me a sample code please
|
|
|
|
|
It is a simple function, takes no parameters and returns TRUE if the user is an Administrator or FALSE if not.
if(IsUserAnAdmin())
AfxMessageBox(_T("User is an administrator"))
else
AfxMessageBox(_T("User is not an administrator"))
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
You need sample code for using a function that takes no arguments and returns a simple type. Are you really a senior developer?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
pooja_friends wrote: Such as i want to get Which user(administrator or user),user type etc
You can use CheckTokenMembership . Here is the link to this in MSDN -> http://msdn.microsoft.com/en-us/library/aa376389(VS.85).aspx[^]
Source for IsUserAdmin is shown here, you can customize it for your needs.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
'IsUserAnAdmin' : undeclared identifier
I have got this error
|
|
|
|
|
pooja_friends wrote: 'IsUserAnAdmin' : undeclared identifier
MSDN says that you'll need to link to shell32.lib and #include <shlobj.h> to use this function.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
how can i link shell32.lib
|
|
|
|
|
pooja_friends wrote: how can i link shell32.lib
#pragma comment(lib, "Shell32.lib")
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
My code
#include "stdafx.h"
#include "useradmin.h"
#include "useradminDlg.h"
#include <shlobj.h>
#pragma comment(lib, "Shell32.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
void CUseradminDlg::OnOK()
{
// TODO: Add extra validation here
if(IsUserAnAdmin())
AfxMessageBox(_T("User is an administrator"));
else
AfxMessageBox(_T("User is not an administrator"));
CDialog::OnOK();
}
I got Following error :
**********************
77) : error C2065: 'IsUserAnAdmin' : undeclared identifier
Generating Code...
Error executing cl.exe.
what is problem
|
|
|
|
|
pooja_friends wrote: 77) : error C2065: 'IsUserAnAdmin' : undeclared identifier
Probably your SDK is too old. See question no. 2.2 in this FAQ article[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
CString s;
// Get and display the name of the computer.
bufCharCount = INFO_BUFFER_SIZE;
if( !GetComputerName( infoBuf, &bufCharCount ) )
::MessageBox(0,"GetComputerName","Cannot computer name",0);
s.Format("%s", infoBuf );
::MessageBox(0,s,"Computer Name",0);
// Get and display the user name.
bufCharCount = INFO_BUFFER_SIZE;
if( !GetUserName( infoBuf, &bufCharCount ) )
::MessageBox(0,"GetUserName","Can not read user name",0);
s.Format("%s", infoBuf );
::MessageBox(0,s,"User Name",0);
This code display system name and user name correctly
I want user account type (administrator or limited)
|
|
|
|
|
pooja_friends wrote: I want user account type (administrator or limited)
I have already answered this query.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Hi friend,
I am using this code in my system to identify What is computer name & currently who is using it.
<code>/////////////////////////////////////////////////////////////////////
DWORD i;
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
// Get and display the name of the computer.
bufCharCount = INFO_BUFFER_SIZE;
if( !GetComputerName( infoBuf, &bufCharCount ) )
::MessageBox(0,"GetComputerName","Cannot computer name",0);
s.Format("%s", infoBuf );
::MessageBox(0,s,"Computer Name",0);
// Get and display the user name.
bufCharCount = INFO_BUFFER_SIZE;
if( !GetUserName( infoBuf, &bufCharCount ) )
::MessageBox(0,"GetUserName","Can not read user name",0);
s.Format("%s", infoBuf );
::MessageBox(0,s,"User Name",0);
/////////////////////////////////////////////////////////////////////
</code>
Have Good Luck...
Jagdish Bhimbha
S/W Developer
|
|
|
|