🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.os2.programmer.misc
2 messages
2 total messages Started by Keith Bennett Fri, 01 Mar 1996 00:00
PM Programming Question; pls help
#170
Author: Keith Bennett
Date: Fri, 01 Mar 1996 00:00
60 lines
2984 bytes
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.

The WM_CLOSE section looked something like this:

// *******************************************************************
case WM_CLOSE:
// *******************************************************************
{
	cout << "Got CLOSE msg." << endl;
	mr = WinDefWindowProc (hwnd, msg, mp1, mp2);
	break;
}

When I commented out the WinDefWindowProc(), none of the windows
closed.

Is there something I look for in the way the windows are being
created that would explain why the main window closes when my message
box window closes?

I am very inexperienced with PM programming, so feel free to state the 
obvious; it may not be obvious to me.

The posting of the WM_CLOSE message is happening from a separate
thread from the thread where the window was created.

------------------------------------------------------------------------

Is it true that I must call WinDestroyWindow() to free the memory PM
allocates for the 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.

Any suggestions?

Thanks....
- Keith

-- 
--------------------------------------------------------------------------
Keith Bennett                             Bennett Business Solutions, Inc.
Silver Spring, MD USA                     OS/2 & DOS Software Development
kbennett@cpcug.org                        (301) 871-7696
Re: PM Programming Question; pls help
#169
Author: wilan01
Date: Mon, 04 Mar 1996 00:00
67 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads