|
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
|
|
|
|
|
BOOL IsUserAdmin(VOID)
/*++
Routine Description: This routine returns TRUE if the caller's
process is a member of the Administrators local group. Caller is NOT
expected to be impersonating anyone and is expected to be able to
open its own process and process token.
Arguments: None.
Return Value:
TRUE - Caller has Administrators local group.
FALSE - Caller does not have Administrators local group. --
*/
{
BOOL b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(b)
{
if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
{
b = FALSE;
}
FreeSid(AdministratorsGroup);
}
return(b);
}
I have add this function to find User account type but i got following error
CheckTokenMembership' : undeclared identifier
|
|
|
|
|
Hello...
The function CheckTokenMembership() requires following things :
Header : Declared in Winbase.h; include Windows.h.
Library : Use Advapi32.lib.
DLL : Requires Advapi32.dll
Check by including this header file.
Next solution is you can you something like :
Bool IsUserAdmin(VOID)
{
DWORD i;
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
char admin[]="Admin"
Have Best Luck this time...
Jagdish Bhimbha
S/W Developer
|
|
|
|