c++ - wxDev-C++ - HtmlHelp 未声明

标签 c++ c

在我的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;

这给了我一个错误,说它是未声明的。然后,我宣布HWMD help;在 switch 语句之前并将代码更改为:

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

关于c++ - wxDev-C++ - HtmlHelp 未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26786139/

相关文章:

c++ - 如何解决 "Cannot Access Memory at Address c++"问题

c++ - 根据颜色范围创建蒙版

c++ - 链表中的自结构和指针

c++ - 复制传递给模板函数的指针

c++ - 无法理解这是循环依赖还是 Clang

c - 如果文件大小不变, fopen 更新模式 ("rb+") 是否会更改文件的磁盘位置?

c - 在 Makefile 中运行 unix 命令以解析文本并将其传递给链接行作为定义 -D

pcap_loop 的最后一个参数中的编译器警告。指向不同大小的整数

c - 具有全局值的回溯的递归差异?

c - 对象符号覆盖库符号?