Sign in to follow this  
xeddiex

Win32: MoveWindow - Logical or Device?

Recommended Posts

Not really. Device units are in pixels but Logical units (or coordinates) can be pixels or any other coordinate system. It all depends on the current mappping mode - which defaults to MM_TEXT (units of pixels). Anyway, I've found the answer; They're in Screen Coordinates [makes sense [rolleyes]] which are in device units, which are pixels. lol.

Thanks for the help anyways, ace_lovegrove.

Share this post


Link to post
Share on other sites
I'd bet that they're in logical coordinates of the parent window, which for a top-level window would be the desktop, which probably always has logical units set to pixels. Did you test it with moving a child window inside it's parent, or did you only test top-level windows?

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
I'd bet that they're in logical coordinates of the parent window, which for a top-level window would be the desktop, which probably always has logical units set to pixels. Did you test it with moving a child window inside it's parent, or did you only test top-level windows?


They're not, I did the latter test. The scaling by 10 pixels for every 1 logical unit didn't have any effect on MoveWindow:


case WM_KEYDOWN :
// Get Screen DC
hdc = GetDC(NULL);
SetMapMode(hdc, MM_ISOTROPIC);
SetWindowExtEx(hdc, 1, 1, NULL);
SetViewportExtEx(hdc, 10, 10, NULL);

if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
{
GetWindowRect(hwnd, &rect);
ProcessKeys(hwnd, hdc, wParam, &rect);
}

ReleaseDC(hwnd, hdc);

return 0;


code snippet of ProcessKeys function that does the test:

void ProcessKeys(HWND hwnd, HDC hdc, WPARAM wParam, RECT *rect)
{
POINT pt = {0};

switch ( wParam )
{

case VK_LEFT :
if ( rect->left != 0 )
{
rect->left--;
rect->right = (rect->right - rect->left) - 1;
rect->bottom = rect->bottom - rect->top;

pt.x = rect->left;
pt.y = rect->top;

MoveWindow(hwnd, pt.x, pt.y, rect->right, rect->bottom, TRUE);
}
break;

Share this post


Link to post
Share on other sites
It seems to me that the logical coordinate system is a proprety of the DC and so can't affect MoveWindow (since a DC isn't involved for that). Also, you can have multiple DCs per window presumably with different coordinate systems, so how would MoveWindow know which one to use?

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
Are you allowed to change things like the logical coordinate system for the desktop? Did you test other functions to see if your attempted changes actually had any affect?



Yes. You can change the Screen, Whole Window and Client coordinates. This is done by mapping logical coordinates to device coordinates. These three device coordinate systems are in units pixels. Always. The Screen Coordinates are what you work with on the Desktop. You can map a metric (There's five windows predefined metric mapping modes) or a program defined coordinate system to device coordinates via SetWindowMode and freinds but if the function itself doesn't work in logical units; it's of no use.

The problem with MoveWindow is that it only accepts Screen Coordinates, which are in device units. My Mapping Mode won't have any effect. Problem would be solved it accepted logical coordinates so I could do my own scaling. So long as a functions description says it accepts logical coordinates, that's all one really needs to know to work with a diffrent coordinate system besides device coordinates. But this paticluar functions description doesn't mention its coordinate system at all.


Quote:
Original post by ZQJ
It seems to me that the logical coordinate system is a proprety of the DC and so can't affect MoveWindow (since a DC isn't involved for that). Also, you can have multiple DCs per window presumably with different coordinate systems, so how would MoveWindow know which one to use?


Exactly, The Mapping Mode is an attribute of the current Device Context. This is how I now know, apart from my needless test, that MoveWindow only woks in device coordinates because Logical Coordinates can only be mapped and specified with GDI functions. MoveWindow is non-GDI. It's actually part of the WUI (Windows User Interface) system.

Thanks for all the help guys,
xeddiex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this