PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Setfocus on a tab control  (Read 401 times)

Petrus Vorster

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 356
Setfocus on a tab control
« on: August 19, 2017, 05:26:39 PM »

Hi All

I am adding to an old program.
It has a tabcontrol with multiple pages.

I have always used the FF_control_setfocus to the First Textbox on every child-form during the Function FORM1_TABCONTROL1_TCN_SELCHANGE event. That way once you click a tab, it sets the focus to the relevant textbox.

Now I had to add another Tabcontrol on one of the Child Forms.
The same command now doesn't work. For instance, if i click Tab1 on form 1 it opens the relevant tab with the right child form(the one with another tab control on it), but cannot set the set-focus tp a text-box on it . It simply ignores the command.

If i move the command to that Tab-control's celchange event it work, but not from the first tab-control.
(If this now makes any sense :) )

Surely one could set the focus to a textbox on a child form on a different tab-control?
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: Setfocus on a tab control
« Reply #1 on: August 19, 2017, 08:23:08 PM »

When I hear questions like this I tend to think that it may be a timing issue where the focus is set but then an action with the sub tab control is stealing that focus elsewhere. A simple solution would be to create a user defined message (say, MSG_USER_SETFOCUS) and then use POSTMESSAGE in your SelChange event to post that message to the Form. When you send it you could even specify the handle of the control that you want to set focus to as the WPARAM of the message. Maybe something like:

PostMessage HWND_FRMMAIN, MSG_USER_SETFOCUS, HWND_FRMMAIN_TEXT1, 0

The in the CUSTOM handler of the form you would catch and handle the MSG_USER_SETFOCUS message.

Select Case wMsg
   Case MSG_USER_SETFOCUS
      SetFocus wParam
 
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Petrus Vorster

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 356
Re: Setfocus on a tab control
« Reply #2 on: August 20, 2017, 05:07:07 AM »

Thanks for the reply Paul.
This is what I have done so far:
On the main form's tabcontrol selchange I did this:

Code: [Select]
Function FORM1_TABCONTROL1_TCN_SELCHANGE ( _
                                         ControlIndex  As Long,      _  ' index in Control Array
                                         hWndForm      As Dword,     _  ' handle of Form
                                         hWndControl   As Dword,     _  ' handle of Control
                                         ByVal lpNMHDR As NMHDR Ptr  _  ' pointer to NMHDR
                                         ) As Long
 
 mytab& = FF_TabControl_GetSelectedTab(HWND_FORM1_TABCONTROL1)
 If mytab& = 0 Then FF_Control_SetFocus(hwnd_form2_text1)
 If mytab& = 1 Then FF_Control_SetFocus(hwnd_form3_text1)
 If mytab& = 2 Then FF_Control_SetFocus(hwnd_form4_text1)
 If mytab& = 3 Then FF_Control_SetFocus(hwnd_form5_text1)
 If mytab& = 4 Then FF_Control_SetFocus(hwnd_form6_text1)
 If mytab& = 5 Then
   FF_Control_SetFocus(hwnd_form7_xpbutton2)
   Loadinfo
 End If
 If mytab& = 6 Then '--International menu
     FF_TabControl_SetTabFocus( HWND_INTERNAT_TABCONTROL1,0)
     PostMessage HWND_Receive, MSG_USER_SETFOCUS, HWND_RECEIVE_TEXT1, 0     'The form name is "receive"
     
 End If
   Function = 0   ' change according to your needs
End Function

Then in the receiving Form's custom i did this:
Code: [Select]
Function RECEIVE_CUSTOM ( _
                        hWndForm      As Dword, _  ' handle of Form
                        wMsg          As Long,  _  ' type of message
                        wParam        As Dword, _  ' first message parameter
                        lParam        As Long   _  ' second message parameter
                        ) As Long
Select Case wMsg
   Case MSG_USER_SETFOCUS
      SetFocus wParam
   Function = 0   ' change according to your needs
   End Select
   
End Function

Do i need to declare something first? I am getting a compiler error #516. Probably just a TYPO I made.
Logged

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2785
    • Josť Roca Software
Re: Setfocus on a tab control
« Reply #3 on: August 20, 2017, 05:12:18 AM »

In PowerBASIC, constants use a % prefix, so the constant must be %MSG_USER_SETFOCUS, and, of course, you have to define that constant, i.e. %MSG_USER_SETFOCUS = some value.

Petrus Vorster

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 356
Re: Setfocus on a tab control
« Reply #4 on: August 20, 2017, 05:25:07 AM »

Thanks JosŤ.

I will go do that immediately.
Logged

Petrus Vorster

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 356
Re: Setfocus on a tab control
« Reply #5 on: August 20, 2017, 05:31:10 AM »

So obvious to declare that first!!
Now the Postmessage runs correctly, but the focus still isn't set.

Will dig a bit and see what i can come up with.

Thanks a million.
Logged

Petrus Vorster

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 356
Re: Setfocus on a tab control
« Reply #6 on: August 20, 2017, 07:32:43 AM »

O, I can be the biggest Idiot some times.
Overlook the simple obvious. Right there, smack bang, right in front of me...

Thanks guys, remind me next time just to read my code a few times! :)
Logged