用户机器的分辨率不同,用VC做的程序,界面不能适应性的发生变化,我做的全屏程序,请问如何做到窗口大小发生变化,窗口里的元素大小与位置也将相应的作出变化。

解决方案 »

  1.   

    GetSystemMetric得到窗口的分辨率以后,根据缩放的比例用SetWindowPos改控件的大小和位置
      

  2.   

    //首先得到整个屏幕的句柄
    HDC hDisplay = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
    _ASSERT(NULL!=hDisplay);
    //得到屏幕的大小
    int nScreenWidth = GetDeviceCaps(hDisplay, HORZRES);
    int nScreenHeight = GetDeviceCaps(hDisplay, VERTRES);
    //创建内存DC
    HDC hMemDc = CreateCompatibleDC(hDisplay);
    _ASSERT(NULL != hMemDc);
    //创建位图
    HBITMAP hBmp = CreateCompatibleBitmap(hDisplay, nScreenWidth, nScreenHeight);
    _ASSERT(NULL != hBmp);
    //选择位图
    HBITMAP hOldBmp = (HBITMAP)SelectObject(hMemDc, hBmp);
    _ASSERT(NULL != (DWORD)hOldBmp || GDI_ERROR != (DWORD)hOldBmp);
    //复制图形
    BOOL blnReturnValue = BitBlt(hMemDc, 0, 0, nScreenWidth, nScreenHeight, hDisplay, 0, 0, SRCCOPY);
    _ASSERT(0 != blnReturnValue);
    //再次选择
    hBmp = (HBITMAP)SelectObject(hMemDc, hOldBmp);
    _ASSERT(NULL != (DWORD)hBmp || GDI_ERROR != (DWORD)hBmp);
    DeleteDC(hMemDc);
    hMemDc = NULL;
    int nBits = GetDeviceCaps(hDisplay, BITSPIXEL);  //每个象素的位数
    DWORD dwLineBits = 0;  //每行字节数
    switch (nBits)
    {
    case 16:
    dwLineBits = nScreenWidth*2;
    break;
    case 24:
    dwLineBits = (nScreenWidth+1)*3-((nScreenWidth+1)*3)%4;
    break;
    case 32:
    dwLineBits = nScreenWidth*4;
    break;
    default:
    AfxMessageBox("windows screen's format is not right!!");
    break;
    }
    用以上这个方法肯定可以得到屏幕的大小,当然你要用你得稍微改一下!然后具体的你要更改的比例你得自己设定。
      

  3.   

    软件启动更改系统分辩率,结束或被de-active,还原原来的分辩率
      

  4.   

    根据分辨率调整大小
    EnumDisplaySettings
    SetWindowPos