Start the Control Panel in the application In the application, start the control panel in the application, just open the corresponding CPL file with the shellexecute function, for example to modify the Windows password in the application, just open the password.cpl file, start the ODBC Manager Just open odbccp32.cpl. Function declaration: Function Long ShellExecute (Long hwindow, String lpOperation, String lpFile, String lpParameters, String lpDirectory, Long nShowCmd) Library 'shell32.dll' Alias for ShellExecuteA Function Long GetDesktopWindow () Library 'user32.dll' script is as follows: String ls_cpl_nameString ls_null SetNull (ls_null) ls_cpl_name = "Password.cpl" ShellExecute (GetDesktopWindow (), ls_null, 'rundll32.exe', "shell32.dll, Control_RunDLL" ls_cpl_name ",", ls_null, 0)
-------------------------------------------------- ---- Data Type Conversion Table Microsoft PB (16bit) PB (32bit) Bool Boolean Boolean Byte, Char Char Charchar * Ref String Ref String ColorRef uint Ulong Double Double Double Double Double Double Double Double Double DoubLe uint Ulong hfile uint Ulong hinstance uint Ulong Hwnd uint Ulong Int Int Int Long Long Long Lparam uint Ulong Lpbyte Ref Int Ref Long Lpcwstr Ref Blob Ref Blob (Unicode use ToUnicode ()) Lpcvoid Ref String Ref String Lpdword Ref uint Ref Ulong Lpfiletime Ref Time ref Time Lpint ref Int ref Long Lpstr, Lpcstr ref String ref String Lpvoid ref Structstruct_inst ref Struct struct_instLpword ref Int ref Ulong Mcierror Long Long Pbyte ref Int [#] ref Long [#] Short Int Int Structure ref Struct struct_inst ref Struct Struct_instUint Uint Uint Void ** Subroutine Subroutineword Int Long WPARM uint Ulong
-------------------------------------------------- - Top the specified window to the top of the window Sometimes we need to use BringWindOWTotop to bring the specified window to the top of the window list. If it is partially or all hidden under other windows, the hidden section is displayed completely. But in some cases this function does not meet the effects we want, if a window is not part of the front application, then once the window calls this function, the window will take the window to the window of its own application. top. However, it will not make that application becomes a front desk application. This means that the window will remain hidden after calling this function. So how do you make your application a foreground application? We can use the SetForegroundWindow function. For example: FUNCTION long FindWindowA (ulong Winhandle, string wintitle) Library "user32" FUNCTION ulong SetForegroundWindow (ulong hwnd) LIBRARY "user32.dll" long ll_winhandle ll_winhandle = FindWindowA (0, "test") if ll_winhandle> 0 then SetForegroundWindow (ll_winhandle) End IF ------------------------------------------------ ---------- Switch in the program Declaration: Function Boolean Immsimulatehotkey (Ulong Hwnd, Ulong DwhotKeyid) library "imm32.dll" function ulong getKeyboardLayout (Ulong dwlayout) library "user32.dll" function boolean ImmIsIME (uLong hklKeyboardLayout) library "iMM32.DLL" script as follows: constant int IME_THotKey_IME_NonIME_Toggle = 112 ulong hklCurrent ulong hnd // switch to the English input method hklCurrent = GetKeyboardLayout (0) if ImmIsIME (hklCurrent) then hnd = Handle (parent) ImmSimulateHotKey (hnd, IME_THotKey_IME_NonIME_Toggle) end if // switch to Chinese input method hklCurrent = GetKeyboardLayout (0) if not ImmIsIME (hklCurrent) then hnd = Handle (parent) ImmSimulateHotKey (hnd, IME_THotKey_IME_NonIME_Toggle) end if
-------------------------------------------------- --------------- Use the exitwindowex shutdown system to facilitate users, sometimes you need to add exit and turn off your computer in your application, in fact, as long as you can implement a few lines of code. First, declare the API function: Function Long ExitWindowSex (long uflags, long dwreserved) library "user32" then calls: EXITWINDOWEX (1, 0) Parameter type and instructions: uflags long, specify one or more signs (with Or The operation is compliant to join together) EWX_FORCE Forced to stop the process EWX_LOGOFF abort process without the response, then log out of EWX_SHUTDOWN turns off the system power supply (if possible, the ATX power can be) EWX_REBOOT Reboot System EWX_SHUTDOWN Close the system dwreserved long, keep, set to zero - -------------------------------------------------- ---------- WinHelpA function display with Pop-Up help First, go to the Window painter and select Declare, Global External functions from the menu Paste this declaration:. fUNCTION integer WinHelpA (long hWnd, string lpHelpFile, integer wCommand, integer dwData) LIBRARY "User32.dll" This tells PowerBuilder how to call a function that resides in a DLL. Next, you create a help file with indexed topics using a tool like Doc-to-help or RoboHelp. Here's the Code You Would Put in Some Event That Corresponds To The User Hitting F1, or Whate: WinHelpa (Handle (PARENT), "Application.hlp", 8, 1) This Example Comes from A Control ON A Window. The First Parameter Gets A Handl e to the window, which is the control's parent. "Application.hlp" IS Your Help file. The number "8" TELLS The Function To Display The Yellow Context-Sensitive Help.The Last Parameter, A "1" in this Example, Means Topic Number 1.
-------------------------------------------------- ---------- show / Hide windows taskbar first declare an external function as follows: function long FindWindowExA & (long hWnd, long hWndChild, ref string lpszClassName, & ref string lpszWindow) library 'user32'Function long ShowWindow & (long hWnd, long nCmdShow) library 'user32' add the following in the Script: Constant Long SW_HIDE = 0Constant Long SW_NORMAL = 1Constant Long SW_SHOWMINIMIZED = 2 Constant Long SW_SHOWMAXIMIZED = 3 Constant Long SW_SHOWNOACTIVATE = 4Constant Long SW_SHOW = 5 Constant Long SW_MINIMIZE = 6 Constant Long SW_SHOWMINNOACTIVE = 7Constant Long SW_SHOWNA = 8 Constant Long SW_RESTORE = 9Constant Long SW_SHOWDEFAULT = 10String ls_ShellTaskBarWnd = "Shell_TrayWnd" String ls_isnull Long ll_HTaskBar, ll_HDeskTop ll_HTaskBar = FindWindowExA (0, 0, ls_ShellTaskBarWnd, ls_Null) ShowWindow (ll_HTaskBar, SW_HIDE) MessageBox ( ' Pause ',' can you see taskbar? ') Ll_htaskbar = findwindowexa (0, 0, ls_shelltaskbarwnd, ls_null) showWindow (ll_htaskbar, sw_show) --------------------- ----- ------------------- Windows style About dialog box uses the API function shelLabouta to display a ABOUT dialog that is consistent with Windows * as a system style. First, the following statement external function: function int ShellAboutA (ulong al_hWnd, string as_szApp, & string as_szOtherStuff, ulong hIcon) library "shell32" Script as follows: ShellAboutA (handle (parent), "Window Title # more text", & "Still more text ", 0) where: Window Title Window Title More Text Still More Text Your Description
-------------------------------------------------- ------ Get the Windows System Directory Sometimes you need to use the Windows system directory in your application, you can implement it with the getWindowsDirectory function. First, the following statement external function: Function uint GetWindowsDirectoryA (& ref string dirtext, uint textlen) & library "KERNEL32.DLL" Script follows: String ls_WinPath ls_WinPath = Space (128) GetWindowsDirectoryA (ls_WinPath, 128) -------- -------------------------------------------------- --- limit the application to run only once 1. declare external functions as follows: fUNCTION uLong ShowWindow (ulong winhandle, int wincommand) Library "user32" fUNCTION uLong BringWindowToTop (ulong HWND) Library "user32" fUNCTION long FindWindowA (ulong winhandle, string wintitle ) Library "User32" 2. Create a window 'w_test'. Set the title to "Test Window". Add the following code in the Application's Open event: long ll_winhandle ll_winhandle = findwindowa (0, "test window) if ll_winhandle > 0 THENBRINGWINDOWTOP (LL_WinHandle) showwindow (ll_winhandle, 5) Returnend IF Open (w_test)
-------------------------------------------------- -------- Transfer long file name to Short message name 1. Declare the external function as follows: Function Long GetshortPathNamea (String LPLONG, REF STRING LPSHORT, long lbuff) library 'kernel32'2. Define function f_convert (string as_long ), The function code is as follows: string ls_bufferlong ll_rc ls_buffer = space (255) LL_RC = GetshortPathNamea (as_long, ls_buffer, 255) Return Ls_buffer
-------------------------------------------------- ------------- Use the animated mouse pointer although not mentioned in the help of PB, you can actually use the animated mouse pointer, just specify the path and file name, For example: ST_1.Pointer = "C: /Windows/cursor/Hourglas.ani" In the Response window, the response window cannot be placed directly to Menu, but we can implement it through the script, add: this in the OPEN event of the window: .changemenu (m_test)
-------------------------------------------------- ---------- The mode running the application runs the following script: handle (getApplication ()), if you return 0, the application is running in the development mode, otherwise running the compiled EXE file --- -------------------------------------------------- ---------------- The control in the moving window is written in the following scripts in the MouseDown event: Send (Handle (THIS), 274, 61458 0) If the control does not have a mousedown event, the definition event is as follows: UE_MOUSEDOWN PBM_LButtondown Write the above code in the MouseDown event of the window, and then press the left mouse button in any place in the window customer area to drag the window.
-------------------------------------------------- -------------------------- Capture Control Menu CLOSE Event Users Press the CLOSE button in the Control Menu (Window Top Level) Close the window The PBM_SYSCOMMAND event is triggered, and the definition event is as follows: UE_close PBM_SYSCOMMAND Add to code in the event: if message.wordparm = 61536 Then MessageBox ("", "Window will be closed") Endiff
-------------------------------------------------- ----------------------------- Use DWSYNTAX to get color values Sometimes we need to use color values directly in the script, how to get? Open DWSYNTAX, click the 'RGB' button, select "OK" after selecting the colors you want, and "Paste" in the Script window, OK!
-------------------------------------------------- --------------------- In most applications in PowerBuilder, the UNDO feature is available in most applications in PowerBuilder, and undo () can also be used in PowerBuilder. The function implements this feature. The undo () function can be used in DataWindow, EditMask, MultilineEdit, RichtextEdit, and SingLineEdit objects. If only an object is Undo *, simply use the following script in the UNDO menu item: Objectname.undo (), but When there are multiple objects in the window, we don't know which object to perform undo () * when writing scripts, how to solve this problem? In PowerBuilder, the Undo () and other functions can only be used for visual objects, while all visual objects are inherited from the system object class GraphicObject. So we can define an instance variable go_object of a GraphicObject object, wait until running with the getFocus () function to determine the specific * object. Then () function to determine the type of the current object with the Typeof, then Choose case statements refer to different types of instance variables depending on the code is as follows: graphicobject go_object DataWindow dw_object EditMask em_object MultiLineEdit mle_object RichTextEdit rte_object SingleLineEdit sle_object go_object = getfocus () choose case TypeOf (go_object) case DataWindow! dw_object = go_object dw_object.undo () case EditMask! em_object = go_object em_object.undo () case MultiLineEdit! mle_object = go_object mle_object.undo () case RichTextEdit! rte_object = go_object rte_object.undo () case SingleLineEdit! SLE_OBJECT = Go_Object SLE_OBJECT.UNDO () Case Else MessageBox ("Error", "CAN NOTO") End Choose In fact, we can simply solve this problem with dynamic call functions (only three lines of code), that is, graphicobject Object calls the undo () function, and then add keyword Dynamic before the function name. Because the object class graphicobject does not have undo () object functions, if you do not add keyword Dynamic, there will be an error when compiling. Using Dynamic keywords, PowerBuilder does not check the function and the validity of the function and the parameters used, and check the function when it is running. The code is as follows: GraphicObject Go_Object Go_Object = getFocus () Go_Object.dynamic undo () allows the dynamic call function to be one of the features of PowerBuilder 5.0. The method of flexibly uses dynamic function calls in programming helps improve the maintenanceability and reusability of the designed program. The above procedures run in Powerbuileer 5.0, and Window95 environments.
-------------------------------------------------- -------- How to call the data pipe in Script First open the PIPE panel, define the source database, source table, target database, target table, and place the name of the reputation, in this case, PIPE name PIPE_SAMPLE. Open the User Object Drawboard, define a user object, inherit the self-system object Pipeline, and define the following instance variable in this object: StaticText Read StaticText Written StaticText Error These three variables are used to record the number of rows read at the time of execution of the data pipeline The number of lines written, the number of rows of errors occur. Write the following statement in the PIPEMETER event of the user object: read.text = string (ROWSREAD) Written.Text = String (RowsWritten) Error.Text = String (RowsineError) then name the storage, in this case U_PIPE_SAMPLE . Open the window drawing board, create a window, place a data window object and three static text objects in this window, named DW_1, ST_READ, ST_WRITTEN, ST_ERROR, this data window is used to record the error message that occurred during the pipe execution. Don't specify the data window for the data window object. The following instance variable is defined in this window: Transaction I_SRC, I_DSTU_PIPE_SAMPLE I_PIPE Writes in the window of the OPEN event: i_src = create transaction i_src.dbms = 'odbc' i_src.dbparm = "ConnectString = 'DSN = Database name"; UID = username; PWD = password "connect us" i_src; if i_src.sqlcode <> 0 THEN MessageBox ("Source Database Connection Error", i_Src.sqlerrtext) Return End if i_dst = Create Transaction i_dst.dbms = 'ODBC' I_DST. DBPARM = "ConnectString = 'DSN = Database name"; UID = username; pwd = password "connect us i_dst; if i_dst; if i_dst.sqlcode <> 0 THEN MessageBox (" Target Database Connection Error ", i_dst.sqlerrtext) Returnend IF in Window placing a button to run the data pipeline, the following statement is written in this button's Clicked event: i_pipe = create u_pipe_sample i_pipe.read = st_read i_pipe.written = st_written i_pipe.error = st_error i_pipe.dataobject = "Pipe_Sample" // Execute Pipe i_pipe.start (i_SRC, I_DST, DW_1)
-------------------------------------------------- -------------------- How to implement the column in DataWindow We often encounter a column when using DataWindow during the development of PowerBuilder applications. The data is too long and cannot be displayed simultaneously. If the automatic horizontal scroll is used, * is not easy enough. Introduce a method to implement multi-line display, that is, realize the automatic folding of column data. The specific steps are as follows : 1) Open this DataWindow. 2 in DataWindow Painter to double-click the mouse on the column that needs to be set, bounce back this column. 3) Select the Position tab, select the autosize height multi-selection box. 4) Select Edit label, not selecting the Auto Horz Scroll Multival. 5) Click the OK button to save the modified modification. 6) Point Detail Band (ie, write a gray long belt with Detail), right-click, select Properties. .. Menu item. 7) Select AutoSize Height Multival. 8) Click the OK button to save your modifications. 9) Save this dataWindow. Note: Connect the Chinese characters (there is no punctuation or space separation in the middle), system Will be considered a word without automatic folding. Restriction application only Run a key: showwindow, bringwindow, and findwindow API functions
1. Statement the external function as follows:
FUNCTION boolean ShowWindow (ulong winhandle, & int wincommand) Library "user32" FUNCTION boolean BringWindowToTop (ulong HWND) & Library "user32" FUNCTION long FindWindowA (ulong Winhandle, & string wintitle) Library "user32" 2. Create a window 'w_test' Set the title to "Test Window".
3. Add the following code in the Open event of Application:
Long ll_winhandle
LL_WinHandle = FINDWINDOWA (0, "Test Window")
IF ll_winhandle> 0 THEN
BringWindowTotop (ll_winhandle)
ShowWindow (LL_WinHandle, 5)
Return
END IF
Open (w_test)