ThaiPBL.com

PowerBuilder Library Thailand

อีเมล พิมพ์ PDF

รวบรวมบรรดา API ทั้งหลายเท่าที่หามาได้

รวบรวมบรรดา API ทั้งหลายเท่าที่หามาได้และที่สำคัญคือใช้กับ PB ได้ สามารถใช้ได้ตั้งกะ รุ่นที่ 4-6 นะครับ รุ่นสูงกว่านี้คงต้องนำไปทดลองเอาเองนะครับ
สำหรับรายชื่อของ API ทั้งหลายก็มีดังตารางนี่เลยครับ
Arc GetCurrentDirectoryA Mouse_Event
Beep GetCurrentThread MoveToEx
BringWindowToTop GetCursor MoveWindow
Chord GetCursorPos Pie
CloseHandle GetDC Polygon
CloseWindow GetKeyboardState PostMessageA
CopyFileA GetKeyState Rectangle
CreateDirectoryA GetModuleHandleA ReleaseCapture
DeleteFileA GetParent SetCapture
DeleteMenu GetPixel SetComputerNameA
DestroyWindow GetSystemTime SetCurrentDirectoryA
DllRegisterServer GetSystemMenu SetCursorPos
Ellipse GetSystemMetrics SetFocus
ExitWindowsEx GetThreadPriority SetKeyboardState
FatalExit GetUserNameA SetPixel
FindWindowA GetWindowsDirectoryA Sleep
FreeLibrary GlobalMemoryStatus SndPlaySoundA
GetBkColor LineTo SwapMouseButton
GetCapture LoadLibraryA WaveOutGetNumDevs
GetComputerNameA mciSendStringA WinExec
GetClassNameA MessageBoxA ...
ADDITIONS: GetVolumnInformationA ...

Arc( )
ฟังก์ชั่นนี้ใช้สำหรับวาดรูป วงกลม หรือ วงรีก็ได้ขึ้นอยู่กับการกำหนดตำแหน่ง
Global External Function:
FUNCTION boolean Arc(ulong hwnd, long r1, long r2, long r3, long r4, long a1, long a2, long a3, long a4) LIBRARY "Gdi32.dll"

Script:
Boolean rtn
ulong l_handle, l_device
long lv[8]
l_handle = handle(w_main) // 'w_main' is the name of the sample window.
l_device = GetDC(l_handle)
lv[ ] = {10,40,300,220,0,0,180,0}
rtn = Arc(l_device, lv[1], lv[2], lv[3], lv[4], lv[5], lv[6], lv[7], lv[8])


Beep( )
เป็น ฟังก์ชั่นที่ใช้ในการกำเนิดเสียง ซึ่งก็เหมือนกับคำสั่ง beep ใน PB

Global External Function:
FUNCTION boolean Beep(long freq,long dur) LIBRARY "Kernel32.dll"

Script:
Boolean rtn
Long ll_freq, ll_dur
ll_freq = 500
ll_dur = 20
rtn = Beep(ll_freq, ll_dur)


BringWindowToTop( )
เป็นการสั่งให้ windows control ตัวที่เราต้องการขึ้นมาอยู่บนสุดซึ่งก็คล้ายกับคำสั่ง
<window > .bringtotop = true

Global External Function:
FUNCTION boolean BringWindowToTop(ulong w_handle) LIBRARY "User32.dll"

Script:
Boolean rtn
ulong l_handle
l_handle = handle(w_win2)
rtn = BringWindowToTop(l_handle)


Chord( )
ฟังก์ชั่นนี้ก็เป็นส่วนหนึ่งของการวาดรูปเช่นเดียวกับ Arc แต่จะวาดเป็นลักษณะเหมือนกับเราตัดเอาส่วนหนึ่งของวงกลมออกมา งงไหม ถ้างง ลองดูตัวอย่างดีกว่า
Global External Function:
FUNCTION boolean Chord(ulong hwnd,long x1,long y1,long x2,long y2,long r1, long r2, long r3, long r4) LIBRARY "Gdi32.dll"

Script:
boolean rtn
ulong l_handle, l_device
long lv[8]
l_handle = handle(w_main)
l_device = GetDC(l_handle)
// This can be done in one line: i.e. l_device = GetDC(handle(w_main))
lv[ ] = {5,5,200,200,0,0,200,300}
rtn = Chord(l_device, lv[1], lv[2], lv[3], lv[4], lv[5], lv[6], lv[7], lv[8])


CloseHandle( )
ก็เป็นการยกเลิกการ handle ที่เรากำหนดขึ้นมาด้วยคำสั่ง handle คล้ายๆกับคำสั่ง destroy ของ pb นั่นแหละครับ

