VC ++中的GDI泄漏问题 [英] GDI Leak Problem in VC++

查看:204
本文介绍了VC ++中的GDI泄漏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们庞大的应用软件中发现了GDI泄漏。



以下是一个测试此问题的简单程序。

想法是主对话框打开另一个对话框(对话框A)。

如果对话框A包含CStatic控件的位图功能,

它将创建GDI泄漏。



即使我使用DeleteObject(位图)。



我做了些什么事错了?

您有什么想法吗?



谢谢。



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.

// 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
  DialogBoxA: public CDialog
  {
     ...

     CStatic m_static;
     CButton m_button ;

     ...
  }


  /////////////////////////////////////////////////////////

  void DialogBoxA::DoDataExchange(CDataExchange* pDX)
  {
     CDialog::DoDataExchange(pDX);
     DDX_Control(pDX, RED_LIGHT0, m_static);
     DDX_Control(pDX, RED_LIGHT1, m_button);
  }

  BOOL DialogBoxA::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
  }





我使用LoadImage()而不是LoadBitmap(),这是同样的问题。



And I use "LoadImage()" instead of "LoadBitmap()", it is same problem.

推荐答案

是吗,通过机会,'假阳性'?例如,请参阅默认Win32项目具有恒定的内存泄漏数量在堆栈溢出 [ ^ ]。
Is it, by chance, a 'false-positive'? See, for instance "Default Win32 project has constant number of memory leaks" at Stack Overflow[^].


谢谢每一个人。

我根据这个网站的建议解决了问题。

http://stackoverflow.com/questions/8489301/possible-memory-leak-using-gethbitmap-and-mfc-cstaticsetbitmap
Thanks every one.
I solved problem according to this website suggestion.
http://stackoverflow.com/questions/8489301/possible-memory-leak-using-gethbitmap-and-mfc-cstaticsetbitmap


这篇关于VC ++中的GDI泄漏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