473,698 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Activate a window to forground using API

I developed this module, examples on the internet seem to be much longer..
Can someone explain to me why my solution doesn't work?

Module modAPI

Declare Function SetForegroundWi ndow Lib "user32" (ByVal hwnd As Long) As
Long

Public Sub ActivateAppWind ow()

SetForegroundWi ndow(fMain.Hand le.ToInt32)

End Sub

End Module
Nov 21 '05 #1
18 2722
Hi,

API declare is wrong. Types have changed since vb6. Use integer
instead of long. In this case i would use intptr.

Declare Function SetForegroundWi ndow Lib "user32" (ByVal hwnd As intptr) As
integer

Public Sub ActivateAppWind ow()

SetForegroundWi ndow(fMain.Hand le)

End Sub
Ken
----------------

"D Witherspoon" <dw**********@n oway.org> wrote in message
news:un******** ******@TK2MSFTN GP14.phx.gbl...
I developed this module, examples on the internet seem to be much longer..
Can someone explain to me why my solution doesn't work?

Module modAPI

Declare Function SetForegroundWi ndow Lib "user32" (ByVal hwnd As Long) As
Long

Public Sub ActivateAppWind ow()

SetForegroundWi ndow(fMain.Hand le.ToInt32)

End Sub

End Module

Nov 21 '05 #2
Module Module1
Public Declare Function SetForegroundWi ndow Lib "user32" (ByVal hwnd As
Integer) As Integer

Public Sub SetForeground(B yVal iHandle As Integer)
SetForegroundWi ndow(iHandle)
End Sub
End Module

Usage:
-------

SetForeground (frm.Handle.Int 32)

'frm' is the Form to set as the foreground window

Example:
---------

Declaration:
------------

Dim frm As New Form2

Behind Button1 (for example):
------------------------------

frm.Show()

Behind Button2 (for example):
------------------------------

SetForeground (frm.Handle.Int 32)

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #3
"Ken Tucker [MVP]" <vb***@bellsout h.net> schrieb:
API declare is wrong. Types have changed since vb6. Use integer
instead of long. In this case i would use intptr.

Declare Function SetForegroundWi ndow Lib "user32" (ByVal hwnd As intptr)
As
integer

Public Sub ActivateAppWind ow()

SetForegroundWi ndow(fMain.Hand le)


Note that this will only work as long as your application is the active
application. Otherwise 'AttachThreadIn put' is needed too. In other words,
it's not as easy (and not recommended) to "steal" the focus from another
application.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
"Crouchie19 98" <cr**********@s pamcop.net> schrieb:
Public Declare Function SetForegroundWi ndow Lib "user32" (ByVal hwnd As
Integer) As Integer


I prefer this declaration/usage, although your code should work:

\\\
Public Declare Function SetForegroundWi ndow Lib "user32.dll " ( _
ByVal hWnd As IntPtr _
) As Boolean
..
..
..
Dim Success As Boolean = SetForegroundWi ndow(frm.Handle )
///

Just my 2 Euro cents...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
D,

These questions make me forever curious.

Although as Herfried already said have I the same opinion that you should
avoid this kind of instruction.

Why not just
me.topmost = true

Cor
Nov 21 '05 #6
Cor,

"Cor Ligthert" <no************ @planet.nl> schrieb:
Although as Herfried already said have I the same opinion that you should
avoid this kind of instruction.

Why not just
me.topmost = true


I doubt that a topmost window is a viable solution in this situation...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
> "Cor Ligthert" <no************ @planet.nl> schrieb:
Although as Herfried already said have I the same opinion that you should
avoid this kind of instruction.

Why not just
me.topmost = true


I doubt that a topmost window is a viable solution in this situation...

After that I had sent this message I thought,
me.topmost = true
me.topmost = false

Maybe does that the job that is asked, however I am more interested in that
statusbar problem, but the information from the OP is to few and I think
that this is a on the border solution.

Cor
Nov 21 '05 #8
Me.TopMost will make a form the topmost in the application but not over
other applications.

When you refer to the status bar problem are you talking about my problem
with the app not showing up in the taskbar.

