C++窗口中球拍的边距错误
C++ Wrong margin of the rackets in a window
int width = 800;
int height = 600;
int interval = 1000 / 60;
int score_player1 = 0;
int score_player2 = 0;
int racket_width = 10;
int racket_height = 80;
int racket_speed = 8;
int racket_left_x = 10;
int racket_left_y = 50;
int racket_right_x = width - racket_width - 10;
int racket_right_y = 50;
完整代码(无球类(:http://pastebin.com/TA9NkV5c
从右球拍到窗口右侧的距离小于左侧。这些变量的计算是正确的,但仍然不平等。
https://i.stack.imgur.com/OjqtZ.png链接到图像
您已经将窗口设置为800像素的宽度,但其他所有内容都是相对于客户端区域定位的,客户端区域比窗口宽度窄边框的厚度。
使用AdjustWindowRect计算窗口的大小,以便使客户端区域达到所需的大小。
// Initialize a RECT with the size you want the client area to be.
RECT rc = { 0, 0, width, height };
// Now adjust the rectangle to the size the window would need to be.
AdjustWindowRect(&rc, my_style_flags, FALSE);
// Now create the window using the sizes in rc. Make sure you use
// consistent style flags or the adjustment may not be correct.
const int window_width = rc.right - rc.left;
const int window_height = rc.bottom - rc.top;
my_hwnd = CreateWindow(..., my_style_flags, x, y, window_width, window_height, ...);
相关文章:
- [longjmp/setjmp]c++ 相同的代码窗口有异常 Linux 没有错误并且运行良好
- 可能的Qt5错误:调用setFixedSize()禁用主窗口的关闭按钮(在Win7下)
- OpenGL C++(制作简单窗口时抛出错误)
- 创建进程 API 失败,在窗口 122 上出现错误代码 10
- _CrtIsValidHeapPointer(块)错误在应用单例-帕特恩后退出主窗口时引发
- C++,弹出调试断言失败窗口,我得到矢量迭代器不兼容的错误运行时
- 使用程序集嵌入数据时"Undefined reference"错误,使用适用于窗口的 mingw-w64 编译(COFF 而不是 ELF)
- Visual Studio 2019 不会打开包含源文件的窗口,也不会定位为出现错误的行
- 将 c++ 程序语法错误重定向到窗口中的文件
- 咖啡窗口的错误
- SFML 中的分段错误 调用 sf::窗口::关闭后
- 提升 1.58.0 窗口进程.h 错误
- 模型对话框移动到主窗口后面的Qt错误
- SDL窗口的错误
- QT:错误 ["*"令牌之前的预期")",并且主窗口未命名类型]
- MPI_Win_free会导致无效窗口错误
- Mingw makefile 编译错误窗口
- wxwidgets 错误窗口.H 已包括在内
- Qt链接器错误窗口
- _mkdir给出错误窗口