Global External Function:
FUNCTION boolean CloseHandle(ulong w_handle) LIBRARY "Kernel32.dll"

Script:
boolean rtn
ulong l_handle
string ls_wname
ls_wname = "<Window Title>"
l_handle = A(0, ls_wname) // Usually you would already have the handle.
rtn = CloseHandle(l_handle)


CloseWindow( )
คำสั่งนี้จะเป็นการ ย่อหน้าต่างตัวที่เรากำหนดลงไปใว้ที่  taskbar ด้านล่าง โดยเราต้องกำหนดชื่อ title ของวินโดวส์ตัวที่เราต้องการให้ถูกต้องด้วย ซึ่งถ้าเราใช้คำสั่งของ pb ก็คือ
<window>.WindowState = Minimized!

Global External Function:
FUNCTION boolean CloseWindow(ulong w_handle) LIBRARY "User32.dll"

Script:
boolean rtn
ulong l_handle
string ls_wname
ls_wname = "<Window Title>"
l_handle = FindWindowA(0, ls_wname) // Be sure to use the exact title of the window you are targeting.
rtn = CloseWindow(l_handle)


CopyFileA( )
ฟังก์ชั่นนี้จะทำการ copy ไฟล์จากต้นทางที่เรากำหนดไปยังปลายทางที่เรากำหนด ถ้าหากว่าเรากำหนด flag ให้เป็น true ก็จะไม่มีการเขียนทับลงไฟล์เดิมที่มีอยู่แล้ว

Global External Function:
FUNCTION boolean CopyFileA(ref string cfrom, ref string cto, boolean flag) LIBRARY "Kernel32.dll"

Script:
string l_from, l_to
boolean l_flag, rtn
l_flag = false
l_from = "c:pwrspb5i32excodeeach.bmp"
l_to = "c: est.bmp"
rtn = CopyFileA(l_from, l_to, l_flag)
MessageBox("CopyFile", string(rtn))


CreateDirectoryA( )
เป็นการสร้าง ไดเรคตอรี่ใหม่ภายใต้ ไดเรคตอรี่ ปัจจุบัน

Global External Function:
FUNCTION boolean CreateDirectoryA(ref string pathname, int sa) LIBRARY "Kernel32.dll"

Script:
boolean rtn
string l_dir
l_dir = "API Demo"
rtn = CreateDirectoryA(l_dir, 0)
If rtn then
MessageBox("New Directory Created", "API Demo directory is located under pwrs.")
else
MessageBox("CreateDirectory", "Failed")
end if


DeleteFileA( )
เป็นฟังก์ชั่นที่ใช้ลบไฟล์ ตามที่เราต้องการ

Global External Function:
FUNCTION boolean DeleteFileA(ref string filename) LIBRARY "Kernel32.dll"

Script:
string l_file
boolean rtn
l_file = string(sle_to.text)
rtn = DeleteFileA(l_file)
MessageBox("DeleteFile", string(rtn))


DeleteMenu( )
คำสั่งนี้จะทำการลบหัวข้อในเมนูที่เรากำหนด ถ้าหากว่าเมนูถูกเปิดอยู่ ก็จะมีการยกเลิก handle ก่อน

Global External Function:
FUNCTION boolean DeleteMenu(ulong mhand, uint upos, uint flag) LIBRARY "user32.dll"

Script:
ulong m_handle
boolean rtn
m_handle = GetSystemMenu(handle(w_main), false) // Need to get the handle of the system menu first.
rtn = DeleteMenu(m_handle, 1, 0) // The second argument, the '1', refers to the position in the menu.
Messagebox("Return Code", string(m_handle))
Messagebox("Return Code", string(rtn))


DestroyWindow( )
ก็เหมือนกับคำสั่ง close( ) ของตัว pb แหละครับ คือจะทำการปิด windows ตัวที่เราต้องการ

Global External Function:
FUNCTION boolean DestroyWindow(ulong w_handle) LIBRARY "USER32.DLL"

Script:
boolean rtn
ulong l_handle
open(w_win2) // Open a test window
l_handle = handle(w_win2)
rtn = DestroyWindow(l_handle)

DllRegisterServer( )
ฟังก์ชั่นนี้จะทำการลงทะเบียน OCX เพื่อให้โปรแกรมสามารถใช้งาน OCX ได้ เราสามารถที่จะเขียนสคริปต์นี้ใว้ที่ constructor event  เพื่อที่จะทำให้โปรแกรมติดตั้ง OCX ลงไปในเครื่องที่เรานำโปรแกรมไปลงซึ่งอาจจะยังไม่ได้ติดตั้ง OCX เอาใว้และจะทำให้เกิดการหา OCX ไม่เจอ

Global External Function:
FUNCTION long DllRegisterServer() LIBRARY "c:windowsocxname.ocx"

