Page 1 of 1

Example 9: Using Windows API

PostPosted: Wed Oct 30, 2013 2:03 pm
by David de Argentina
ThinBasic is capable to call API services directly into the tBasic Program.

In order to use this services, you must declare the functions you will use.

There are 2 ways to declare the functions:

a) Declaring them directly into the .tBasic program like:

Code: Select all
DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hWnd AS DWORD, lpText AS ASCIIZ, lpCaption AS ASCIIZ, BYVAL dwType AS DWORD) AS LONG


b) Using an include file that has all the API Functions:
You need to inform to the .tBasic program you will use this services using this line:

Code: Select all
#Include "Win32API.inc"


or

Code: Select all
#Include "RichEdit.inc"


Or something like this, according what API you will use

All the include files are in this link:

https://app.box.com/s/eradrsfxf2h4t2l0g14u

Unzip this files into the \inc Folder

Example of use:

a) Declaring the function directly into the .tBasic program

Code: Select all
' Function Declaration
DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hWnd AS DWORD, lpText AS ASCIIZ, lpCaption AS ASCIIZ, BYVAL dwType AS DWORD) AS LONG

' Possible icon styles: change as you need
' %MB_ICONHAND                  = &H00000010&
' %MB_ICONQUESTION              = &H00000020&
' %MB_ICONEXCLAMATION           = &H00000030&
' %MB_ICONASTERISK              = &H00000040&

' Execution
MessageBox (0,"Hello World!, hello NeoBook!, hello thinBasic!", "Welcome message", %MB_ICONASTERISK )


b: Including the Win32API.inc into the tBasic program ( the win32API.inc file is into the \inc folder )

Code: Select all
' Include Declaration
#Include "Win32API.inc"

' Possible icon styles: change as you need
' %MB_ICONHAND                  = &H00000010&
' %MB_ICONQUESTION              = &H00000020&
' %MB_ICONEXCLAMATION           = &H00000030&
' %MB_ICONASTERISK              = &H00000040&

' Execution
MessageBox (0,"Hello World!, hello NeoBook!, hello thinBasic!", "Welcome message", %MB_ICONASTERISK )


Enjoy !