Author Topic: how to attach a file.hlp to MessageBox with the button "Help"?  (Read 1497 times)

Mikl__

  • Member
  • ****
  • Posts: 758
how to attach a file.hlp to MessageBox with the button "Help"?
« on: December 18, 2018, 08:35:49 PM »
Help me to attach a file.hlp to MessageBox with the button "Help" (MB_HELP). Thank you in advance.

TimoVJL

  • Member
  • ***
  • Posts: 408
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #1 on: December 18, 2018, 10:57:39 PM »
Maybe it's useless with MessageBox(), but with MessageBoxIndirect()
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

VOID CALLBACK MsgBoxCallback(LPHELPINFO lpHelpInfo)
{
//MessageBox(0,0,0,MB_OK);
WinHelp(0, "MyHelp.hlp", HELP_CONTEXT, lpHelpInfo->dwContextId);
}

void __cdecl WinMainCRTStartup(void)
{
MSGBOXPARAMS mbp;

//memset(&mbp, 0, sizeof(mbp));
mbp.cbSize = sizeof(mbp);
mbp.hwndOwner = 0;
mbp.hInstance = GetModuleHandle(NULL);
mbp.lpszText = "Text";
mbp.lpszCaption = "Caption";
mbp.dwStyle = MB_HELP;
mbp.lpszIcon = 0;
mbp.dwContextHelpId = 1; // help topic ID
mbp.lpfnMsgBoxCallback = MsgBoxCallback;
mbp.dwLanguageId = 0;
int rc = MessageBoxIndirect(&mbp);
ExitProcess(0);
}
« Last Edit: December 19, 2018, 10:28:13 PM by TimoVJL »
May the source be with you

Mikl__

  • Member
  • ****
  • Posts: 758
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #2 on: December 19, 2018, 12:06:59 AM »
Paljon kiitoksia, Timo!
Can just do the same with simple MessageBox? How do MsgBoxCallback? Via WM_HELP? Or track pressing the F1 key?

sinsi

  • Member
  • *****
  • Posts: 1176
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #3 on: December 19, 2018, 12:14:28 AM »
Use your main window's handle when calling the message box
Code: [Select]
    invoke MessageBox,mainwnd,0,0,MB_OK or MB_HELP
In your main window's message loop for WM_HELP
Code: [Select]
    invoke ShellExecute,0,0,offset hlpfile,0,0,1
I can walk on water but stagger on beer bourbon.

Mikl__

  • Member
  • ****
  • Posts: 758
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #4 on: December 19, 2018, 12:19:48 AM »
Hi, sinsi!
Thank you very much!

AW

  • Member
  • *****
  • Posts: 2231
  • Let's Make ASM Great Again!
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #5 on: December 19, 2018, 01:24:34 AM »
In the meantime I found a place where you can download the Winhelp compiler and produce great retro old-fashioned help files even from Windows 10 64-bit (I tested  :t). http://www.divcomsoft.com/info/helpcompilers.php

Mikl__

  • Member
  • ****
  • Posts: 758
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #6 on: December 19, 2018, 03:24:40 AM »
Hi, José!
Thank you very much!

jj2007

  • Member
  • *****
  • Posts: 9635
  • Assembler is fun ;-)
    • MasmBasic
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #7 on: December 19, 2018, 03:38:41 AM »
José,
That page links to a Microsoft ftp server, and it doesn't work. But this one is OK - first link on top: http://www.rtfc.de/rtfc0031.html

Direct link: http://download.microsoft.com/download/word97win/Utility/4.03/WIN98/EN-US/Hcwsetup.exe

Mikl__

  • Member
  • ****
  • Posts: 758
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #8 on: December 19, 2018, 03:44:15 AM »
Ciao, jj2007! Come sta?

jj2007

  • Member
  • *****
  • Posts: 9635
  • Assembler is fun ;-)
    • MasmBasic
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #9 on: December 19, 2018, 02:29:43 PM »
Sto bene, Mikl, e tu? Gli orsi nel tuo cortile si comportano bene? ;-)

I've made a little test with the WM_HELP message. It works but the message gets already fired when you show the MsgBox; therefore you must check for iCtrlId (demo attached):
Code: [Select]
GuiParas equ "Help demo", x660, y50, w100, h100
include \masm32\MasmBasic\Res\MbGui.asm
Event Message
  .if uMsg_==WM_HELP
mov ecx, lParam_
hi equ [ecx.HELPINFO]
deb 4, "Help", hi.iContextType, hi.iCtrlId, hi.hItemHandle, hi.dwContextId, hi.MousePos.x
.if hi.iCtrlId ; #### this check is essential! ####
PrintLine "Lauching help"
ShEx "\Masm32\help\hlhelp.chm"
.endif
  .endif
