 |
|
 |
I do not know if I have to consider trinium's posting real or not.
Please tell me if those mentioned memory leaks are real or not.
I like the approach but I do not want to fight against hidden memory leaks if they are really there...
Thanks
Pat
|
|
|
|
 |
|
 |
Well he never elaborated. The only thing I can see that might possibly be wrong is the code doesn't destroy/release resource (icons, etc.) handles, but I really don't think that is necessary.
"Make everything as simple as possible, but not simpler." - Albert Einstein
|
|
|
|
 |
|
 |
I've spent more time on this and I can say the approach on the article is nice, you have not implemented the message registration system the article mentions, I'll try to add it. At the moment I extended your project supporting dialog boxes as a derived class of CWindows, (I renamed you CBaseWindows as CWindows)
add to the .h
class CDialog : public CWindow
{
public:
virtual BOOL Create(HWND hWndParent,DWORD IDD_DIALOG);
CDialog(HINSTANCE hInst)
:CWindow(hInst) {};
protected:
LRESULT CALLBACK CDialog::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
inline static CDialog *GetObjectFromWindow(HWND hWnd)
{
return (CDialog *)GetWindowLong(hWnd, GWL_USERDATA);
}
};
add to the .cpp
BOOL CDialog::Create(HWND hWndParent, DWORD IDD_DIALOG )
{
m_hwnd = CreateDialogParam(hInstance,
MAKEINTRESOURCE(IDD_DIALOG),
hWndParent ,
(DLGPROC)CWindow::stWinMsgHandler,
(LPARAM)this);
return (m_hwnd != NULL);
}
at LRESULT CALLBACK CWindow::stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
replace
if (uMsg == WM_NCCREATE )
{
SetWindowLong(hwnd, GWL_USERDATA, (long)((LPCREATESTRUCT(lParam))->lpCreateParams));
}
with
if (uMsg == WM_NCCREATE )
{
SetWindowLong(hwnd, GWL_USERDATA, (long)((LPCREATESTRUCT(lParam))->lpCreateParams));
}
else if ( uMsg == WM_INITDIALOG )
{
SetWindowLong(hwnd, GWL_USERDATA, (long)lParam);
}
I still have to check the memory leaks, this tiny project deserves the effort...
I got a dialog box based app up and running in 5 minutes... good...
|
|
|
|
 |
|
 |
in fact it does leak...
if the window is registered in a dll UnregisterClass() has to be called at
case DLL_PROCESS_DETACH:
the other problem is resource leak if the Icons,Cursors and brushes are not default shared objects..
nice article on resource leak.
http://msdn.microsoft.com/en-us/magazine/cc301756.aspx
|
|
|
|
 |
|
 |
I use only stock objects which do not require a call to deleteobject and all icons and cursors are stock as well. Its ambiguous whether the HDC used in painting should be released.
Like I said in the article text, this is a crude example. If you plan to extend it then memory leaks may be an issue, but I am still not convinced that the code as it is written is leaky.
Besides, I don't program in C++ anymore and the article is 10 years old. I don't plan to fix it. I do hope you found it useful.
"Make everything as simple as possible, but not simpler." - Albert Einstein
|
|
|
|
 |
|
 |
Please don't get me wrong, of course your article was very valuable, it saved me a lot of time...
Yes I have extended the thing and changed a bit the approach; if I ever get the time I'll post it quoting your article of course.
thanks
|
|
|
|
 |
|
 |
Great article, nicely done!
|
|
|
|
 |
|
 |
your win32 wrapper class has 34 memory leaks.
HeapCreate, HeapAlloc and some StdHandler's
why post this stuff if you people dont know what the hell your doing.
all right, im done.
the only thing as endless as the universe is human stupidity - Einstien & me.
|
|
|
|
 |
|
 |
It might help if you would point them out instead of insulting me.
"Live long and prosper." - Spock
|
|
|
|
 |
|
 |
I think you've just embarrassed yourself here mate.
After all, its a bit rich to accuse the article's author of immaturity when you haven't shown much maturity yourself. And if you must be gratuitously rude, you could at least get your facts right. 34 memory leaks indeed!!
trinium wrote: the only thing as endless as the universe is human stupidity
Well you've just demonstrated that!
|
|
|
|
 |
|
 |
I am surprised that why folks at Microsoft implemented the thigns the way they are? Having internal maps containing Pointer to Handles relationships... A simple memory overhead... Dumb heads... I am working on an OCR Project, usign MFC... I dont like because it quite bulky and further more,you have to mold yourself into the MFC way... And I dont like that... Pure Win32 is quite unmanageable... So I planned to write my own class library having on suppor for simple GUI elements... I was going in same direction to call the memebers but now I am corrected...
Thanks a lot!
Polite Programmer
More Object Oriented then C#
|
|
|
|
 |
|
 |
