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

Keep form active?

21
Hello,

Is it possible to keep a form active, also when clicking on another application? I don't mean in the foreground, because I got that already, but now when I click on another application, my form becomes inactive.

Already thanks for the help.
Jan 4 '08 #1
9 3240
lotus18
866 512MB
Hello,

Is it possible to keep a form active, also when clicking on another application? I don't mean in the foreground, because I got that already, but now when I click on another application, my form becomes inactive.

Already thanks for the help.
I don't think it would be possible (i think). BTW, for what purpose?
Jan 4 '08 #2
QVeen72
1,445 Expert 1GB
Hello,

Is it possible to keep a form active, also when clicking on another application? I don't mean in the foreground, because I got that already, but now when I click on another application, my form becomes inactive.

Already thanks for the help.
Hi,

What Version of VB?
you want it to be on Top of all other windows...?

Regards
Veena
Jan 4 '08 #3
Bullitt
21
It's because the script isn't noticing keypresses while it's inactive, and it would be handy if I can use the keyboard for navigating between different screens or applications. I can open other applications now, but I cant go back, except when using alt-tab. So it works but I can be improved.
Jan 4 '08 #4
Bullitt
21
It is VB6.0, and it doesn't need to be on top, but it needs to be active. Another inactive application may be on top.
Jan 4 '08 #5
Ali Rizwan
925 512MB
It is VB6.0, and it doesn't need to be on top, but it needs to be active. Another inactive application may be on top.
Use timer and code

Form1.setfocus

or want code for setting window always on top to other all windows??

REGARDS

>> ALI <<
Jan 5 '08 #6
Killer42
8,435 Expert 8TB
Windows sends keypresses to the window which has the focus. The only way (as far as I know) that you could see them when you don't, is to use the API to intercept the windows messages being sent to the other application. This topic has been covered a number of times. Just try searching on "keylogger". You'll find that we're not very keen on helping people build them, though.
Jan 7 '08 #7
Bullitt
21
Thanks for the tip, I'm going to try it with RegisterHotKey from the user32.dll.
Jan 7 '08 #8
Killer42
8,435 Expert 8TB
Thanks for the tip, I'm going to try it with RegisterHotKey from the user32.dll.
Let us know how it turns out.
Jan 8 '08 #9
Bullitt
21
I got it all worked out now and it works.

I got a module called modHotkey.bas that holds the following script:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Declare Function RegisterHotKey Lib "user32" _
  4.     (ByVal hwnd As Long, ByVal id As Long, _
  5.     ByVal fsModifiers As Long, ByVal vk As Long) As Long
  6. Private Declare Function UnregisterHotKey Lib "user32" _
  7.     (ByVal hwnd As Long, ByVal id As Long) As Long
  8.  
  9. Public Enum ModConst
  10.     MOD_ALT = &H1
  11.     MOD_CONTROL = &H2
  12.     MOD_SHIFT = &H4
  13. End Enum
  14.  
  15. Public Const WM_HOTKEY = &H312
  16.  
  17. Private m_hkCount As Long
  18.  
  19. Function HotKeyActivate(ByVal hwnd As Long, _
  20.     Modifier As ModConst, Optional KeyCode As Integer) As Long
  21.  
  22.     m_hkCount = m_hkCount + 1
  23.  
  24.     ' 0 for no success, otherwise success
  25.     HotKeyActivate = RegisterHotKey(hwnd, m_hkCount, Modifier, KeyCode)
  26.  
  27. End Function
  28.  
  29. Function HotKeyDeactivate(ByVal hwnd As Long)
  30.     Dim i As Integer
  31.     For i = 1 To m_hkCount
  32.         UnregisterHotKey hwnd, i
  33.     Next i
  34.     m_hkCount = 0
  35. End Function
Then I also have a module called modSubClass.bas with the following script.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Declare Function CallWindowProcA Lib "user32" ( _
  4.     ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _
  5.     ByVal Msg As Long, ByVal wParam As Long, _
  6.     ByVal lParam As Long) As Long
  7.  
  8. Public oldProc As Long
  9.  
  10. Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, _
  11.     ByVal wParam As Long, ByVal lParam As Long) As Long
  12.  
  13.     'wParam - the number of the hotkey, its identification.
  14.     'lParam - HiWord is the Modifiere e.g. Shift, Ctrl, Alt
  15.     'lParam . LoWord is the KeyCode
  16.  
  17.     WndProc = 0
  18.     If uMsg = WM_HOTKEY Then
  19.         If wParam = 1 Then
  20.             MsgBox "This is the script he runs when I press my hotkey"
  21.         End If
  22.     Else
  23.         'All other messages to the old Windowprocedure
  24.         WndProc = CallWindowProcA(oldProc, hwnd, uMsg, wParam, lParam)
  25.     End If
  26. End Function
And in my form I have the following to activate the hotkey:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Declare Function SetWindowLongA Lib "user32" ( _
  4.     ByVal hwnd As Long, ByVal nIndex As Long, _
  5.     ByVal dwNewLong As Long) As Long
  6. Private Const GWL_WNDPROC = -4
  7.  
  8. Private Sub Form_Load()
  9.     oldProc = SetWindowLongA(Me.hwnd, GWL_WNDPROC, AddressOf WndProc)
  10.     HotKeyActivate Me.hwnd, MOD_ALT, Asc("S")     'hotkey 1
  11. End Sub
  12.  
  13. Private Sub Form_Unload(Cancel As Integer)
  14.     HotKeyDeactivate Me.hwnd
  15.     SetWindowLongA Me.hwnd, GWL_WNDPROC, oldProc
  16. End Sub
This example only uses ALT+S as a hotkey. When you want to add hotkeys, just make them in the form script where the other one is. And in the module modSubClass, you just make in the wndProc.

If wParam = ? Then
MsgBox "This is the script he runs when I press my hotkey"
End If

With the '?' the numer of the hotkey. This number is given by m_hkCount and the first hotkey has 1, the second has 2 and so on.

Thanks for bringing me on the right track.
Jan 9 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Hung Huynh | last post by:
Hello, I have 2 separate web sites on 2 different boxes www.xyz.com on box 1 www2.xyz.com on box 2 Users log into box 1 via regular ASP/Database authentication, and I keep a session...
6
by: Mario Reiley | last post by:
Hi, Group I am C# and VB.6 programmer but in this moments I have the followin question: How Can I keep my application on the top of all applications on my Windows desktop. Please let me...
3
by: Laszlo Szijarto | last post by:
Is there any way to stop a form from ever becoming the Active Form in an application? Thank you, Laszlo
4
by: Rob | last post by:
Is there a way to keep a form on top of everything - even other apps ?
2
by: kevintan | last post by:
Hi all, Not sure whether you guys can help. Looking at both forms in javascript below: <html> <head> <script language="Javascript">
8
by: George | last post by:
Hello everyone, I am using C# on a Pocket PC 2003 project based on .Net Compact Framework of Visual Studio 2005. I want to re-draw some controls of a Form (Window) at a regular interval (for...
0
by: Duvik | last post by:
Hello experts, I am a very beginner and I wrote my first application in C#. I get an image from a scanner and process it but during the process (several seconds) the main form becomes inactive,...
10
by: John Brown | last post by:
Hi there, Does anyone know how to (generically) determine the currently active form for an application using a "static" function (so I can call it from anywhere). There is no offiical way I've...
4
osward
by: osward | last post by:
I had made a table colum sortable and paging the table, following are the code // Display Event List echo "<center>"._EVENTLIST."</center><br>"; $now = Date(Y-m-d); // sort table...
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:
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...
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
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
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,...
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.