Page 1 of 1

Posted: Fri Aug 09, 2002 4:02 pm
by BackupUser
Restored from previous forum. Originally posted by Kendrel.

I need help on converting the following VB functions to Purebasic code...
please help if you can... iam getting crazy with this one!

Public Function OpenPr() As Boolean
' Some memory we'll be using

Dim ProcessID As Long

' Find the window

' Get the process id
GetWindowThreadProcessId getUO, ProcessID

' Get a valid Process Handle
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
If ProcessHandle = 0 Then
OpenPr = False
Exit Function
Else
OpenPr = True
Exit Function
End If
End Function





Public Function getUO() As Long
Dim hwnd As Long
Dim desktop As Long
Dim sWindowText As String
Dim sClassname As String
Dim r As Long

desktop = GetDesktopWindow

hwnd = GetWindow(desktop, GW_CHILD)

Do While hwnd 0
DoEvents
sWindowText = Space$(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
sClassname = Space$(255)
r = GetClassName(hwnd, sClassname, 255)
sClassname = Left(sClassname, r)
If Left$(sWindowText, 13) = "ProgName" And sClassname = "ProgName" Then
getUO = hwnd
Exit Function
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
End Function

Posted: Fri Aug 09, 2002 7:10 pm
by BackupUser
Restored from previous forum. Originally posted by Danilo.

This should be a start:

Code: Select all

Procedure.l getUO()
     hwnd.l
     desktop.l
     sWindowText.s
     sClassname.s
     r.l


     desktop = GetDesktopWindow_()
     hwnd = GetWindow_(desktop, #GW_CHILD)
     While hwnd  0
       While WindowEvent():Wend 
       sWindowText = Space(255)
       r = GetWindowText_(hwnd, sWindowText, 255)
       sWindowText = Left(sWindowText, r) 
       sClassname = Space(255)
       r = GetClassName_(hwnd, sClassname, 255)
       sClassname = Left(sClassname, r)
       If Left(sWindowText, 13) = "ProgName" And sClassname = "ProgName"
          ProcedureReturn hwnd
       EndIf
       hwnd = GetWindow_(hwnd, #GW_HWNDNEXT)
     Wend
EndProcedure


Procedure.l OpenPr()
     ;' Some memory we'll be using

     ProcessID.l

     ;' Find the window

     ;' Get the process id
     GetWindowThreadProcessId_( getUO(), @ProcessID )

     ;' Get a valid Process Handle
     ProcessHandle = OpenProcess_(#PROCESS_ALL_ACCESS, #False, ProcessID) 
     If ProcessHandle = 0
        ProcedureReturn #False
     Else
        ProcedureReturn #True
     EndIf
EndProcedure
cya,
...Danilo

(registered PureBasic user)