How manage instances of image viewer (None Specified)
At 08 APR 1999 11:58:55AM Oystein Reigem wrote:
I have this app that needs to show images. Each row in the main database table can have one or more images - typically one, sometimes two, but seldom more than three. The images are stored externally in normal image files and not as BLOBs. I use an image viewer to show the images. The user will normally want to see all the images for the current row, but not images for other rows.
Until now I've used an image viewer with an MDI interface. There was never more than one instance of the image viewer running. But for various reasons I've decided to switch to a different image viewer. The one I've chosen isn't MDI, so there will often be more than one instance running.
So now I wonder how to handle all the instances. When the user switches from one row to a different one, I could of course use the following crude method: Use Windows' FindWindow function to find each open instance in turn, and close them, and afterwards start a new instance for each image of the new row. But there is overhead involved with closing and opening the viewer program. As I said most rows will have just one image, and since the viewer can be used as a DDE server (I can use DDE to ask the latest instance of the viewer to show a new image), it seems such a waste to close and open all the time.
So what I'd like to do is to (1) find out how many instances of the viewer are open, (2) close all but one, (3) tell the remaining instance to show the first image of the new row, and (4) start a new instance for each of the remaining images of the new row.
Anybody out there who knows what I need to do? Which Windows functions? Can I e.g use GetTopWindow and GetNextWindow to run through all windows to find out how many viewer instances there are, and their handles? Please supply prototype records with your suggested Windows functions…
![]()
- Oystein -
At 09 APR 1999 11:29AM Oystein 2 wrote:
Oystein,
Anybody out there who knows what I need to do?
Sure!
Which Windows functions? Can I e.g use GetTopWindow and GetNextWindow to run through all windows to find out how many viewer instances there are, and their handles?
You can forget about function GetTopWindow because that is for child windows. (You don't know much, do you?)
Windows has a window manager which keeps a list of all windows running. Use function GetNextWindow to walk along that list and check each window to see if it's an instance of your viewer.
Use function FindWindow to find a place to start. It doesn't matter which window you start with. E.g start with your viewer. FindWindow will find one instance for you. Or you can start with OpenEngine (class name "Arev"). No, rather start with the viewer, because if FindWindow doesn't find an instance you know you're finished already.
GetNextWindow only gets you a window handle. To check if the current handle in the window manager's list belongs to an instance of your viewer, you must get the class name of the handle. You can do that with function GetClassName.
Please supply prototype records with your suggested Windows functions…
No sweat! All the aforementioned functions are in the USER dll, so open row DLL_USER in SYSPROCS and add the following lines ("prototypes"):
USHORT PASCAL GetNextWindow (USHORT, USHORT)
USHORT PASCAL GetClassName (USHORT, LPCHAR, USHORT)
You'll find the prototype for FindWindow is there already:
SHORT PASCAL FindWindow (LPCHAR, LONG)
Save and remember to run run Declare_FCNS "DLL_USER" from the Exec line.
So what I'd like to do is to (1) find out how many instances of the viewer are open,
…which you will be able to do now…
(2) close all but one,…
Just in case you don't know how to close a window when you know its handle:
equ WM_CLOSE$ to 16 /* \0010\ */
…
Void=SendMessage( WindowHandle, WM_CLOSE$, true$, 0 )
- Oystein 2 -
At 09 APR 1999 01:44PM Oystein Reigem wrote:
Oystein 2,
Thanks a lot!!
- Oystein -