Script:
Long ll_rtn
ll_rtn = DllRegisterServer()

ถ้า ll_rtn มีค่าเป็น 0 แสดงว่ามีการลงทะเบียนใว้แล้ว


( )Ellipse
เป็นคำสั่งวาดวงกลมตามขอบเขตที่เรากำหนดลงไปให้กับตัวฟังก์ชั่น

Global External Function:
FUNCTION boolean Ellipse(ulong hwnd,long x1,long y1,long x2,long y2) LIBRARY "Gdi32.dll"

Script:
Boolean rtn
ulong l_handle, l_device
long lv[4]
l_handle = handle(w_main)
l_device = GetDC(l_handle)
lv[ ] = {5,5,300,300}
rtn = Ellipse(l_device, lv[1], lv[2], lv[3], lv[4])


ExitWindowsEx( )
เป็นคำสั่งที่สั่งให้ OS ทำการ ชัตดาวน์ระบบ

Global External Function:
FUNCTION boolean ExitWindowsEx(uint dwReserved, uint uReserved) LIBRARY "User32.dll"

Script:
boolean rtn
rtn = ExitWindowsEx(0,0) // Zero's tell it to shut down immediately.


FatalExit( )
ฟังก์ชั่นนี้จะหยุดการทำงานของโปรแกรม และอาจทำให้เกิด GPF ขึ้นและจ้องทำการ รีบูทระบบ

Global External Function:
SUBROUTINE FatalExit(int exitcode) LIBRARY "Kernel32.dll"

Script:
int rtn
rtn = MessageBox("This API call is suppose to produce a GPF!","Are You Sure?", Exclamation!, YesNo!,2)
If rtn = 1 Then
MessageBox("Final Notice!","You will have to reboot after this API call!")
FatalExit(1)
End If


FindWindowA( )
จะคล้ายๆกับ handle( ) ของตัว pb เป็นการหาตัววินโดวส์ที่เปิดอยู่ โดยการกำหนดชื่อ title ของตัว วินโดวส์ลงไป

Global External Function:
FUNCTION ulong FindWindowA(ulong classname,string windowname) LIBRARY "User32.dll"

Script:
ulong l_handle
string ls_wname
ls_wname = "<Window Title>" // i.e. "File Manager" or "Numbers.txt - NotePad"
l_handle = FindWindowA(0, ls_wname)


FreeLibrary( )
ทำการถอน dll ออกจาก เมโมรี่
. Warning: Unloading a dll that is being used will cause a GPF.

Global External Function:
SUBROUTINE FreeLibrary(ulong libhandle) LIBRARY "Kernel32.dll"

Script:
ulong modhandle // This would usually be an instance variable
modhandle = LoadLibrary("<32 bit dll filename>") // This would usually be done in another event.
FreeLibrary(modhandle)


GetBkColor( )
จะอ่านค่าของ background color ของวินโดวส์ที่เรากำหนด ใน pb เราก็สามารถอ่านค่านี้ได้โดย
ulong l_color
l_color = w_main.BackColor

Global External Function:
FUNCTION ulong GetBkColor (ulong hwnd) LIBRARY "Gdi32.dll"

Script:
ulong l_handle, l_device, l_color
l_handle = handle(w_main)
l_device = GetDC(l_handle)
l_color = GetBkColor(l_device)


GetCapture( )
This function returns the handle of the window that has captured the mouse. Keep in mind that the window receives mouse input regardless of where the cursor is positioned. This function, however, doesn't appear to do anything at all. (Maybe you'll have more luck with it.) There is no PowerBuilder equivalent.

Global External Function:
FUNCTION ulong GetCapture( ) LIBRARY "User32.dll"

Script:
ulong l_handle
l_handle = GetCapture( )


GetComputerNameA( )
ฟังก์ชั่นนี้จะอ่านชื่อของ คอมพิวเตอร์ ออกมาที่สำคัญอย่าลืมกำหนดขนาดความยาวของตัวแปรที่จะนำไปรับค่าให้พอด้วยมิเช่นนั้นอาจจะเกิด GPF ขึ้นได้

Global External Function:
FUNCTION boolean GetComputerNameA(ref string cname,ref long nbuf) LIBRARY "Kernel32.dll"

Script:
string ls_compname
long ll_buf
ll_buf = 25
ls_compname = space(ll_buf)
GetComputerNameA(ls_compname, ll_buf)
MessageBox("Computer name is:", ls_compname)


GetClassNameA( )
ฟังก์ชั่นนี้จะอ่านชื่อของ class name ของ object  ออกมาที่สำคัญอย่าลืมกำหนดขนาดความยาวของตัวแปรที่จะนำไปรับค่าให้พอด้วยมิเช่นนั้นอาจจะเกิด GPF ขึ้นได้


