Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6962239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:38:01+00:00 2026-05-27T15:38:01+00:00

I am writing an opencv application to draw using laser beam using visual studio

  • 0

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 available in GDI32.dll , but confused on how to integrate GDI32.dll with my vc code. can you suggest some good solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:38:02+00:00Added an answer on May 27, 2026 at 3:38 pm

    The code below draws a blue rectangle on the desktop.

    #include <iostream>
    #include <Windows.h>
    
    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 <stdio.h>
    #include <time.h>
    #include <windows.h>
    #include <iostream>
    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<HEIGHT;y++){
           for (x=0;x<WIDTH;x++){
              // setcolor(col(x,y));
              // gotoxy(x+3,y+3);printf("Û");
    
           }
    
       }
       //setcolor(15);
    }
    
    
    int col( int x, int y){
        int n,icount=0;
        float p,q,r,i,prev_r,prev_i;
    
        p= (( (float)x ) * width_fact) + (float)xmin;
        q= (( (float)y ) * height_fact) +(float)ymin;
    
        prev_i = 0;
        prev_r = 0;
    
        for (n=0; n <= NUMCOLOURS; n++){
            r = (prev_r * prev_r) - (prev_i * prev_i) +p;
            i = 2 * (prev_r * prev_i) +q;
    
            if (( r*r + i*i) < MAGNITUDE_CUTOFF ){
                prev_r = r;
                prev_i = i;
            }
            else {
                return n;
            }
        }
        return n;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application using the OpenCV libraries, the Boost libraries and a
I'm writing a C++ application that makes heavy use of OpenCV. Unfortunately, some of
I'm writing small application using OpenCV. Everything works great on my computer. I can
I'm writing a project in C++ using OpenCV. I have coordinates of 4 vertices
I am writing an AR application on iOS and am using CATransform3D transforms on
I am writing a function that takes a OpenCV Mat structure and does some
When writing Python code using compiled extensions (the OpenCV Python bindings, for example), PyCharm
I am writing an application that takes an input image and looks in a
I am trying to compile the facedetect.cpp in the OpenCV\Samples\C folder, in Visual Studio
I'm writing a program using JOGL/openCL to utilize the GPU. I have code that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.