Solved

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

Posted on 2002-03-15
7
390 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 28
Running shell command from Access 3 68
Perl Awk Need Help 3 109
Replacement selected text 2 58
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

914 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

19 Experts available now in Live!

Get 1:1 Help Now