Global External Function:
Function long GetClassNameA(ulong hwnd, ref string cname, int buf) Library "User32.dll"

Script:
string l_class
long rtn
ulong l_handle
l_handle = handle(w_main)
l_class = space(50)
rtn = GetClassNameA(l_handle,l_class,50)
Messagebox("Classname", l_class)


GetCurrentDirectoryA( )
ฟังก์ชั่นนี้จะอ่านชื่อของ ไดเรคตอรี่ ออกมาที่สำคัญอย่าลืมกำหนดขนาดความยาวของตัวแปรที่จะนำไปรับค่าให้พอด้วยมิเช่นนั้นอาจจะเกิด GPF ขึ้นได้

Global External Function:
FUNCTION ulong GetCurrentDirectoryA(ulong BufferLen, ref string currentdir) LIBRARY "Kernel32.dll"

Script:
string ls_curdir
ulong l_buf
l_buf = 100
ls_curdir = space(l_buf)
GetCurrentDirectoryA(l_buf, ls_curdir)
MessageBox("Current Directory:", ls_curdir)


GetCurrentThread( )
ฟังก์ชั่นนี้จะคืนค่าของ thread's handle

Global External Function:
FUNCTION ulong GetCurrentThread() LIBRARY "Kernel32.dll"

Script:
ulong rtn
rtn = GetCurrentThread()
MessageBox("Current Thread Handle", string(rtn))


GetCursor( )
ฟังก์ชั่นนี้จะคืนค่า handle ของ cursor. 

Global External Function:
FUNCTION ulong GetCursor( ) LIBRARY "User32.dll"

Script:
ulong l_cursor
l_cursor = GetCursor( )


GetCursorPos( ) & SetCursorPos( )
ฟังก์ชั่นนี้จะคืนค่าของตำแหน่ง  x และ y ของ cursor โดยเก็บใว้ใน Structure. SetCursorPos จะย้ายตำแหน่งของ cursor ไปยังตำแหน่งที่ต้องการได้

Global External Function:
FUNCTION boolean GetCursorPos(ref mousepos mousepos2) LIBRARY "User32.dll"
FUNCTION boolean SetCursorPos(int cx, int cy) LIBRARY "User32.dll"

Structure: (Mousepos)
long xpos, long ypos

Script:
mousepos mouseloc
GetCursorPos(mouseloc)
Messagebox("Cursor Position", "X = " + string(mouseloc.xpos) + " Y = " + string(mouseloc.ypos))
SetCursorPos(300,350)
Messagebox("Cursor Position", "X = " + string(mouseloc.xpos) + " Y = " + string(mouseloc.ypos))


GetDC( )
This function returns the device context of the targeted window's handle that it receives. The device context is required if you wish to perform any graphical function calls. There is no PowerBuilder equivalent.

Global External Function:
Function ulong GetDC(ulong hwnd) library "user32.dll"

Script:
ulong l_handle, l_device
l_handle = handle(w_main)
l_device = GetDC(l_handle)
MessageBox("Handle", string(l_device))


GetKeyboardState( ) & SetKeyboardState( )
ฟังก์ชั่นแรกจะอ่านค่าของคีย์บอร์ดไปเก็บลง array ส่วนฟังก์ชั่นที่ 2 จะทำการกำหนดค่าให้กับคีย์บอร์ด

Global External Function:
FUNCTION boolean GetKeyboardState(ref integer kbarray[256]) LIBRARY "USER32.DLL"
FUNCTION boolean SetKeyboardState(ref integer kbarray[256]) LIBRARY "USER32.DLL"

Script:
//GetKeyboardState( )
boolean rtn
integer ipkey[256]
rtn = GetKeyboardState(ipkey)

//SetKeyboardState( )
rtn = SetKeyboardState(ipkey)
if rtn = false then
Messagebox("Failed","Something went wrong when loading into array")
else
Messagebox("Successful","Keyboard state is loaded back into buffer")
end if


GetKeyState( )
ฟังก์ชั่นจะคืนค่าของแป้นที่ถูกกด ถ้าเป็น 0 แสดงว่าไม่มีการกดคีย์บอร์ด

Global External Function:
Function int GetKeyState(integer VirtualKeycode) Library "User32.dll"

Script:
int rtn
rtn = GetKeyState(65) // 65 = A
if rtn = 0 then
MessageBox("Key State","Letter 'A' not pressed!")
else
MessageBox("Key State","Letter 'A' is pressed!")
end if


GetModuleHandleA( )
ฟังก์ชั่นนี้จะคืนค่า handle ของ  module หรือ dll ที่อยู่ในเมโมรี่
Global External Function:
Function long GetModuleHandleA(string modname) Library "Kernel32.dll"

