游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2433|回复: 2

请问应该如何使用AdjustWindowRect

[复制链接]

6

主题

55

帖子

55

积分

注册会员

Rank: 2

积分
55
发表于 2005-8-28 16:55:00 | 显示全部楼层 |阅读模式
下面的程序结果是 w:634 h:455

#include <windows.h>
#include <stdio.h>

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
                WNDCLASS        wc;
                HWND                hWnd;
                RECT                r;
                char                s[32];
                int                        w = 640, h = 480;
                DWORD                style = WS_OVERLAPPED | WS_SYSMENU;

                memset (&wc, 0, sizeof(wc));
                wc.lpfnWndProc        = DefWindowProc;
                wc.hInstance                = hInstance;
                wc.hCursor                = LoadCursor (NULL,IDC_ARROW);
                wc.lpszClassName        = "TEST_WINDOW_CLASS";
                RegisterClass (&wc);

                r.left = 0;
                r.top = 0;
                r.right = w;
                r.bottom = h;

                AdjustWindowRect(&r, style, FALSE);

                w = r.right;
                h = r. bottom;

        hWnd = CreateWindowEx(        0,
                                wc.lpszClassName, "test",
                                style,
                                0, 0, w, h,
                                NULL, NULL, hInstance, NULL);
                ShowWindow(hWnd, SW_SHOW);
        SetForegroundWindow(hWnd);

        GetClientRect(hWnd, &r);
        sprintf(s, "w:%d, h:%d", r.right, r.bottom);
        MessageBox(hWnd, s, 0, 0);

        DestroyWindow(hWnd);

        return 0;
}

为什么不是w:640, h:480呢

0

主题

237

帖子

237

积分

中级会员

Rank: 3Rank: 3

积分
237
发表于 2005-8-29 11:02:00 | 显示全部楼层

Re:请问应该如何使用AdjustWindowRect

因??djustWindowRect好像不是指client rect, 而是Window的外框, 所以你要再?算client rect然後再resize. (CreateWindowEx 之後加入以下)

SIZE szDesiredClient={640,480};
RECT rcDesiredWindowRect;
memset(&rcDesiredWindowRect, 0, sizeof(rcDesiredWindowRect));

// get the current window rect and its client rect
RECT rcCurrentWindowRect;
RECT rcCurrentClientRect;

GetWindowRect(hWnd, &rcCurrentWindowRect);
GetClientRect(hWnd, &rcCurrentClientRect);

// get the difference between the current and desired client areas
SIZE szClientDifference;

szClientDifference.cx = (rcCurrentClientRect.right  - szDesiredClient.cx);
szClientDifference.cy = (rcCurrentClientRect.bottom - szDesiredClient.cy);

// get the desired window rect by adding the client area difference to the
// current window rect
rcDesiredWindowRect.left   = rcCurrentWindowRect.left;
rcDesiredWindowRect.top    = rcCurrentWindowRect.top;
rcDesiredWindowRect.right  = (rcCurrentWindowRect.right  - szClientDifference.cx);
rcDesiredWindowRect.bottom = (rcCurrentWindowRect.bottom - szClientDifference.cy);

// resize the window according to the new rect
MoveWindow(hWnd, rcDesiredWindowRect.left, rcDesiredWindowRect.top,
        (rcDesiredWindowRect.right - rcDesiredWindowRect.left),
        (rcDesiredWindowRect.bottom - rcDesiredWindowRect.top), TRUE);

132

主题

1341

帖子

1341

积分

金牌会员

Rank: 6Rank: 6

积分
1341
发表于 2005-8-29 11:06:00 | 显示全部楼层

Re:请问应该如何使用AdjustWindowRect

DWORD style = WS_OVERLAPPED | WS_SYSMENU;
改为:
DWORD style = NULL;
试下
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-27 15:24

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表