draw on desktop using visual c++

前端 未结 1 782
执笔经年
执笔经年 2021-02-06 08:54

I am writing an opencv application to draw using laser beam using visual studio VC++ console application. I want to draw lines on desktop. I know that the drawing functions are

1条回答
  •  情话喂你
    2021-02-06 09:10

    The code below draws a blue rectangle on the desktop.

    #include 
    #include 
    
    int main() {    
    
        /* hide console window */
        ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false);
    
        /* Calling GetDC with argument 0 retrieves the desktop's DC */
        HDC hDC_Desktop = GetDC(0);
    
        /* Draw a simple blue rectangle on the desktop */
        RECT rect = { 20, 20, 200, 200 };
        HBRUSH blueBrush=CreateSolidBrush(RGB(0,0,255));
        FillRect(hDC_Desktop, &rect, blueBrush);
    
        Sleep(10);
        return 0;
    }
    

    Just for fun. A Mandelbrot fractal drawn directly on the desktop.

    #define MAGNITUDE_CUTOFF 100
    #define NUMCOLOURS 256
    #define WIDTH 640
    #define HEIGHT 200
    #define UP 72
    #define DOWN 80
    #define LEFT 75
    #define RIGHT 77
    #define SPACE 32
    #define ENTER 13
    #define ESCAPE 27
    #define TAB 9
    #define INSERT 82
    
    #include 
    #include 
    #include 
    #include 
    using namespace std;
    
    int col(int x, int y);
    void fract(void);
    
    char op;
    int ch,max_iterations;
    double xmin = -2.10, xmax = 0.85, ymin = -1.5 , ymax = 1.5;
    double  width_fact, height_fact;
    
    
    int main(){
    
        COLORREF color = RGB(255,0,0); // COLORREF to hold the color info
    
    
        SetConsoleTitle("Pixel In Console!"); // Set text of the console so you can find the window
        HWND hwnd = FindWindow(NULL, "Pixel In Console?"); // Get the HWND
        HDC hdc = GetDC(hwnd); // Get the DC from that HWND
    
        width_fact = (xmax-xmin)/WIDTH;
        height_fact = (ymax-ymin)/HEIGHT;
    
    
        for( int x = 0 ; x < 640 ; x++ ){
            for (int y = 0;y < 480; y++ ){
    
             int blue = (col(x,y) & 0x0f) << 4;
             int green =    (col(x,y) & 0xf0) << 0;
             int red =  (col(x,y) & 0xf00) >> 4;
             SetPixel(hdc, x,y, RGB(red,green,blue));
    
            }
        }
    
    
        system("pause");
    
        ReleaseDC(hwnd, hdc); // Release the DC
        DeleteDC(hdc); // Delete the DC
        return(0);
    }
    
    void fract(){
       int x,y,icount=0;
       width_fact = (xmax-xmin)/WIDTH;
       height_fact = (ymax-ymin)/HEIGHT;
    
       for (y=0;y

    0 讨论(0)
提交回复
热议问题