The getcwd function will "get the current working directory" which is not always the same as the directory the process executable is residing in. There are many standard API calls that will change the current working directory of your process. In fact... the CreateProcess function itself has the option of starting your process in an arbitrary working directory.
In InitInstance(), member m_pszExeName is your image name. So, use SearchPath() on the result of CString(m_pszExeName) + CString(".exe"). Use the lpFilePart parameter of the call to isolate the path from the file name.
I made a custom CButton::DrawItem() so that I could draw some buttons the way I want them. One of the things I'm doing with it, is making the button "pin-able" to the right side of the parent dialog's (cwnd) display rectangle (using it both as a child to a CDialog and another CButton, in different cases). It seems though, that when a window is maximized, then restored, the restore doesn't call CButton::DrawItem(), leaving my button in the middle of nowhere. If I track the messages, it doesn't seem the framework ever asks the CButton object (or the parent dialog for that matter) to redraw when it is restored.
Seems like maximize and restore are treated differently in the framework. Has anyone seen this before or know how to deal with it?
I was trying to have the CButton automatically reposition himself within the DrawItem(), that doesn't work too well though (because of the order that the DrawItem() calls are made in) and because WM_SIZE handles some sizing changes different than others. So it was just easier to reposition the button from within the parent if it needs to move (from OnSize() with SetWindowPos() rather than Invalidate()).
I'm having trouble setting precision for floats using ostringstream.
I want all floats to have one digit after the decimal point (i.e 1.0f and 10.0f to be formated as "1.0" and "10.0"). However the 10 is coming out as "10.".
Is there any way to do it?
This is my code:
Seems to be a fairly common hurdle when dealing with the streams.
Found an answer on stackOverflow, it's a requirement that "fixed" is used before trying to
set the precision. If this is not done, the call to setprecision will specify the _total_ number of digits to be displayed. Occurring after "fixed", it will specify the number of places after the decimal point to display.