Article View: comp.windows.ms.programmer
Article #234Declaring instance-specific variables (Summary)
From: Santanu Lahiri
Date: Wed, 08 Apr 1992 19:48
Date: Wed, 08 Apr 1992 19:48
60 lines
3297 bytes
3297 bytes
A couple of days ago I posted an item asking for help on creating instance specific data for a window. I am summarizing the responses I have received so far: -------------------------------------------------------------------- neil@bedford.pro suggested the following: >I think that there are two approaches. > >The first is to disable the menu item which allows the user to pull up another >box when one is already up (& enable it when the box goes away). > >The other is that the WM_INITDIALOG message can give you an instance pointer >which you can use to separate the incarnations. Later he elaborated on another method: >Set/Get WindowLong is perfect for storing a pointer to instance data. >I don't think it will work for dialog boxes, however. I think db are a >different beast. ------------------------------------------------------------------------- sybase!juan@Sun.COM suggested the following: >You can place any instance specific data in the Window extra bytes of your >main application window. You can allocate the necessary memory and place >either a HANDLE or a pointer in the window extra bytes. If you place a >handle, you must use GetWindowWord()/SetWindowWord(). If you use a pointer >you need to use GetWindowLong()/SetWindowLong() to retrieve the pointer. >You must also remember to tell windows that you need this extra data bytes. ------------------------------------------------------------------------- There was also a post by Peter Haller indicating a similar approach. ========================================================================= I finally did solve the problem, and I used the approach outlined by Juan. Neil's initial suggestion of graying the appropriate menu item will also work as it prevents a second instance from being created. However, since I wanted to allow multiple instances, that approach did not apply. The [Set/Get]WindowWord approach required my setting the cbWndExtra field to a non-zero number when registering the window class. During the WM_CREATE message, I create the necessary child windows and store the handles in this extra space using SetWindowWord(). When my window procedure receives a WM_COMMAND message, I simply retrieve the child window handles. Of course, as this was supposed to be a Directory Search function, I have to store the current drive and directory as well. But this can be (and was) achieved using a similar approach. The code worked for upto five windows, at which point I got sick of testing it. Thanks to all those who replied to my post. Santanu -- Santanu ------------------------------------------------------------------------------- :: cat flames > /nev/dull slahiri@magnus.acs.ohio-state.edu
Technical Details
Message-ID:
<1992Apr8.194852.28217@magnus.acs.ohio-state.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!slahiriShow Full Headers
Complete Article Headers
Newsgroups: comp.windows.ms.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!slahiri From: slahiri@magnus.acs.ohio-state.edu (Santanu Lahiri) Subject: Declaring instance-specific variables (Summary) Message-ID: <1992Apr8.194852.28217@magnus.acs.ohio-state.edu> Sender: news@magnus.acs.ohio-state.edu Nntp-Posting-Host: top.magnus.acs.ohio-state.edu Organization: The Ohio State University Distribution: usa Date: Wed, 8 Apr 1992 19:48:52 GMT Lines: 60