Page 1 of 1

How to call a win32.chm file via F1 in the IDE?

Posted: Fri Apr 19, 2019 2:13 pm
by Kurzer
Hello everybody,
I have a question regarding the PureBasics F1 help function.

As described in the PureBasic help, one can include the old Microsoft Win32.hlp help file into PureBasics help functionality.
https://www.purebasic.com/documentation ... _help.html

The WIn32.hlp is automatically called with the correct context when the caret is on a Win API command in the IDE and the user presses F1. For Example if the user press F1 and the caret is placed on 'CreateWindowEx_('

The *.hlp help file format is very old and you will find here http://laurencejackson.com/win32/ the same Win32 help but in chm format, which is a modern help format and offers a table of contence and a better search.

Image

Is it somehow possible to call this WIn32.CHM file via F1 instead of the old WIn32.hlp file?

Greetings, Kurzer

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Fri Apr 19, 2019 2:54 pm
by RSBasic
win32.chm is very outdated. Many functions are not documented in the help file. E.g. GetLastInputInfo_(), ProcessIdToSessionId_(), GetProductInfo_(), InternetGetConnectedStateEx_(), CreateHardLink_(), ...
If you want to read information from a function that is not documented in win32.chm, you must always use Google.
I recommend Google. E.g. GetLastInputInfo msdn
Or you can create a PB tool to access the MSDN page.

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Fri Apr 19, 2019 3:12 pm
by Little John
RSBasic wrote:Or you can create a PB tool to access the MSDN page.
See this code by ts-soft on the German forum. :-)

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Fri Apr 19, 2019 5:14 pm
by Kurzer
Thank you for your contributions and hints. Image

It don't mind if I can't call the chm directly. It would have been just a "nice to have".

For me the online msdn page is a bit confusing, but I'm not a hardcore winapi user either. I mainly look into this Win32 help out of curiosity. For the F1 help I leave the old Win32.hlp file in the help folder and call the chm file manually or via the help menu of the IDE.

Out of curiosity I changed the hard coded call of the "Win32.hlp" file in the PureBasic editor with a hex editor to "Win32.chm". This works, but obviously the transfer of the topic (the winapi command under the caret) has to be done differently than with a ".hlp" file. So it didn't worked for me, except that the chm file can be called with F1 and then shows me "The topic doesn't exist". :lol:

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Fri Apr 19, 2019 5:56 pm
by RSBasic
kurzer wrote:Out of curiosity I changed the hard coded call of the "Win32.hlp" file in the PureBasic editor with a hex editor to "Win32.chm".
Good idea :)
kurzer wrote:
kurzer wrote:Out of curiosity I changed the hard coded call of the "Win32.hlp" file in the PureBasic editor with a hex editor to "Win32.chm".
You may be able to develop an application called "Win32.exe" and change it to this application in the hex editor. Your Win32.exe application only needs to forward the parameter to Win32.chm (hh.exe).

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Fri Apr 19, 2019 7:15 pm
by Kurzer
RSBasic wrote:You may be able to develop an application called "Win32.exe" and change it to this application in the hex editor. Your Win32.exe application only needs to forward the parameter to Win32.chm (hh.exe).
Hehe, yes good idea, RSBasic. :D I had this idea too, but unfortunately I don't know the convention for parameters for a CHM file call.

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Sat Apr 20, 2019 3:49 am
by chi
If you don't mind using a different key than F1, you could use your own shortcut (e.g. Alt-F1) with this little IDE Tool (needs no arguments).

Code: Select all

EnableExplicit

