Note that there are some explanatory texts on larger screens.

plurals
  1. POWinAPI - GDI: DrawText() and ExtTextOut() ugly (AA enabled)
    text
    copied!<p>Im trying to make line numbering for a rich edit control using the method described <a href="http://groups.google.com/group/borland.public.cppbuilder.vcl.components.using/tree/browse_frm/thread/e1c1093aabd7b345/640a45bd65903e29?rnum=1&amp;_done=/group/borland.public.cppbuilder.vcl.components.using/browse_frm/thread/e1c1093aabd7b345/640a45bd65903e29?pli=1&amp;#doc_2a5c8e53253996e1" rel="nofollow">here</a> (not MFC though). While it works fine, the rendering of line numbers is really ugly compared to the rich edit.</p> <p>I made a small program to reproduce the problem: (sorry that I copy paste but couldnt find a normal file hosting service -.-):</p> <pre><code>#include &lt;Windows.h&gt; LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch( msg ) { case WM_CLOSE: ShowWindow(hWnd, SW_HIDE); DestroyWindow(hWnd); break; case WM_PAINT: { HDC hdc = GetDC(hWnd); HDC bdc = CreateCompatibleDC(hdc); HBITMAP bitmap = CreateCompatibleBitmap(hdc, 400, 100); int height = -MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72); HFONT font = CreateFont( height, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE, "Consolas"); HGDIOBJ oldbm = SelectObject(bdc, bitmap); HGDIOBJ oldft = SelectObject(bdc, font); RECT rc = { 0, 0, 200, 20 }; FillRect(bdc, &amp;rc, (HBRUSH)GetStockObject(WHITE_BRUSH)); DrawText(bdc, " 1 2 3 4 5 6 7 8 9", 19, &amp;rc, DT_LEFT|DT_EDITCONTROL); BitBlt(hdc, 20, 20, rc.right - rc.left, rc.bottom - rc.top, bdc, 0, 0, SRCCOPY); SelectObject(bdc, oldbm); SelectObject(bdc, oldft); DeleteObject(bitmap); DeleteObject(font); DeleteDC(bdc); } return 1; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_KEYUP: switch(wParam) { case VK_ESCAPE: SendMessage(hWnd, WM_CLOSE, 0, 0); break; } break; default: break; } return DefWindowProc(hWnd, msg, wParam, lParam); } INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd) { HWND hwnd = 0; WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, (WNDPROC)WndProc, 0L, 0L, hInst, NULL, NULL, NULL, NULL, "TestClass", NULL }; RegisterClassEx(&amp;wc); int w = GetSystemMetrics(0); int h = GetSystemMetrics(1); DWORD style = WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_SYSMENU|WS_BORDER|WS_CAPTION; hwnd = CreateWindowA("TestClass", "Winapi1", style, (w - 400) / 2, (h - 200) / 2, 400, 200, NULL, NULL, wc.hInstance, NULL); if( !hwnd ) { MessageBoxA(NULL, "Could not create window!", "Error!", MB_OK); goto _end; } ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); MSG msg; ZeroMemory(&amp;msg, sizeof(msg)); while( msg.message != WM_QUIT ) { while( PeekMessage(&amp;msg, NULL, 0U, 0U, PM_REMOVE) ) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } } _end: UnregisterClass("TestClass", wc.hInstance); return 0; } </code></pre> <p>A comparison of the result with typing the text into a rich edit:</p> <p><em>(...can't post image -.- ...)</em></p> <p>While the difference is 'subtle' if I enlarge the image it shows that rich edit uses some kind of coloring.</p> <p>I tried the following things:</p> <ul> <li>using ExTextOut</li> <li>saving the bitmap to file to see if its ugly too (it is)</li> <li>drawing directly into hdc (also ugly plus it flickers but thats not an issue right now)</li> </ul> <p>What am I missing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload