wxDev-C++ - HtmlHelp undeclared

wxDev-C++ - HtmlHelp undeclared

本文关键字:undeclared HtmlHelp wxDev-C++      更新时间:2023-10-16

C程序的菜单中,我有一个帮助部分。

按下时,应打开一个帮助文件。

我使用Helpinator Professional制作了一个简单的帮助文件。

现在,历史前期:

我尝试通过包含<winuser.h>来使用WinHelp()方法。它打开了该文件,但它给了我一个错误,说该文件不是Windows帮助文件或已损坏。然后我读到WinHelp()已经过时了,我应该通过包含<htmlhelp.h>来使用HtmlHelp()。我通过编写它的完整路径来包含它,因为编译器设置中的wxDev-C++目录通常不包含,我也不知道它是如何检查目录的。

我在resources.h文件中包含了。交换机语句中的代码:

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