Script:
ulong rtn
rtn = GetModuleHandleA("User32.dll")
MessageBox("Return Code", string(rtn))


GetParent( )
ฟังก์ชั่นนี้จะรับค่า handle ของ child และคืนค่า handle ของ parent. ถ้าใน PB ก็จะใช้  objectname.GetParent( )

Global External Function:
FUNCTION ulong GetParent(ulong hwnd) LIBRARY "User32.dll"

Script:
ulong l_handle, rtn
l_handle = handle(cb_getparent) // Command Button name
rtn = GetParent(l_handle)
Messagebox("GetParent", "Parent handle = " + string(rtn) + " / Child handle = " + string(l_handle))


GetPixel( ) & SetPixel( )
ฟังก์ชั่นแรกจะคืนค่าสีที่กำหนดใน Pixel. ฟังก์ชั่นที่สองจะกำหนดสีให้กับ Pixel
Global External Function:
FUNCTION ulong GetPixel(ulong hwnd, long xpos, long ypos) LIBRARY "Gdi32.dll"
FUNCTION ulong SetPixel(ulong hwnd, long xpos, long ypos, ulong pcol) LIBRARY "Gdi32.dll"

Script:
long lx, ly
ulong rtn
ulong l_handle, l_device
lx = 100
ly = 100
l_handle = handle(w_main)
l_device = GetDC(l_handle)
rtn = GetPixel(l_device, 100, 100)
MessageBox("Position " + string(lx) + "," + string(ly),"Color = " + string(rtn))
SetPixel(l_device, lx, ly, 0) // This call will set the pixel at lx, ly to black.


GetSystemMenu( )
ฟังก์ชั่นนี้จยอมให้ application ทำการเข้าถึง system or window menu เพื่อ copying และ modifying.
Global External Function:
FUNCTION boolean GetSystemMenu(ulong mhandle, boolean flag) LIBRARY "user32.dll"

Script:
boolean flag
ulong l_handle, m_handle
l_handle = handle(w_main)
flag = false
m_handle = GetSystemMenu(l_handle, flag)
Messagebox("Return Code", string(m_handle))


GetSystemTime( )
ฟังก์ชั่นจะอ่านค่าของเวลาในระบบมาเก็บลง structure

Global External Function:
SUBROUTINE GetSystemTime(ref systemtime systimeptr) Library "Kernel32.dll"

Structure: (SystemTime)
uint year, uint month, uint dayofweek, uint day, uint hour, uint minute, uint second, uint millisecond

Script:
systemtime s_systime
string l_day, l_date, l_time
GetSystemTime(s_systime)
l_date = string(s_systime.month) +"/"+ string(s_systime.day) &
+"/"+ string(s_systime.year)
l_time = string(s_systime.hour) +":"+ string(s_systime.minute) &
+":"+ string(s_systime.second) +":"+ string(s_systime.millisecond)
CHOOSE CASE s_systime.dayofweek
CASE 1
l_day = "Sunday"
CASE 2
l_day = "Monday"
CASE 3
l_day = "Tuesday"
CASE 4
l_day = "Wednesday"
CASE 5
l_day = "Thursday"
CASE 6
l_day = "Friday"
CASE 7
l_day = "Saturday"
END CHOOSE
Messagebox("System Time:",l_date + " " + l_day + " " + l_time)


GetThreadPriority( )
ฟังก์ชั่นจะคืนค่าของระดับ priority ของ thread. 

Global External Function:
FUNCTION int GetThreadPriority(ulong hthread) LIBRARY "Kernel32.dll"

Script:
ulong l_handle
integer rtn
l_handle = GetCurrentThread()
rtn = GetThreadPriority(l_handle)
MessageBox("Current Thread Priority", string(rtn))


GetSystemMetrics( )
ฟังก์ชั่นนี้จะรายงานถึงขนาดของความละเอียดหน้าจอที่ใช้งานอยู่

Global External Function:
FUNCTION int GetSystemMetrics(int indexnum) LIBRARY "user32.dll"

Script:
int l_xx, l_yy
l_xx = GetSystemMetrics(0)
l_yy = GetSystemMetrics(1)
Messagebox("Screen Resolution", string(l_xx) + " , " + string(l_yy))


GetUserNameA( )
ฟังก์ชั่นจะอ่านชื่อของ ผู้ใช้ที่ทำการ logon อยู่ อย่าลืมกำหนดความยาวของตัวแปรให้ยาวพอด้วยมิเช่นั้นอาจจะเกิด GPF ได้

Global External Function:
FUNCTION boolean GetUserNameA(ref string uname, ref ulong slength) LIBRARY "ADVAPI32.DLL"

