Article View: comp.os.os2.programmer.misc
Article #169Re: PM Programming Question; pls help
From: wilan01
Date: Mon, 04 Mar 1996 00:00
Date: Mon, 04 Mar 1996 00:00
67 lines
3795 bytes
3795 bytes
In <4h7v58$3cu@cpcug.org>, kbennett@cpcug.org (Keith Bennett) writes: >I have an object that creates a window, draws text in it, and puts a >button window in it. I want to be able to remove it either by the >user pressing the button, or by deleting the object. My destructor >calls a member function Close(). I've tried several approaches in >Close(), but none seem to take care of all my needs. > >The most obvious approach (to me) was to send this window a WM_CLOSE >message. When I created it, I used WinCreateStdWindow, and got a >hwndFrame and hwndClient. When I send the WM_CLOSE to the client, it >closes the window, but closes the application's window too. This is >not what I want. Two different people have advised me to check that >I'm not sending the WM_CLOSE to the app's main window, but I checked >by printing out handles and I'm not. I also checked by putting a >cout<< in the WM_CLOSE section of my window's procedure. [snip] >When I commented out the WinDefWindowProc(), none of the windows >closed. Passing WM_CLOSE to WinDefWindowProc causes a WM_QUIT message to be sent to the message queue on which the window was created. This causes your application to terminate, which is not what you want. So, instead of passing the message on, just call WinDestroyWindow in your WM_CLOSE processing. Think of it like this - WM_CLOSE means "The user has asked for this window to be closed, (by selecting the close item on the sysmenu)". The default processing is to close the application, since this is what you want in a simple 1 window application. In you case, where you have multiple windows, you have to intercept the WM_CLOSE, and process it yourself by destroying just one window. >------------------------------------------------------------------------ > >Is it true that I must call WinDestroyWindow() to free the memory PM >allocates for the window? You should call WinDestroy Window when you've finished with the window, obviously enough. This will free any storage allocated by PM for that window. > >Right now, I'm managing to close just the message box window by >sending a click message to its OK button. My concern is that this >will not free the memory for that window. A Windows programmer >friend told me that I need to free (destroy) the window explicitly or >the memory will never be deallocated. > It's a mystery to me how clicking a button will cause a StdWindow to be destroyed. What are you doing in response to the WM_COMMAND message? Are you passing it to WinDefDlgProc? Your Windows programmer friend's advice is good (and 16-bit Windows does have this problem), but PM will reclaim resources that are unfreed when a process ends. However good citizens dispose of their own rubbish, even though there are street cleaners. The simple rule is, if you want to close a window, call WinDestroyWindow. Since you seem to be writing in C++, put the call in the destructor, and destroy the C++ object. >Thanks.... >- Keith > >-- Cheers _____________________________________________________________________ Andy Wilkins wilan01@ingres.com UK Desktop Development Computer Associates
Technical Details
Message-ID:
<4hefps$oo9@zebedee.ingres.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<4h7v58$3cu@cpcug.org>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cd94,32221af43e415bbf X-Google-Attributes: gid10cd94,public X-Google-Thread: 11307a,32221af43e415bbf X-Google-Attributes: gid11307a,public From: wilan01@ingres.com@ Subject: Re: PM Programming Question; pls help Date: 1996/03/04 Message-ID: <4hefps$oo9@zebedee.ingres.co.uk> X-Deja-AN: 141981183 references: <4h7v58$3cu@cpcug.org> organization: Computer Associates reply-to: wilan01@ingres.com newsgroups: comp.os.os2.programmer.misc,bit.listserv.os2-l