在我的C
程序菜单中,我有一个帮助部分。
按下时,应打开帮助文件。
我使用Helpinator Professional
制作了一个简单的帮助文件。
现在,史前:
我尝试使用WinHelp()方法,包括<winuser.h>
。它打开了文件,但它给了我一个错误,说该文件不是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
答案 0 :(得分:0)
您应该将此行添加到.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