Script:
string ls_username
string ls_var
ulong lu_val
boolean rtn
lu_val = 255
ls_username = Space( 255 )
rtn = GetUserNameA(ls_username, lu_val)
Messagebox("GetUserNameA", "Username = " + string(ls_username))


GetVolumnInformationA( )
ฟังก์ชั่นจะรายงาน รายละเอียดของ ฮาร์ดดิสก์

Global External Function:
FUNCTION boolean GetVolumeInformation(ref string lpRootPathName,ref string lpVolumeNameBuffer,ulong nVolumeNameSize,ref ulong lpVolumeSerialNumber,ref ulong lpMaximumComponentLength,ref ulong lpFileSystemFlags,ref string lpFileSystemNameBuffer,ulong nFileSystemNameSize) Library "kernel32.dll"

Script:
boolean rtn
string lprootpathname = "c:"
string lpVolumeNameBuffer = space(256)
ulong nVolumeNameSize = 256
ulong lpVolumeSerialNumber
ulong lpMaximumComponentLength
setnull(lpVolumeSerialNumber)
lpMaximumComponentLength = 256
ulong lpFileSystemFlags
setnull(lpFileSystemFlags)
string lpFileSystemNameBuffer = space(256)
ulong nFileSystemNameSize = 256

rtn = GetVolumeInformationA(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,&
lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags,&
lpFileSystemNameBuffer, nFileSystemNameSize)
sle_1.text = lprootpathname
sle_2.text = lpVolumeNameBuffer
sle_3.text = string(nVolumeNameSize)
sle_4.text = string(lpVolumeSerialNumber)
sle_5.text = string(lpMaximumComponentLength)
sle_6.text = string(lpFileSystemFlags)
sle_7.text = string(lpFileSystemNameBuffer)
sle_8.text = string(nFileSystemNameSize)


GetWindowsDirectoryA( )
ฟังก์ชั่นจะคืนค่าของ ไดเรคตอรี่เริ่มต้น อย่าลืมกำหนดความยาวของตัวแปรให้ยาวพอด้วยมิเช่นั้นอาจจะเกิด GPF ได้

Global External Function:
FUNCTION ulong GetWindowsDirectoryA(ref string wdir, ulong buf) LIBRARY "kernel32.dll"

Script:
ulong l_buf
string windir
l_buf = 144
windir = space(144)
GetWindowsDirectoryA(windir, l_buf)
MessageBox("Current Directory", windir)


GlobalMemoryStatus( )
ฟังก์ชั่นจะรายงาน รายละเอียดของเมโมรี่ลง structure

Global External Function:
SUBROUTINE GlobalMemoryStatus(ref memory mem2) LIBRARY "Kernel32.dll"

Structure: (Memory)
ulong m_length, ulong m_loaded, ulong m_totalphys, ulong m_availphys, ulong m_totalpagefile, ulong m_availpagefile, ulong m_totalvirtual, ulong m_availvirtual

Script:
memory sysmem
GlobalMemoryStatus(sysmem)
Messagebox("Memory Length", string(sysmem.m_length))
Messagebox("Memory Loaded", string(sysmem.m_loaded))
Messagebox("Total Physical Memory", string(sysmem.m_totalphys))
Messagebox("Total Available Memory", string(sysmem.m_availphys))
Messagebox("Total Page Size", string(sysmem.m_totalpagefile))
Messagebox("Available Page Size", string(sysmem.m_availpagefile))
Messagebox("Total Virtual Memory", string(sysmem.m_totalvirtual))
Messagebox("Available Virtual Memory", string(sysmem.m_availvirtual))


LoadLibraryA( )
ฟังก์ชั่นจะทำการโหลด uot;) // Pathing isn't necessary if dll is in dos search path.
If modhandle > 0 Then
MessageBox("Return Code", "Load Successful -> handle = " + string(modhandle))
else
MessageBox("Result","Unable to load module")
end if

mciSendStringA( )
ฟังก์ชั่นนี้จะทำการรันไฟล์  AVI โดยเรียกจาก ไลบราลี่ "winmm.dll".  

Global External Function:
FUNCTION long mciSendStringA(string cmd, REF string rtn, long size, long wnd) LIBRARY "winmm.dll"

Script:
string s_errortext
string filename
filename = "c:pwrspb5i32excodepbspin.avi"
mciSendStringA ("open "+Filename+" type AVIVideo alias test wait",s_errortext, 0,0)
mciSendStringA ("Window test handle " + string(handle(w_main)) + " wait",s_errortext, 0, 0)
mciSendStringA ("Put test destination wait",s_errortext, 0, 0)
mciSendStringA ("Play test wait", s_errortext, 0, 0)
mciSendStringA ("Close test", s_errortext, 0, 0)