If CreateMutex_(0, 1, "Win32.chm") = 0 Or GetLastError_() <> 0
  PostMessage_(FindWindow_(0,"Win32 Programmer's Reference"), #WM_CLOSE, 0, 0)
EndIf

Prototype HtmlHelp(a, b.s, c, d)

#HH_DISPLAY_TOPIC  = 0
#HH_DISPLAY_TOC    = 1
#HH_KEYWORD_LOOKUP = $D

Structure tAKLIN
  cbStruct.l
  fReserved.l
  pszKeywords.s
  pszUrl.s
  pszMsgText.s
  pszMsgTitle.s
  pszWindow.s
  fIndexOnFail.l
EndStructure

Procedure HtmlHelp(HelpFile.s, Keyword.s) ;by ts-soft (https://www.purebasic.fr/english/viewtopic.php?p=355981#p355981)
  Protected AKLIN.tAKLIN
  Protected HtmlHelp_.HtmlHelp
  Protected hWnd
  Protected DLL = OpenLibrary(#PB_Any, "HHCtrl.ocx")
  If DLL
    CompilerIf #PB_Compiler_Unicode
      HtmlHelp_ = GetFunction(DLL, "HtmlHelpW")
    CompilerElse
      HtmlHelp_ = GetFunction(DLL, "HtmlHelpA")
    CompilerEndIf
    With AKLIN
      \cbStruct = SizeOf(tAKLIN)
      \fReserved = 0
      \pszKeywords = Keyword
      \fIndexOnFail = #True
    EndWith
    hWnd = HtmlHelp_(0, HelpFile, #HH_KEYWORD_LOOKUP, AKLIN)
    HtmlHelp_(0, HelpFile, #HH_DISPLAY_TOC, 0)
    CloseLibrary(DLL)
    ProcedureReturn hWnd
  EndIf
EndProcedure

Define chm$ = "D:\Program Files\PureBasicTools\Win32.chm"
Define word$ = RTrim(GetEnvironmentVariable("PB_TOOL_Word"), "_")
Define hWnd_chm = HtmlHelp(chm$, word$)

If hWnd_chm
  While IsWindow_(hWnd_chm)
    Delay(1000)
  Wend
EndIf
[/size]Edit: fixed mix-up with constants (#HH_DISPLAY_TOPIC = 0, #HH_DISPLAY_TOC = 1), changed the order of execution (#HH_KEYWORD_LOOKUP before #HH_DISPLAY_TOC) to provide a better experience ;)

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Sat Apr 20, 2019 5:11 pm
by Kurzer
Chi and ts-soft,

thank you both. What a great solution.
This works like a charm. Jippie Image

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Sun Apr 21, 2019 9:57 am
by Kurzer
chi wrote: HtmlHelp_(0, HelpFile, #HH_DISPLAY_TOPIC, 0)
hWnd = HtmlHelp_(0, HelpFile, #HH_KEYWORD_LOOKUP, AKLIN)
@ts-soft: Thank you for creating the original snipplet, I try to understand all of it, but I did not understand exactly this part. Can you explain why you are calling HtmlHelp_() twice? The first call would display the topic content (if it were the only call), but the second call immediately commands the help to display the keyword.

@chi: You've implemented the ingenious mutex() check to see if the help has already been called from the PB IDE.
Will a WInAPI created mutex be automatically released when PB exits the program? To be on the safe side I added the following to the program, because I wasn't sure.

Code: Select all

Define iMutex.i = CreateMutex_(0, 1, "Win32.chm")
If iMutex = 0 Or GetLastError_() <> 0
	PostMessage_(FindWindow_(0,"Win32 Programmer's Reference"), #WM_CLOSE, 0, 0)
EndIf
; ... calling the Help and wait for user quits the help window ...
If iMutex <> 0
	ReleaseMutex_(iMutex)
EndIf
End

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Sun Apr 21, 2019 11:19 am
by BarryG
kurzer wrote:Will a WInAPI created mutex be automatically released when PB exits the program?
Yes. From MSDN for CreateMutex: "The system closes the handle automatically when the process terminates."

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Sun Apr 21, 2019 7:05 pm
by chi
kurzer wrote:Can you explain why you are calling HtmlHelp_() twice? The first call would display the topic content (if it were the only call), but the second call immediately commands the help to display the keyword.
HH_KEYWORD_LOOKUP command
You must first call the HH_DISPLAY_TOPIC command before calling this command to ensure that the help window is created.

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Sun Apr 21, 2019 7:55 pm
by Kurzer
Thank you very much for the explanation, Chi.

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Sun Apr 21, 2019 11:32 pm
by ts-soft
double holds better :mrgreen:

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Mon Apr 22, 2019 6:40 am
by chi
made small changes... previous code updated

Re: How to call a win32.chm file via F1 in the IDE?

Posted: Mon Apr 22, 2019 2:00 pm
by Kurzer
Thank you, I've updated my own code. Image