Solved

Focus problem

Posted on 2000-03-01
14
181 Views
Last Modified: 2010-05-18
I have an array of txtBoxes named(txtFact) and a HScrollBar and some others controls on my form.
I want to execute the HScrollBar.GotFocus when the user click on the HScrollBar, but it doesn't work.
I made a test, i put a watchPoint: Form1.ActiveControl.Name and the Result is TxtFact.
Then why when i click on the HScrollBar the sub GotFocus is not execute.

Guys, go to see the : Erick37's comment March 01 2000 - 02:59PM EST  it is very good.
0
Comment
Question by:dosyl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 

Expert Comment

by:jhedlund
ID: 2573969
This works fine for me.  I put a text box and a HScrollBar on a form, and in their _GotFocus events I put the following code:

       Debug.Print "ActiveControl: " & Me.ActiveControl.Name

And it properly identified the text box when it had focus, and the HScrollBar when it had focus.

Can you give a little more information ?  What version VB?  Try what I did, and see what results you get...
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 100 total points
ID: 2573981
Is the ScrollBar's TabStop property set to True?
0
 
LVL 1

Author Comment

by:dosyl
ID: 2574002
Erick37, that's it, i don't remember why i put it to False; but it is possible to do the GotFocus sub with the TabStop=False? If Yes how?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:dosyl
ID: 2574029
I remember why I put the TabStop's property; it is because i don't like to see the HScrollBar flashed.
0
 

Expert Comment

by:jhedlund
ID: 2574031
You can add the following line to HScrollBar_Change event:

        HScrollBar.SetFocus

0
 
LVL 32

Expert Comment

by:Erick37
ID: 2574040
It may be possible using subclassing to do this.  Let me see...
0
 
LVL 1

Author Comment

by:dosyl
ID: 2574041
I remember why I put the TabStop's property; it is because i don't like to see the HScrollBar flashed.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2574108
I can post the code for a scrollbar hook that intercepts the left mouse button click event.  This will give you a Click event for the scrollbar.  You may be able to replace the GotFocus with Click.

If you need to do this for many controls, the coding can get a bit complicated.

If you cannot live with the flashing, let me know.
0
 
LVL 1

Author Comment

by:dosyl
ID: 2574159
Erick37, Scuse but i don't understand there is no Click Event or MouseSomething Event in a HScrollBar.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2574225
No, but you can make one.  This creates a Click method for the HScroll1 scrollbar:

'~~~~FORM CODE~~~~
Option Explicit

Private Sub Form_Load()
'
' Hook into the message stream.
'
glPrevWndProc = fSubClass(HScroll1.hwnd)
End Sub

Private Sub Form_Unload(Cancel As Integer)
'
' Stop intercepting messages.
'
Call pUnSubClass(HScroll1.hwnd)
End Sub

Public Sub HScroll_Click(ByVal wParam As Long, ByVal lParam As Long)
    Debug.Print "HScroll Click " & Hex(lParam)
End Sub

'~~~~MODULE CODE~~~~
'MUST be in a module (bas file)
'Warning: since subclassing is used, DO NOT
'pause the code or add breakpoints while running
'this code in the VB IDE.

Option Explicit
Public glPrevWndProc As Long

Public Const GWL_WNDPROC = (-4)
Public Const WM_LBUTTONDOWN = &H201

'The SetWindowLong function changes an attribute of the specified window.
'Calling SetWindowLong with the GWL_WNDPROC index creates a subclass of
'the window class used to create the window. An application should not
'subclass a window created by another process. The SetWindowLong function
'creates the window subclass by changing the window procedure associated
'with a particular window, causing Windows to call the new window procedure
'instead of the previous one. An application must pass any messages not
'processed by the new window procedure to the previous window procedure by
'calling CallWindowProc. This allows the application to create a chain of
'window procedures.
'
'Parameters
'hwnd - Identifies the window to which the window belongs.
'
'nIndex - Set to GWL_WNDPROC to set a new address for the window procedure.
'
'dwNewLong - Address of the new window procedure.
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

'The CallWindowProc function passes message information to the specified window
'procedure. Use this function for window subclassing. Usually, all windows
'with the same class share one window procedure. A subclass is a window or
'set of windows with the same class whose messages are intercepted and processed
'by another window procedure before being passed to the window procedure of the class.
'
'Parameters:
'lpPrevWndFunc - Pointer to the previous window procedure.
'                If this value is obtained by calling the GetWindowLong function
'                with the nIndex parameter set to GWL_WNDPROC, it is the address
'                of a window or a handle representing that address.
'
'hwnd - Identifies the window procedure to receive the message.
'
'Msg - Specifies the message.
'
'wParam - Depends on the value of the Msg parameter.
'
'lParam - Depends on the value of the Msg parameter.
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Sub pUnSubClass(lhWnd As Long)
'
' Stops the form from intercepting Window's messages
' by resetting the default procedures associated
' with the form.
'
Call SetWindowLong(lhWnd, GWL_WNDPROC, glPrevWndProc)
End Sub


Public Function pMyWindowProc(ByVal hw As Long, ByVal uMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long
'
' This is the callback procedure used when a message is received
' by this form.  The desired message is processed and all others are
' passed back to the original procedure associated with the form.
'

If uMsg = WM_LBUTTONDOWN Then
    Call Form1.HScroll_Click(wParam, lParam)
End If

pMyWindowProc = CallWindowProc(glPrevWndProc, hw, uMsg, wParam, lParam)
End Function

Public Function fSubClass(lhWnd As Long) As Long
'
' Subclass the form by replacing the "normal" procedures associated
' with the form with procedure "pMyWindowProc".
'
' NOTE: Comment all calls to fSubClass while in IDE.
'
fSubClass = SetWindowLong(lhWnd, GWL_WNDPROC, AddressOf pMyWindowProc)
End Function

0
 
LVL 1

Author Comment

by:dosyl
ID: 2576651
Erick37
What is the reason we can't put breakpoint, i read your warning but i don't understand why Vb do this?
Your idea to make a Click Event is very good.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2577109
For some reason VB IDE will crash if you pause the code while it is running a subclassed window.

When debugging with breakpoints or stepping thru code, comment out the calls in the Load and Unload events and run without the subclassing.
0
 
LVL 1

Author Comment

by:dosyl
ID: 2577312
Edited text of question.
0
 
LVL 1

Author Comment

by:dosyl
ID: 2577321
I accept this answer because it was solution for my problem.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 385
Adding to a VBA? 6 90
vb6 connector to SQL Server 2 42
how to loop through and process two columns in excel 8 71
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question