|
||||||||||||||||||||||||||
|
32 Bit - Windows API Calls for PowerBuilder
Document:
The following information lists the PowerBuilder syntax for calling Windows API functions. Also included is the PowerBuilder script needed to make the function call. If you would like an example of these API calls the sample pbl is located on the Powersoft FTP server. The file can be downloaded from: NOTE: Any function that requires a NULL will fail in v5.0.03 due to a problem in the way that version handles nulls. You'll want to move to v5.0.04 or go back to v5.0.02 or before. These API calls are only a subset of all the API calls available. For a more complete listing of API calls you can consult the windows SDK helpfile which is named either win32.hlp or win32sdk.hlp(depending on what compiler the SDK has been installed from). If you install the C++ Class Builder this help file will be installed for you. Technote #44648 can assist you with the function declaration of the API call from powerscript. The following API calls are referenced in this document: Arc( ) This function draws an arc based on the coordinates the function receives. There is no PowerBuilder equivalent. 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( ) The Beep function causes the system to make an internal beep sound. This is identical to the PowerBuilder function Beep( ). 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( ) The BringWindowToTop function sends a message to the target window telling it to come to the foreground. The PowerBuilder equivalent is limited to PowerBuilder Windows only, the script is as follows: <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( ) A Chord is a region bounded by the intersection of an ellipse and a line segment. This function draws a chord based on the coordinates the function receives. There are no PowerBuilder equivalents. 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( ) The CloseHandle function releases an open object handle. The closest PowerBuilder equivalent is the function Destroy, but it is only used with PowerBuilder created objects. 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 = FindWindowA(0, ls_wname) // Usually you would already have the handle. rtn = CloseHandle(l_handle) CloseWindow( ) This function does not close a window as one might think. CloseWindow minimizes the window that is targeted. The closest PowerBuilder equivalent is the WindowState command, but this is limited to PB windows only. The syntax in PowerBuilder is as follows: <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( ) This function copies a file by taking the source and destination names as a string by reference. If the flag is set to true the file will not overwrite an existing file, if set to false it will overwrite an existing file. There is no PowerBuilder equivalent. 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:\pwrs\pb5i32\ex\code\beach.bmp" l_to = "c:\test.bmp" rtn = CopyFileA(l_from, l_to, l_flag) MessageBox("CopyFile", string(rtn)) CreateDirectoryA( ) This function create a new directory folder under the current directory, which under PowerBuilder would be 'c:\pwrs\pb5i32' if you installed shortnames. The second argument is exclusively used by NT and can be ignored under Win95. There is no PowerBuilder equivalent. 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( ) This function receives a string by reference containing a fully path qualified filename and deletes that file. There is no PowerBuilder equivalent. 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( ) The DeleteMenu function deletes an item from the specified menu. If the menu item opens a menu or submenu, this function destroys the handle to the menu or submenu and frees the memory used by the menu or submenu. 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( ) This function sends a destroy message to the targeted window. The closest PowerBuilder equivalent is Close(<window>), but this is limited to PB windows only. 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( ) This function triggers an OCX to self-register. This function when called from the constructor event of an application allows a PB application to dynamically register an OCX on the machine it is run on. There is no PowerBuilder equivalent. Global External Function: FUNCTION long DllRegisterServer() LIBRARY "c:\windows\ocxname.ocx" Script: Long ll_rtn ll_rtn = DllRegisterServer() //Note: A return code of zero most likely means the OCX is already registered. Ellipse( ) An Ellipse function draws a circular object based on the coordinates the function receives. There is no PowerBuilder equivalent. 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( ) This function sends a call to the Windows OS telling it to shut down. This function is especially good for increasing the security of your application. There is no PowerBuilder equivalent. 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( ) This function abruptly stops an application from running. As a result, nothing gets closed properly and objects are left hanging in memory. This function will produce a GPF the moment it is called and you will need to reboot. FatalExit is meant to be used for debugging purposes and is not recommended otherwise. There is no PowerBuilder equivalent. 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( ) This function gets the handle any window that is called by name. A common pitfall is to make a call with the window's save name rather than the name that appears in the title bar, i.e. "Microsoft Word - api32.doc" . The PowerBuilder equivalent is the function Handle( ), but it is limited to PB windows only. 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( ) This function releases a dll from active memory. This function works in conjunction with LoadLibraryA( ) function. There is no PowerBuilder equivalent. 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( ) This function returns the background color reference number of the window targeted. The PowerBuilder equivalent is as follows: 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( ) This function returns the computer's name into a string by reference. Be sure to allocate enough space for the string or you'll get a GPF when you exit PowerBuilder. There is no PowerBuilder equivalent. 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( ) This function returns the class name of any object or window whose handle it receives. Be sure to allocate enough space for the string or you'll get a GPF when you exit PowerBuilder. There is no PowerBuilder equivalent to this function. 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( ) This function returns the current working directory into a string by reference. Be sure to allocate enough space for the string or you'll get a GPF when you exit PowerBuilder. There is no PowerBuilder equivalent. 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( ) This function returns the current thread's handle. There is no PowerBuilder equivalent. Global External Function: FUNCTION ulong GetCurrentThread() LIBRARY "Kernel32.dll" Script: ulong rtn rtn = GetCurrentThread() MessageBox("Current Thread Handle", string(rtn)) GetCursor( ) This function returns a handle of the cursor. There is no PowerBuilder equivalent. Global External Function: FUNCTION ulong GetCursor( ) LIBRARY "User32.dll" Script: ulong l_cursor l_cursor = GetCursor( ) GetCursorPos( ) & SetCursorPos( ) This function returns the x and y position of the cursor into a structure. SetCursorPos moves the cursor to the coordinates it receives. There is no PowerBuilder equivalent. 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( ) The first function returns the present state of every key on the keyboard into an array of 256 integers based on the characters ASCII representation. The second function sets the keyboard to the state given in the array. A zero value represents that the key is not pressed. There is no PowerBuilder equivalent. 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( ) This function returns the present state of a specific key on the keyboard based on that key's ASCII representation. A zero value represents that the key is not pressed. There is no PowerBuilder equivalent. 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( ) This function returns the handle of a module or dll that is in active memory. The function FreeLibrary works directly with this function in releasing the dll from memory based on the handle that this function returns. There is no PowerBuilder equivalent. Global External Function: Function long GetModuleHandleA(string modname) Library "Kernel32.dll" Script: ulong rtn rtn = GetModuleHandleA("User32.dll") MessageBox("Return Code", string(rtn)) GetParent( ) This function receives the handle of a child and returns the handle of its parent. The PowerBuilder function 'GetParent' is identical. The PB syntax is as follows: 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( ) The first function returns the color of a specific pixel. The SetPixel function changes the targeted pixel to the color sent. There is no PowerBuilder equivalent. 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( ) This function allows the application to access the system or window menu for copying and modifying. There is no PowerBuilder equivalent.
Последнее обновление: 11.08.2016 |
|
||||||||||||||||||||||||
(c)2002-2025 Ikar Ikar Home Center ICQ: 167220388 | ||||||||||||||||||||||||||
На сайте могут быть опубликованы рекламные материалы и ссылки. Всю ответственность за содержание рекламных материалов, текстов ссылок и контент рекламируемых сайтов несет рекламодатель. |