Search code examples
windowswinapigdi

DS_ABSALIGN style to avoid calculations


I have a tablet with a stylus, in normal operation it's easy to draw and figure out where the stylus is since hardware feeds the correct coordinates. Then i rotate the monitor 90 º via ChangeDisplaySettingsEx API, in this situation i have to apply a translation (2nd monitor) + rotation which i'd like to avoid. Then i read about this style DS_ABSALIGN in MSDN:

Indicates that the coordinates of the dialog box are screen coordinates. If this style is not specified, the coordinates are client coordinates.

I'd like to draw to a DC in screen coordinates which is what i'm being feeded, not client coordinates, but defining that style doesn't make any difference.

//unaffected by the style
DrawIcon(hDevCtx, m_Point.x, m_Point.y, LoadCursor(NULL, IDC_ARROW));

Is it there any way to draw an icon in screen coordinates?

edit: finally i had no choice but to do the calculations for every turn so i close the question


Solution

  • The coordinates you pass to DrawIcon() depend on the kind of DC you have. For example let's say you used GetDC() to get the DC. If you pass it a window handle, the coordinates you pass to DrawIcon() will be relative to the client area of that window. If you pass 0 to GetDC() the coordinates will be relative to desktop screen. If you want to draw on desktop screen then use GetDC(0) or a better method if there is one. If you just want to convert screen coordinates to client coordinates or vice versa use ScreenToClient() or ClientToScreen()