To store the pointer to the window in USERDATA is quite a good idea.
I've ever tried to do some work on wrapping the hwdn, and I met the problem how to obtain any pointer of my class from the hwnd.
I found how MFC does this is quite excellent but too complicated. It seems that MFC hooks all call to ::CreateWindowEx() and keeps a map of all windows. So it is possible to call FromHandle() on all hwnds in MFC( as I think GetObjectFromWindow() is only available on windows created as CBaseWindow or derived classes in your code)
I think this level of GetObjectFromWindow() is enough in many cases.
Thanks.
旧日重来
|
|
|
|
 |
|
 |
This is an excellent piece of work. It has given me a few ideas that I'll be using in my own code. One trivial point (hope you don't mind)... It would probably be better to use #include <windows.h> instead of #include "stdafx.h" at the beginning of BaseWindow.cpp. After all this code doesn't use MFC, and using the standard windows header file would help make it more portable.
Regards, David
|
|
|
|
 |
|
 |
Thanks!
When I update it I'll make your change.
"Live long and prosper." - Spock
|
|
|
|
 |
|
 |
My previous remarks regarding "stdafx.h" were off the mark.
Your source download doesn't include a copy of your header file stdadx.h. To get your source to compile I grabbed another copy off one of my MFC projects.
The thing is - the contents of stdafx.h is not always the same, and it doesn't necessarily contain MFC stuff. stdafx.h is automatically generated when you create a project (Yes, I've been caught out by a wizard again).
The bottom line - ignore my previous comments about stdafx.h, but you might like to add your stdafx.h to the set of source files to avoid confusion.
regards,
David
|
|
|
|
 |
|
 |
Authos says :
... and I am married with two kids (both boys). ...
What`s this world coming to ?
I am the MIGHTY KEEPER of the BOOK OF KNOWLEDGE . Contact me to get your copy .
|
|
|
|
 |
|
 |
To even think this way.
I have 2 sons you dimwit. Can't read? Stay away from CP.
"Live long and prosper." - Spock
|
|
|
|
 |
|
 |
It was just a joke . I thought you`ll notice that .
(As a coder you should have thought of this , and avoid that way of expressing .)
Anyway , your self-description rocks .
And I gave you 5 for the article . Sorry for the bad joke but I couldn`t help it .
I am the MIGHTY KEEPER of the BOOK OF KNOWLEDGE . Contact me to get your copy .
|
|
|
|
 |
|
 |
TomKat wrote:
It was just a joke . I thought you`ll notice that .
(As a coder you should have thought of this , and avoid that way of expressing .)
Sorry. Someone else did the same thing a while back and I don't think it was a joke then.
"Live long and prosper." - Spock
|
|
|
|
 |
|
 |
Hi
maybe this is wrong taht I have said my problem here.However,Sorry.
I have an academic project that I hav to perform it in 6 days from now. The project is to develope a wrapper class for users so that they don't need to use windows programing functions.I should develope a class that the user could make a simple window with menue textbox and scrollbar easily without dealing with message handling and difficult adjustments of windows programming.
I dont know the exacr hierarchy of my classes.
please help me
MehdiC++
|
|
|
|
 |
|
 |
Well i download your cource code, and i cant get it to compile.
So i make my own implementation of your code, and now i get this error...
c:\Documents and Settings\Justin\My Documents\Visual Studio Projects\oglTwoDee\oglTwoDeeWin32.cpp(128): error C2084: function 'LRESULT GLWindow::WinMsgHandler(HWND,UINT,WPARAM,LPARAM)' already has a body
c:\Documents and Settings\Justin\My Documents\Visual Studio Projects\oglTwoDee\oglTwoDeeWin32.h(77) : see previous definition of 'WinMsgHandler'
and i look back at your code, and well its right,
you have a body for that function in the .h, and in the .cpp
I am new to this win32 stuff, but would like to see a working code package, so i can move onto better things.
THANKS
|
|
|
|
 |
|
 |
The source was orininally compiled under Visual C++ 6.
Under VC 7 it will not compile with out a few tweaks.
Mainly, take out the #include "stdafx.h" in the BaseWindow.cpp and add #include .
After doing that, my code compiles.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
|
|
|
|
 |
|
 |
drunkenZim wrote:
and i look back at your code, and well its right,
you have a body for that function in the .h, and in the .cpp
WinMsgHandler has no implementation in the base class, it is a pure virtual function thus making BaseWindow an abstract class. The only other implementation is in the derivedwindow.h file and there is no .cpp file. Perhaps in the class you made, you have 2 bodies for that function, put my code does not.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
|
|
|
|
 |
|
 |
In DerivedWindow.h there is a winMsgHandler,
and in DerivedWindow.cpp there is another body.
This is from the code i just downloaded at the top of this page.
|
|
|
|
 |
|
 |
I downloaded it last night and could have sworn there was no .cpp file for derivedwindow. Its not in my project, so maybe the conversion to vc7 didn't pull it over.
In any case, just get rid of one of the bodies. Sorry, I'll fix it.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
|
|
|
|
 |