CloseWindow API function in DLL_USER (None Specified)
At 04 MAY 1998 02:55:52PM David Pociu wrote:
As part of my application, I need to be able to close the "main" OI window (RTI_OINSIGHT).
I looked at the Windows API and found the CloseWindow function that is prototyped as follows:
Declare Function CloseWindow Lib "user32" Alias "CloseWindow" (ByVal hwnd As Long) As Long
I therefore proceeded to add the following entry to SYSPROCS*DLL_USER:
LONG PASCAL CloseWindow(LONG) as MyCloseWindow
I then ran RUN DECLARE_FCNS "DLL_USER" from the System Editor's command line.
So far so good. However, after I get the handle for "RTI_OINSIGHT" and pass it to the MyCloseWindow function in my code, nothing happens.
This is the code I'm using:
hWnd1%=FindWindow("RTI_OINSIGHT":\00\, "")
rv=MyCloseWindow(hWnd1%)
I'm not sure if the contents of the hWnd1% variable need to be "massaged" before being passed on to MyCloseWindow, or if I actually missed something in the process I described.
Thanks in advance for the help.
At 04 MAY 1998 05:36PM Donald Bakke wrote:
Dave,
This may be irrelevant but why do you need to close RTI_OINSIGHT? I'm guessing this is to shut down your application completely but this occurs when you exit your last application window, unless this isn't a runtime application.
Anyway, I've never used the CloseWindow function probably because I try to avoid User32 functions for those installs that still run on Win 3.x. At one time however I did attempt to use the WM_CLOSE SendMessage command on RTI_OINSIGHT and it wouldn't respond (although it worked against non-RTI applications).
I believe PS prevented these types of shut downs because of other complications, but I'm just speculating here. Perhaps there is a better way to accomplish your goal.
At 04 MAY 1998 09:24PM David Pociu wrote:
Hi Don,
In my application (which runs in multi-useer development mode) I have a main window (not MDI) from which other windows are started.
Now I want those windows to register in the Win95 taskbar. For that purpose I start them with a '' parent instead of having the main window as a parent.
I'm looking for an easy way to shut down OI when the main (first) window is closed. As you can imagine, because the subsequent windows are not children of the main window, they do not get shut down if the main window does. Now I know that I can register my "child" windows in some hidden list and close them one by one from there when the main window get closed, but why do that if I can just close the main OI window and everything else gets closed at that time? (It works great if I close it manually)
Lazy, I guess, but hey, if I can get away with that…. ;)
So does anyone know the answer to how to close the main OI window programatically?
Thanks
At 05 MAY 1998 07:49AM Cameron Purdy wrote:
Dave,
Try USER (not USER32) and try a USHORT instead of a LONG.
Cameron Purdy
Revelation Software
At 05 MAY 1998 09:09AM David Pociu wrote:
The main window still does not close. Here is what I'm using:
1) The contents of DLL_USER:
USER
VOID PASCAL MessageBeep(SHORT)
SHORT PASCAL MessageBox(SHORT,LPCHAR,LPCHAR,SHORT)
USHORT PASCAL IsWindow(USHORT)
VOID PASCAL BringWindowToTop(USHORT)
USHORT PASCAL ShowWindow(USHORT,SHORT)
LONG PASCAL SendMessage(USHORT,USHORT,USHORT,LONG)
LONG PASCAL PostMessage(USHORT,USHORT,USHORT,LONG)
SHORT PASCAL FindWindow (LPCHAR, LONG)
USHORT PASCAL GetWindow (USHORT, USHORT)
USHORT PASCAL ArrangeIconicWindows(USHORT)
USHORT PASCAL GetSystemMetrics(USHORT)
LONG PASCAL GetSysColor(USHORT)
USHORT PASCAL GetFocus(VOID)
USHORT PASCAL SetFocus(USHORT)
SHORT PASCAL GetSystemMenu(SHORT, SHORT)
SHORT PASCAL GetMenu(SHORT)
VOID PASCAL GetCursorPos(LPCHAR)
USHORT PASCAL GetAsyncKeyState(SHORT)
LONG PASCAL GetTickCount(VOID)
USHORT PASCAL GetFreeSystemResources(USHORT)
SHORT PASCAL FindWindow(LPVOID, LPCHAR ) As FindWindowByTitle
USHORT PASCAL CloseWindow(USHORT) as MyCloseWindow
2) I run: RUN DECLARE_FCNS "DLL_USER" in System Editor and it processes fine.
3) On the CLOSE event of newly created test form I have the following code:
declare function FindWindow, MyCloseWindow
call forward_event(CancelFlag)
hWnd1%=FindWindow("RTI_OINSIGHT":\00\, "")
ret=MyCloseWindow(hWnd1%)
RETURN 0
4) I tried this code with forward_event and without it. Still nothing. The hWnd1% variable gets filled in with a valid integer. The ret variable returns a 1 under Win95 and 0 under WinNT Server 4.0.
Any more ideas?
Thanks
At 05 MAY 1998 09:23AM Aaron Kaplan wrote:
Utility( 'DESTROY','SYSTEM')
At 05 MAY 1998 09:30AM Donald Bakke wrote:
Dave,
So does anyone know the answer to how to close the main OI window programatically?
I don't so I can't help you here. So I have to give an alternate solution.
I'm looking for an easy way to shut down OI when the main (first) window is closed. As you can imagine, because the subsequent windows are not children of the main window, they do not get shut down if the main window does. Now I know that I can register my "child" windows in some hidden list and close them one by one from there when the main window get closed, but why do that if I can just close the main OI window and everything else gets closed at that time? (It works great if I close it manually) Lazy, I guess, but hey, if I can get away with that…. ;)
I have three applications that work exactly the way yours does and I wanted to make sure that if the main window was closed that all other OI windows would be closed as well. The following code is from the CLOSE event of one of those main windows (TW_MAIN) and may help you in case you decide to stop being lazy .
<code> rv=No$ ; preset the Return variable to 0 Window_list=Utility("OBJECTLIST", Null$, "WINDOW") Object_count=Count(Window_list, @FM) + (Window_list NE Null$) Display_caution=No$ ebb=Yes$ For Loop=1 to Object_count Window=Window_list If Window NE "TW_MAIN" then Display_caution=Yes$ ; * more than just TW_MAIN is running Next Loop If Display_caution EQ Yes$ then Msg_struct=Null$ Msg_struct =Caution: Exiting will close all":CRLF$:"Bug Base windows":CRLF$:CRLF$:"Are you sure you want to exit?" Msg_struct =BNY" Msg_struct =A" Msg_struct =?" Msg_struct =No$ Msg_struct =-2 Msg_struct =C" Msg_struct=300 Msg_struct =Exit Bug Base" ebb=Msg(@Window, Msg_struct) end If ebb EQ Yes$ then For Loop=1 to Object_count Window=Window_list If Window NE "TW_MAIN" then Record=Get_Property(Window, "RECORD") If Record GT Null$ then response1=Send_Event(Window, "WRITE") response2=End_Window(Window) end Next Loop rv=1 end Return rv</code>
At 05 MAY 1998 09:47AM David Pociu wrote:
I ended up using the most simple of the solutions: Utility( "DESTROY" , "SYSTEM").
Thanks Aaron, Cam, and Don for all your help (I knew I could count on you guys!).
I am still curious though why the CloseWindow function did not work. Just in case I'll need it some other time…
At 05 MAY 1998 03:56PM Donald Bakke wrote:
Dave,
I ended up using the most simple of the solutions: Utility( "DESTROY" , "SYSTEM").
Please keep me informed whether this works well or not. Several OI versions ago I tried using this but it seemed to not unload certain DLL's and it was impossible to restart OI without rebooting. I'm wondering if this has been resolved.
Thanks,
At 05 MAY 1998 10:34PM David Pociu wrote:
Don,
It works like a charm. No problems re-loading OI afterwards.