Thread: How to redraw the desktop screen

  1. #1
    Registered User
    Join Date
    Jun 2017
    Posts
    2

    How to redraw the desktop screen

    Hello everyone, I'm trying to redraw the screen after printing something on the screen, here is my code :
    The comments is the missing code that I need
    Code:
    #include <windows.h>
    #include <tchar.h>
    #include <iostream>
    
    
    int main()
    {
        HDC hdc = CreateCompatibleDC(NULL);
        HBITMAP hbitmap = (HBITMAP)LoadImage(NULL,_T("C:\\Printer.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    
    
        while (1)
        {    
    
            // Save the screen before printing
    
            SelectObject(hdc, hbitmap);
            HDC hdc_x = GetDC(HWND_DESKTOP);
            BitBlt(hdc_x, 488, 359, 300, 300, hdc, 0, 0, SRCCOPY);
            ReleaseDC(HWND_DESKTOP, hdc_x);
    
            // Print the screen before the printing
    
            Sleep(1000);
        }
        return 0;
    }
    As you can see I want to display something on the screen for 1 frame than delete it by redraw the desktop and wait for 1 sec.
    My question is how do I save the screen state before the drawing and how do I redraw it again after.
    Thank you all and have a nice day!

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Try:
    Code:
    HWND = GetDesktopWindow();
    InvalidateRect(hwnd, NULL, FALSE);  // or maybe TRUE for last param
    UpdateWindow(hwnd);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. restoring desktop after full screen use
    By megafiddle in forum Windows Programming
    Replies: 7
    Last Post: 04-09-2011, 09:05 PM
  2. sdl screen resize and redraw problem
    By mad_muppet in forum Game Programming
    Replies: 1
    Last Post: 08-09-2008, 08:55 PM
  3. docking bar for window desktop screen
    By sgh in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2008, 02:14 AM
  4. Returning from fullscreen mode, redraw desktop
    By darksaidin in forum Windows Programming
    Replies: 4
    Last Post: 08-23-2003, 06:02 PM
  5. Graphic screen redraw
    By bob5845 in forum C++ Programming
    Replies: 0
    Last Post: 04-09-2002, 08:45 PM

Tags for this Thread