Windows Leeks

Started by
3 comments, last by FuMo 23 years, 10 months ago
I am trying to write a windows text editor that has a more attractive look (it looks a bit like sonique). But I am getting a memory leeks every time I redisplaying or resizing the app. I have separate functions to paint and resize the main window that I call when the appropriate message is sent to the app. And here seems to lie the problem because if I call them out side the msg look I don''t get any memory leeks but it is very inefficient and untidy code. Here is the main gist of the message proc: switch (uMsg) { case WM_PAINT: DisplayWindow(); break; case WM_MOUSEMOVE: if (wParam == MK_LBUTTON) { SetWindowPos( hWnd,HWND_TOP,wdXPos,wdYPos,wdWidth,wdHeight,NULL); } else { CalcRGN(); // Calculate the windows new region SetWindowPos( hWnd,HWND_TOP,wdXPos,wdYPos,wdWidth,wdHeight,NULL); DisplayWindow(); } } Any help or a website that has got advanced windows programming tuts (ie stopping mem leeks) would be much appreciated I am not using MFC because I want to learn as much about windows programming as possible.
+---------------------------------------------+| "Hard work never killed anyone but I figure || why take the chance?" Ronald Regan |+---------------------------------------------+
Advertisement
Are you using VC++? If you are, then check out _CrtDumpMemoryLeaks() and related functions in the MSDN docs. There are a bunch of runtime library functions that will help you to detect memory leaks if you run your program from the debugger. You can find out if and where a leak is occuring, as well as see a dump of some of the data from the leak.

Good luck!
If you''re not using VC++, you might be able to do what they do. They overloaded the new and delete operators with different parameters. Then they used a define to redifine them. It does take a lot of work though.

For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
Your code does not show alot so I''m guessing here.

A common problem is that reources are not deleted once they are no longer needed, i.e. CreateBrush, CreateFont, etc....

Remember to deselect them from the DC first.

SelectObject(HDC hDC,HGDIOBJ hObj) returns the previously selected object type (i.e. if you select a pen then it returns the previous pen), us this returned value to deselect your object.
Thanks for all the help its been very helpful
+---------------------------------------------+| "Hard work never killed anyone but I figure || why take the chance?" Ronald Regan |+---------------------------------------------+

This topic is closed to new replies.

Advertisement