PowerBuilder API Application 10

zhaozj2021-02-11  210

1. How to make PB windows in the top

The display hierarchy of the SETWINDOWPOS function window is modified to hwnd_topmost, allowing the specified window to be overwritten by other windows, which is declared as:

Function Long SetWindowpos (Long Hwnd, Long ORD, Long X, Long Y, Long

DX, Long Dy, long uflag) library "user32.dll"

The parameter 1 is the window handle to be displayed on the top, the parameter 2 specifies the hierarchy, the parameter 7 is additional option, the rest

The parameter specifies that the window position and size are ignored. Add it in the open or Activate event of the window

Function call:

SetwindowPos (Handle (this), - 1, 0, 0, 0, 0, 3)

Parameter 2 Take -1 Indicates that at the top layer display window, take 1 to the bottom layer display; the last parameter is 1,

Indicates that the window size remains the same, and the 2 indicates that the retaining position is constant, so the 3 (= 1 2) indicates the size and

The position remains the same, and 0 means changes to the size and position of the window to the specified value.

2. How to get an optical disk in PB

Get the drive (such as: floppy drive, hard disk, optical drive, network image driver via getDriveType function

Information of the device, etc.), the function declaration is:

Function UNIT GetDriveTypea (String Drive) Library "kernel32.dll"

The parameter is a disk (such as "C:"), return value: 1 means unknown, 2 means the floppy drive, 3 indicates a local hard disk

4 denotes a network driver, 5 represents the optical drive. So the following code can obtain the disc of the disc:

For i = ASC ('d') TO ASC ('Z')

/ / List all possible CDROM drives

IF GetDriveTypea (CHAR (i) ":") = 5 THEN

// If you find CDROM

MessageBox ("CDROM", CHAR (i) ":")

/ / Display disc drive letter

EXIT // Exit cycle

END IF

NEXT

3. How to get directory information in PB

(1) Get the current directory. You can get the current directory through the getCurrentDirectory function, the function

Declare:

Function Ulong getCurrentDirectory (Ulong Bufflen, Ref string dir)

Library "kernel32.dll"

The parameter 2 is a character buffer that accepts the current directory, and the front must be added to the address reference; parameter 1 is used

The length of the character buffer. The calling process is:

String Curdir

Curdir = Space (256)

/ / Open a memory space for the character buffer

GetCurrentDirectory (256, Curdir)

MessageBox ("Current Path", Curdir)

(2) Get a Windows and system catalog. To use getWindowsDirectory and getSystemDirec

Two functions must be made as follows:

Function uint getWindowsDirectorya (Ref string dir, uint buflen)

Library kernel32.dll

Function uint getSystemDirectorya (Ref string dir, uint buflen)

Library "kernel32.dll"

4. How to cancel the current user, turn off the computer, turn off the computer, restart the computer through the EXITWINDOWSEX function to achieve these three functions, first as the following statement:

Function Long ExitWindowSex (Long Uflag, Long Nouse) library "user32.dll"

Parameter 2 reserved no need, can be 0; parameter 1 take 0 can log out of the current user, take 1 can turn off the computer, take 2

The computer can be restarted, and its value is added 4 indicates that the force ends "unresponsive" processes.

5. Control the program (referred to as the RUN program) running by RUN

In the PB program design, you can run some programs with Run (). But the Run program cannot be coordinated with the PB main program.

Work, if the user is called multiple times, multiple instances of the RUN program will be launched, when the main program exits, the Run program

Still run. You can use the following functions to make them coordinate:

Function Ulong Findwindowa (Ulong Classname, String Windown)

Library "User32.dll"

Function Long SetParent (Long Childwin, Long Parentwin) Library "User32.dll"

(1) Make the RUN program only runs an instance

Handle = FindWindowsa (NUL, WTITLE)

/ / Find whether the RUN program has been running, wtitle is the window title for the Run program

IF Handle> 0 THEN RETURN

// If you have been running back

Run ("c: /luhan.chm")

/ / Otherwise running the RUN program

(2) When the PB main program is exited, the Run program is also closed.

Handle = FindWindowa (NUL, WTITLE)

SetParent (Handle, Handle (W_Main))

/ / Make the Run program window into the sub-window of the PB main program

6. Image Network Drive

To use the resource image of the remote host to the local drive in the program, you can use the following functions:

Function Long WnetdConnectiona (String Path, String PWD, String DRV)

Library "mpr.dll"

The following code can put the shared folder MY Documents image on the remote host Alexand to the local J

plate:

WNetaddConnectiona ("// Alexander / My Documents", "", "J:") // Parameter 2

For the access password

Its role is equivalent to executing at the DOS prompt: NET USE J: // alexander / my documents

7. Tasklets that display or hide Windows

To display or hide the taskbar, you first get its window handle. The taskbar is a special window, it

The window class is: shell_traywnd, there is no title, so it can only be used with the FindWindowEx function.

Handle:

Function Long FindWindowEx (Long Ph, Long Ch, Ref String CN, Ref

String wn) library "user32.dll"

Function Long ShowWindow (long hwnd, long ncmdshow) library "user32.dll"

Use ShowWindow to display or hide the window, the second parameter is 0 indicates hidden, indicating the display:

Handle = findwindowex (0, 0, "shell_trayWnd", WN) // Wn is an empty string

ShowWindow (Handle, 0) // Hide Task Bar 8. How to convert long file names to a short message name

Convert the file name to 8.3 format through the getShortPathname function, which is declared as:

Function Long Getshortpathname (String LF, Ref string sf, long

Bufflen

Library "kernel32.dll"

The parameter 1 is a long file name, the parameter 2 is a buffer that saves the short file name, and the parameter 3 is the length of the buffer. E.g:

Getshortpathnamea ("C: / My Document / Powerbuilder Programming Practice .doc", sf, 256)

/

// sf = spCACE (256)

9. How to achieve delay in PB

The delay function is useful, and the PB is not provided, but can be extended by the SLEEP function of Wind32:

Function Long Sleep (Long MS) Library "kernel32.dll"

Call: SLEEP (1000) // Delay 1 second

10. How to play music in PB

PB does not provide any multimedia function, to play music can only be implemented through the Win32 API Plays

:

Function Long Plays (String FileName, Int Mod, Int Flags) Library

Winmm.dll

Parameter 1 is the name of the WAV file, the parameter 2 must take 0, the parameter 3 takes 1 means the background play, take 8 to repay,

Therefore

9

(

= 1 8

) Means looping in the background.

转载请注明原文地址:https://www.9cbs.com/read-3690.html

New Post(0)