프로그래밍/VC++

GDI+를 이용 Drop Shadow 주기

panpro 2007. 6. 12. 19:42

void CGDIPlusTestDlg::OnPaint()
{
 if (IsIconic())
 {
  CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트

  SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

  // 클라이언트 사각형에서 아이콘을 가운데에 맞춥니다.
  int cxIcon = GetSystemMetrics(SM_CXICON);
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
  int x = (rect.Width() - cxIcon + 1) / 2;
  int y = (rect.Height() - cyIcon + 1) / 2;

  // 아이콘을 그립니다.
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트

  //dc.Rectangle(10, 10, 29, 29);
 
  Graphics graphics(dc.GetSafeHdc());
  GraphicsPath path;

  Font font(L"HY견고딕", 70);
  Point pt(30, 30);
  PointF ptf(30, 30);
  SolidBrush brush(Color(128, 0, 0, 0));
  SolidBrush brush2(Color(255, 0, 100, 0));

  CRect rClient;
  GetClientRect(&rClient);

  int width = rClient.Width();
  int height = rClient.Height();

  Bitmap bm(width / 5, height / 5);
  Graphics g(&bm);
  g.SetTextRenderingHint(TextRenderingHintAntiAlias);

  //Matrix mx(0.25f, 0, 0, 0.25f, 2, 2);
  Matrix mx(0.2f, 0, 0, 0.2f, 1.0f, 1.0f);
  g.SetTransform(&mx);

  g.DrawString(L"하하하 팬소년", wcslen(L"하하하 팬소년"), &font, ptf, &brush);

  graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
  // 그림자
  Rect rect(0, 0, width, height);
  graphics.DrawImage(&bm, rect, 0, 0, bm.GetWidth(), bm.GetHeight(), UnitPixel);
 
  // 실제 글자
  graphics.DrawString(L"하하하 팬소년", wcslen(L"하하하 팬소년"),
   &font, ptf, &brush2);
 
  CDialog::OnPaint();
 }
}