Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default hotkey in usrform


I want to focus the specific control in that userform if press the F3
key.
Current, the userform have many controls.

in that case, even if any control has focus, i want to be focused the
specific control(combobox or textbox, etc) of the userform when the F3
key pressed.



*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default hotkey in usrform

Hi x taol,
You can do that by subclassing your UserForm (do not forget to take all the
precautions of use relating to the use of this method). By way of example:

In a standard module:
Option Explicit
Private Declare Function RegisterHotKey& Lib "user32" _
(ByVal hWnd&, ByVal id&, ByVal fsModifiers&, ByVal vk&)
Private Declare Function UnregisterHotKey& Lib "user32" _
(ByVal hWnd&, ByVal id&)
Private Declare Function SetWindowLong& Lib "user32" Alias _
"SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function CallWindowProc& Lib "user32" _
Alias "CallWindowProcA" (ByVal lpPrevWndFunc&, ByVal hWnd& _
, ByVal Msg&, ByVal wParam&, ByVal lParam&)
Private Const GWL_WNDPROC = (-4)
Private OldWndProc&

' Start the hook, and register the hotkey
Sub StartHook(ByVal hWnd&)
RegisterHotKey hWnd, 0, 0, &H72 ' F3
OldWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)
End Sub

' Stop the hook, and unregister the hotkey
Sub StopHook(ByVal hWnd&)
UnregisterHotKey hWnd, 0
SetWindowLong hWnd, GWL_WNDPROC, OldWndProc
End Sub

Function WndProc&(ByVal hWnd&, ByVal uMsg&, ByVal wParam&, ByVal lParam&)
Select Case uMsg
Case &H82 ' (WM_NCDESTROY)
Call StopHook(hWnd)
Case &H312 ' (WM_HOTKEY)
If wParam = 0 And UserForm1.Visible Then
UserForm1.ComboBox1.SetFocus
End If
End Select
WndProc = CallWindowProc(OldWndProc, hWnd, uMsg, wParam, lParam)
End Function

In the UserForm module:
Option Explicit
Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)
Private hWnd&

Private Sub UserForm_Initialize()
hWnd = FindWindow(vbNullString, Me.Caption)
Call StartHook(hWnd)
End Sub

Private Sub UserForm_Terminate()
Call StopHook(hWnd)
End Sub

Regards,
MP

"x taol" a écrit dans le message de news:
...

I want to focus the specific control in that userform if press the F3
key.
Current, the userform have many controls.

in that case, even if any control has focus, i want to be focused the
specific control(combobox or textbox, etc) of the userform when the F3
key pressed.



*** Sent via Developersdex
http://www.developersdex.com ***


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel2007 hotkey L@ja New Users to Excel 0 January 29th 08 12:23 PM
MessageBox and then return to usrForm Fabrizio Excel Programming 4 June 22nd 06 12:37 PM
Global macro hotkey Mikus Excel Programming 1 August 17th 05 08:54 PM
adding usr defined event procedure of textbox in usrform ?? tom taol Excel Programming 2 December 30th 04 12:13 PM
Alt + Enter hotkey - what does this do? R Avery Excel Programming 2 October 14th 04 05:23 PM


All times are GMT +1. The time now is 07:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"