By getting the window handle, then getting the window DC, and then drawing
1#include <Windows.h>2#include <stdio.h>3 4 //Desktop Drawing Line5 voidDrawLine ()6 {7 //get the console window8 //hwnd hwnd = Getconsolewindow ();9 //Get OutputTen //HDC hdc = GetDC (hwnd); One //Get Desktop Window AHWND hwnd =GetDesktopWindow (); - //Get Output -HDC HDC =GETWINDOWDC (HWND); theHpen Hpen = CreatePen (Ps_solid,2, RGB (255,255,255)); -SelectObject (hdc, hpen);//Select Pen - while(1) - { +LineTo (HDC,Ten,Ten); -Sleep ( -); +LineTo (HDC, -, -); ASleep ( -); atLineTo (HDC, -, -); -Sleep ( -); -LineTo (HDC, -, -); -Sleep ( -); -LineTo (HDC, the, -); -Sleep ( -); inLineTo (HDC, the, the); - } to + -System"Pause"); the } * $ //display pictures on the desktop or consolePanax Notoginseng voiddrawpic () - { the //get the console window + //hwnd hwnd = Getconsolewindow (); A //Get Output the //HDC hdc = GetDC (hwnd); + //Get Desktop Window -HWND hwnd =GetDesktopWindow (); $ //Get Output $HDC HDC =GETWINDOWDC (HWND); -Hbrush brush = CreateSolidBrush (RGB (255,0,0)); -SelectObject (hdc, brush);//Select Pen the while(1) - {WuyiRectangle (HDC, -, -, -, -); theSleep ( -); - } WuSystem"Pause"); - About } $ - //Desktop Output Text - voidDrawText () - { AHWND hwnd =GetDesktopWindow (); +HDC HDC =GETWINDOWDC (HWND); theSetTextColor (HDC, RGB (0,0,255)); - //Set Background $SetBkColor (HDC, RGB (255,0,0)); the the while(1) the { the Hfont Hfont, hfontold; -Hfont =Createfonta ( in the, the $, the 0, About 0, the Fw_regular, the FALSE, the FALSE, + FALSE, - Gb2312_charset, the Out_default_precis,Bayi Clip_default_precis, the proof_quality, theFixed_pitch |Ff_modern, - "Official Script" - ); the the //Select Font theHfontold =SelectObject (hdc, hfont); the //output text in area - /*RECT Rctext; the rctext.left = ten; the rctext.top = ten; the rctext.right = n;94 rctext.bottom = n; the Drawtexta (hdc, "Desktop text output test", strlen ("Desktop text output test"), &rctext, dt_center);*/ theTextouta (HDC,0,0,"Desktop text output test", strlen ("Desktop text output test")); the SelectObject (hdc, hfontold);98Sleep ( -); About } - }101 102 voidMain ()103 {104 //drawpic (); the //drawLine ();106 DrawText ();107System"Pause");108}
117.C language realization Desktop output picture, desktop output text, desktop draw line