返回首页

我想下面的代码,但我得到我的第二个监视器上没有,但应该是我的绘画图像的黑色矩形(使用GDI)。有没有人听说过这个问题吗?我做第二个监视器上(位图或文字)任何绘图呈现为一个黑色的矩形。谢谢!


LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)  

{

   static UINT         uTimer;   // timer identifier



   // Handles screen saver messages  

   switch(message)  

   { 

      // <snip>

      case WM_PAINT:   //  Sent when the system or another application makes a request to paint a portion of an application's window (e.g., UpdateWindow/RedrawWindow)

      {

         PAINTSTRUCT lpPaint = {0};

         HDC hdc = BeginPaint(hwnd, &lpPaint );

            EnumDisplayMonitors(hdc, NULL, MonitorNumProcPaint, 0);  // For every monitor attached, call the passed in function

         EndPaint(hwnd, &lpPaint);

         return true;

      }

      // <snip>

   }

}

 

BOOL CALLBACK MonitorNumProcPaint(HMONITOR hMonitor, HDC hdc, LPRECT lprcMonitor, LPARAM data)

{

   // If the coordinates of the top left corner are 0,0, then we're rendering on the primary monitor, otherwise we're not.

   if (lprcMonitor->left == 0 && lprcMonitor->top == 0)

      return (PaintPrimaryDisplay(hMonitor, hdc, lprcMonitor, data));

   else

      return (PaintNonPrimaryDisplay(hMonitor, hdc, lprcMonitor, data));

}

 

bool PaintNonPrimaryDisplay(HMONITOR hMonitor, HDC hdc, LPRECT lprcMonitor, LPARAM data)

{

   Gdiplus::Graphics * pGraphics = Gdiplus::Graphics::FromHDC(hdc);

 

   if (gpBitmapMotivation2)

   {

      pGraphics->DrawImage(gpBitmapMotivation2, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right - lprcMonitor->left, lprcMonitor->bottom - lprcMonitor->top);

   }

 

   int sizeX = (int) ceil( (lprcMonitor->right - lprcMonitor->left) * SS_SCREEN_PERCENTAGE);

   int sizeY = (int) ceil( (lprcMonitor->bottom- lprcMonitor->top)  * SS_SCREEN_PERCENTAGE);

   DrawMyText(lprcMonitor, sizeX, sizeY, pGraphics, "MyText"); // This custom function sets up the font, etc and renders the text.



   BitBlt(hdc, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right - lprcMonitor->left, lprcMonitor->bottom - lprcMonitor->top, hdc, lprcMonitor->left, lprcMonitor->top, SRCCOPY);

 

   return true;

}

回答

评论会员:barneyman 时间:2012/02/06
你通过hWnd是所有显示器最大化...

你最好在WM_CREATE调用每个监视器创建一个子窗口,如果你想单独绘制图像
评论会员:查尼科尔森 时间:2012/02/06
喜barneyman,
如果你的意思的HWND进入的ScreenSaverProc时,我不知道你的说法。应要求我必须为每个显示器MonitorNumProcPaint,它的params包括LPRECT lprcMonitor功能被称为特定显示器的位置和大小。

所以,如果我画在lprcMonitor-GT的矩形;左,那将是我在任何显示器的左侧。该值增加和减去的数字,我已经验证了这一点,和黑色矩形向左或向右移动。我的第二个监视器上的黑色的矩形definately是由于我的PaintNonPrimaryDisplay的回调。如果我删除,呼叫,然后第二个监视器说相同......通过屏幕保护程序没有被涂到它。

我要绘制单独的图像。一个设置主显示器,然后为每个显示器不同图像其后。但无论我做什么渲染是一个黑色的矩形。像在画布上被设置,但它没有呈现。我试着打坐标,如果我的画坐标,但他们似乎确定。

我明白任何援助,任何人都可以给,谢谢!|