Menu

about keeping background untouched

2007-08-30
2012-09-26
  • aventura_alex

    aventura_alex - 2007-08-30

    Hi everybody. This is supposed to be sort of basic GDI question. Not that basic as I have spent a while already on that. The thing is:
    1. I had made a checkered background
    2. I made a rotating rectangle over it inside a WM_TIMER message
    so far so good but
    3. here is my question: I was trying to keep the background untoutched after drawing each rotating rectangle frame. I try to copy the bitmap associated with the client area into a compatible DC. After that I would gladly paste it back on the client area. Unfortunatelly all I get after that is a black background behind my rotating rectangle. Thus, my question. Doesn't the client area has an associated bitmap so that I can copy into another bitmap from a compatible DC and then back into the client area? if it isn't so? how could I possibly do that: copy everything that is on the client area to a temporary bitmap, draw on the client area and next time I need to draw again, I would restore the client area.

     
    • aventura_alex

      aventura_alex - 2007-08-31

      hi folks,
      before anyone care to answer this thread, what you might like as an exercise, I managed to solve the problem. I'm not sure what was going wrong as I didn't find the mistake in it but just wrote it all over.
      in fact now I have created 2 buffers instead of one, not that this is the solution to the original problem but an improvement, since now I'm writing on memory first and only then writing over the canvas.
      the second buffer I'm using only to recover the original background not to leave a trail of a rotating rectangle. I'm still having some issues on what's the best moment to recover/repaint the background but all in all I have had a good improvement since I was first thinking that BitBlt was not working here :P
      it might be something to do with scope. I'm not 100 per cent sure when I should and when I should not use global handles with these functions. If I run the risk of losing something when the wm_timer exits, etc etc.
      so, later I might have a closer look in the old code and if I find something's the matter I may come here and let you know :)
      big hugs
      Alexandre

       
    • aventura_alex

      aventura_alex - 2007-08-30

      Could anyone explain me this excerpt:
      When an application creates a DC, the system automatically stores a set of default objects in it. (There is no default bitmap or path.)
      Does it mean that my client area has no default bitmap and thus I cannot just do:
      hdc = GetDC(hwnd);
      GetClientRect(hwnd,&rc);
      if ((hdcDisplay = CreateCompatibleDC(hdc))== NULL) {
      MessageBox(0,"Failed to create display device context","Error",MB_OK);
      PostQuitMessage(0);
      }
      if ((bmpClient = CreateCompatibleBitmap(hdc,rc.right,rc.bottom)) == NULL) {
      MessageBox(0,"Failed to create a compatible bitmap","Error",MB_OK);
      PostQuitMessage(0);
      }
      if ((oldBmp = (HBITMAP)SelectObject(hdcDisplay,bmpClient)) == NULL) {
      MessageBox(0,"Failed to select compatible bitmap to compatible DC","Error",MB_OK);
      PostQuitMessage(0);
      }
      if ((GetDeviceCaps(hdc,RASTERCAPS) & RC_BITBLT)== 0) {//this a temporary test
      MessageBox(0,"Device does not support BitBlt function","Error",MB_OK);
      PostQuitMessage(0);
      }
      if (visible) { //hide visible
      if (BitBlt(hdc,0,0,rc.right,rc.bottom,hdcDisplay,0,0,SRCCOPY)==0) {
      MessageBox(0,"Failed to recover bitmap from compatible DC","Error",MB_OK);
      PostQuitMessage(0);
      }
      } else {
      if (BitBlt(hdcDisplay,0,0,rc.right,rc.bottom,hdc,0,0,SRCCOPY)==0) {
      MessageBox(0,"Failed to save bitmap to compatible DC","Error",MB_OK);
      PostQuitMessage(0);
      }
      }

      any mistake in the code above?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.