luckygoldstar
MIS
Currently, I am working on a project to incorporated HTML Help.
Method A - Working & need improvement & your feedback.
1) write a method call Help1Click and the code is as follow:
void __fastcall TForm1::Help1Click(TObject *Sender)
{
SHELLEXECUTEINFO ShellInfo; // Name structure
memset(&ShellInfo, 0, sizeof(ShellInfo)); // Set up memory block
ShellInfo.cbSize = sizeof(ShellInfo); // Set up structure size
ShellInfo.hwnd = Handle; // Calling window handle
ShellInfo.lpVerb = "open"; // Open the file with default program
ShellInfo.lpFile = "Help.chm"; // File to open
ShellInfo.nShow = SW_NORMAL; // Open in normal window
ShellInfo.fMask = SEE_MASK_NOCLOSEPROCESS; // Necessary if you want to wait for spawned process
bool res = ShellExecuteEx(&ShellInfo); // Call to function
}
Using the ShellExecuteEx, I can open an Help.chm with ease.
But context-id help is not addressed yet in this case. Moreover, I don't know how to retrieve this Help.chm every time correctly if somehow my program was diverted to retrieve other files in other folders or directories. Then my path was not right. What is the syntax/codes that go together with ShellExecuteEx to retrieve ShellInfo.lpfile = "Help.chm" correctly. I cannot find a full example on the web. So if you know please advise.
Method B: The source below is written into unit1.cpp of the program
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// initialize helpfile location -- m_asHelpFile is an AnsiString type private
// member of the TForm1 class
m_asHelpFile = ::ExtractFilePath(ParamStr(0)) + "..\\TestCHM\\help.chm";
m_asHelpFile = ::ExpandFileName(m_asHelpFile);
// make sure the helpfile exists and display a message if not
if (!FileExists(m_asHelpFile)) ShowMessage("Help file not found\n" + m_asHelpFile);
HelpContext = 1000;
}
// -------------------------------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
::HtmlHelp(0, NULL, HH_CLOSE_ALL, 0);
}
// -----------------------------------------------------------------------------------------------------
bool __fastcall TForm1::ApplicationEvents1Help(WORD Command, int Data, bool &CallHelp)
{
if (Command == HELP_CONTEXT || Command == HELP_CONTEXTPOPUP)
{
// all context calls come here and get diverted to HTML Help Context call
HtmlHelp(NULL, m_asHelpFile.c_str(), HH_HELP_CONTEXT, Data);
// VCL should not call WinHelp
CallHelp = false;
}
return true;
}
Method B involves a event handler to call HTML Help in unit1.h, unit1.cpp. This works when I have just a 1 unit program. I can press F1 to invoke the HTML Help at a desired help page (context id help). But when I have multiple units program with unit1.h declared in other units then calling my program, the F1 Help Key pressed has no reaction(i.e bool _fastcall) was not executed. But when I closed all windows invoked by units other then unit1. That is unit1 is the form window left opened, then I press F1, the HTML Help was shown. I wonder if you have clue as to why bool _fastcall is not triggered when all form windows are opened. It should be event driven condition. Now , it is rather like a structured program instead.
Thanking for your help.
Method A - Working & need improvement & your feedback.
1) write a method call Help1Click and the code is as follow:
void __fastcall TForm1::Help1Click(TObject *Sender)
{
SHELLEXECUTEINFO ShellInfo; // Name structure
memset(&ShellInfo, 0, sizeof(ShellInfo)); // Set up memory block
ShellInfo.cbSize = sizeof(ShellInfo); // Set up structure size
ShellInfo.hwnd = Handle; // Calling window handle
ShellInfo.lpVerb = "open"; // Open the file with default program
ShellInfo.lpFile = "Help.chm"; // File to open
ShellInfo.nShow = SW_NORMAL; // Open in normal window
ShellInfo.fMask = SEE_MASK_NOCLOSEPROCESS; // Necessary if you want to wait for spawned process
bool res = ShellExecuteEx(&ShellInfo); // Call to function
}
Using the ShellExecuteEx, I can open an Help.chm with ease.
But context-id help is not addressed yet in this case. Moreover, I don't know how to retrieve this Help.chm every time correctly if somehow my program was diverted to retrieve other files in other folders or directories. Then my path was not right. What is the syntax/codes that go together with ShellExecuteEx to retrieve ShellInfo.lpfile = "Help.chm" correctly. I cannot find a full example on the web. So if you know please advise.
Method B: The source below is written into unit1.cpp of the program
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// initialize helpfile location -- m_asHelpFile is an AnsiString type private
// member of the TForm1 class
m_asHelpFile = ::ExtractFilePath(ParamStr(0)) + "..\\TestCHM\\help.chm";
m_asHelpFile = ::ExpandFileName(m_asHelpFile);
// make sure the helpfile exists and display a message if not
if (!FileExists(m_asHelpFile)) ShowMessage("Help file not found\n" + m_asHelpFile);
HelpContext = 1000;
}
// -------------------------------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
::HtmlHelp(0, NULL, HH_CLOSE_ALL, 0);
}
// -----------------------------------------------------------------------------------------------------
bool __fastcall TForm1::ApplicationEvents1Help(WORD Command, int Data, bool &CallHelp)
{
if (Command == HELP_CONTEXT || Command == HELP_CONTEXTPOPUP)
{
// all context calls come here and get diverted to HTML Help Context call
HtmlHelp(NULL, m_asHelpFile.c_str(), HH_HELP_CONTEXT, Data);
// VCL should not call WinHelp
CallHelp = false;
}
return true;
}
Method B involves a event handler to call HTML Help in unit1.h, unit1.cpp. This works when I have just a 1 unit program. I can press F1 to invoke the HTML Help at a desired help page (context id help). But when I have multiple units program with unit1.h declared in other units then calling my program, the F1 Help Key pressed has no reaction(i.e bool _fastcall) was not executed. But when I closed all windows invoked by units other then unit1. That is unit1 is the form window left opened, then I press F1, the HTML Help was shown. I wonder if you have clue as to why bool _fastcall is not triggered when all form windows are opened. It should be event driven condition. Now , it is rather like a structured program instead.
Thanking for your help.