首页 > 解决方案 > hwnd 是 winuser.h 的 udefined c++ 导入

问题描述

#include "stdafx.h"
#include <winuser.h>
#include <iostream>
#define WIN32_LEAN_AND_MEAN

using namespace std;

typedef struct tagRECT
{
    LONG    left;
    LONG    top;
    LONG    right;
    LONG    bottom;
} RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;

int main()
{
    RECT newrect;
    AdjustWindowRect(&newrect, WS_BORDER, true);
    cout << "Hello, world, from Visual C++!" << endl;

}

此代码无法编译,有超过 500 个错误。最常见的是HWND is undefined。我很困惑,因为 winuser 是标准标题。请问怎么修?主要目标是编写将给我 hwnd 窗口大小的代码,这是一些如何使用 AdjustWindowRect 函数接近目标的第一个示例。

标签: c++visual-studio

解决方案


永远不要<winuser.h>直接包含,<windows.h>而是包含,可能WIN32_LEAN_AND_MEAN先定义,以减少该标题带来的所有内容。


推荐阅读