guys. I found really strange problem. With some fonts (there is a ChooseFont in my program) ::TextOut(..) draw text a little offset to the left from chosen position (smth like 2 pxl). DrawText(..) goes the same way. SetTextAlign DON'T solve this problem! GetTextMetrics(..) -> lpOverhead = 0.Ehm... and when i calculate next position using GetExtendPoint32(..) it also do not consider that offset. I got no help both on biggest russian forum and MSDN. Help please, it's really not a simple problem. Test it before answering. Here is the simplest code example.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HFONT font =(HFONT) GetStockObject(DEFAULT_GUI_FONT);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Разобрать выбор в меню:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: добавьте любой код отрисовки...
SelectObject(hdc,font);
::TextOut(hdc,0,0,L"fff",3); //first "f" written not fully
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
I found the issue. GetCharABCWidths(..). Return widths A,B,C (beforechar,char,afterchar). Some fonts have A<0, which cause TextOut() and DrawText() ehm draw text with offset to the left.