Thanks for visiting my site lucky visitor:
This page was last updated on: March 21, 2009
Copyright © 2002. XcelFiles. All Rights Reserved Ivan F Moala



- Example for Calculator applet
Keeping a Window on Top {always} is just a matter of setting the Windows position style with the appropriate API and Flags. Here is the code routine to Keep a Window on top.
APIS & Constants
'// Used to set the Windows Style
Private Declare Function SetWindowPos _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) _
As Long
'// Positions
Private Const HWND_TOPMOST = -1
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Usage:
SetWindowPos Windowhdl, _
HWND_TOPMOST, _
0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
NB: Wndowhdl will need to be defined ie. you will need to get the handle of the Window that you will be working with. To do this there are various methods. Download the workbook to view one way of getting the Active Window handle.
What can I use this for:
Basically anytime you need to keep a Window eg another application Window, Userfrom etc and have this remain on Top even if it doesn't have the focus. Good example of this is to have a userform remain on Top. Also the NotePad utility.
Example for calculator applet
Here is an example of how to use this (see image below).
Have you ever needed to use the Windows Applet "Calculator" just do some quick calculations etc. Once you have got the result you then just copy it and paste it to your cell, BUT selecting the cell activates Excel and the calculator is no longer visible so to use it again you need to reactivate it. Using this code the calculator remains on TOP ALL the TIME.
Code notes:
- Testing done on WinXP / Excel2000
- International versions other then English:
Because the code also uses APIs to search for Calculators Window handle using it's Caption title you need to change the Applets Title in the code
eg. English = "Calculator", I believe for International versions this will be different.
- Code gets the default Applets System Dir or Windows directory to get the Calculator prgm, so if your Applet is in another directory then change the code to reflect this. Code to do this is also via API AND File System Object.
- A small class module is used just to keep the Windowhandle of the module. Using a class in this way allows us to KEEP the variable for this after code execution to open Calculator.
- The CLOSE button for the calculator was removed....this was so that we can close the calculator down via code and also so that we only get one instance of the Applet at any one time
