I have found a GDI leak in our huge application software.
Below is a simple program to test this problem.
The Idea is that the main dialog box opens another dialog box(dialog box A).
If the dialog box A include a bitmap function for a CStatic control,
it will create GDI leak.
Even when I use "DeleteObject(bitmap)".
Have I done some thing wrong ?
Do you have any thoughts?
Thanks.
Below is a simple program to test this problem.
The Idea is that the main dialog box opens another dialog box(dialog box A).
If the dialog box A include a bitmap function for a CStatic control,
it will create GDI leak.
Even when I use "DeleteObject(bitmap)".
Have I done some thing wrong ?
Do you have any thoughts?
Thanks.
// Resource File ... DIALOG_BOXA DIALOGEX 0, 0, 219, 142 STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_BORDER EXSTYLE WS_EX_STATICEDGE FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "OK",IDOK,46,121,50,14 PUSHBUTTON "Cancel",IDCANCEL,119,121,50,14 CONTROL 131,RED_LIGHT0,"Static",SS_BITMAP,7,17,80,37 PUSHBUTTON "",RED_LIGHT1,7,60,80,37,BS_BITMAP | NOT WS_TABSTOP END // head file Dialog_Box_A: public CDialog { ... CStatic m_static; CButton m_button ; ... } ///////////////////////////////////////////////////////// void Dialog_Box_A::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, RED_LIGHT0, m_static); DDX_Control(pDX, RED_LIGHT1, m_button); } BOOL Dialog_Box_A::OnInitDialog() { CDialog::OnInitDialog(); HBITMAP bitmap ; // This will create GDI leak !!! bitmap = LoadBitmap ( AfxGetApp()->m_hInstance,BEACON_BIG_RED_ON) ; m_static.SetBitmap (bitmap ); DeleteObject(bitmap); // This is OK !!! bitmap = LoadBitmap ( AfxGetApp()->m_hInstance,BEACON_BIG_RED_ON) ; m_button.SetBitmap (bitmap ); DeleteObject(bitmap); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }