如何使用GDIPLUS绘制第二台显示器 [英] How to draw over second monitor with GDIPLUS
本文介绍了如何使用GDIPLUS绘制第二台显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在桌面上绘制一些文字和线条。
我正在使用gdiplus.h来创建具有DrawString功能的打印文本。 />
但是它只能在主屏幕显示器上打印文字。
如果有演示模式,有2个显示器我需要在第二台显示器上打印文本。
I'm want to draw some text and lines over the desktop.
I'm using gdiplus.h for print texts with the function DrawString.
But its only print text on a primary screen monitor.
If has in presentation mode, with 2 monitors I need to print text in a second monitor.
#define _WIN32_WINNT 0x500
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
int main() {
HWND desktop = GetDesktopWindow();
HDC hdc = GetWindowDC(desktop);
ULONG_PTR m_gdiplusToken;
// Initialize GDI+
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
while (true)
{
HPEN newpen;
LPPOINT point = NULL;
newpen = CreatePen(PS_COSMETIC, 20, RGB(255, 0, 0));
SelectObject(hdc, newpen);
MoveToEx(hdc, 1500, 500, point);
LineTo(hdc, 1600, 550 );
//this block works for draw line in second monitor
TextOut(hdc, 1500, 300, TEXT("Text of text out"), 17); // this works too
//But if I'm use gdiplus only print things on the primary screen
Gdiplus::Graphics g(hdc);
Pen pen(Gdiplus::Color(0, 0, 255), 2);
g.DrawLine(&pen, 1500, 0, 1700, 600);// dont work
g.DrawLine(&pen, 0, 0, 1200, 600);// work, but is in the primary screen
FontFamily fontFamily(L"Times New Roman");
Font font(&fontFamily, 24, FontStyleRegular, UnitPixel);
SolidBrush brush(Color(255, 0, 0, 255));
g.DrawString(TEXT("test of GDI+"), 13, &font, PointF(1600.0f, 300.0f), &brush); // dont work
g.DrawString(TEXT("test of GDI+"), 13, &font, PointF(500.0f, 300.0f), &brush); // work, but is in the primary screen
}
Gdiplus::GdiplusShutdown(m_gdiplusToken);
return 0;
}
推荐答案
this(多个监视器上的设备上下文) [ ^ ]可能有用
这篇关于如何使用GDIPLUS绘制第二台显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文