C + + draws text graphics on window desktop

Source: Internet
Author: User

Causes

Recently encountered a project, need to display some information on the left side of the computer, so found some information on the Internet, successfully implemented on the desktop to draw information.

Code

#include"stdafx.h"#include<iostream>#include<windows.h>#include<io.h>#include<map>#include<fstream>#include<atlimage.h>using namespacestd;voidDraw () {//get a DC for drawing, I'm going to use the desktop right here.HDC HDC =GETWINDOWDC (GetDesktopWindow ()); //Create a solid line brush with a red 1 pixel widthHpen hpen1 = CreatePen (Ps_solid,1, RGB (255,0,0)); //create a broken brush with a green 5-pixel width, if you want to create other kinds of brushes see MSDNHpen hpen2 = CreatePen (Ps_dash,5, RGB (0,255,0)); //Create a solid blue paint brushHbrush hbrush1 = CreateSolidBrush (RGB (0,0,255)); //create a transparent paint brush, if you want to create other kinds of brushes see MSDNHbrush HBRUSH2 =(Hbrush) getstockobject (Null_brush); //Select Hpen1 and HBRUSH1 into HDC and save the original HDC brush and BrushHpen Hpen_old =(Hpen) SelectObject (hdc, HPEN1); Hbrush Hbrush_old=(Hbrush) SelectObject (hdc, HBRUSH1); //draw a rectangle with a width of 200 pixels and a height of 50 pixels at (40,30)Rectangle (HDC, +, -, ++ $, -+ -); //change Hpen1 and Hbrush1, and then draw a rectangle at (40,100) to see what the difference is .SelectObject (hdc, HPEN2);    SelectObject (hdc, HBRUSH2); Rectangle (HDC, +, -, ++ $, -+ -); //draw an ellipse and seeEllipse (HDC, +, $, ++ $, $+ -); //Draw a line (0,600) to (800,0) to seeMovetoex (HDC,0, -, NULL); LineTo (HDC, -,0); //at (700,500) draw a yellow dot, but this point is only one pixel size, you look carefully to findSetPixel (HDC, the, -, RGB (255,255,0)); //text,//parameters: Desktop handle, xy coordinate, text, text widthTextouta (HDC, the, -,"ha ha haha",6); //restore the original brush and paint brushSelectObject (hdc, hpen_old); SelectObject (hdc, hbrush_old);}intMain () { while(true) {draw (); Sleep ( -); } System ("prase");}

C + + draws text graphics on window desktop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.