Microsoft
Foundation
Classes (MFC)
Site Map Feedback
Up Controls Files Moving Data

The intention is to provide simple, free access to usable solutions to common but difficult programming problems, presenting 'usage', rather than 'how' (no maths), 'who' (no name-dropping) or 'when' (no history).

The lumps of code on this site should be educational as well as stopping experts from having to re-invent the wheel all the time. The focus is on providing the lumps, usage and keeping everything simple. Developing code knowing that it'll be published on this site helps the developer keep code lumpy and clear. Keeping things simple (particularly debugging) by minimising the extents of the programming language results in only using templates where absolutely necessary and not using the Standard Template Library (STL) at all.

Feel free to use the Feedback link at the top of every page to reoprt about bugs or ask for pages to be rephrased or extended. If you have other or better code and are willing to share, be aware that this site does no name-dropping: when you have a snack bar or get into a car, you don't get told who put the nuts in (the exception being methods that take the name of the award-winning inventor)!

There's a lot of content in this section, so it has been put it in a list.
Don't forget the other MFC sections in the menu above!

Tiny but possibly helpful things

CString itoa(int i) {
  char s[20];
  itoa(i, s, 10); // s.Format("%i", i);
  return s;
}

CString itoa(long i) {
  char s[20];     // CString S;
  ltoa(i, s, 10); // S.Format("%l", i);
  return s;       // return S;
}

CString itoa(double i) {
  char s[20];                 // CString S;
  ltoa((long)(i+0.5), s, 10); // S.Format("%l", i+0.5);
  return s;                   // return S;
}

#define   Black RGB(  0,  0,  0)
#define  DkGray RGB(128,128,128)
#define  LtGray RGB(192,192,192)
#define   White RGB(255,255,255)
#define     Red RGB(255,  0,  0)
#define   Green RGB(  0,255,  0)
#define    Blue RGB(  0,  0,255)
#define  Yellow RGB(255,255,  0)
#define Magenta RGB(255,  0,255)
#define    Cyan RGB(  0,255,255)

void ShowLastError() {
  LPVOID lpMsgBuf; // Default language:
  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);
  MessageBox(NULL, (LPTSTR)lpMsgBuf, "Error Information", MB_OK|MB_ICONINFORMATION);
  LocalFree(lpMsgBuf);
}

#define Redraw(nID) {GetDlgItem(nID)->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);}

void SizeComboDrop(CComboBox* Combo) { // Size the drop-down width to the content for old versions of Windows:
  CRect Rect;
  Combo->GetDroppedControlRect(Rect);
  Combo->ShowWindow(SW_HIDE); // The SetWindowPos insists on opening and closing the popup...
  Combo->SetWindowPos(NULL,0,0,Rect.Width(), min(::GetSystemMetrics(SM_CYFULLSCREEN), (Combo->GetCount()+1)*Combo->GetItemHeight(0)+Combo->GetItemHeight(-1)), SWP_NOZORDER|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE);
  Combo->ShowWindow(SW_SHOW);
}

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


 (2408) Last modified: Wed, 02 Sep 2009 17:05:40 +0100