Click here to Skip to main content
15,911,141 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralForcing redrawing of property pages... Pin
Bob The Builder (BtB)10-Feb-04 2:12
Bob The Builder (BtB)10-Feb-04 2:12 
Generalproblem with ShellExecute and environment variables Pin
feline_dracoform10-Feb-04 0:20
feline_dracoform10-Feb-04 0:20 
GeneralRe: problem with ShellExecute and environment variables Pin
Luuk Weltevreden10-Feb-04 0:39
Luuk Weltevreden10-Feb-04 0:39 
GeneralRe: problem with ShellExecute and environment variables Pin
feline_dracoform10-Feb-04 0:50
feline_dracoform10-Feb-04 0:50 
GeneralRe: problem with ShellExecute and environment variables Pin
Luuk Weltevreden10-Feb-04 1:23
Luuk Weltevreden10-Feb-04 1:23 
GeneralRe: problem with ShellExecute and environment variables Pin
feline_dracoform11-Feb-04 0:51
feline_dracoform11-Feb-04 0:51 
GeneralRe: problem with ShellExecute and environment variables Pin
Luuk Weltevreden11-Feb-04 6:14
Luuk Weltevreden11-Feb-04 6:14 
QuestionWindows listbox has a resource error? Pin
Luuk Weltevreden10-Feb-04 0:11
Luuk Weltevreden10-Feb-04 0:11 
Hi,

I have a control with a listbox and an edit on it. The control can be resized and both controls get resized as well. I checked my program with boundschecker and it found a resource error in each of those controls. It calls ReleaseDC while there are still non-stock objects in it. Well I checked and rewrote my drawing code like 10 times and it still didn't go away. I -know- it's flawless. So I reproduced the control step by step and noticed the resource error wasn't there when I didn't have the listbox on my control. Huh? So step by step I traced the error to the point that I resize the listbox.

Every time I resize the listbox my DC gets corrupted. Well I looked at the class styles of the listbox, and indeed it has the CS_PARENTDC style, so it could be very well possible that the listbox is the cause of my problem. But, here's the catch. It's just a stock listbox. I didn't do anything with it, straight from the Win32 API WTF | :WTF: Did anyone else notice this error by Microsoft or am I overlooking something and is it a mistake made by myself?

To reproduce:
- Make a window
- Add a listbox
- On resize, resize the listbox
- Make sure you call both GetDC() and ReleaseDC() in any paint event (doesn't even have to be a paint event I suppose) of the window (you don't have to actually draw something, it just matters to call ReleaseDC() so boundschecker jumps in)
- Run boundschecker and resize the window a bit, it will trigger the error eventually

I tracked it even further. The following messages generate the error:

WM_NCPAINT
WM_ERASEBKGND

So what I did to solve it is to subclass the listboxes and handle these messages. Then I do the following:

LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&) throw()
{
	// Store contents of the DC
	HDC hDC = ListBox.GetWindowDC();
	int nSaved = ::SaveDC(hDC);

	// Pass this message to the listbox class procedure
	ListBox.DefWindowProc(uMsg, wParam, lParam);

	// Restore contents of the DC
	::RestoreDC(hDC, nSaved);
	ListBox.ReleaseDC(hDC);

	// Message has been handled
	return 0;
}


It works, but I don't like it that I have to do this to solve a problem which shouldn't be solved by me at all and neither to solve it this way. So again, does anyone have the same problems I have and if so how did you solve it?
AnswerRe: Windows listbox has a resource error? Pin
Anonymous10-Feb-04 8:13
Anonymous10-Feb-04 8:13 
GeneralRe: Windows listbox has a resource error? Pin
Luuk Weltevreden10-Feb-04 8:35
Luuk Weltevreden10-Feb-04 8:35 
GeneralMFC drawing confusion Pin
Madhur Baheti9-Feb-04 23:40
Madhur Baheti9-Feb-04 23:40 
GeneralRe: MFC drawing confusion Pin
CodeBrain10-Feb-04 0:44
CodeBrain10-Feb-04 0:44 
GeneralRe: MFC drawing confusion Pin
Mike Dimmick10-Feb-04 1:01
Mike Dimmick10-Feb-04 1:01 
GeneralRegarding Screen changes Pin
santosh k9-Feb-04 23:17
santosh k9-Feb-04 23:17 
GeneralRe: Regarding Screen changes Pin
Luuk Weltevreden10-Feb-04 0:34
Luuk Weltevreden10-Feb-04 0:34 
GeneralRe: Regarding Screen changes Pin
Luuk Weltevreden10-Feb-04 3:52
Luuk Weltevreden10-Feb-04 3:52 
GeneralRegarding Screen changes Pin
santosh k9-Feb-04 23:12
santosh k9-Feb-04 23:12 
GeneralSmall Problem. Pin
Prakash Nadar9-Feb-04 22:26
Prakash Nadar9-Feb-04 22:26 
GeneralRe: Small Problem. Pin
10-Feb-04 1:43
suss10-Feb-04 1:43 
GeneralRe: Small Problem. Pin
Steve S10-Feb-04 1:54
Steve S10-Feb-04 1:54 
GeneralSpreadsheet writing Pin
Ger Hayden9-Feb-04 21:58
Ger Hayden9-Feb-04 21:58 
GeneralRe: Spreadsheet writing Pin
Brian D10-Feb-04 1:46
Brian D10-Feb-04 1:46 
GeneralRe: Spreadsheet writing Pin
David Crow10-Feb-04 3:34
David Crow10-Feb-04 3:34 
GeneralListCtrl Pin
Ger Hayden9-Feb-04 21:57
Ger Hayden9-Feb-04 21:57 
GeneralRe: ListCtrl Pin
David Crow10-Feb-04 3:33
David Crow10-Feb-04 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.