473,586 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to: Maximize window from the Main function?

MJB
In the main function of my form I check to see if the application is already
running. If it is, I throw up a message box telling the user. What I would
like to do is also maximize the application, but I am unable to do so. Does
anyone have any experience with this.

TIA,
Matt
Jul 21 '05 #1
10 9730
joe
This won't set the window to maximized, but it has
basically the same affect. I think there is
Dim ScrnRec As Rectangle
ScrnRec = Screen.PrimaryS creen.Bounds()

Me.Top = ScrnRec.Top
Me.Left = ScrnRec.Left
Me.Width = ScrnRec.Width
Me.Height = ScrnRec.Height
You could also try...

Me.WindowState= FormWindowState .Maximized
-----Original Message-----
In the main function of my form I check to see if the application is alreadyrunning. If it is, I throw up a message box telling the user. What I wouldlike to do is also maximize the application, but I am unable to do so. Doesanyone have any experience with this.

TIA,
Matt
.

Jul 21 '05 #2
try this:
this.WindowStat e = FormWindowState .Maximiz
but you cant do it from Main - use the constructor or or the OnLoad event or
whatever
"MJB" <mb*@email.co m> wrote in message
news:OR******** ******@TK2MSFTN GP10.phx.gbl...
In the main function of my form I check to see if the application is already running. If it is, I throw up a message box telling the user. What I would like to do is also maximize the application, but I am unable to do so. Does anyone have any experience with this.

TIA,
Matt

Jul 21 '05 #3
Hi,

I assume that you will kill the second instance and activate the first one,
if so all you have to do is call SetActiveWindow API:

[DllImport("user 32.dll")]
IntPtr SetActiveWindow ( IntPtr hWnd);

This will do the trick.

You need the hWnd of the first app, if you need code to get it let me know.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"MJB" <mb*@email.co m> wrote in message
news:OR******** ******@TK2MSFTN GP10.phx.gbl...
In the main function of my form I check to see if the application is already running. If it is, I throw up a message box telling the user. What I would like to do is also maximize the application, but I am unable to do so. Does anyone have any experience with this.

TIA,
Matt

Jul 21 '05 #4
Hello,

"Ignacio Machin" <ignacio.mach in AT dot.state.fl.us > schrieb:
I assume that you will kill the second instance and activate the first one, if so all you have to do is call SetActiveWindow API:


You will have to attach the window to the thread's message queue
('AttachThreadI nput'):

<msdn>
The window must be attached to the calling thread's message queue.
</msdn>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Jul 21 '05 #5
Hi Matt,

Have my application class. :-)

You can call it from Sub Main, Sub MainForm_Load or sometime later.

Regards,
Fergus

<code>
Imports System.Diagnost ics.Process

Public Class clsApp

'============== =============== =============== =============== ========
Public Shared Function tThereIsAnInsta nceOfThisProgra mAlreadyRunning _
(Optional tToActivateTheP revInstance As Boolean = False, _
Optional ProgramTitle As String = "?") As Boolean
Dim sProcessName As String
Dim aoProcList() As System.Diagnost ics.Process

sProcessName = GetCurrentProce ss.ProcessName
aoProcList = GetProcessesByN ame (sProcessName) 'At least 1.

If aoProcList.Leng th = 1 Then
'There's just me.
Return False
End If

If tToActivateTheP revInstance Then
ActivateMyBette rHalf (ProgramTitle)
End If

'Another me beat me to it.
Return True
End Function

'============== =============== =============== =============== ========
Public Shared Sub ActivateMyBette rHalf _
(Optional ProgramTitle As String = "?", _
Optional tToCallAppExit As Boolean = False)
Dim MainForm As Form = Nothing

If ProgramTitle = "?" Then
MainForm = Form.ActiveForm 'Assumes that it's the main Form.
If MainForm Is Nothing Then
Throw New Exception ("No ProgramTitle and no Main Form??")
End If
ProgramTitle = MainForm.Text
MainForm.Text = "About to die" 'So AppActivate avoids self.
End If

MsgBox ("This is " & ProgramTitle & "(2) saying ""Bye, bye"" :-(")
AppActivate (ProgramTitle)

If MainForm Is Nothing = False Then
MainForm.Close
End If

If tToCallAppExit Then
Application.Exi t
End If

'Or leave it to the caller to close down further as necessary.
End Sub

End Class

'============== =============== =============== =============== ========
Public Module MainMod
Public Sub Main
MsgBox ("Point 1")
If clsApp.tThereIs AnInstanceOfThi sProgramAlready Running (True,
"Form1") Then
Return
End If

MsgBox ("Point 2")
If clsApp.tThereIs AnInstanceOfThi sProgramAlready Running Then
clsApp.Activate MyBetterHalf ("Form1")
Return
End If

Dim F As New Form1
F.Show
Application.Run ()
End Sub
End Module

'============== =============== =============== =============== ========
Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load

MsgBox ("Point 3")
If clsApp.tThereIs AnInstanceOfThi sProgramAlready Running Then
'Form.ActiveFor m is not yet valid. So give the name.
clsApp.Activate MyBetterHalf (Me.Text)
Me.Close
Return
End If
End Sub

'============== =============== =============== =============== ========
Private Sub btnTest_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles btnTest.Click
MsgBox ("Point 4")
If clsApp.tThereIs AnInstanceOfThi sProgramAlready Running Then
clsApp.Activate MyBetterHalf (,True)
End If
End Sub
</code>
Jul 21 '05 #6
Hello,

"Fergus Cooney" <fi******@tesco .net> schrieb:
aoProcList = GetProcessesByN ame (sProcessName) 'At least 1.


Notice that _different_ applications can have the same name. I would use a
'Mutex' for detecting other instances of the application:

http://groups.google.de/groups?selm=...TNGP09.phx.gbl

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Jul 21 '05 #7
Hi Herfried,

Mutex looks good. Simple too. :-)

Now, how do you activate the other instance? Is it possible to associate a
value with a mutex?

Regards,
Fergus
Jul 21 '05 #8
Hello,

"Fergus Cooney" <fi******@tesco .net> schrieb:
Mutex looks good. Simple too. :-)

Now, how do you activate the other instance? Is it possible
to associate a value with a mutex?


I think that's not easy. You can use 'AppActivate' with the other
instance's process ID (see documentation for 'AppActivate'). I recently
posted a 'PrevInstance' function which returned the 'Process' object for the
other instance by looping through the process list and comparing process
name and file name.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Jul 21 '05 #9
Hi,

A mutex is a good idea, now the tricky part is set the focus to that other
process , I proposed using SetActiveWindow API call but as you mentioned you
need to be attached to the calling thread's message queue.

I'm using SetForegroundWi ndow to do this in a pocketPC application and it
works great:
[DllImport("user 32dll",EntryPoi nt="SetForegrou ndWindow")]

public static extern bool SetForegroundWi ndow(IntPtr hWnd);
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in message
news:ul******** ******@TK2MSFTN GP12.phx.gbl...
Hello,

"Fergus Cooney" <fi******@tesco .net> schrieb:
aoProcList = GetProcessesByN ame (sProcessName) 'At least 1.
Notice that _different_ applications can have the same name. I would use

a 'Mutex' for detecting other instances of the application:

http://groups.google.de/groups?selm=...TNGP09.phx.gbl
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
10902
by: Sanjay Seshasainam | last post by:
How can I maximize a process window I am using the Process class in System.Diagnostics. I can identify the specific process I want using the window title after that I want to maximize the window. I can get the handle for the window using MainWindowHandle how do I maximize the window ? Thanks, Sanjay
0
834
by: Laura Zeafla via .NET 247 | last post by:
I used the .NET forms application wizard. From the form youclick a button and it calls a C++ function through its dll. This function is supposed to pop-up a command prompt window. Something about using this forms application wizard prevents thewindow from opening. The program otherwise runs correctly. Inoticed that the wizard gave me a main...
8
8892
by: jrefactors | last post by:
I want to maximize the browser window when I open a new window. Now I do the following, but different monitor size will yield different width and height values. window.open('index.jsp',myform.target,'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,width=800,height=600'); Any ideas? please help. thanks!!
7
5446
by: Colleyville Alan | last post by:
I have an app that uses Access to grab various PowerPoint slides using the followhyperlink command. I have set the PPT window to run in a minimized state: FollowHyperlink link Set oPres = oPPT.ActivePresentation oPPT.WindowState = ppWindowMinimized Then I do the copy and paste part: With oPres
1
2636
by: Brandon | last post by:
Hello there. I'm currently working on a moderately complex Visual C# windows application that I have run into a bit of a problem on. To start things off, the application has normally been run under Windows XP with the theme mode set to Windows Classic (disabling the newer XP theme) at a resolution of 1280 x 1024 on a dual monitor system. ...
10
339
by: MJB | last post by:
In the main function of my form I check to see if the application is already running. If it is, I throw up a message box telling the user. What I would like to do is also maximize the application, but I am unable to do so. Does anyone have any experience with this. TIA, Matt
2
2806
by: jj | last post by:
I have a single threaded application in c# that scans through a file system. While doing this if I try to minimize, maximize buttons on the top,right hand corner of my form do not do as they are supposed to do. To maximize the window I have to go to "task manager" and double click the application. How do I control those maximize, minimize...
5
3194
by: Mrozu | last post by:
Hi When I maximize a form in VB.Net 2003 the bottom of the form gets hidden by the start bar (so my status bar is invisible). How can I get my app to maximize to the usable screen area above the start bar? Thx Mrozu
2
2025
by: mac | last post by:
Hi! Is there anyone knows on how to maximze the Web form during run time? please help me to the code of what im going to do with this. Thanks and Best Regards
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.