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.