Click here to Skip to main content
16,005,473 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How do I select a peice of a bmp to another file? Pin
Craig Miller15-Aug-01 13:58
Craig Miller15-Aug-01 13:58 
GeneralRe: How do I select a peice of a bmp to another file? Pin
Christian Graus15-Aug-01 14:08
protectorChristian Graus15-Aug-01 14:08 
GeneralRe: How do I select a peice of a bmp to another file? Pin
Craig Miller15-Aug-01 16:17
Craig Miller15-Aug-01 16:17 
Generalheader files Pin
15-Aug-01 12:08
suss15-Aug-01 12:08 
GeneralRe: header files Pin
Christian Graus15-Aug-01 12:13
protectorChristian Graus15-Aug-01 12:13 
QuestionHow to get Folder where the application is installed Pin
Francis B.15-Aug-01 11:43
Francis B.15-Aug-01 11:43 
AnswerRe: How to get Folder where the application is installed Pin
Matt Gullett15-Aug-01 11:55
Matt Gullett15-Aug-01 11:55 
AnswerRe: How to get Folder where the application is installed Pin
Quint15-Aug-01 12:03
Quint15-Aug-01 12:03 
The best way to do this is to get the folder from the application .EXE path.
To do that, you need to use the Win32 API GetModuleFileName(). That API will return the complete pathname of the calling process' EXE. Unfortunately, it can return an 8.3 style filename and can mangle your directory names. I've included a Win95 safe short->long pathname conversion function ( Win95 doesn't support this ). Finally, once you have a nice looking path, you chop off the .EXE name path off with another funciton I've included GetPathOnlyFromPathname.

CString MyPath =
GetPathOnlyFromPathname(GetLongPathname(GetAppPathname()));

where you have the following 3 utility functions:

CString GetAppPathname(void);
CString GetLongPathname(const CString & ShortPathname);
CString GetPathOnlyFromPathname(const CString & PathName);

// returns the full pathname of the application
CString CVChatApp::GetAppPathname(void)
{
char szAppPath[2048];
GetModuleFileName(NULL, szAppPath, sizeof(szAppPath));
return (GetLongPathname(szAppPath));
}

The GetModuleFileName call will return an 8.3 style pathname to the EXE. You may want to convert that into a long filename so the directory name doesn't get mangled:

// convert a short DOS type 8.3 pathname to a Long Filename is the
// version of Windows support the export of the "GetLongPathName" API ( Win95 doesn't )
CString GetLongPathname(const CString & ShortPathname)
{
CString FullPath;

// Win95 doesn't have the GetLongPathName function,
// so we need to check the dll to see if it exists to avoid
// a fatal run-time error.
// Also, note that the name of the function as specified in the DLL
// is different than the called name, due to UNICODE macro preprocessors
// AND, I think GetLongPathName is a pascal-style called function, so
// have to add __stdcall (__cdecl is the default, which is buggy)

HMODULE hm;
hm = GetModuleHandle("kernel32.dll");
typedef unsigned long (__stdcall *PFI)(LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer);
PFI pGetLongPathName;
FARPROC pTemp;
pTemp = GetProcAddress(hm, "GetLongPathNameA");
char strLongName[MAX_PATH];
strcpy(strLongName, "");

if (pTemp != NULL)
{
DWORD dw;
pGetLongPathName = (PFI)pTemp;
dw = (*pGetLongPathName)(ShortPathname, strLongName, MAX_PATH);
}
else
{
strcpy(strLongName, ShortPathname);
}

FullPath = strLongName;
return FullPath;
}

and you'll need one other function:

CString GetPathOnlyFromPathname(const CString & PathName)
{
CString PathOnly = PathName;

// ReverseFind the first '\'
int iFound = PathOnly.ReverseFind('\\');

if(iFound != -1)
{
PathOnly = PathOnly.Left(PathOnly.ReverseFind('\\'));

// put a trailing '\' on if the last char is a ':'
if(PathOnly.GetAt(PathOnly.GetLength()-1) == ':')
PathOnly += "\\";
}
else
{
PathOnly.Empty();
}
return(PathOnly);
}

Hope this helps...
GeneralIncrementing ActiveX version Pin
15-Aug-01 9:49
suss15-Aug-01 9:49 
GeneralNeed help on Controls Please Pin
15-Aug-01 6:35
suss15-Aug-01 6:35 
GeneralCSocket Help Pin
aarong15-Aug-01 6:31
aarong15-Aug-01 6:31 
GeneralRe: CSocket Help Pin
RobJones15-Aug-01 13:17
RobJones15-Aug-01 13:17 
GeneralInstallation program Pin
Blumin Alexander15-Aug-01 5:46
Blumin Alexander15-Aug-01 5:46 
GeneralRe: Installation program Pin
Not Active15-Aug-01 9:39
mentorNot Active15-Aug-01 9:39 
GeneralRe: Installation program Pin
Blumin Alexander15-Aug-01 9:50
Blumin Alexander15-Aug-01 9:50 
GeneralRe: Installation program Pin
Derek Waters15-Aug-01 14:14
Derek Waters15-Aug-01 14:14 
GeneralSaving msdev customizing Pin
15-Aug-01 5:22
suss15-Aug-01 5:22 
GeneralRe: Saving msdev customizing Pin
Michael Dunn15-Aug-01 6:30
sitebuilderMichael Dunn15-Aug-01 6:30 
GeneralRe: Saving msdev customizing Pin
15-Aug-01 12:27
suss15-Aug-01 12:27 
Questionhow to get user group name (in Win NT)? plz Pin
jancsi15-Aug-01 5:08
jancsi15-Aug-01 5:08 
AnswerRe: how to get user group name (in Win NT)? plz Pin
Ben Burnett15-Aug-01 11:13
Ben Burnett15-Aug-01 11:13 
GeneralPlease help... Pin
15-Aug-01 4:51
suss15-Aug-01 4:51 
GeneralRe: Please help... Pin
Ulf Öhlén15-Aug-01 5:29
Ulf Öhlén15-Aug-01 5:29 
GeneralCTreeCtrl and directory listings Pin
Josh Knox15-Aug-01 4:49
Josh Knox15-Aug-01 4:49 
GeneralRe: CTreeCtrl and directory listings Pin
15-Aug-01 4:55
suss15-Aug-01 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.