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__

Many thanks to everyone who helped me in writing this program!
; GUI #
include win64a.inc
HELPINFO struct
cbSize dq ?
iContextType dq ?
iCtrlId dq ?
hItemHandle dq ?
dwContextId dq ?
MousePos POINT <>
HELPINFO ends
.code
WinMain proc
local msg:MSG
xor ebx,ebx
mov esi,IMAGE_BASE
mov edi,offset ClassName
mov ecx,offset FileName
invoke LoadCursorFromFile
push rax ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push COLOR_WINDOW+1;hbrBackground
push 10003h ;hCursor
push rax    ;hIcon
push rsi ;hInstance
push rbx    ;cbClsExtra & cbWndExtra
pushaddr WndProc  ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
invoke RegisterClassEx,esp ;addr WNDCLASSEX
push rbx
push rsi ;rsi=400000h
shl esi,9 ;rsi=CW_USEDEFAULT
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
sub esp,20h
mov r9d,WS_OVERLAPPEDWINDOW or WS_VISIBLE
    invoke CreateWindowEx,0,edi,edi
mov hwnd,rax
lea edi,msg
@@: invoke GetMessage,edi,NULL,0,0
    invoke TranslateMessage,edi
invoke DispatchMessage,edi
jmp @b
WinMain endp
WndProc proc hWnd:QWORD,uMsg:QWORD,wParam:QWORD,lParam:QWORD
local ps:PAINTSTRUCT
local expRect:RECT
mov  hWnd,rcx
mov wParam,r8
mov lParam,r9
cmp edx,WM_DESTROY
je wmDESTROY
        cmp edx,WM_PAINT
        je wmPAINT
        cmp edx,WM_HELP
        je wmHELP
        cmp edx,WM_KEYDOWN
        je wmF1
leave
jmp NtdllDefWindowProc_
wmDESTROY: invoke RtlExitUserProcess,NULL
wmPAINT:invoke BeginPaint,,addr ps
        invoke GetClientRect,hWnd,addr expRect
        mov edx,offset message
        invoke DrawText,ps.hdc,,-1,addr expRect,DT_SINGLELINE or DT_CENTER or DT_VCENTER
        invoke EndPaint,hWnd,addr ps
jmp wmBYE
wmHELP: mov rax,[r9+HELPINFO.iCtrlId]
cmp rax,hwnd
je wmBYE
mov r8d,offset hlpfile
invoke ShellExecute,0,0,,0,0,1
        jmp wmBYE
wmF1: cmp r8,VK_F1
        jne wmBYE
mov edx,offset message2
mov r8d,offset ClassName
invoke MessageBox,hwnd,,,MB_HELP
wmBYE:  leave
        ret
WndProc endp
.data
ClassName db "Uncle Remus tales:#3 Simple window",0
FileName db "..\Images\br_Rabbit3.cur",0
message db "Press on F1 button",0
message2 db 'Press on "Help"',0
hlpfile db 'tut_01.hlp',0
hwnd dq ?
end

aw27

I have done an example in C/C++ including an WinHelp file with help context 10 which will be requested in the example. It will be elementary to convert to asm but I will not do it because am very lazy these days.




#include "windows.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR    lpCmdLine,
_In_ int       nCmdShow)
{
WNDCLASS windowClass = { 0 };
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hInstance = NULL;
windowClass.lpfnWndProc = WndProc;
windowClass.lpszClassName = L"Window in Console Application";
windowClass.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&windowClass))
MessageBox(NULL, L"Error registering class", L"Error", MB_OK);
HWND windowHandle = CreateWindow(L"Window in Console Application",
NULL,
WS_POPUP,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
NULL,
NULL,
NULL,
NULL);

MessageBox(windowHandle, L"Help me", L"Hello HELP", MB_HELP);
MSG messages;
while (GetMessage(&messages, NULL, 0, 0) > 0)
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}

return messages.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message)
{
case WM_HELP:
WinHelp(0, L"MyHelp.hlp", HELP_CONTEXT, 10);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wparam, lparam);
}
return 0;
}

felipe

here it's a version from the c one. It's a console application. Unfortunately, like all the others old .hlp files i can only see the content with the help of a program that i donwloaded from this forum (don't remember where). This program just open the helpless windows 8.1 help which dosn't help me at all... :icon_exclaim:

aw27

In this thread there is a link to a google drive where there is winhlp32-windows-7-10-x86-64.zip

Help files downloaded from the internet will need to be unblocked - right click/properties/Unblock or whatever equivalent they invented.


hutch--

This one that Jim posted a while ago works fine.

http://masm32.com/board/index.php?topic=5201.0

felipe

I think that's the one i use (jim's version). It works pretty well.  :t

Mikl__

Hi, All!
Why do I click on the "Help" button, but the call for help does not occur?
asm-file; GUI #
include win64a.inc
MSGBOXDATA struct       
     params              MSGBOXPARAMS <>
     pwndOwner           QWORD ?
     wLanguageId         DWORD ?,?
     pidButton           QWORD ?         ; // Array of button IDs
     ppszButtonText      QWORD ?         ; // Array of button text strings
     cButtons            DWORD ?
     DefButton           DWORD ?
     CancelId            DWORD ?
     Timeout             DWORD ?
MSGBOXDATA ends
.code
hlpfile     db 'Uncle Remus Tales.chm',0
MsgBoxText1:    du <Win64 Assembly is Great>
MsgCaption8: du <SoftModalMessageBox>
sBTN1: du <OK>
sBTN2: du <Help>

dwBtnIds  dd 1,0
dwTxtTbl  dq sBTN1,sBTN2
align 16

WinMain proc
local mb:MSGBOXPARAMS
local mbxData:MSGBOXDATA

mov mbxData.params.cbSize,sizeof MSGBOXPARAMS
and mbxData.params.hwndOwner,0
mov mbxData.params.hInstance,IMAGE_BASE
movr mbxData.params.lpszText,MsgBoxText1         ;text address
  movr mbxData.params.lpszCaption,MsgCaption8    ;title address
        mov mbxData.params.dwStyle,MB_USERICON or MB_HELP
  movr mbxData.params.lpszIcon,1000
mov mbxData.params.dwContextHelpId,1
movr mbxData.params.lpfnMsgBoxCallback,MsgBoxCallback
  and mbxData.params.dwLanguageId,0
        and mbxData.pwndOwner,0
    and mbxData.wLanguageId,0
movr mbxData.pidButton,dwBtnIds
    movr mbxData.ppszButtonText,dwTxtTbl
    mov mbxData.cButtons,2
    and mbxData.DefButton,0
    mov mbxData.CancelId,1
    or mbxData.Timeout,-1
lea ecx,mbxData
      invoke SoftModalMessageBox
invoke RtlExitUserProcess,NULL
WinMain endp
align 16
MsgBoxCallback proc lpHelpInfo:qword;(LPHELPINFO lpHelpInfo)
mov r8d,offset hlpfile
invoke ShellExecute,0,0,,0,0,1
leave
retn
MsgBoxCallback endp
end
rc-file1000 ICON DISCARDABLE "br_Bear4.ico"

Mikl__


aw27

mov r8d,offset hlpfile ?

Ah, you build with /LARGEADDRESSAWARE:NO  :(