waiiit a minute... the only difference between the two sets of code is that you put the original HBRUSH from hdc into hbrush2. But effectively, there is no difference between the two sets. This is what you did for the first:
Code:
switch (iMsg)
{
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
hbrush = CreateHatchBrush(HS_FDIAGONAL,RGB(50,50,50)); Create hbrush
SelectObject(hdc,hbrush); //select hbrush
Ellipse(hdc,25,25,100,100); //draw ellipse
DeleteObject(hbrush); //delete hbrush
Ellipse(hdc,100,100,200,200); //draw ellipse (?...)
EndPaint(hwnd,&ps);
break;
case WM_LBUTTONDOWN:
hdc = GetDC(hwnd);
Ellipse(hdc,150,150,300,300); //draw ellipse
ReleaseDC(hwnd,hdc);
break;
}
This is what you did in the second:
Code:
switch (iMsg)
{
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
hbrush = CreateHatchBrush(HS_FDIAGONAL,RGB(50,50,50)); Create hbrush
hbrush2 = SelectObject(hdc,hbrush); //select hbrush, put the original brush in hbrush2
Ellipse(hdc,25,25,100,100); //draw ellipse
DeleteObject(hbrush); //delete hbrush
Ellipse(hdc,100,100,200,200); //draw ellipse (?...)
EndPaint(hwnd,&ps);
break;
case WM_LBUTTONDOWN:
hdc = GetDC(hwnd);
Ellipse(hdc,150,150,300,300); //draw ellipse
ReleaseDC(hwnd,hdc);
break;
//you still haven't selected hbrush2 back into hdc,
//and it will now go out of scope!
}
* and by the way, you did put the closing curly brace in your own code, right?