Event Paint
  GuiTextBox 9, 9, 99.0-18, 99.0-18, "Hit F1", bcol RgbCol(160, 255, 255)
Event Key
 .if VKey==VK_F1
  MsgBox hWnd_, "Click the ? to get macro help", "Hi", MB_OK or MB_HELP
 .endif
GuiEnd

OPT_Susy Console ; force console build

TimoVJL

  • Member
  • ***
  • Posts: 408
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #10 on: December 20, 2018, 01:52:09 AM »
@jj2007 if key F2 opens that MessageBox that WM_HELP handling works normally ?
May the source be with you

jj2007

  • Member
  • *****
  • Posts: 9635
  • Assembler is fun ;-)
    • MasmBasic
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #11 on: December 20, 2018, 05:40:33 AM »
Excellent point, Timo! In fact, F1 seems to trigger WM_HELP, F2 doesn't.

Vortex

  • Member
  • *****
  • Posts: 1987
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #12 on: December 20, 2018, 05:41:57 AM »
Hi  Mikl__,

You can subclass the message box and control the help button.

Code: [Select]
include MBox.inc
   
.data

capt        db "Hello!",0
msg         db 'Customized message box',0
msg2        db 'You clicked the Help button',0
ButtonText  db 'Click here',0
bclass      db 'Button',0
   
.data?
   
pOldProc    dd ?
HelpBtnID   dd ?
   
.code
   
start:
   
    invoke  CustMsgBox,0,ADDR msg,ADDR capt,ADDR ButtonText
    invoke  ExitProcess,0
   
CustMsgBox  PROC uses esi handle:DWORD,message:DWORD,caption:DWORD,button:DWORD

LOCAL ThreadID:DWORD
LOCAL hWnd:DWORD
LOCAL hThread:DWORD
LOCAL hClick:DWORD
   
    invoke  CreateThread,0,0,ADDR ThreadProc,\
            ADDR caption,0,ADDR ThreadID
    mov     hThread,eax

    invoke  GetCurrentProcess
    invoke  WaitForInputIdle,eax,INFINITE
    invoke  EnumWindows,ADDR EnumWndProc,\
            ADDR ThreadID

    invoke  FindWindowEx,hWnd,0,ADDR bclass,0
    mov     hClick,eax

    invoke  FindWindowEx,hWnd,eax,ADDR bclass,0
    invoke  GetDlgCtrlID,eax
    mov     HelpBtnID,eax

    invoke  SetWindowText,hClick,button
    invoke  SetWindowLong,hWnd,GWL_WNDPROC,\
            ADDR MsgboxProc
    mov     pOldProc,eax
   
    invoke  WaitForSingleObject,hThread,INFINITE
    invoke  CloseHandle,hThread
    ret   
   
CustMsgBox ENDP


ThreadProc PROC pParams:DWORD
   
    mov     eax,pParams
    invoke  MessageBox,DWORD PTR [eax-8],\
            DWORD PTR [eax-4],DWORD PTR [eax],\
            MB_HELP
    ret
   
ThreadProc ENDP


EnumWndProc PROC hWnd:DWORD,lParam:DWORD
   
    LOCAL pid:DWORD
   
    invoke  GetWindowThreadProcessId,hWnd,ADDR pid
    mov     edx,lParam
    cmp     eax,[edx]
    jne     @f
    push    hWnd
    pop     DWORD PTR [edx-4]  ; get the handle of the window
    xor     eax,eax            ; displaying the message box
    ret
@@:
    mov     eax,TRUE
    ret
   
EnumWndProc ENDP
   
MsgboxProc PROC hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
   
    .IF uMsg == WM_COMMAND
   
        mov     eax,wParam
        mov     edx,eax
        shr     edx,16
       
        .IF dx==BN_CLICKED
       
            mov  ecx,HelpBtnID
           
            .IF ax==cx

                invoke  MessageBox,0,ADDR msg2,ADDR capt,MB_OK

            .ENDIF
           
        .ENDIF
       
    .ENDIF
   
    invoke  CallWindowProc,pOldProc,hWnd,uMsg,wParam,lParam
    ret
   
    MsgboxProc    ENDP

END start

jj2007

  • Member
  • *****
  • Posts: 9635
  • Assembler is fun ;-)
    • MasmBasic
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #13 on: December 20, 2018, 01:24:12 PM »
Very cute technique, Erol :t

Mikl__

  • Member
  • ****
  • Posts: 758
Re: how to attach a file.hlp to MessageBox with the button "Help"?
« Reply #14 on: December 23, 2018, 12:59:15 AM »
Buona sera, jj2007! I cuccioli di orso sono cresciuti molto e sono diventati pericolosi, quindi ho dovuto darli allo zoo.
Hi, Erol! Thank you very much for excellent example!
« Last Edit: December 23, 2018, 11:55:21 PM by Mikl__ »