c++ - 调用多个 WinAPI 函数导致大约 30 个错误

标签 c++ c winapi

出于某种原因,我尝试调用 AdjustWindowRect 或 GetClientRect,我提供的参数没有问题。我遇到了大约 30 个错误,其中没有一个与调用 WinAPI 函数有关。

什么会导致这样的事情?

谢谢

例如:

以下代码:

   case WM_GETMINMAXINFO:
          {
              LPMINMAXINFO p_info = (LPMINMAXINFO)lParam;
              RECT rc = {0,0,d->w,d->h};
              DWORD dwStyle = GetWindowLongPtr( hWnd, GWL_STYLE ) ;
              AdjustWindowRect(&rc,dwStyle,FALSE);
              int total_border_width = 2 * GetSystemMetrics( SM_CXFRAME ) + 4;
              int total_border_height = 2 * GetSystemMetrics( SM_CYFRAME ) + 
                 GetSystemMetrics( SM_CYCAPTION ) - GetSystemMetrics( SM_CYBORDER ) + 5;
              POINT min,max;

              min.x = d->min_w > 0 ? d->min_w + total_border_width : p_info->ptMinTrackSize.x;
              min.y = d->min_h > 0 ? d->min_h + total_border_height : p_info->ptMinTrackSize.y;
              max.x = d->max_w > 0 ? d->max_w + total_border_width : p_info->ptMaxTrackSize.x;
              max.y = d->max_h > 0 ? d->max_h + total_border_height : p_info->ptMaxTrackSize.y;

              p_info->ptMinTrackSize = min;
              p_info->ptMaxTrackSize = max;
          }

产生:

Error   6   error C2065: 'max' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  844
Error   13  error C2065: 'max' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  848
Error   16  error C2065: 'max' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  849
Error   21  error C2065: 'max' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  852
Error   5   error C2065: 'min' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  844
Error   7   error C2065: 'min' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  846
Error   10  error C2065: 'min' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  847
Error   19  error C2065: 'min' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  851
Error   12  error C2065: 'total_border_height' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  847
Error   18  error C2065: 'total_border_height' : undeclared identifier  c:\Users\Josh\Documents\AL51\src\win\wwindow.c  849
Error   9   error C2065: 'total_border_width' : undeclared identifier   c:\Users\Josh\Documents\AL51\src\win\wwindow.c  846
Error   15  error C2065: 'total_border_width' : undeclared identifier   c:\Users\Josh\Documents\AL51\src\win\wwindow.c  848
Error   1   error C2143: syntax error : missing ';' before 'type'   c:\Users\Josh\Documents\AL51\src\win\wwindow.c  841
Error   2   error C2143: syntax error : missing ';' before 'type'   c:\Users\Josh\Documents\AL51\src\win\wwindow.c  842
Error   4   error C2146: syntax error : missing ';' before identifier 'min' c:\Users\Josh\Documents\AL51\src\win\wwindow.c  844
Error   8   error C2224: left of '.x' must have struct/union type   c:\Users\Josh\Documents\AL51\src\win\wwindow.c  846
Error   14  error C2224: left of '.x' must have struct/union type   c:\Users\Josh\Documents\AL51\src\win\wwindow.c  848
Error   11  error C2224: left of '.y' must have struct/union type   c:\Users\Josh\Documents\AL51\src\win\wwindow.c  847
Error   17  error C2224: left of '.y' must have struct/union type   c:\Users\Josh\Documents\AL51\src\win\wwindow.c  849
Error   3   error C2275: 'POINT' : illegal use of this type as an expression    c:\Users\Josh\Documents\AL51\src\win\wwindow.c  844
Error   20  error C2440: '=' : cannot convert from 'int' to 'POINT' c:\Users\Josh\Documents\AL51\src\win\wwindow.c  851
Error   22  error C2440: '=' : cannot convert from 'int' to 'POINT' c:\Users\Josh\Documents\AL51\src\win\wwindow.c  852

最佳答案

Visual C++ 只支持 C90(不支持 C99),因此在编译 C 程序时,必须将所有变量声明放在 block 的顶部,在任何语句之前。

minmaxtotal_border_heighttotal_border_width 的声明都在至少一个语句之后 block 。

关于c++ - 调用多个 WinAPI 函数导致大约 30 个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8045440/

相关文章:

c++ - 如何连续运行 MPI 程序?

c++ - 在 C++ 中存储 XML 树的最有效数据结构

c++ - 使用全局变量给出错误

c++ - 派生类中的成员新/删除重载有用吗?

c++ - 链接问题

c++ - 为什么 Windows API 根据我的日志记录语句响应错误代码

delphi - Windows 资源管理器在复制并找到现有文件时重命名文件

c - 为什么会发生字节溢出以及它们的作用是什么?

c - 我对输出感到困惑。所以我期待对我的输出的解释

c# - 如何在 Windows 中打开/关闭 radio ?