Click here to Skip to main content
15,914,111 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to change the text color and background color of a combo box Pin
frydaysoft17-Oct-00 1:17
sussfrydaysoft17-Oct-00 1:17 
GeneralMFC -> COM, ActiveX Pin
RK16-Oct-00 12:34
RK16-Oct-00 12:34 
GeneralRe: MFC -> COM, ActiveX Pin
Bashir Irfan Malik16-Oct-00 22:27
Bashir Irfan Malik16-Oct-00 22:27 
GeneralRe: MFC -> COM, ActiveX Pin
RK17-Oct-00 9:31
RK17-Oct-00 9:31 
GeneralBitmap Display Problems Pin
Frederic Katz16-Oct-00 9:31
sussFrederic Katz16-Oct-00 9:31 
GeneralRe: Bitmap Display Problems Pin
Remus Lazar16-Oct-00 22:38
Remus Lazar16-Oct-00 22:38 
General#How to get the file path of my finished program in the code?# Pin
Fredrik16-Oct-00 0:10
Fredrik16-Oct-00 0:10 
GeneralRe: #How to get the file path of my finished program in the code?# Pin
#realJSOP16-Oct-00 0:55
professional#realJSOP16-Oct-00 0:55 
Here's three functions I use for getting the program path.

JustPath() - extracts the path from a string containing a filename.

AddBackSlash() - adds a backslash to the end of a string if it's needed.

GetProgramPath() gets the path and module filename of the running program (calls JustPath and AddBackSlash).


//------------------------------------------------------------------------------
Returns just the path if present of the specified filename string.
//------------------------------------------------------------------------------
CString JustPath(LPCSTR f)
{
char drive[_MAX_DRIVE],
dir[_MAX_DIR],
file[_MAX_FNAME],
ext[_MAX_EXT];
CString st;
_splitpath((char *)f, drive, dir, file, ext);
st = drive;
st += dir;
return st;
}

//----------------------------------------------------------------------------/
// Add a back slash to the end of the path if it doesn't exist.
//----------------------------------------------------------------------------/
void AddBackSlash(CString& path)
{
int length = path.GetLength();

if (length > 1)
{
if (path.GetAt(length - 1) != '\\')
{
path += "\\";
}
}
else if (1 == length)
{
CString temp = path;
temp.MakeUpper();
TCHAR ch = temp.GetAt(0);

if (ch >= 'A' && ch <= 'Z')
{
path += ":\\";
}
else if (ch != '\\') // add a back slash anyway
{
path += "\\";
}
}
else
{
path += "\\";
}
}


//-----------------------------------------------------------------------------/
// Get the path were the program was run from
//-----------------------------------------------------------------------------/
CString GetProgramPath(BOOL bStripFileName/*=TRUE*/)
{
CString sPath;
TCHAR szFullPath[MAX_PATH];
::GetModuleFileName(NULL, szFullPath, MAX_PATH);
if (bStripFileName)
{
sPath = JustPath(szFullPath);
AddBackSlash(sPath);
}
return sPath;
}
GeneralThanks, that worked like a charm! :) (NT) Pin
Fredrik16-Oct-00 21:38
Fredrik16-Oct-00 21:38 
Generalproblem about compatibility in WinCE Pin
zone15-Oct-00 23:51
zone15-Oct-00 23:51 
GeneralImplement drag source Pin
Eq15-Oct-00 21:55
Eq15-Oct-00 21:55 
GeneralMapping a range of messages Pin
ariel benary15-Oct-00 20:50
ariel benary15-Oct-00 20:50 
GeneralRe: Mapping a range of messages Pin
Martin Speiser26-Oct-00 4:55
Martin Speiser26-Oct-00 4:55 
Generalwindows programing Pin
koteswara15-Oct-00 19:53
koteswara15-Oct-00 19:53 
QuestionTransparent Bitmap Problem? Pin
rainliu15-Oct-00 17:44
sussrainliu15-Oct-00 17:44 
Generaldao 3.6 memory leak Pin
Gozer15-Oct-00 15:15
Gozer15-Oct-00 15:15 
GeneralCImageList problems Pin
#realJSOP15-Oct-00 5:33
professional#realJSOP15-Oct-00 5:33 
GeneralRe: CImageList problems Pin
Michael Dunn15-Oct-00 17:34
sitebuilderMichael Dunn15-Oct-00 17:34 
GeneralSelecting a row with CListCtrl Pin
Gonçalo15-Oct-00 2:25
Gonçalo15-Oct-00 2:25 
GeneralRe: Selecting a row with CListCtrl Pin
Michael Dunn15-Oct-00 7:53
sitebuilderMichael Dunn15-Oct-00 7:53 
GeneralRe: Selecting a row with CListCtrl Pin
Ariel27-Feb-01 14:50
Ariel27-Feb-01 14:50 
GeneralRe: Selecting a row with CListCtrl Pin
Michael Dunn27-Feb-01 15:51
sitebuilderMichael Dunn27-Feb-01 15:51 
GeneralRe: Selecting a row with CListCtrl Pin
Ariel28-Feb-01 19:57
Ariel28-Feb-01 19:57 
GeneralMoving Exes Pin
mrtoast14-Oct-00 1:14
mrtoast14-Oct-00 1:14 
GeneralRe: Moving Exes Pin
Member 120896514-Oct-00 1:19
Member 120896514-Oct-00 1:19 

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.