TopMost without SetFocus

G

Guest

How do I load a form as the top most form without setting focus to it?
I am using vb.net 2005
Using topmost it take the focus away from the application I am typing into
then when it closes it send the focus back.
 
A

AMDRIT

The only way I know to do that is through unmanaged code, api calls.


before opening your form, get the active window

Public Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow"
() As Long

open your window
frm.show()

and set it to the top most form
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long

Set the previous active window back to active
Public Declare Function SetActiveWindow Lib "user32" Alias "SetActiveWindow"
(ByVal hwnd As Long) As Long
 
A

Armin Zingler

AMDRIT said:
The only way I know to do that is through unmanaged code, api
calls.


before opening your form, get the active window

Public Declare Function GetActiveWindow Lib "user32" Alias
"GetActiveWindow" () As Long

open your window
frm.show()

and set it to the top most form
Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam
As Long, lParam As Any) As Long

Set the previous active window back to active
Public Declare Function SetActiveWindow Lib "user32" Alias
"SetActiveWindow" (ByVal hwnd As Long) As Long


These are declartions for VB6, not for VB.Net


Armin
 
G

Guest

Is there any way I can call the form from vb.net 2005?
vb6 requires handle call, how is done in 2005?

Is there any way I can bring the form up then Push it to the top without
focus?

Thanks,
ATracy
 
A

AMDRIT

Yes I know this, stated as much in my opening sentance. In order to make
them useful, you would have to perform a dll import.

I didn't provide any code, since I was still working on my solution. but is
some additional reading.

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconcreatingprototypesinmanagedcode.htm

Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential)> _
Public Structure RECT
Dim left As Integer
Dim top As Integer
Dim right As Integer
Dim bottom As Integer
End Structure

Public Class User32
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function MessageBox(ByVal hWnd As Integer, ByVal txt As
String, ByVal caption As String, ByVal Typ As Integer) As Integer
End Function

<DllImport("user32", CharSet:=CharSet.Auto)> _
Public Shared Function GetActiveWindow() As Integer
End Function

<DllImport("user32", CharSet:=CharSet.Auto)> _
Public Shared Function SendMessage(ByVal hwnd As Integer, ByVal wMsg As
Integer, ByVal wParam As Integer, ByRef lParam As RECT) As Integer
End Function

<DllImport("user32", CharSet:=CharSet.Auto)> _
Public Shared Function SendMessage(ByVal hwnd As Integer, ByVal wMsg As
Integer, ByVal wParam As Integer, ByRef lParam As Integer) As Integer
End Function

<DllImport("user32", CharSet:=CharSet.Auto)> _
Public Shared Function SetActiveWindow(ByVal hwnd As Integer) As Integer
End Function
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top