Solved

Mfc Dialog-App activating HtmlHelp: ok from Explorer, fails in VisStudio

Posted on 2002-03-15
7
389 Views
Last Modified: 2013-11-20
Mfc Dialog-App activating HtmHelp: ok from Explorer, fails in VisStudio

I've got an Mfc generated Dialog App with a menu and various controls.  I want to use HtmlHelp, and am having a strange problem with "Help + Topics" and "Help + Index"

I compile/link with Debug configuration to create files
.\Debug\InVerse.exe
.\Debug\InVerse.chm

The code below works fine when I dbl-click on InVerse.exe from the Explorer.  It displays the 'Contents' and 'Index' correctly.  It seems to be able to 'find' InVerse.chm.  

But it fails (ret = 0) when I run it from VisStudio 6.0 sp5's IDE.  It fails both when I step through the code with the debugger, or run via Ctrl+F5.  The same behavior happens with a Release configuration and Ctrl-F5.  Runs ok from the Explorer, but not in the IDE.

void CInVerseDlg::OnHelp()
{
  HWND ret = HtmlHelp(NULL, "InVerse.chm", HH_DISPLAY_TOC, NULL);
  if (ret == 0) {
    AfxMessageBox("Unable to display HH_DISPLAY_TOC");
  }
}

void CInVerseDlg::OnHelpIndex()
{
  HWND ret = HtmlHelp(NULL,"InVerse.chm", HH_DISPLAY_INDEX, 0);
  if (ret == 0) {
    AfxMessageBox("Unable to display HH_DISPLAY_INDEX");
  }
}

What am I doing wrong or leaving out?  I'm aware that Dialogs work differently than Sdi/Mdi apps, but I'm baffled that it works ok 'outside' the IDE and not 'inside'.

TIA
0
Comment
Question by:l_d_allan
  • 4
  • 3
7 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
Comment Utility
You need to specify the full path to the .chm file.  I don't know where (which directory) you have the chm file, but you can never depend upon a bar (pathless) filename.

Remember, when running from the IDE, your program is in the .\debug or .\release directory. I'm not sure what the 'current default' will be in that case.  When ypou double-click in the explorer, the default directory will be the program directory.

BTW there is a variable in your CWinApp-derived class named m_pszHelpFilePath.  I'm pretty sure that it is the path of the executable.  You can use that to build a fully-qualified pathname for your chm file.

-- Dan
0
 

Author Comment

by:l_d_allan
Comment Utility
Hi Dan,

Ahhh, Mr. Mfc ... out in front and pulling away ...

Works great ... I'd seen a reference in other places that sometimes you needed to specify the full path ... and didn't think to do that here.  Gettin' groggy here in Blissful Colorado.

Thought I'd check ... is it ok to change the
AfxGetApp()->m_pszHelpFilePath() directly?  It is declared as a publicly visible const char*.  The MSDN documentation for m_pszHelpFilePath discusses using _strdup and free.  Since I'm only changing the last 3 characters, am I ok to ignore the malloc/free/_strdup info?  In my CInVerseApp::InitInstance, I strcat "chm" to &m_pszHelpFilePath[len - 3], as shown below

BOOL CInVerseApp::InitInstance()
{
...
  char* pszHFP=(char*)AfxGetApp()->m_pszHelpFilePath;
  int len = strlen(pszHFP);
  pszHFP[len - 3] = '\0';
  strcat(pszHFP,"chm");

  int nResponse = dlg.DoModal();
  if (nResponse == IDOK)
  ...
}

void CInVerseDlg::OnHelp()
{
  const char* pszHFP=AfxGetApp()->m_pszHelpFilePath;
  HWND ret = HtmlHelp(NULL, pszHFP, HH_DISPLAY_TOC, NULL);
  if (ret == 0) {
    MessageBox("Can't display HH_DISPLAY_TOC",pszHFP);
  }
}

void CInVerseDlg::OnHelpIndex()
{
  const char* pszHFP = AfxGetApp()->m_pszHelpFilePath;
  HWND ret = HtmlHelp(NULL, pszHFP, HH_DISPLAY_INDEX, 0);
  if (ret == 0) {
    MessageBox("Can't display HH_DISPLAY_INDEX", pszHFP);
  }
}

Thx again,
Lynn Allan
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Don't CHANGE m_pszHelpFilePath.  Just USE it.

m_sMyHelpFile.Format("%s\\"InVerse.chm",  m_pszHelpFilePath );

...
HtmlHelp(NULL, m_sMyHelpFile, HH_DISPLAY_INDEX, 0);

-- Dan
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:l_d_allan
Comment Utility
>> Remember, when running from the IDE, your
>> program is in the .\debug or .\release
>> directory. I'm not sure what the 'current default'
>> will be in that case.  When you double-click
>> in the explorer, the default directory will be the
>> program directory.

Actually, I think both InVerse.exe and InVerse.chm are in the same directory.  I have Custom Build steps to compile the .hhp so that both are in $(OutDir).
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Even so, I think the the 'current active directory' at the time that you run will be the direct parent of $(OutDir) -- that is, your project directory.  

It is easy to test.  Just copy the chm to there and see if the problem disappears.  Then add the code I gave (sans the typo) to your CMyApp::InitInstance() fn.

-- Dan
0
 

Author Comment

by:l_d_allan
Comment Utility
Hello Dan,

Good suggestion ...

I suppose "a poor craftsman blames his tools", but this exercise to wire a MFC dialog-app to WinHelp/HtmlHelp has been really frustrating.  Nice feeling when it works, but does it have to be so obscure?  I was trying to explain to my wife all the 'machinery' behind getting a simple popup window up.  

And at least so far, HtmlHelp popups look lousy compared with what you can do with WinHelp.  But WinHelp is a hassle for an end-user to navigate once in the 'Books'.  Almost unusable.

Oh, well, if this stuff was easy, I suppose it wouldn't pay particulary well.  And MFC is difficult enough that it certainly presents "barriers to entry" for people crowding the field.

An aside or two:  is it proper etiquette (sp?) for an 'Asker' to accept the answer once an excellent answer has been provided?  Or leave it open for a while?  

When tracking down previous PAQ's about HthmHelp, I came across a comment by you to another Expert to not prematurely post a reply as an answer, but rather as a comment.  So as to not discourage other experts from adding comments.  On the other hand, should the Asker accept the answer expeditiously so as to not waste time of experts?  "Inquiring minds want to know :-)"  I'd like to be a good citizen on this site.

And another question ... would you be the person to ask about tracking down "Unique Software"?  Do you suppose the $40 diskette for "IBM PC 8088 Macro Assembler Programming" is still available?  I thought maybe it might be a collector's item on E-Bay, but no luck :-)

Have a great weekend!

Lynn Allan
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
>>would you be the person to ask about tracking down "Unique Software"?  Do

wow, blast from the past.  I dug up a copy of the Listing Diskette, but I no longer have a computer that can read 5-1/4" diskettes!

-- Dan
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now