GetNextWindow_() is not a function

Windows specific forum
rambodash
User
User
Posts: 23
Joined: Thu Jun 13, 2013 1:00 am

GetNextWindow_() is not a function

Post by rambodash »

I was trying to use win32 GetNextWindow_() but it says it isn't a function in PB 5.20 Are some win32 functions just not supported? Is there a way around so I can call it?

Code: Select all

DEFINE title$ = Space(100)
DEFINE hwnd.l = GetTopWindow_(GetDesktopWindow_())

REPEAT
  hwnd = GetNextWindow_(hwnd, #GW_HWNDNEXT)
  IF hwnd = #NULL : BREAK : ENDIF
  GetWindowText_(hwnd, @title$, len(title$))
  debug title$
FOREVER
rambodash
User
User
Posts: 23
Joined: Thu Jun 13, 2013 1:00 am

Re: GetNextWindow_() is not a function

Post by rambodash »

answering my own question. GetNextWindow is a macro: http://stackoverflow.com/questions/7982 ... indow-in-c
GetWindow needs to be used instead

working code:

Code: Select all

EnableExplicit
DEFINE title$ = Space(100)
DEFINE hwnd.l = GetTopWindow_(GetDesktopWindow_())

REPEAT
  hwnd = GetWindow_(hwnd, #GW_HWNDNEXT)
  IF hwnd = #Null : BREAK : ENDIF
  GetWindowText_(hwnd, @title$, GetWindowTextLength_(hwnd)+1)
  debug hwnd
  debug title$
FOREVER
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: GetNextWindow_() is not a function

Post by netmaestro »

It's true, macros aren't imported into PureBasic. You could make one of your own if you wanted to though.
Are some win32 functions just not supported?
You will run into the occasional API that isn't natively imported into PB and when that happens you must find your own way to make it available. You have two choices, both of which usually work but not always. These are: 1) OpenLibrary and 2) Import.

What follows is an example of the PrintWindow API, which is found in user32.dll but is not natively imported in PB. We use OpenLibrary to get it into our program. Note the commented Import block. This is normally another way to get the API into your program but - and this is why I chose it - not in this case. It does not reside in the user32.lib file that ships with PureBasic. So if you comment out the OpenLibrary block and uncomment the Import block, you will find it doesn't work. So the safest way to get an API that isn't natively imported is to get the function from the dll. Personally, I prefer Import as it's simpler and cleaner, but only if the command is going to be there.

Code: Select all

Prototype PrintWindow(hWnd, hDC, nFlags)
user32 = OpenLibrary(#PB_Any,  "user32.dll")
Global PrintWindow_.PrintWindow = GetFunction(user32, "PrintWindow")

; Import "user32.lib"
;   PrintWindow_(hwnd, hdc, flags) As "_PrintWindow@12"
; EndImport

hwnd = FindWindow_(0, "PureBasic 5.20 LTS (x86)") ; Change this to whatever the title of your IDE main window is
GetWindowRect_(hwnd, this.RECT)
w = this\right-this\left
h = this\bottom-this\top
CreateImage(0, w, h, 24)

hdc = StartDrawing(ImageOutput(0))
  PrintWindow_(hwnd, hdc, 0)
StopDrawing()

OpenWindow(0,0,0,512,512,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,0,0,ImageID(GrabImage(0,#PB_Any,0,0,512,512)))

Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
I can make the Import version work on my machine by selecting a different .lib file:

Code: Select all

Import "c:\program files\microsoft platform sdk\lib\user32.lib"
but I can't use the one that ships with PB.
BERESHEIT
Post Reply