如何在DELPHI中调帮助文件?(50分)

  • 主题发起人 主题发起人 gongshan
  • 开始时间 开始时间
G

gongshan

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个浏览器形式的帮助文件(扩展名是chm),<br>却不知道在DELPHI开发的程序中如何调用。哪位能告诉我?<br>如果能顺便告诉我在VB中如何调用,更是万分感谢
 
调用api试试WinExec<br><br><br>The WinExec function runs the specified application. <br><br>Note &nbsp;This function is provided only for compatibility with 16-bit Windows. Win32-based applications should use the CreateProcess function. <br><br>UINT WinExec(<br>&nbsp; LPCSTR lpCmdLine, &nbsp;// command line<br>&nbsp; UINT uCmdShow &nbsp; &nbsp; &nbsp;// window style<br>);<br>Parameters<br>lpCmdLine <br>[in] Pointer to a null-terminated character string that contains the command line (file name plus optional parameters) for the application to be executed. If the name of the executable file in the lpCmdLine parameter does not contain a directory path, the system searches for the executable file in this sequence: <br>The directory from which the application loaded. <br>The current directory. <br>The Windows system directory. The GetSystemDirectory function retrieves the path of this directory. <br>The Windows directory. The GetWindowsDirectory function retrieves the path of this directory. <br>The directories listed in the PATH environment variable. <br>uCmdShow <br>[in] Specifies how a Windows-based application window is to be shown and is used to supply the wShowWindow member of the STARTUPINFO parameter to the CreateProcess function. For a list of the acceptable values, see the description of the nCmdShow parameter of the ShowWindow function. For a non-Windows – based application, the PIF file, if any, for the application determines the window state. <br>Return Values<br>If the function succeeds, the return value is greater than 31.<br><br>If the function fails, the return value is one of the following error values: <br><br>Value Meaning <br>0 The system is out of memory or resources. <br>ERROR_BAD_FORMAT The .exe file is invalid (non-Win32 .exe or error in .exe image). <br>ERROR_FILE_NOT_FOUND The specified file was not found. <br>ERROR_PATH_NOT_FOUND The specified path was not found. <br><br><br>Remarks<br>In Win32, the WinExec function returns when the started process calls the GetMessage function or a time-out limit is reached. To avoid waiting for the time out delay, call the GetMessage function as soon as possible in any process started by a call to WinExec. <br><br>Requirements <br>&nbsp; Windows NT/2000: Requires Windows NT 3.1 or later.<br>&nbsp; Windows 95/98: Requires Windows 95 or later.<br>&nbsp; Header: Declared in Winbase.h; include Windows.h.<br>&nbsp; Library: Use Kernel32.lib.<br><br>
 
这种方法太老了吧,直接用hhctrl.ocx上的函数吧,下面的例子只实现了直接转跳到标题<br>,你如果要实现更多的功能,自己查msdn了<br>HTMLHelp API Reference<br>The HtmlHelp API currently resides in the file HTMLHELP.DLL, however this is very likely to be moved to a different DLL before HTML Help ships. If you are not using GetProcAddress to get a pointer to the HtmlHelp function, then you must plan on changing the library you link to. <br><br>The functionality provided by the HtmlHelp API resides in the file HHCTRL.OCX. Because this functionality requires loading various other DLLs such as ole32.dll, the API itself resides in a DLL that requires no additional DLLs to be loaded. Only when the API is actually called will ole32 and other DLLs be loaded. <br><br>The HtmlHelp API is modeled after the WinHelp API function to make it easy to convert existing programs to use HTML Help instead of WinHelp to display their help. By the time HTML Help ships, there will also be an IHHWindow interface that can be used in place of the HtmlHelp API. This can be used by programs that already load OLE32.DLL or by programs like Visual Basic. <br><br>In its simplest form, the HtmlHelp API creates a child window which in turn hosts SHDOCVW and displays the HTML file you specify. The window is a child of whatever parent window you specify, and will automatically stay on top of that parent window, and close when the parent window is closed. You can also take complete control of the window-creation process by defining the window styles, coordinates, caption, and display state. This means you can embed SHDOCVW even in a non-OLE activated program. <br><br>SYNTAX <br><br>HWND HtmlHelp(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD dwData); <br><br>hwndCaller <br>Specifies the handle of the window calling the HtmlHelp API. If the HtmlHelp API call results in messages being sent from the HTML Help window, they will be sent to this window handle. <br>pszFile <br>Specifies an HTML file, a URL, a compiled HTML file, or a window definition (preceeded with a ‘&gt;’ character). If the command being used does not require a file or URL, this value may be NULL. <br>uCommand <br>Specifies the action to perform. See the Comments section for details. <br>dwData <br>Specifies any data that may be required based on the value of the uCommand parameter. <br>Comments <br><br>太长了,自己查msdn帮助吧<br>在delphi中的函数定义<br>Function HtmlHelpA(hwnd:integer;lpHelpFile:string;wCommand:integer;dwData:string) :integer;stdcall;External 'hhctrl.ocx';<br>wCommand要自己查msdn中需要的参数,然后换成0、1这些<br>使用参数<br>Command Description pszFile dwData <br>HH_DISPLAY_TOPIC Displays an HTML file. If a window type is not specified, a default window type is used. If the window type or default window type is already being displayed, the HTML file will replace what is currently being displayed. File, URL, or compiled HTML file. If the greater then character (&gt;) is used, it must be followed by the name of the window type to display the topic in. May be zero or a pointer to a File, URL, or compiled HTML file. This parameter may be a pointer to a filename within a compiled HTML file if the pszFile parameter points to that compiled HTML file. <br><br>HtmlHelpA(Handle,'c:/htmlhelp2/rshelp.chm',0,'欢迎.htm'
 
用API比较简单<br>shellexec()
 
我同意bugs的<br>SHELLEXECUTEINFO<br>Contains information used by ShellExecuteEx. <br><br>typedef struct _SHELLEXECUTEINFO{<br>&nbsp; &nbsp; DWORD cbSize; <br>&nbsp; &nbsp; ULONG fMask; <br>&nbsp; &nbsp; HWND hwnd; <br>&nbsp; &nbsp; LPCTSTR lpVerb; <br>&nbsp; &nbsp; LPCTSTR lpFile; <br>&nbsp; &nbsp; LPCTSTR lpParameters; <br>&nbsp; &nbsp; LPCTSTR lpDirectory; <br>&nbsp; &nbsp; int nShow; <br>&nbsp; &nbsp; HINSTANCE hInstApp; <br>&nbsp;<br>&nbsp; &nbsp; // Optional members <br>&nbsp; &nbsp; LPVOID lpIDList; <br>&nbsp; &nbsp; LPCSTR lpClass; <br>&nbsp; &nbsp; HKEY hkeyClass; <br>&nbsp; &nbsp; DWORD dwHotKey; <br> union {<br> HANDLE hIcon;<br> HANDLE hMonitor;<br> };<br>&nbsp; &nbsp; HANDLE hProcess; <br>} SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO; <br>&nbsp;<br>Members<br>cbSize <br>Size of the structure, in bytes. <br>fMask <br>Array of flags that indicate the content and validity of the other structure members. This can be a combination of the following values. SEE_MASK_CLASSKEY &nbsp;Use the class key given by the hkeyClass member. &nbsp;<br>SEE_MASK_CLASSNAME &nbsp;Use the class name given by the lpClass member. &nbsp;<br>SEE_MASK_CONNECTNETDRV &nbsp;Validate the share and connect to a drive letter. The lpFile member is a Universal Naming Convention (UNC) path of a file on a network. &nbsp;<br>SEE_MASK_DOENVSUBST &nbsp;Expand any environment variables specified in the string given by the lpDirectory or lpFile member. &nbsp;<br>SEE_MASK_FLAG_DDEWAIT &nbsp;Wait for the DDE conversation to terminate before returning (if the ShellExecuteEx function causes a DDE conversation to start). For circumstances in which this flag is necessary, see the Remarks section. <br>SEE_MASK_FLAG_NO_UI &nbsp;Do not display an error message box if an error occurs. &nbsp;<br>SEE_MASK_HMONITOR Use this flag when specifying a monitor on multimonitor systems. The monitor is specified in the hMonitor member. This flag cannot be combined with SEE_MASK_ICON. <br>SEE_MASK_HOTKEY &nbsp;Use the hot key given by the dwHotKey member. <br>SEE_MASK_ICON &nbsp;Use the icon given by the hIcon member. This flag cannot be combined with SEE_MASK_HMONITOR. <br>SEE_MASK_IDLIST &nbsp;Use the item identifier list given by the lpIDList member. The lpIDList member must point to an ITEMIDLIST structure. <br>SEE_MASK_INVOKEIDLIST &nbsp;Use the IContextMenu interface of the selected item's context menu handler. Use either lpFile to identify the item by its file system path or lpIDList to identify the item by its PIDL. This flag allows applications to use ShellExecuteEx to invoke verbs from context menu extensions instead of the static verbs listed in the registry. <br>SEE_MASK_NOCLOSEPROCESS &nbsp;Use to indicate that the hProcess member receives the process handle. This handle is typically used to allow an application to find out when a process created with ShellExecuteEx terminates. In some cases, such as when execution is satisfied through a DDE conversation, no handle will be returned. The calling application is responsible for closing the handle when it is no longer needed. <br>SEE_MASK_NO_CONSOLE Use to create a console for the new process instead of having it inherit the parent's console. It is equivalent to using a CREATE_NEW_CONSOLE flag with CreateProcess. <br>SEE_MASK_UNICODE Use this flag to indicate a Unicode application. <br><br>hwnd <br>Window handle to any message boxes that the system might produce while executing this function. <br>lpVerb <br>String, referred to as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's context menu are available verbs. For more specific information about verbs, see Object Verbs. For further discussion of context menus, see Extending Context Menus. The following verbs are commonly used. edit &nbsp;Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail. <br>explore Explores the folder specified by lpFile. &nbsp;<br>find Initiates a search starting from the specified directory. <br>open &nbsp;Opens the file specified by the lpFile parameter. The file can be an executable file, a document file, or a folder. <br>print &nbsp;Prints the document file specified by lpFile. If lpFile is not a document file, the function will fail. <br>properties &nbsp;Displays the file or folder's properties. <br><br>If you set this parameter to NULL:<br><br>For systems prior to Microsoft&amp;reg; Windows&amp;reg; 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used. <br>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. <br>lpFile <br>Address of a null-terminated string that specifies the name of the file or object on which ShellExecuteEx will perform the action specified by the lpVerb parameter. The system registry verbs that are supported by the ShellExecuteEx function include "open" for executable files and document files and "print" for document files for which a print handler has been registered. Other applications might have added shell verbs through the system registry, such as "play" for AVI and WAV files. To specify a shell namespace object, pass the fully qualified parse name and set the SEE_MASK_INVOKEIDLIST flag in the fMask parameter. <br>Note If the path is not included with the name, the current directory is assumed. <br><br>lpParameters <br>Address of a null-terminated string that contains the application parameters. The parameters must be separated by spaces. To include double quotation marks, enclose each mark in a pair of quotation marks, as in the following example. <br>sei.lpParameters = "An example: /"/"/"quoted text/"/"/"";<br><br>In this case, the application receives three parameters: An, example:, and "quoted text".<br><br>If the lpFile member specifies a document file, this member should be NULL. <br><br>lpDirectory <br>Address of a null-terminated string that specifies the name of the working directory. If this member is not specified, the current directory is used as the working directory. <br>nShow <br>Flags that specify how an application is to be shown when it is opened. It can be one of the SW_ values listed for the ShellExecute function. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it. <br>hInstApp <br>If the function succeeds, it sets this member to a value greater than 32. If the function fails, it is set to an SE_ERR_XXX error value that indicates the cause of the failure. Although hInstApp is declared as an HINSTANCE for compatibility with 16-bit Windows applications, it is not a true HINSTANCE. It can be cast only to an integer and compared to either 32 or the following SE_ERR_XXX error codes. SE_ERR_FNF &nbsp;File not found. <br>SE_ERR_PNF &nbsp;Path not found. <br>SE_ERR_ACCESSDENIED &nbsp;Access denied. <br>SE_ERR_OOM &nbsp;Out of memory. <br>SE_ERR_DLLNOTFOUND &nbsp;Dynamic-link library not found. <br>SE_ERR_SHARE &nbsp;Cannot share an open file. <br>SE_ERR_ASSOCINCOMPLETE &nbsp;File association information not complete. <br>SE_ERR_DDETIMEOUT &nbsp;DDE operation timed out. <br>SE_ERR_DDEFAIL &nbsp;DDE operation failed. <br>SE_ERR_DDEBUSY &nbsp;DDE operation is busy. <br>SE_ERR_NOASSOC &nbsp;File association not available. <br><br>lpIDList <br>Address of an ITEMIDLIST structure to contain an item identifier list uniquely identifying the file to execute. This member is ignored if the fMask member does not include SEE_MASK_IDLIST. <br>lpClass <br>Address of a null-terminated string that specifies the name of a file class or a globally unique identifier (GUID). This member is ignored if fMask does not include SEE_MASK_CLASSNAME. <br>hkeyClass <br>Handle to the registry key for the file class. This member is ignored if fMask does not include SEE_MASK_CLASSKEY. <br>dwHotKey <br>Hot key to associate with the application. The low-order word is the virtual key code, and the high-order word is a modifier flag (HOTKEYF_). For a list of modifier flags, see the description of the WM_SETHOTKEY message. This member is ignored if fMask does not include SEE_MASK_HOTKEY. <br>hIcon <br>Handle to the icon for the file class. This member is ignored if fMask does not include SEE_MASK_ICON. <br>hMonitor <br>Handle to the monitor upon which the document is to be displayed. This member is ignored if fMask does not include SEE_MASK_HMONITOR. <br>hProcess <br>Handle to the newly started application. This member is set on return and is always NULL unless fMask is set to SEE_MASK_NOCLOSEPROCESS. Even if fMask is set to SEE_MASK_NOCLOSEPROCESS, hProcess will be NULL if no process was launched. For example, if a document to be launched is a URL and an instance of Microsoft&amp;reg; Internet Explorer is already running, it will display the document. No new process is launched, and hProcess will be NULL. <br>Remarks<br>The SEE_MASK_DDEWAIT flag must be specified if the thread calling ShellExecuteEx does not have a message loop or if the thread or process will terminate soon after ShellExecuteEx returns. Under such conditions, the calling thread will not be available to complete the DDE conversation, so it is important that ShellExecuteEx complete the conversation before returning control to the caller. Failure to complete the conversation can result in an unsuccessful launch of the document.<br><br>If the calling thread has a message loop and will exist for some time after the call to ShellExecuteEx returns, the SEE_MASK_DDEWAIT flag is optional. If the flag is omitted, the calling thread's message pump will be used to complete the DDE conversation. The calling application regains control sooner, since the DDE conversation can be completed in the background. <br><br>Requirements <br>&nbsp; Windows NT/2000: Requires Windows NT 3.51 or later. <br>&nbsp; Windows 95/98: Requires Windows 95 or later. <br>&nbsp; Header: Declared in Shellapi.h. <br>------------------------------------------------------------以上是结构<br><br><br>ShellExecuteEx<br>Performs an action on a file. <br><br><br><br>BOOL ShellExecuteEx(<br>&nbsp; &nbsp; LPSHELLEXECUTEINFO lpExecInfo<br>);<br><br>Parameters<br>lpExecInfo <br>Address of a SHELLEXECUTEINFO structure that contains and receives information about the application being executed. <br>Return Values<br>Returns TRUE if successful, or FALSE otherwise. Call GetLastError for error information. <br><br>Remarks<br>With multiple monitors, if you specify an hwnd and set the lpVerb member of lpExecInfo to "Properties" , any windows created by ShellExecuteEx may not appear in the correct position. <br><br>If the function succeeds, it sets the hInstApp member of the SHELLEXECUTEINFO structure to a value greater than 32. If the function fails, hInstApp is set to the SE_ERR_XXX error value that best indicates the cause of the failure. Although hInstApp is declared as an HINSTANCE for compatibility with 16-bit Microsoft Windows applications, it is not a true HINSTANCE. It can only be cast to an integer and compared to either 32 or the SE_ERR_XXX error codes.<br><br>Note: the SE_ERR_XXX error values are provided for compatibility with ShellExecute. To retrieve more accurate error information, use GetLastError. It may return one of the following values: <br><br>ERROR_FILE_NOT_FOUND &nbsp;The specified file was not found. <br>ERROR_PATH_NOT_FOUND &nbsp;The specified path was not found. <br>ERROR_DDE_FAIL &nbsp;The DDE transaction failed. <br>ERROR_NO_ASSOCIATION &nbsp;There is no application associated with the given file name extension. <br>ERROR_ACCESS_DENIED &nbsp;Access to the specified file is denied. <br>ERROR_DLL_NOT_FOUND &nbsp;One of the library files necessary to run the application can't be found. <br>ERROR_CANCELLED &nbsp;The function prompted the user for additional information, but the user canceled the request. <br>ERROR_NOT_ENOUGH_MEMORY &nbsp;There is not enough memory to perform the specified action. <br>ERROR_SHARING_VIOLATION &nbsp;A sharing violation occurred. <br><br>See Also<br>IShellExecuteHook<br><br>Requirements <br>&nbsp; Version 4.00 and later of Shell32.dll<br><br>&nbsp; Windows NT/2000: Requires Windows NT 4.0 or later. <br>&nbsp; Windows 95/98: Requires Windows 95 or later. <br>&nbsp; Header: Declared in shellapi.h. <br>&nbsp; Import Library: shell32.lib<br>---------------------------------------------以上是api<br>
 
多人接受答案了。
 
后退
顶部