I've been using FreeBasic for a while now and I like it a lot. So far, I have been programming in PHP and I want to master the skills in programming desktop applications. I think this language is great. Generally I manage to find information in the forum, although the language is not well described (like php).
I would like to ask for a little help on a feature that I have encountered in VisualBasic and Wscript.Shell. Is there any opportunity to use something similar to AppActivate () to show a specific application in focus. For example:
Generally I manage to find information in the forum, ...
Should IMO only be the second place, to do 'look ups' ...
... although the language is not well described.
I disagree with that.
The online FB-Manual, the primary source of information: is found here.
It is the most 'up-to-date' source (all other doc. is created from there).
What you want to do, requires to call the OS (WinAPI-call's).
#Include "windows.bi"
#Include "win\tlhelp32.bi"
Sub WinActivate(processname As String) 'coded by UEZ
Dim As DWORD pid = 0
Dim As HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
Dim As PROCESSENTRY32 process
process.dwSize = Sizeof(PROCESSENTRY32)
If Process32First(snapshot, @process) Then
While Process32Next(snapshot, @process)
If Str(process.szExeFile) = processname Then
pid = process.th32ProcessID
Exit While
End If
Wend
End If
CloseHandle(snapshot)
If pid = 0 Then Exit Sub
Dim As HWND hCurrentWnd = 0
Dim As DWORD lpdwProcessId
Do
hCurrentWnd = FindWindowEx(Null, hCurrentWnd, Null, NULL)
lpdwProcessId = 0
GetWindowThreadProcessId(hCurrentWnd, @lpdwProcessId)
If lpdwProcessId = pid Then
Dim As WINDOWPLACEMENT State
State.length = Sizeof(WINDOWPLACEMENT)
GetWindowPlacement(hCurrentWnd, @State)
Select Case State.showcmd
Case SW_SHOWMINIMIZED
ShowWindow(hCurrentWnd, SW_RESTORE)
Case SW_HIDE
ShowWindow(hCurrentWnd, SW_SHOW)
End Select
SetActiveWindow(hCurrentWnd)
End If
Loop Until hCurrentWnd = 0
End Sub
Dim As String processname = "notepad.exe"
WinActivate(processname)
Sleep
Start notepad.exe and minimize it and run the code. It should bring up the notepad window.
Generally I manage to find information in the forum, ...
Should IMO only be the second place, to do 'look ups' ...
... although the language is not well described.
I disagree with that.
The online FB-Manual, the primary source of information: is found here.
It is the most 'up-to-date' source (all other doc. is created from there).
What you want to do, requires to call the OS (WinAPI-call's).
Thanks for the link, MrSwiss,
I had high expectations because I'm a little bit over satisfied after php, where there are tons of examples for each function. Maybe I spoke a little incorrectly. I'm sorry!
UEZ wrote:For Windows you can start with something like this here:...
Perfect, UEZ! Exactly what I was looking for!
You are amazing guys! I did not expect such an immediate response!
#Include "windows.bi"
Sub WinActivate(WinTitle As String)
Dim As HWND hCurrentWnd = 0
hCurrentWnd = FindWindow(Null, WinTitle)
if hCurrentWnd then
ShowWindow(hCurrentWnd, SW_RESTORE)
SetForegroundWindow(hCurrentWnd)
print "activated ";Time()
endif
End Sub
Dim As String WinTitle = "Senza nome - Blocco note" ' replace with a title that is active on your system
WinActivate(WinTitle)
Sleep
#Include "windows.bi"
Sub WinActivate(WinTitle As String)
Dim As HWND hCurrentWnd = 0
hCurrentWnd = FindWindow(Null, WinTitle)
if hCurrentWnd then
ShowWindow(hCurrentWnd, SW_RESTORE)
SetForegroundWindow(hCurrentWnd)
print "activated ";Time()
endif
End Sub
Dim As String WinTitle = "Senza nome - Blocco note" ' replace with a title that is active on your system
WinActivate(WinTitle)
Sleep
Wow! Really simple and understandable.
Thank you, jj2007!