PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: paulDiagnos on May 25, 2007, 09:03:02 AM

Title: Controlling another Form...
Post by: paulDiagnos on May 25, 2007, 09:03:02 AM
Hi guys,

Im interested in controlling another form using power basic. Im quite happy sending messages to the form simply to find the EnumWindows CODEPTR(EnumWindowsProc), 0 and the ParentCallback, and child call backs i need.

i have sucessfully found the window i need and press a button on it using :sendmessage HWND ,%WM_COMMAND, %BN_CLICKED,HwndchilD

but i need to change a activate a tab.  I have tried varius sendmessages but so far no luck.

below i have put some code which might explain a little better what im trying to do...



FUNCTION PBMain AS LONG
EnumWindows CODEPTR(EnumWindowsProc), 0
END Function

FUNCTION EnumWindowsProc(BYVAL lHandle AS LONG, BYVAL lNotUsed AS LONG) PRIVATE AS LONG
        DIM gsTitle AS GLOBAL STRING
        gsTitle = STRING$(256,0)
        GetWindowText lHandle, BYVAL STRPTR(gsTitle), 256
        gsTitle = EXTRACT$(gsTitle,CHR$(0))
        IF LEN(gsTitle) THEN
              If GSTITLE = "My external Control Panel" Then
                    HWND =LHANDLE                    
                  Call SetWindowPos(lHandle, %HWND_TOP,0,0, 0, 0,%SWP_NOSIZE)
                    EnumChildWindows(lHandle, CODEPTR(ParentCallback), 0&)
      End If       
        END IF       
        FUNCTION = %True
End FUNCTION



FUNCTION ChildCallback (BYVAL hWndChild AS LONG, lRaram AS LONG) AS LONG
DIM szClass AS ASCIIZ * %MAX_PATH
DIM szText  AS ASCIIZ * %MAX_PATH
DIM lRes                AS LONG
lRes = GetClassName(hWndChild, szClass, SIZEOF(szClass))
lRes = GetWindowText(hWndChild, szText, SIZEOF(szText))
FUNCTION = 1
END Function


FUNCTION ParentCallback (BYVAL hWndChild AS LONG, lRaram AS LONG) AS LONG
DIM szClass AS ASCIIZ * %MAX_PATH
DIM szText  AS ASCIIZ * %MAX_PATH
DIM lRes                AS LONG
lRes = GetClassName(hWndChild, szClass, SIZEOF(szClass))
lRes = GetWindowText(hWndChild, szText, SIZEOF(szText))

''If szText = "Calibrate" Then
   put$ filenum, "  Child: Class=" & szClass & " " & "Text=" & szText +$crlf
   'sendmessage HWND ,%WM_COMMAND, %BN_CLICKED,HwndchilD      ' here i have success sending a message to press a button
   
'##### here is wher ei really want to press a tab
   sendmessage HWND ,%WM_NOTIFY, ,HwndchilD
'#####   

   
End If
Function = 1
END FUNCTION


really hope one of you wizards can help
Title: Re: Controlling another Form...
Post by: TechSupport on May 25, 2007, 06:19:25 PM
I assume that your code is able to correctly find the windows handle of the Tab Control, right?

If it can, then you simply need to call the following function to programatically change the tab.

Example:

FF_TabControl_SetTabFocus HWND_FORM1_TABCONTROL1, 2   '<--- tab is zero based


Title: Re: Controlling another Form...
Post by: TechSupport on May 25, 2007, 06:22:43 PM
Or, if you know the Form but not the Tab Control handle (and you know the Tab Control ID) then you can do the following:


FF_TabControl_SetTabFocus GetDlgItem( hWndForm, IDC_FORM1_TABCONTROL1), 2


If you don't know the Tab Control ID then you can use EnumWindows to find the Form and then EnumChildWindows on that Form to find the Tab Control windows handle.

Title: Re: Controlling another Form...
Post by: TechSupport on May 25, 2007, 06:26:05 PM
If you are enum'ing the child windows and want to test for each of their ID's then you would use the GetDlgCtrlID( hWndControl ) to see if it matches the Tab Control ID. This may be easier than testing for class names.
Title: Re: Controlling another Form...
Post by: paulDiagnos on May 30, 2007, 05:36:19 AM
cool, Ok, didnt even think to try the Tab controls in firefly.

il give it a try thanks...
Title: Re: Controlling another Form...
Post by: paulDiagnos on May 30, 2007, 10:11:42 AM
worked fine, but also good to have a sneaky look at the ff code gen files.

theres a macro in winapi. TabCtrl_SetCurFocus(hwndchild, 1) gets the job done

thanks again guys