confused by SelectObject funcion

I saw a segment in my book about double buffering constructor:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
BackBuffer::BackBuffer(HWND hWnd, intwidth, intheight) 
{ 
mhWnd = hWnd; 
HDC hWndDC = GetDC(hWnd); 
mWidth = width; 
mHeight = height; 
mhDC = CreateCompatibleDC(hWndDC); 
mhSurface = CreateCompatibleBitmap( 
hWndDC, width, height); 
ReleaseDC(hWnd, hWndDC); // when release the DC, does mhDC and mhSurface still bounding with the hWndDC? don't we just make use of the hWndDC? use it, and then get rid of it?

mhOldObject = (HBITMAP)SelectObject(mhDC, mhSurface);  // select object first

// why use the white brush, I mean, we can just ignore this, because default is white.
// initialize the backbuffer to non-zero
HBRUSH white = (HBRUSH)GetStockObject(WHITE_BRUSH); 
HBRUSH oldBrush = (HBRUSH)SelectObject(mhDC, white);  // when use it second, won't overwrites the first? or not the same type, 
//won't overwrites? if the second use of SelectObject's 
//second parameter is HBITMAP like first, will overwrites?

Rectangle(mhDC, 0, 0, mWidth, mHeight); // what does the mhDC mean? it just initialized by CreateCompatibleDC(hWndDC) as a system DC  
//I think in this line, it means the DC to the buffer window. is it?
//I think draw a rectangle will draw the black outline, right?

SelectObject(mhDC, oldBrush); 
} 
Last edited on
1
2
3
4
5
6
mhOldObject = (HBITMAP)SelectObject(mhDC, mhSurface);  // select object first

HBRUSH white = (HBRUSH)GetStockObject(WHITE_BRUSH); 
HBRUSH oldBrush = (HBRUSH)SelectObject(mhDC, white);  // when use it second, won't overwrites the first? 
//or not the same type, won't overwrites?
// if the second use of SelectObject's second parameter is HBITMAP like first, will overwrites? 


As you guessed in your example, selecting the brush into the context will not
overwrite the previous selection of the bitmap because they are different types of objects.



Topic archived. No new replies allowed.