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

Working on new editor enhancements?
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 591
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

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

Post 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
PB 5.73 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 53y
"Happiness is a pet." | "Never run a changing system!"
RSBasic
Moderator
Moderator
Posts: 1122
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

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

Post 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.
ImageImageImageImage
Little John
Addict
Addict
Posts: 4006
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

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

Post 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. :-)
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 591
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

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

Post 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:
PB 5.73 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 53y
"Happiness is a pet." | "Never run a changing system!"
RSBasic
Moderator
Moderator
Posts: 1122
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

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

Post 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).
ImageImageImageImage
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 591
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

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

Post 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.
PB 5.73 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 53y
"Happiness is a pet." | "Never run a changing system!"
User avatar
chi
Addict
Addict
Posts: 862
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

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

Post 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 ;)
Last edited by chi on Mon Apr 22, 2019 6:38 am, edited 1 time in total.
Et cetera is my worst enemy
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 591
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

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

Post by Kurzer »

Chi and ts-soft,

thank you both. What a great solution.
This works like a charm. Jippie Image
PB 5.73 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 53y
"Happiness is a pet." | "Never run a changing system!"
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 591
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

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

Post 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
PB 5.73 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 53y
"Happiness is a pet." | "Never run a changing system!"
BarryG
Addict
Addict
Posts: 1709
Joined: Thu Apr 18, 2019 8:17 am

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

Post 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."
User avatar
chi
Addict
Addict
Posts: 862
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

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

Post 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.
Et cetera is my worst enemy
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 591
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

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

Post by Kurzer »

Thank you very much for the explanation, Chi.
PB 5.73 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 53y
"Happiness is a pet." | "Never run a changing system!"
User avatar
ts-soft
Always Here
Always Here
Posts: 5758
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post by ts-soft »

double holds better :mrgreen:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
chi
Addict
Addict
Posts: 862
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

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

Post by chi »

made small changes... previous code updated
Et cetera is my worst enemy
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 591
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

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

Post by Kurzer »

Thank you, I've updated my own code. Image
PB 5.73 x64, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 53y
"Happiness is a pet." | "Never run a changing system!"
Post Reply