?
Solved

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

Posted on 2002-03-15
7
Medium Priority
?
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 400 total points
ID: 6870518
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
ID: 6870781
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
ID: 6871563
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:l_d_allan
ID: 6871885
>> 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
ID: 6871928
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
ID: 6872070
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
ID: 6924208
>>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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 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