• <i id='zyPLS'><tr id='zyPLS'><dt id='zyPLS'><q id='zyPLS'><span id='zyPLS'><b id='zyPLS'><form id='zyPLS'><ins id='zyPLS'></ins><ul id='zyPLS'></ul><sub id='zyPLS'></sub></form><legend id='zyPLS'></legend><bdo id='zyPLS'><pre id='zyPLS'><center id='zyPLS'></center></pre></bdo></b><th id='zyPLS'></th></span></q></dt></tr></i><div id='zyPLS'><tfoot id='zyPLS'></tfoot><dl id='zyPLS'><fieldset id='zyPLS'></fieldset></dl></div>

    <small id='zyPLS'></small><noframes id='zyPLS'>

    <legend id='zyPLS'><style id='zyPLS'><dir id='zyPLS'><q id='zyPLS'></q></dir></style></legend>
  • <tfoot id='zyPLS'></tfoot>
        <bdo id='zyPLS'></bdo><ul id='zyPLS'></ul>

        EnumDisplayMonitors 回调

        EnumDisplayMonitors callback(EnumDisplayMonitors 回调)
              <tbody id='S0qkP'></tbody>

                <bdo id='S0qkP'></bdo><ul id='S0qkP'></ul>
              • <small id='S0qkP'></small><noframes id='S0qkP'>

              • <tfoot id='S0qkP'></tfoot>

                <legend id='S0qkP'><style id='S0qkP'><dir id='S0qkP'><q id='S0qkP'></q></dir></style></legend>
                <i id='S0qkP'><tr id='S0qkP'><dt id='S0qkP'><q id='S0qkP'><span id='S0qkP'><b id='S0qkP'><form id='S0qkP'><ins id='S0qkP'></ins><ul id='S0qkP'></ul><sub id='S0qkP'></sub></form><legend id='S0qkP'></legend><bdo id='S0qkP'><pre id='S0qkP'><center id='S0qkP'></center></pre></bdo></b><th id='S0qkP'></th></span></q></dt></tr></i><div id='S0qkP'><tfoot id='S0qkP'></tfoot><dl id='S0qkP'><fieldset id='S0qkP'></fieldset></dl></div>

                • 本文介绍了EnumDisplayMonitors 回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 EnumDisplayMonitors 创建每个监视器的动态数组并存储 DISPLAY_DEVICE 结构.为什么下面的代码不正确?

                  I am trying to use the EnumDisplayMonitors to create a dynamic array of each monitor and store the DISPLAY_DEVICE structure. Why is the below code not correct?

                  BOOL CALLBACK MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
                  
                      MONITORINFOEX iMonitor;
                      iMonitor.cbSize = sizeof(MONITORINFOEX);
                      GetMonitorInfo(hMonitor, &iMonitor);
                  
                      if (iMonitor.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER)
                      {
                          return true;
                      }
                      else
                      {
                          *reinterpret_cast<ScreenArray*>(dwData) = ScreenArray(&iMonitor);
                          return true;
                      };
                  
                  }
                  

                  调用使用

                  ScreenArray monitorArray[15];
                  
                  int i = 0;
                  EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, reinterpret_cast<LPARAM>(&monitorArray[i++]));
                  

                  数组中的第一个 (monitorArray[0]) 为第二个监视器返回正确的信息,但 monitorArray[1] 是最大值.

                  The first in the array (monitorArray[0]) returns correct information for the second monitor but monitorArray[1] is max values.

                  已解决我使用的方法只是实现我创建的一个函数:

                  Solved The method I used was just implementing a function I created:

                  MonitorArray *mA = reinterpret_cast<MonitorArray*>(dwData);
                          mA->addScreen(&iMonitor);
                  

                  推荐答案

                  回调为每个监视器调用一次,但您的回调不会在每次调用时通过数组递增.你需要做更多这样的事情:

                  The callback is called once for each monitor, but your callback is not incrementing through the array each time it is called. You need to do something more like this instead:

                  struct ScreenArrayInfo
                  {
                      ScreenArray *Array;
                      int Count;
                      int MaxCount;
                  };
                  
                  BOOL CALLBACK MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
                  {
                      MONITORINFOEX iMonitor;
                      iMonitor.cbSize = sizeof(MONITORINFOEX);
                      GetMonitorInfo(hMonitor, &iMonitor);
                  
                      if (iMonitor.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER)
                      {
                          return true;
                      }
                      else
                      {
                          ScreenArrayInfo *info = reinterpret_cast<ScreenArrayInfo*>(dwData);
                          if (info->Count == info->MaxCount) return false;
                          info->Array[info->Count] = ScreenArray(&iMonitor);
                          Info->Count++;
                          return true;
                      };
                  }
                  
                  ScreenArray monitorArray[15];
                  ScreenArrayInfo info;
                  info.Array = monitorArray;
                  info.Count = 0;
                  info.MaxCount = 15;
                  
                  EnumDisplayMonitors(NULL, NULL, &MyInfoEnumProc, reinterpret_cast<LPARAM>(&info));
                  

                  或者:

                  #include <vector>
                  
                  BOOL CALLBACK MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
                  {
                      MONITORINFOEX iMonitor;
                      iMonitor.cbSize = sizeof(MONITORINFOEX);
                      GetMonitorInfo(hMonitor, &iMonitor);
                  
                      if (iMonitor.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER)
                      {
                          return true;
                      }
                      else
                      {
                          reinterpret_cast< std::vector<ScreenArray>* >(dwData)->push_back(ScreenArray(&iMonitor));
                          return true;
                      };
                  }
                  
                  std::vector<ScreenArray> monitorArray;
                  EnumDisplayMonitors(NULL, NULL, &MyInfoEnumProc, reinterpret_cast<LPARAM>(&monitorArray));
                  

                  这篇关于EnumDisplayMonitors 回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                • <i id='Ji0WE'><tr id='Ji0WE'><dt id='Ji0WE'><q id='Ji0WE'><span id='Ji0WE'><b id='Ji0WE'><form id='Ji0WE'><ins id='Ji0WE'></ins><ul id='Ji0WE'></ul><sub id='Ji0WE'></sub></form><legend id='Ji0WE'></legend><bdo id='Ji0WE'><pre id='Ji0WE'><center id='Ji0WE'></center></pre></bdo></b><th id='Ji0WE'></th></span></q></dt></tr></i><div id='Ji0WE'><tfoot id='Ji0WE'></tfoot><dl id='Ji0WE'><fieldset id='Ji0WE'></fieldset></dl></div>
                  <tfoot id='Ji0WE'></tfoot>
                    <tbody id='Ji0WE'></tbody>

                    • <small id='Ji0WE'></small><noframes id='Ji0WE'>

                        • <bdo id='Ji0WE'></bdo><ul id='Ji0WE'></ul>

                          <legend id='Ji0WE'><style id='Ji0WE'><dir id='Ji0WE'><q id='Ji0WE'></q></dir></style></legend>