在我的C
程序菜单中,有一个“帮助”部分。
按下时,它应该打开一个帮助文件。
我使用Helpinator Professional
制作了一个简单的帮助文件。
现在,史前:
我尝试通过包括<winuser.h>
来使用WinHelp()方法。它打开了文件,但给了我一个错误,说该文件不是Windows帮助文件或已损坏。然后,我读到WinHelp()已过时,应该使用HtmlHelp()代替,包括<htmlhelp.h>
。我通过编写完整路径来包含它,因为通常不会在编译器设置中包含wxDev-C ++的目录,而且我也不完全知道它如何检查目录。
我包含在我的resources.h文件中。
switch语句中的代码:
case ID_Help:
HtmlHelp(hwnd, "file location", HH_DISPLAY_TOPIC, 0);
break;
这给了我一个错误,说这是未声明的。然后,我在switch语句之前声明了
HWMD help;
,并将代码更改为:case ID_Help:
help = HtmlHelp(hwnd, "file location", HH_DISPLAY_TOPIC, 0);
break;
而且它仍然告诉我它是未声明的。
我该怎么办?我被卡住了。我在途中还遇到了其他问题,其中一些是上面提到的,但暂时不要理会。
源代码:
#include "resources.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char window_class[] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = window_class;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_HAND);
wincl.lpszMenuName = MAKEINTRESOURCE (ID_Menu); /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) (COLOR_BACKGROUND + 2);
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
window_class, /* Classname */
"Slacker Tracker v0.1", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
600, /* The programs width */
600, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
MessageBox(NULL, "Message box #1 at your service.", "MESSAGE BOX #1", 0);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LPCTSTR name = "D:\\winapi\\1\\help.chm";
HANDLE file;
int size;
char buffer[100];
wchar_t error[256];
HWND help;
switch (message) /* handle the messages */
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_File_Exit:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_NewMsgBox:
MessageBox(NULL, "Message box #3 at your service", "MESSAGE BOX #3", 0);
break;
case ID_Help:
//WinHelp(hwnd, "D:\\winapi\\1\\help.chm", HELP_INDEX, 0);
help = HtmlHelp(hwnd, "D:\\winapi\\1\\help.chm", HH_DISPLAY_TOPIC, 0);
break;
case ID_FSize:
file = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (file == INVALID_HANDLE_VALUE){
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error, 255, NULL);
MessageBoxW(NULL, error, (LPCWSTR)L"file", 0);
}
else{
size = GetFileSize(file, NULL);
itoa(size, buffer, 10);
MessageBox(NULL, buffer, "File Size", MB_OK);
}
CloseHandle(file);
break;
}
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "Message box #2 at your service", "MESSAGE BOX #2", 0);
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
编译日志:
main.c: In function 'WindowProcedure':
main.c:99:36: error: 'HtmlHelp' undeclared (first use in this function)
main.c:99:36: note: each undeclared identifier is reported only once for each function it appears in
最佳答案
您应该将此行添加到您的.cpp文件。
#include "htmlhelp.h"
然后,您需要分配事件以致电帮助。 (这是我认为这是未定义的地方)
void CTestHelpDlg::OnHelp()
{
HtmlHelp(this->m_hWnd, "HelpSample.chm", HH_DISPLAY_TOPIC, NULL);
}
进一步的文档和我用来学习它的教程在这里
http://www.codeguru.com/cpp/w-p/help/html/article.php/c6503/Starting-Out-with-HtmlHelp.htm