Maximizing previous instance of my app
Maximizing previous instance of my app
Maximizing previous instance of my app
Maximizing previous instance of my app
Maximizing previous instance of my app
Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app
Maximizing previous instance of my app Maximizing previous instance of my app
Maximizing previous instance of my app
Go Back  Xtreme Visual Basic Talk > > > Maximizing previous instance of my app


Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2003, 01:22 AM
BostjanK's Avatar
BostjanK BostjanK is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Ljubljana, Slovenia
Posts: 324
Default Maximizing previous instance of my app


Hi!

How can I maximize the previous instance of my app if the user starts new instance.
I check if a previous instance is running by App.PrevInstance, but I don't know how to maximize it.

Thanks for your help.

Bostjan
__________________
Slovenia - the green treasure of Europe
Reply With Quote
  #2  
Old 08-18-2003, 02:22 AM
Jigment Jigment is offline
Regular
 
Join Date: Jan 2003
Location: England
Posts: 88
Default

Public Const WM_CLOSE = &H10
Public Const SW_HIDE = 0
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6


hwnd = FindWindow(vbNullString, "My App")
Call SetActiveWindow(hwnd)
Call SendMessageLong(hwnd, SW_MAXIMIZE , 0&,0&)

Maybe along those lines?

Last edited by Jigment; 08-18-2003 at 02:29 AM.
Reply With Quote
  #3  
Old 08-18-2003, 03:13 AM
BostjanK's Avatar
BostjanK BostjanK is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Ljubljana, Slovenia
Posts: 324
Default

It doesn't work - I hvae checked the handle and it is correct, but nothing happens afterwards.
__________________
Slovenia - the green treasure of Europe
Reply With Quote
  #4  
Old 08-18-2003, 04:48 AM
DeX's Avatar
DeXMaximizing previous instance of my app DeX is offline
Senior Contributor

* Expert *
 
Join Date: Aug 2003
Location: Berkhamsted, England
Posts: 940
Default

Try this:

Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long Private Const WM_CLOSE = &H10 Private Const SW_HIDE = 0 Private Const SW_MAXIMIZE = 3 Private Const SW_MINIMIZE = 6 Private Const SW_RESTORE = 9 Private Const SW_SHOW = 5 Private Const SW_SHOWDEFAULT = 10 Private Const SW_SHOWMAXIMIZED = 3 Private Const SW_SHOWMINIMIZED = 2 Private Const SW_SHOWMINNOACTIVE = 7 Private Const SW_SHOWNA = 8 Private Const SW_SHOWNOACTIVATE = 4 Private Const SW_SHOWNORMAL = 1 Private Sub Command1_Click() Dim hWnd As Long hWnd = FindWindow(vbNullString, "My App") ShowWindow hWnd, SW_MAXIMIZE End Sub

The problem is if you are using this code to maximize another instance of your program then it won't work as it is because FindWindow will allways return the current window's hWnd (provided the captions match). If you use this code in the Form_Load even then you simply have to change the application's caption before calling FindWindow. If you close the program before Form_Load has completed this won't matter because the form will never show.
Reply With Quote
  #5  
Old 08-18-2003, 04:58 AM
BostjanK's Avatar
BostjanK BostjanK is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Ljubljana, Slovenia
Posts: 324
Default

I'm not calling these procedures from a form, but from Sub Main.
It doesn't work though - even if I change the caption of the main window.
__________________
Slovenia - the green treasure of Europe
Reply With Quote
  #6  
Old 08-18-2003, 05:18 AM
DeX's Avatar
DeXMaximizing previous instance of my app DeX is offline
Senior Contributor

* Expert *
 
Join Date: Aug 2003
Location: Berkhamsted, England
Posts: 940
Default

Ok in Sub Main() the form has not yet been created so FindWindow returns the hWnd of the previous instance. I also found that the code posted above didn't work in Sub Main() for some reason - all it did was maximize the previous instance and not bring it to the front. Try adding AppActivate "My App" before running the ShowWindow API. For example here's what my Sub Main() looks like:

Code:
Sub Main() Dim hWnd As Long If App.PrevInstance Then hWnd = FindWindow(vbNullString, "My App") AppActivate "My App" ShowWindow hWnd, SW_MAXIMIZE Else Form1.Show End If End Sub
Reply With Quote
  #7  
Old 08-18-2003, 05:44 AM
BostjanK's Avatar
BostjanK BostjanK is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Ljubljana, Slovenia
Posts: 324
Default

It works now - thanks.
__________________
Slovenia - the green treasure of Europe
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to restore previous instance of App? goodmorningsky General 3 08-10-2003 11:01 AM
Previous and current version instance check? bkbig General 3 02-15-2003 10:46 AM
How to detect previous instance of a dll in VB??? npolo API 0 01-23-2003 10:56 AM
Can not always detect Previous Instance Neptune General 4 04-12-2001 08:37 AM
activating previous instance of a form Nominex General 1 02-11-2001 08:11 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Maximizing previous instance of my app
Maximizing previous instance of my app
Maximizing previous instance of my app Maximizing previous instance of my app
Maximizing previous instance of my app
Maximizing previous instance of my app
Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app Maximizing previous instance of my app
Maximizing previous instance of my app
Maximizing previous instance of my app
 
Maximizing previous instance of my app
Maximizing previous instance of my app
 
-->