在我的C
程序的菜單中我有一個幫助部分。wxDev-C++ - HtmlHelp未聲明
當按下時,它應該打開一個幫助文件。
我用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;
這給我一個錯誤,說這是未申報。然後,我宣佈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
你能不能把實際源的一部分?你看到的實際錯誤信息是什麼? – 2014-11-06 18:23:26
@RichardChambers 更新OP。 – JohnyB 2014-11-06 18:42:41
請參閱[在應用程序中包含HTML幫助文件](http://msdn.microsoft.com/zh-cn/library/aa733984(v = vs.60).aspx),您確實需要#include包含所需的必要聲明和定義。您還需要確保'Htmlhelp.lib'被指定爲鏈接庫。您可能想要創建一個示例Win32項目,並在該向導中指定上下文敏感幫助以創建一個可用的示例。 –
2014-11-06 18:52:45