0

When I draw text on an dc, the text comes out with rough edges, and on the multiple windows that this WindowProc handles, the text between each of them look different, which looks unprofessional. Is there a way to draw it so it comes out with crisp, smooth edges?

    case WM_PAINT:
    {
    GetClientRect(hwnd, &rect);
    hdc = BeginPaint(hwnd, &ps);
    hdcmem = CreateCompatibleDC(hdc);
    BITMAP bm;      
    HBITMAP hbmold =  (HBITMAP)SelectObject(hdcmem, gbutton);
    GetObject(gbutton, sizeof(bm), &bm);
    SetBkMode(hdcmem, TRANSPARENT);
    SetTextColor(hdcmem, RGB(74,88,91));
    HFONT hf = CreateFont(30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Myriad Pro");
    HFONT hfold = (HFONT)SelectObject(hdcmem, hf);
    //the next line works fine, but with rough text edges.
    DrawText(hdcmem, L"Drag a\r\nFile\r\nHere", -1, &rect, DT_CENTER | DT_VCENTER  );
    SelectObject(hdcmem, hfold);

    BitBlt(hdc, 0,0,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);
    SelectObject(hdcmem, hbmold);
    DeleteDC(hdcmem);
    EndPaint(hwnd, &ps);
    break;
    }
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
Geore Shg
  • 1,299
  • 5
  • 23
  • 38

4 Answers4

3
  1. Specify a nonzero qualify for your font.
  2. Make sure your CreateFont call is succeeding -- if it fails you'll be failing back to the (jagged) SYSTEM font.

General notes about your example code:

  1. You're leaking the HFONT.
  2. You should probably static_cast the HFONT rather than the C style cast.
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
3

Myriad Pro is an OpenType font, not supported by GDI. Pick a TrueType font instead.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 1
    +1 -- didn't consider this. @Geore: You'll have to use Uniscribe if you want to support an OpenType font like this. – Billy ONeal Jun 21 '11 at 15:16
0

You probably want to pass ANTIALIASED_QUALITY or CLEARTYPE_QUALITY for the fdwQuality parameter (third to last parameter).

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
0

Ensure that ClearType is enabled in Display Settings.

Ajay
  • 18,086
  • 12
  • 59
  • 105
  • This would affect all applications, not just the OP's – Billy ONeal Jun 21 '11 at 15:10
  • Yes, but if it is disabled, it would affect all applications - and eventually prevent the given application to utilize the feature. – Ajay Jun 21 '11 at 15:12
  • @Ajay: The OP is complaining about his application, not about his whole desktop. – Billy ONeal Jun 21 '11 at 15:13
  • @Billy, I do understand that. See it other way - if you have disabled Windows Theme (at service level!), which application CAN take advantage of it? None. A single application CANNOT be given theming support, where other applications might be able to utilize it. – Ajay Jun 21 '11 at 15:17
  • @Ajay: No, if you disabled the feature, it's disabled. No applications can make use of it. – Billy ONeal Jun 21 '11 at 15:41
  • Exactly. If ClearType is disabled, it is disabled. OP hasn't answered this. May be GDI+, OpenGL or DirectX would be able to draw smooth text even if it is disabled. – Ajay Jun 21 '11 at 15:48
  • @Ajay: The system does not do that. Maybe some app implements their own smoothing and font rendering, but if this is disabled, Windows itself would have jagged fonts – Billy ONeal Jun 21 '11 at 15:49
  • I wouldn't accept or deny with your comment, since I am not sure. But my instincts say that OpenGL/DirectX can do that. The reason is simple - even if ClearType is disabled, Games do display fantastic text. – Ajay Jun 21 '11 at 15:54
  • @Ajay: 1. Okay, I guess we'll ignore how the facts of the system works and go with your "instincts". 2. Games already implement their own anti-aliasing. Of course it's possible to reimplement something like ClearType yourself. But the operating system does not do that. If it's turned off everything's going to be jagged regardless of what the game is set to. – Billy ONeal Jun 21 '11 at 15:56