Running applications from DelphiTM: Using ShellExecute (Part 1) {转贴}[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 ihihonline 的 blog

the shellexecute function will return an error code if the function fails. this can be retrieved using the getlasterror function. if the error code is greater than 32, then the function was successful. if it less than or equal to 32 then an error has occurred. for a complete listing of the error codes refer to the msdn website (link provided in the further reading section).

the easiest way to interpret the error code is with the syserrormessage(getlasterror) function call. this will map the appropriate windows error message returned by the getlasterror api function.

  if shellexecute(handle, 'print', pchar('c:\log.txt'), nil, nil, sw_shownormal) <= 32 then
    showmessage(syserrormessage(getlasterror));

operation type

the shellexecute function allows for operations to be executed on programs and application objects. in some cases, objects may not be able to respond to an operation type. for example, not all document types support the "print" verb. a list of the commonly supported verbs include:

lpoperation value

result description

edit

opens a document for editing in an editor.

explore

explores the folder, using windows explorer, specified by the lpfile parameter.

find

opens the search form initiating a search starting from the directory specified in the lpfile parameter.

open

opens the file, application or folder specified by the lpfile parameter.

print

prints the document file specified by lpfile parameter.

null

more information below

if null is specified then different functionality will occur depending on the operating system version. the following is an extract from the msdn shellexecute document:

for systems prior to microsoft?windows?2000, the default verb is used if it is valid and available in the registry. if not, the "open" verb is used.
for windows 2000 and later systems, the default verb is used if available. if not, the "open" verb is used. if neither verb is available, the system uses the first verb listed in the registry.

if i use the "open" verb on a .pas file, nothing happens. if i use null instead, then the .pas file will be opened in delphi. the registry defines the application that is associated with the .pas file.

show command

the shellexecute requires the nshowcmd type. this represents how the new window will be displayed when it is created via the shellexecute call.

nshowcmd value

result description

sw_hide

hides the window and activates another window.

sw_maximize

maximizes the specified window.

sw_minimize

minimizes the specified window and activates the next top-level window in the z-order.

sw_restore

activates and displays the window. if the window is minimized or maximized, windows restores it to its original size and position. an application should specify this flag when restoring a minimized window.

sw_show

activates the window and displays it in its current size and position.

sw_showdefault

sets the show state based on the sw_ flag specified in the startupinfo structure passed to the createprocess function by the program that started the application. an application should call showwindow with this flag to set the initial show state of its main window.

sw_showmaximized

activates the window and displays it as a maximized window.

sw_showminimized

activates the window and displays it as a minimized window.

sw_showminnoactive

displays the window as a minimized window. the active window remains active.

sw_showna

displays the window in its current state. the active window remains active.

sw_shownoactivate

activates and displays a window. windows restores it to its original size and position. the active window remains active.

sw_shownormal

activates and displays a window. windows restores it to its original size and position.

本文关键:Running applications from DelphiTM: Using ShellExecute (Part 1) {转贴}
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top