News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

how to attach a file.hlp to MessageBox with the button "Help"?

Started by Mikl__, December 18, 2018, 08:35:49 PM

Previous topic - Next topic

Mikl__

Help me to attach a file.hlp to MessageBox with the button "Help" (MB_HELP). Thank you in advance.

TimoVJL

Maybe it's useless with MessageBox(), but with MessageBoxIndirect()#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);
}
May the source be with you

Mikl__

Paljon kiitoksia, Timo!
Can just do the same with simple MessageBox? How do MsgBoxCallback? Via WM_HELP? Or track pressing the F1 key?

sinsi

Use your main window's handle when calling the message box
    invoke MessageBox,mainwnd,0,0,MB_OK or MB_HELP

In your main window's message loop for WM_HELP
    invoke ShellExecute,0,0,offset hlpfile,0,0,1


Mikl__


aw27

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__


jj2007

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__


jj2007

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):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

@jj2007 if key F2 opens that MessageBox that WM_HELP handling works normally ?
May the source be with you

jj2007

Excellent point, Timo! In fact, F1 seems to trigger WM_HELP, F2 doesn't.

Vortex

Hi  Mikl__,

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

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


Mikl__

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!