none
GetDeviceCaps() or What?

    שאלה

  • I'm trying to put my dialog in the center of the screen, but my desktop and my atom netbook are entirely different in screen configuration. I've been trying unsuccessfully to use GetDeviceCaps(). Is that the right function and I'm just not using it properly, or do I need another function? Straight C/C++ please.
    Lamblion
    יום שלישי 02 יוני 2009 22:31

תשובות

  • You have to consider your dialog's dimensions in this calculation. Suppose iWidth and iHeight are the dialog's width and height in pixels.

    iX and iY below will give you the screen coordinates for the dialog

    iX = (iHorzPos - iWidth) / 2;

    iY = (iVertPos - iHeight) / 2;

     

    יום רביעי 03 יוני 2009 00:31
  • This works passably well, but it still does not center the window exactly center on my netbook. It does center it on my desktop...

    int iVertPos = GetSystemMetrics(SM_CYSCREEN);
    int iHorzPos = GetSystemMetrics(SM_CXSCREEN);

    iVertPos /= 2;
    iHorzPos / = 2;

    iVertPos -= ((rect.bottom - rect.top)/2);
    iHorzPos -= ((rect.right - rect.left)/2);

    Why won't this center the window on my widescreen netbook as it does on my normal screen desktop?
    Lamblion
    • סומן כתשובה על-ידי Lamblion יום רביעי 03 יוני 2009 01:41
    יום רביעי 03 יוני 2009 01:18

כל התגובות

  • Call GetSystemMetrics() with nIndex = SM_CXFULLSCREEN and SM_CYFULLSCREEN
    יום שלישי 02 יוני 2009 23:45
  • If I do the following this puts my window in the middle on my desktop, which is 1280x1024 resolution, whereas on my netbook, which 1024x760 it puts it on the bottom right...

    int VertPos = GetSystemMetrics(SM_CYSCREEN);
    int iHorzPos = GetSystemMetrics(SM_CXSCREEN);

    iVertPos /= 4;
    iHorzPos /= 4;

    SetWindowPos(hInitWnd, HWND_NOTOPMOST, iHorzPos, iVertPos, 0, 0, SWP_NOSIZE);

    I don't know where I got the /4 but I remember somewhere that this was supposed to work with GetSystemMetrics(). Anyway, my netbook is a widescreen, whereas my desktop is not. I'm trying to figure out how to make the code work for both monitors.

    • נערך על-ידי Lamblion יום רביעי 03 יוני 2009 00:20
    יום רביעי 03 יוני 2009 00:17
  • You have to consider your dialog's dimensions in this calculation. Suppose iWidth and iHeight are the dialog's width and height in pixels.

    iX and iY below will give you the screen coordinates for the dialog

    iX = (iHorzPos - iWidth) / 2;

    iY = (iVertPos - iHeight) / 2;

     

    יום רביעי 03 יוני 2009 00:31
  • Yes, I know that I have to consider the dialog's dimensions, but even if I do it ends up displaying differently on the two computers.
    Lamblion
    יום רביעי 03 יוני 2009 01:07
  • This works passably well, but it still does not center the window exactly center on my netbook. It does center it on my desktop...

    int iVertPos = GetSystemMetrics(SM_CYSCREEN);
    int iHorzPos = GetSystemMetrics(SM_CXSCREEN);

    iVertPos /= 2;
    iHorzPos / = 2;

    iVertPos -= ((rect.bottom - rect.top)/2);
    iHorzPos -= ((rect.right - rect.left)/2);

    Why won't this center the window on my widescreen netbook as it does on my normal screen desktop?
    Lamblion
    • סומן כתשובה על-ידי Lamblion יום רביעי 03 יוני 2009 01:41
    יום רביעי 03 יוני 2009 01:18
  • How are you obtaining the dialog's width and height ?

    Are you using GetWindowRect() for this purpose ?

    • נערך על-ידי Belloc יום רביעי 03 יוני 2009 01:34
    יום רביעי 03 יוני 2009 01:19
  • No, I was using GetClientRect(), but I just tried GetWindowRect() and now it works perfectly. Also, after reading over the function docs I understand why. Thanks for the input. It was bugging me, but now you've set me straight.
    Lamblion
    יום רביעי 03 יוני 2009 01:41