October 29, 2020, 02:13:28 AM

Author Topic: [bb] Use FindWindow Without Class Name by semar [ 1+ years ago ]  (Read 1567 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Use FindWindow Without Class Name
Author : semar
Posted : 1+ years ago

Description : Hi,
as you know, from within VB, the user32 api call FindWindow could also be called without
specify the class name of the application, by passing a vbNullString value.

To simulate the vbNullString from within Blitz, we could declare another FindWindow in the
.decls file, which accepts a number instead of a string for the class parameter:
api_FindWindow_0 (note the % instead of $)

Code: [Select]
.lib "user32.dll"
api_FindWindow% (lpClassName$, lpWindowName$) : "FindWindowA"
api_FindWindow_0% (lpClassName%, lpWindowName$) : "FindWindowA"


In this way, we can call FindWindow using 0 as class name parameter.
So we don't have to know the class name of the window we are searching for. That means, we can actually get any window handler by only specifing it's window title.

Here is an example; try the function FindWindow by using method1 or method2.
You can search outlook window, notepad, without to know any class name !

Note: if you use the class name method (method2), this assumes you are trying this code with B3D; if you try this code using BlitzPlus, you should change the class$ accordingly:

"GX_WIN32_CLASS" ; <- BlitzPlus 1.11
"BLITZMAX_WINDOW_CLASS" ; <- BlitzPlus 1.34
"Blitz Runtime Class" ; <- Blitz3D

Hope you find it useful,
Sergio. [/i]

Code :
Code: BlitzBasic
  1. ;FindWindow without class name demo
  2. ;by Sergio - semar
  3.  
  4. title$ = "myblitzapp"
  5. AppTitle title
  6. Print "handle of " + title + " = " + findwindow(title)
  7. WaitKey
  8. End
  9.  
  10. ;===============================
  11. Function findwindow(name$)
  12. ;===============================
  13. ;api_FindWindow% (lpClassName$, lpWindowName$)
  14. ;api_FindWindow_0% (lpClassName%, lpWindowName$)
  15. ;
  16. ;method 1:
  17. ;passing a null value
  18.  
  19. method = 1 ;change to method 2 but check the class name first !
  20.  
  21. If method = 1 Then
  22. hwnd% =  api_FindWindow_0% (0,name)
  23. Else
  24.  
  25. ;method 2:
  26. ;passing a string value = class name
  27. ;the class name of a b3d application is: "Blitz Runtime Class"
  28.  
  29. class$ = "Blitz Runtime Class"
  30. hwnd% =  api_FindWindow% (class,name)
  31.  
  32. EndIf
  33.  
  34. Return hwnd
  35.  
  36. End Function


Comments :


jfk EO-11110(Posted 1+ years ago)

 btw. since version 1.89(?) of Blitz3D you can usehwnd=systemproperty$("AppHWND")


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal