Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. how to retain a painted region of a window when other window is moved on it

how to retain a painted region of a window when other window is moved on it

Scheduled Pinned Locked Moved Windows API
questionwinformscomgraphicsjson
2 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jayapal Chandran
    wrote on last edited by
    #1

    [^]I am writing a colour picker program using Windows API. It has an option to zoom the area around the mouse position. The program uses a short cut key. To do this i capture 200x200 around the mouse and display by stretching it in a new window using StretchBlt. Here is the code.

    void showZoomDialog()
    {
    HWND hwndPopup = CreateWindowEx(WS_EX_TOOLWINDOW, szClassName, "Zoom", WS_POPUP | WS_BORDER | WS_CAPTION,
    200, 120, 200, 200, NULL, NULL, hinst, NULL);

    ShowWindow(hwndPopup, SW\_SHOWNORMAL);
    UpdateWindow(hwndPopup);
    
    HDC popupdc = GetDC(hwndPopup);
    
    int nScreenWidth = GetSystemMetrics(SM\_CXSCREEN);
    int nScreenHeight = GetSystemMetrics(SM\_CYSCREEN);
    
    HDC hDesktopDC = GetDC(NULL);
    HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
    HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight);
    SelectObject(hCaptureDC,hCaptureBitmap); 
    //BitBlt(popupdc, 0,0, 200, 200, hDesktopDC, mx-100, my-100, SRCCOPY|CAPTUREBLT); 
    StretchBlt(popupdc, 0,0, 200, 200, hDesktopDC, mx-12, my-12, 24, 24, SRCCOPY|CAPTUREBLT);     
    //this is right
    
    ReleaseDC(NULL,hDesktopDC);
    ReleaseDC(NULL,popupdc);
    DeleteDC(hCaptureDC);
    DeleteObject(hCaptureBitmap);    
    

    }

    When i press the short cut key the new window appears with the expected output in it. When i move some other window over it then window is painted white. I searched and found that WM_PAINT message is used. I have not used it as i want to be clear of what it is for. Still understand the working of GDI+. How do i retain the painted window? I don't want other window to erase the content. [Here is the screen shot]

    http://vikku.info/

    Today's Beautiful Moments are Tomorrow's Beautiful Memories

    L 1 Reply Last reply
    0
    • J Jayapal Chandran

      [^]I am writing a colour picker program using Windows API. It has an option to zoom the area around the mouse position. The program uses a short cut key. To do this i capture 200x200 around the mouse and display by stretching it in a new window using StretchBlt. Here is the code.

      void showZoomDialog()
      {
      HWND hwndPopup = CreateWindowEx(WS_EX_TOOLWINDOW, szClassName, "Zoom", WS_POPUP | WS_BORDER | WS_CAPTION,
      200, 120, 200, 200, NULL, NULL, hinst, NULL);

      ShowWindow(hwndPopup, SW\_SHOWNORMAL);
      UpdateWindow(hwndPopup);
      
      HDC popupdc = GetDC(hwndPopup);
      
      int nScreenWidth = GetSystemMetrics(SM\_CXSCREEN);
      int nScreenHeight = GetSystemMetrics(SM\_CYSCREEN);
      
      HDC hDesktopDC = GetDC(NULL);
      HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
      HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight);
      SelectObject(hCaptureDC,hCaptureBitmap); 
      //BitBlt(popupdc, 0,0, 200, 200, hDesktopDC, mx-100, my-100, SRCCOPY|CAPTUREBLT); 
      StretchBlt(popupdc, 0,0, 200, 200, hDesktopDC, mx-12, my-12, 24, 24, SRCCOPY|CAPTUREBLT);     
      //this is right
      
      ReleaseDC(NULL,hDesktopDC);
      ReleaseDC(NULL,popupdc);
      DeleteDC(hCaptureDC);
      DeleteObject(hCaptureBitmap);    
      

      }

      When i press the short cut key the new window appears with the expected output in it. When i move some other window over it then window is painted white. I searched and found that WM_PAINT message is used. I have not used it as i want to be clear of what it is for. Still understand the working of GDI+. How do i retain the painted window? I don't want other window to erase the content. [Here is the screen shot]

      http://vikku.info/

      Today's Beautiful Moments are Tomorrow's Beautiful Memories

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I am afraiod you are doing it the wrong way. All actions in Windows are driven by messages received in the application (or thread) message pump. When a WM_PAINT message is received it indicates that the Window in question requires repainting. If you do your window painting in some other function and ignore the WM_PAINT messages then you will get the result that you see.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups