Passing CString with SendMessage

28 03 2009

pass pointer of CString in wParam or lParam parameters

in thread
CString * myString = new CString(L"BLANK");
AfxGetMainWnd()->SendMessage(WM_USER_THREAD_REPLACE,(WPARAM)myString, 0);

in window procedure
LRESULT CChildView::OnThreadReplace(WPARAM wParam, LPARAM lParam)
{
   CString * string1 = (CString *) wParam;
   Invalidate();
   return 0;
}





Move Controls Between Dialogs

10 03 2009

in OnInitDialog()

//CCard is derived from CBitmapButton
//cardList is a vector of CCard
CCard * c = cardList.at(1);

// Get CWnd of Dialog
HWND aHwnd = GetSafeHwnd();
CWnd *pWnd = CWnd::FromHandle(aHwnd);

// Change the parent of the button to the dialog
c->SetParent(pWnd);





Resize Bitmap to fit CBitmapButton

7 03 2009

Today I’ve learnt that resizing bitmaps is a real PAIN IN THE ASS in Visual C++. The solution I’ve come up with is to derive a class from CBitmapButton and resize the bitmap to fit into the button. Best part is.. ability resize the button with MoveWindow() *clap clap* 😀

Override void DrawItem(LPDRAWITEMSTRUCT lpDIS);

change
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),&memDC, 0, 0, SRCCOPY);

to
BITMAP bits;
pBitmap->GetObject(sizeof(BITMAP),&bits);
pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&memDC,0,0,bits.bmWidth, bits.bmHeight, SRCCOPY);





Convert CString to int

7 03 2009

CString s="122";
int noCards = _wtoi(s);





Write To Output Window

7 03 2009

OutputDebugString(_T"ARghhh!");





Iterate to Load Bitmaps in Resource

5 03 2009

in Resource.h
#define IDB_MOB1 132
#define IDB_MOB2 133
#define IDB_MOB3 134
#define IDB_MOB4 135
#define IDB_MOB5 136
#define IDB_MOB6 137

in cpp

WORD d=IDB_MOB1;
for(int i = 0; i < 6; i++)
{
 CBitmap c;
 c.LoadBitmap(MAKEINTRESOURCE(d++));
 // add to list
 mobList.push_back(c);
}





Iterate String in String Table

5 03 2009

in String Table
IDS_STR0 101 placeholder
IDS_STR1 102 String 1
IDS_STR2 103 String 2
IDS_STR3 104 String 3
IDS_STR4 105 String 4
IDS_STR5 106 String 5
IDS_MAX_STR 107

in cpp

for(int i = IDS_STR0 + 1; i < IDS_MAX_STR; i++)
{
 CString s;
 s.LoadString(i);
}