473,385 Members | 1,342 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,385 software developers and data experts.

TopMost without SetFocus

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.
Jan 24 '06 #1
4 9411
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


"ATracy" <AT****@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
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.

Jan 24 '06 #2
"AMDRIT" <am****@hotmail.com> schrieb
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
Jan 24 '06 #3
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

"Armin Zingler" wrote:
"AMDRIT" <am****@hotmail.com> schrieb
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

Jan 24 '06 #4
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
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"AMDRIT" <am****@hotmail.com> schrieb
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

Jan 24 '06 #5

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

Similar topics

4
by: Michael Fay | last post by:
There have been threads in this newsgroup explaining how to tab out of a subform to the parent form -- without having to use ctrl-tab (of which users might be unaware -- and at any rate, they...
2
by: Robert Misiak | last post by:
Is it possible to display a window on top without it stealing focus? (and I'm not talking about stealing focus from my application - I'm talking about it stealing focus from any application.) ...
3
by: Hovhannes Asatryan | last post by:
Hello guys. I have a problem with a topmost form. I am writting in C#. I have Mdi Form wich has 2 child forms. I want to set one of them as a topmost window, but when I sets MdiParent the...
8
by: ujjc001 | last post by:
Can it be done? I'd go to almost any length to implement a solution. I've tried <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.01)"> to no avail. Thanks! Jeff C.
12
by: E Goforth | last post by:
Hello, I have a VB6 app that calls a VB.NET app via named pipes and a third party component. Inside the VB.NET app I'm trying to force a form to the top, at least temporarily. Inside a form's...
6
by: Strahimir Antoljak | last post by:
I'm running VS.NET 2002 and keep having problems with form keeping on top with its TopMost property. Sometimes my program places the invoked form on top sometimes not. Sometimes when I click on the...
1
by: Phil Galey | last post by:
I have a small application, which is to always stay on top. Another application, which it is supposed to stay on top of, is QuarkXPress 5. I'm using Me.TopMost = True in the Form1_Deactivate...
1
by: Gary Brown | last post by:
Hi, I have a dialog box that must behave as MessageBox does with regard to the TopMost property. It must be TopMost if and only if the calling form is TopMost. A static method creates the...
2
by: =?Utf-8?B?aGVsZmk=?= | last post by:
Hi all, I have replied with my own questions to an older post entry but after a while I thought it's better to start a new thread based on the previous one. Perhaps with the new thread I will...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.