MessageBoxA( )
ก็เหมือนกันกกับ messagebox ของ PB
Global External Function:
FUNCTION long MessageBoxA(ulong hwnd, ref string text, ref string title, ulong style) LIBRARY "User32.dll"

Script:
long rtn
ulong handle1, style1
string text1
string title1
handle1 = handle(parent)
text1 = "This is an API Messagebox"
title1 = "API MessageBox"
style1 = 0
rtn = MessageBoxA(handle1,text1,title1,style1)


Mouse_Event( )
เราสามารถจัดการกับเมาส์ได้โดยฟังก์ชั่นนี้เช่น สั้งย้ายตำแหน่งเมาส์ สั่งกดปุ่มเมาส์ โดยกำหนดค่าไปใน flag

Global External Function:
SUBROUTINE Mouse_Event(ulong dwflag,ulong dx,ulong dy,ulong cbutton,ulong dwextra) LIBRARY "User32.dll"

Structure: (Mousepos)
long xpos, long ypos

Script:
int l_loop, lx, ly, lflag
mousepos mouseloc
lx = mouseloc.xpos
ly = mouseloc.ypos
lflag = 1 //1 = do nothing, 7 = L-button clicked, 25 = R-button clicked
mouse_event(lflag,-80,-50,0,0)


MoveToEx( ) & LineTo( )
ทำการย้ายตำแหน่ง  ไปยังตำแหน่งที่เราต้องการ

Global External Function:
FUNCTION boolean MoveToEx(ulong hwnd,long wx, long wy,ref prepos prepos2) LIBRARY "Gdi32.dll"
FUNCTION boolean LineTo(ulong hwnd,long wx, long wy) LIBRARY "Gdi32.dll"

Structure: (Prepos)
long xpos, long ypos

Script:
ulong l_handle, l_device
prepos previouspos
l_handle = handle(w_main)
l_device = GetDC(l_handle)
MoveToEx(l_device,100,100,previouspos)
LineTo(l_device,200,200)


MoveWindow( )
ย้าย วินโดวส์ ที่เรากำหนดไปยังตำแหน่งที่ต้องการ

Global External Function:
FUNCTION boolean MoveWindow(ulong whand,int wx,int wy,int ww,int wh,boolean wflag) LIBRARY "user32.dll"

Script:
boolean rtn
ulong l_handle, l_device
l_handle = handle(w_main)
rtn = MoveWindow(l_handle,10,10,100,100,true)
MessageBox("Return Code",string(rtn))


Pie( )
ทำการวาด  pie chart 

Global External Function:
FUNCTION boolean Pie(ulong hwnd,long x1,long y1,long x2,long y2,long x3,long y3,long x4,long y4) LIBRARY "Gdi32.dll"

Script:
Boolean rtn
ulong l_handle,l_device
long lv[8]
lv[ ] = {10,50,290,220,0,0,80,0}
l_handle = handle(w_main)
l_device = GetDC(l_handle)
rtn = Pie(l_device,lv[1],lv[2],lv[3],lv[4],lv[5],lv[6],lv[7],lv[8])


Polygon( )
ทำการวาด  polygon 

Global External Function:
FUNCTION boolean Polygon(hdc, ref struct poly poly2, int cnt) LIBRARY "Gdi32.dll"

Structure: (Poly)
long xpos[5], long ypos[5] //The size of the array is proportional to the number of sides in the Polygon.

Script:
ulong l_handle, l_device
int pcnt
l_handle = handle(w_main)
l_device = GetDC(l_handle)
pcnt = 5
poly poly3
poly3.xpos[ ] = {50,100,150,200,250}
poly3.ypos[ ] = {50,100,150,200,250}
Polygon(l_device,poly3,pcnt)


PostMessageA( )
ฟังก์ชั่นจะส่งค่า เช่น  minimize หรือ  close

Global External Function:
FUNCTION boolean PostMessageA(ulong hwndle,UINT wmsg,ulong wParam,ulong lParam) Library "User32.dll"

Script:
ulong l_handle
boolean rtn
l_handle = handle(w_main)
rtn = PostMessageA(l_handle,274,61472,0) // 61472 = minimize, 61488 = maximize, 61728 = normal state


Rectangle( )
ทำการวาดรูปสี่เหลี่ยม

Global External Function:
FUNCTION boolean Rectangle(ulong hwnd,long x1,long y1,long x2,long y2) LIBRARY "Gdi32.dll"

Script:
Boolean rtn
ulong l_handle,l_device
long lv[4]
lv[ ] = { 10,10,275,215}
l_handle = handle(w_main)
l_device = GetDC(l_handle)
rtn = Rectangle(l_device,lv[1],lv[2],lv[3],lv[4])


