The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

The difference between code

I was wondering what the difference was between these two code blocks are. They are nearly identical, the key difference is where the compatibleHC is created and where it is also destroyed. The code seems to run exactly the same, but I was worried there might be a problem with the second version.

Here is the first version :

HDC hdcMem;
   
  for (i = 2; i <= 4; i++) {

      hdcMem = CreateCompatibleDC(hdc);

      SelectObject(hdcMem, phBitmap[i]);
      BitBlt(hdc, icurx, icury,
      pcxSource[i], pcySource[i], hdcMem, 0, 0, SRCCOPY);

      DeleteDC(hdcMem);
  }

This is my original code. It just creates a compatible hdc and then loads a bitmap image into the hdcMem. Then it draws it to the screen.

Here is the second version :

HDC hdcMem;
   
  hdcMem = CreateCompatibleDC(hdc);

  for (i = 2; i <= 4; i++) {

      SelectObject(hdcMem, phBitmap[i]);
      BitBlt(hdc, icurx, icury,
      pcxSource[i], pcySource[i], hdcMem, 0, 0, SRCCOPY);
  }

  DeleteDC(hdcMem);

The difference here is that it creates the compatible hdc before the loops is run, and then destroys it afterwards. It is my impression that this second version will run faster because it doesn't call CreateCompatibleDC as many times as the first version. Are there any negative effects to using the hdcMem context over and over to draw out bitmaps without re-initilizing and deleting it after each use?
Jeff Williams Send private email
Tuesday, October 03, 2006
 
 
This just reminds me of how much I hate Windows bitmap code.
old.fart Send private email
Tuesday, October 03, 2006
 
 
Will SaveDC() and RestoreDC() not work in your case? That should be lot faster than calling CreateCompatibleDC all times.

But may be I am wrong - it's been a while since I did Windoze programming :)
annu_gogte
Tuesday, October 03, 2006
 
 
The single memory DC approach is exactly how I've done it for years and I've never encountered an issue with it.
SomeBody Send private email
Wednesday, October 04, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz