473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 9709
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.PrimaryScreen.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.WindowState = FormWindowState.Maximiz
but you cant do it from Main - use the constructor or or the OnLoad event or
whatever
"MJB" <mb*@email.com> wrote in message
news:OR**************@TK2MSFTNGP10.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("user32.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.com> wrote in message
news:OR**************@TK2MSFTNGP10.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.machin 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
('AttachThreadInput'):

<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.Diagnostics.Process

Public Class clsApp

'================================================= ==================
Public Shared Function tThereIsAnInstanceOfThisProgramAlreadyRunning _
(Optional tToActivateThePrevInstance As Boolean = False, _
Optional ProgramTitle As String = "?") As Boolean
Dim sProcessName As String
Dim aoProcList() As System.Diagnostics.Process

sProcessName = GetCurrentProcess.ProcessName
aoProcList = GetProcessesByName (sProcessName) 'At least 1.

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

If tToActivateThePrevInstance Then
ActivateMyBetterHalf (ProgramTitle)
End If

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

'================================================= ==================
Public Shared Sub ActivateMyBetterHalf _
(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.Exit
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.tThereIsAnInstanceOfThisProgramAlreadyRunni ng (True,
"Form1") Then
Return
End If

MsgBox ("Point 2")
If clsApp.tThereIsAnInstanceOfThisProgramAlreadyRunni ng Then
clsApp.ActivateMyBetterHalf ("Form1")
Return
End If

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

'================================================= ==================
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

MsgBox ("Point 3")
If clsApp.tThereIsAnInstanceOfThisProgramAlreadyRunni ng Then
'Form.ActiveForm is not yet valid. So give the name.
clsApp.ActivateMyBetterHalf (Me.Text)
Me.Close
Return
End If
End Sub

'================================================= ==================
Private Sub btnTest_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnTest.Click
MsgBox ("Point 4")
If clsApp.tThereIsAnInstanceOfThisProgramAlreadyRunni ng Then
clsApp.ActivateMyBetterHalf (,True)
End If
End Sub
</code>
Jul 21 '05 #6
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
aoProcList = GetProcessesByName (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 SetForegroundWindow to do this in a pocketPC application and it
works great:
[DllImport("user32dll",EntryPoint="SetForegroundWin dow")]

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

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

"Fergus Cooney" <fi******@tesco.net> schrieb:
aoProcList = GetProcessesByName (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
Hello,

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> schrieb:
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.


You'll find an implementation in VB6 written by Karl E. Peterson here:

http://www.mvps.org/vb/code/ForceFore.zip

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

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

Similar topics

1
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...
0
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...
8
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. ...
7
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 =...
1
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...
10
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...
2
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...
5
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...
2
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.