SendMessageA( )
ฟังก์ชั่นจะส่งค่าออกไปเช่น Minimize หรือ  close และจะรอจน ค่า นั้นได้ถูกกระทำเรียบร้อยแล้วถึงจะได้ค่ากลับมา

Global External Function:
FUNCTION long SendMessageA(ulong hwndle,UINT wmsg,ulong wParam,ulong lParam) Library "User32.dll"

Script:
ulong l_handle
long rtn
l_handle = handle(w_main)
rtn = SendMessageA(l_handle,274,61728,0)


SetCapture( ) & ReleaseCapture( )
SetCapture function จะ locks controlของ mouse จนกว่าจะสั่งl ReleaseCapture( )

Global External Function:
FUNCTION ulong SetCapture(ulong a) LIBRARY "User32.dll"
FUNCTION boolean ReleaseCapture( ) LIBRARY "User32.dll"

Script:
boolean rtn
ulong l_loop, u_test, u_long
u_test = handle(parent)
u_long = SetCapture(u_test)
SetPointer(SizeNWSE!)
for l_loop = 1 to 150000
next
rtn = ReleaseCapture( )


SetComputerNameA( )
ทำการเปลี่ยนชื่อของ คอมพิวเตอร์

Global External Function:
FUNCTION boolean SetComputerNameA(ref string cname) LIBRARY "kernel32.dll"

Script:
boolean rtn
string l_name
l_name = "PowerBuilder"
rtn = SetComputerNameA(l_name)
if rtn then
MessageBox("Computer name changed to 'PowerBuilder'", "You'll need to reboot for it to take effect")
else
MessageBox("SetComputerName", "Failed")
end if


SetCurrentDirectoryA( )
ทำการเปลี่ยน ไดเรคตอรี่ปัจจุบัน

Global External Function:
FUNCTION boolean SetCurrentDirectoryA(ref string cdir) LIBRARY "kernel32.dll"

Script:
boolean rtn
string l_dir
l_dir = "c:My Documents"
rtn = SetCurrentDirectoryA(l_dir)
MessageBox("SetCurrentDirectory", string(rtn))


SetFocus( )
ทำการเปลี่ยนตำแหน่ง Focus ของ Object 

Global External Function:
SUBROUTINE SetFocus(long objhandle) LIBRARY "User32.dll"

Script:
SetFocus(handle(sle_1)) // This function gets the handle from PB.


SetThreadPriority( )
ทำการกำหนดระดับของ  thread.

Global External Function:
FUNCTION boolean SetThreadPriority(ulong hthread, int npriority) LIBRARY "Kernel32.dll"

Script:
ulong l_handle
boolean rtn
l_handle = GetCurrentThread()
rtn = SetThreadPriority(l_handle, 2) // Set the priority of thread higher.
MessageBox("Current Thread Priority Changed", string(rtn))


Sleep( )
เป็นฟังก์ชั่นที่สั่งให้ OS ละเว้นการกระทำกับ  current thread โดบมีหน่วยเป็น มิลลิวินาที
Global External Function:
SUBROUTINE Sleep(ulong milli) LIBRARY "Kernel32.dll"

Script:
ulong l_delay
l_delay = 2000
Sleep(l_delay)

SndPlaySoundA( ) & WaveOutGetNumDevs()
ทำการรัน WAV ไฟล์

Global External Function:
FUNCTION boolean SndPlaySoundA(string wavfile, uint flag) LIBRARY "WINMM.DLL"
FUNCTION uint WaveOutGetNumDevs() LIBRARY "WINMM.DLL"

Script:
uint lui_NumDevs, l_mode
string ls_file
l_mode = 0
ls_file = string(c:windowsmediachimes.wav)
lui_NumDevs = WaveOutGetNumDevs()
IF lui_NumDevs > 0 THEN
SndPlaySoundA(ls_file, l_mode)
END IF


SwapMouseButton( )
ทำการสลับการทำงานของปุ่มบนเมาส์
Global External Function:
FUNCTION boolean SwapMouseButton(boolean var) LIBRARY "User32.dll"

Script:
boolean rtn, l_mouse
rtn = SwapMouseButton(l_mouse)
If l_mouse = true Then
MessageBox("Change Made","Right button on Left Side")
Else
MessageBox("Change Made","Right button on Right Side")
End If


WinExec( )
เทียบง่ายๆก็คือคำสั่ง run นั่นเอง

Global External Function:
FUNCTION uint WinExec(ref string filename, uint wstyle) LIBRARY "kernel32.dll"

Script:
string ls_filename
uint rtn, wstyle
ls_filename = "c:windowscalc.exe"
wstyle = 1
rtn = WinExec(ls_filename, wstyle)
Messagebox("Return Code", string(rtn))