Skip to content

Instantly share code, notes, and snippets.

@Markonis
Last active December 2, 2015 21:08
Show Gist options
  • Save Markonis/cb7b50172dbbb5bf0c8d to your computer and use it in GitHub Desktop.
Save Markonis/cb7b50172dbbb5bf0c8d to your computer and use it in GitHub Desktop.
Draw something with GDI
void CMyView::DrawSomething(CDC* pDC, bool m) {
CPen newPen(PS_SOLID, VariablePenWidth(5), RGB(0, 0, 0));
CPen* oldPen = pDC->SelectObject(&newPen);
CBrush brush;
brush.CreateSolidBrush(RGB(128, 224, 255));
CBrush* oldBrush = (CBrush*)pDC->SelectObject(&brush);
int prevMode = SetGraphicsMode(pDC->m_hDC,GM_ADVANCED);
XFORM Xform, XformOld;
GetWorldTransform(pDC->m_hDC,&XformOld);
Xform.eM11 = (FLOAT) 1.0;
Xform.eM12 = (FLOAT) 0.0;
Xform.eM21 = (FLOAT) 0.0;
Xform.eM22 = (FLOAT) 1.0;
Xform.eDx = (FLOAT) 0.0;
Xform.eDy = (FLOAT) 0.0;
SetWorldTransform(pDC->m_hDC,&Xform);
// Drawing code goes here...
SetWorldTransform(pDC->m_hDC,&XformOld);
SetGraphicsMode(pDC->m_hDC,prevMode);
pDC->SelectObject(oldPen);
newPen.DeleteObject();
pDC->SelectObject(oldBrush);
oldBrush->DeleteObject();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment