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. C / C++ / MFC
  4. Problem with Painting logic

Problem with Painting logic

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomannouncement
2 Posts 2 Posters 0 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.
  • N Offline
    N Offline
    narayanagvs
    wrote on last edited by
    #1

    Hi, In my application I have a window in which there are few buttons below the window and on clicking each of the buttons Activex controls from a list with certain conditions are shown in the same window above these buttons .This is done using painting logic.The Problem I am having here is there are prev screen left overs when I swiitch between button clicks. This bug appears only once when I open the window and do the button clicks.If at all I Minimize and Maximize my window atleast once this bug doesn't appear and every works fine. I face the issue only when I use DeviceindependentBitmap to Bitblt.I assume the problem is with clipregions. Please suggest me on the same. Below is the snippets of code

    case WM_PAINT:{
    RECT rc;
    HDC hdcMem, hdcOld;
    HBRUSH hbrBkGnd;
    HFONT hfntOld;
    PAINTSTRUCT ps;
    DWORD dwConnectState;

    	// Don't bother Processing any WM\_PAINT messages if you are in the process of 
    	// shutting down Window.
    	if(! bViewClosing )	 
    	{
    	// Get the window update region before calling BeginPaint. 
    	// Note: The BeginPaint function automatically validates the update region, so any call 
    	// to GetUpdateRgn made immediately after the call to BeginPaint retrieves an empty update 
    
    	region. 
    	if(hClipRgn == NULL)
    	{
    		hClipRgn = CreateRectRgn(0,0,0,0);
    		GetUpdateRgn(hWnd, hClipRgn, FALSE);
    	}
    	ws = (WIN\_STRUCTPTR) GetWindowLong( hWnd, 0 );
    	BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
    
    	// Get the size of the client rectangle.
    	GetClientRect(hWnd, &rc);
    
    	// Create a compatible DC.
    	hdcMem = CreateCompatibleDC(ps.hdc);
    
    	bool createFailed = false;
    
    	// Create a DIBSection big enough for our client rectangle.
    	long width = rc.right-rc.left;
    	long height = rc.bottom-rc.top;
    	//Start of CRL00107461 
    	HWND dDeskWnd = GetDesktopWindow();
    	HDC hdc= GetDC(dDeskWnd);
    	int nBitCount = GetDeviceCaps(hdc,BITSPIXEL);
    	if (hbmDIBSection == NULL || dibSectionWidth < width || dibSectionHeight < height)
    	{
    		if (hbmDIBSection != NULL)
    			DeleteObject(hbmDIBSection);
    		
    		BITMAPINFO bmi = {0};
    		bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
    		bmi.bmiHeader.biWidth       = width;
    		bmi.bmiHeader.biHeight      = height;
    		bmi.bmiHeader.biPlanes      = 1;
    	    bmi.bmiHeader.biBitCount    = nBitCount;//32;       // 32 bits per pixel.//CRL00107461
    		bmi.bmiHeader.biCompression = BI\_RGB;
    		bmi.bmiHeader.biSizeImage   = bmi.bmiHeader.biWidth \* bmi.bmiHeader.biHeight \* 4; 
    

    // 4

    N 1 Reply Last reply
    0
    • N narayanagvs

      Hi, In my application I have a window in which there are few buttons below the window and on clicking each of the buttons Activex controls from a list with certain conditions are shown in the same window above these buttons .This is done using painting logic.The Problem I am having here is there are prev screen left overs when I swiitch between button clicks. This bug appears only once when I open the window and do the button clicks.If at all I Minimize and Maximize my window atleast once this bug doesn't appear and every works fine. I face the issue only when I use DeviceindependentBitmap to Bitblt.I assume the problem is with clipregions. Please suggest me on the same. Below is the snippets of code

      case WM_PAINT:{
      RECT rc;
      HDC hdcMem, hdcOld;
      HBRUSH hbrBkGnd;
      HFONT hfntOld;
      PAINTSTRUCT ps;
      DWORD dwConnectState;

      	// Don't bother Processing any WM\_PAINT messages if you are in the process of 
      	// shutting down Window.
      	if(! bViewClosing )	 
      	{
      	// Get the window update region before calling BeginPaint. 
      	// Note: The BeginPaint function automatically validates the update region, so any call 
      	// to GetUpdateRgn made immediately after the call to BeginPaint retrieves an empty update 
      
      	region. 
      	if(hClipRgn == NULL)
      	{
      		hClipRgn = CreateRectRgn(0,0,0,0);
      		GetUpdateRgn(hWnd, hClipRgn, FALSE);
      	}
      	ws = (WIN\_STRUCTPTR) GetWindowLong( hWnd, 0 );
      	BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
      
      	// Get the size of the client rectangle.
      	GetClientRect(hWnd, &rc);
      
      	// Create a compatible DC.
      	hdcMem = CreateCompatibleDC(ps.hdc);
      
      	bool createFailed = false;
      
      	// Create a DIBSection big enough for our client rectangle.
      	long width = rc.right-rc.left;
      	long height = rc.bottom-rc.top;
      	//Start of CRL00107461 
      	HWND dDeskWnd = GetDesktopWindow();
      	HDC hdc= GetDC(dDeskWnd);
      	int nBitCount = GetDeviceCaps(hdc,BITSPIXEL);
      	if (hbmDIBSection == NULL || dibSectionWidth < width || dibSectionHeight < height)
      	{
      		if (hbmDIBSection != NULL)
      			DeleteObject(hbmDIBSection);
      		
      		BITMAPINFO bmi = {0};
      		bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
      		bmi.bmiHeader.biWidth       = width;
      		bmi.bmiHeader.biHeight      = height;
      		bmi.bmiHeader.biPlanes      = 1;
      	    bmi.bmiHeader.biBitCount    = nBitCount;//32;       // 32 bits per pixel.//CRL00107461
      		bmi.bmiHeader.biCompression = BI\_RGB;
      		bmi.bmiHeader.biSizeImage   = bmi.bmiHeader.biWidth \* bmi.bmiHeader.biHeight \* 4; 
      

      // 4

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      You could try to call InvalidateRect[^] when switching control. It will invalidate the background and force a repaint if the bErase parameter is TRUE.

      home

      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