It's tricky and yes, is the only reason I have to resort to trying to bring
the app window into the foreground. Unfortunatly no luck yet with the
status bar thing.

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"Cor Ligthert" <no************ @planet.nl> schrieb:
Although as Herfried already said have I the same opinion that you
should avoid this kind of instruction.

Why not just
me.topmost = true


I doubt that a topmost window is a viable solution in this situation...

After that I had sent this message I thought,
me.topmost = true
me.topmost = false

Maybe does that the job that is asked, however I am more interested in
that statusbar problem, but the information from the OP is to few and I
think that this is a on the border solution.

Cor

Nov 21 '05 #9
Not recommended as in technically or morally ?
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
"Ken Tucker [MVP]" <vb***@bellsout h.net> schrieb:
API declare is wrong. Types have changed since vb6. Use integer
instead of long. In this case i would use intptr.

Declare Function SetForegroundWi ndow Lib "user32" (ByVal hwnd As intptr)
As
integer

Public Sub ActivateAppWind ow()

SetForegroundWi ndow(fMain.Hand le)


Note that this will only work as long as your application is the active
application. Otherwise 'AttachThreadIn put' is needed too. In other
words, it's not as easy (and not recommended) to "steal" the focus from
another application.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #10

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

Similar topics

4
3104
by: Milon | last post by:
Hi all, I am new to Python, and I just wrote a simple script to launch an application from the windows's start menu's run command. (see code as follow) There is an "OK" button on the new application I launched, but I can't get Python to click on it because the new window is not in focus and I read somewhere off the web that I need to activate the new window first before I can do anything on the new window. I couldn't find any useful...
3
5094
by: Michael Wu | last post by:
I wonder if anyone know how to activate a window with a given window handler. I used to do this with the win32 API static native boolean SetForegroundWindow(int hwnd); I wonder if there is native support for that within .NET, instead having to call WIN32 API. Regards
18
9814
by: D Witherspoon | last post by:
I developed this module, examples on the internet seem to be much longer.. Can someone explain to me why my solution doesn't work? Module modAPI Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
1
1529
by: Lex | last post by:
I want to write an app in C# that keeps track of when the foreground window in the OS changes. Is there an event that I can "susbscribe" to for this? Or am I stuck polling using the GetForegroundWindow() method? Regards
10
16494
by: zhou | last post by:
in Visual Basic ,I use Appactivate(AcadApp.caption);
5
1454
by: Ivan V via DotNetMonster.com | last post by:
Hi I would like to knwo if I could activate the up and down arrow in a window form which have the same function as using the tab button. Thanks for all! best rgds, Ivan Vong -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-vb-net/200508/1
2
7898
by: Dave Booker | last post by:
I have a Windows form application that I generally run minimized. When a critical event occurs it instantiates another "Alert" form which I want to grab the user focus. In the Alert constructor I call both this.Show() and this.Activate(), but if the parent application is minimized then the Alert form will also stay minimized (and just flash). How can I cause the Alert form to show itself and grab focus?
1
2760
by: pearturtle123 | last post by:
Hi, I am new to Python and I am using PAMIE to manipulate IE browser. Currently, I have IE window 1 launched, after I clicked on a link on window 1, a second IE window 2 isopened. Then, I want to activate IE window 2 (click button or change url), the focus keeps on IE window 1 and click on the button on window 1. I have used "def windowFind" from the PAMIE and able to find IE window 2. Can someone please tell me how to activate IE window...
0
990
IonutZ
by: IonutZ | last post by:
VB.NET 2008-FORM: Getting a window to forground while only knowing its partial name. Hi guys :) I have the name of an application, it starts with ACI and I want to set it to my forground in order to sendkeys some stuff to it. Now I've read a BUNCH of stuff and could not come up with a solution on my own. This is the code I have for now, a bunch of stuff compiled together :] ]]
10
3266
by: Gary | last post by:
I'm trying to find a way to determin which window Within-Another-Program currently has the focus. THE SITUATION: (Skip down to "My Question" if you don't want the background...) * This is a service desk where people "check in" to use a certain facility or area. * The company is running an application they purchased off-the-shelf. * The application accepts input of member numbers from a serial-port
0
8673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8601
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8892
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7716
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.