Does anyone have an example using these items? It doesn't seem that they are widely used and I am missing something. Thanks...
dlgTplt DLGTEMPLATE <WS_OVERLAPPEDWINDOW, 0, 0, 400, 400, 200, 200>
invoke CreateDialogIndirectParam, hInstance, addr dlgTplt, hWin, addr DlgProc, 0
DlgProc PROC hWnd3:HWND,iMsg:DWORD,wParam:WPARAM, lParam:LPARAM
.if iMsg==WM_INITDIALOG
push hWnd3
pop hwnd3
.elseif iMsg==WM_CLOSE
invoke EndDialog,hWnd3,NULL
mov hwndDlg,0
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
There is a demo based on a MASM32 in-memory dialog here:
http://www.masm32.com/board/index.php?topic=6884.msg51111#msg51111
Note that the CallModelessDialog macro is now included in MASM32 version 10, so you will need to remove the duplicate from the source.
Thanks MichaelW. This is an interesting program, but since I am not a graphic person, it is over my head and it is also making a lot of calls to macros. I would like to get a simple module that explains what I am doing wrong. M$ SDK gives some info, but no example and I have not located one google-ing. It's not all that important, but it does look useful when producing multiple dialogs from one. The code I posted looks like it should work, but it fails.
Hi hotrod,
You can extract binary resource templates from compiled resource ( .res ) files :
http://vortex.masmcode.com/files/Res2objV1.zip
Thanks Vortex. I have used .rc files extensively, but I am trying to get the code I posted to work as defined by M$ "The CreateDialogIndirectParam function creates a modeless dialog box from a dialog box template in memory. Before displaying the dialog box, the function passes an application-defined value to the dialog box procedure as the lParam parameter of the WM_INITDIALOG message. An application can use this value to initialize dialog box controls." and "lpTemplate
[in] Pointer to a global memory object that contains the template CreateDialogIndirectParam uses to create the dialog box. A dialog box template consists of a header that describes the dialog box, followed by one or more additional blocks of data that describe each of the controls in the dialog box. The template can use either the standard format or the extended format.
In a standard template, the header is a DLGTEMPLATE structure followed by additional variable-length arrays. The data for each control consists of a DLGITEMTEMPLATE structure followed by additional variable-length arrays."
The attachment is about as simple as I could make it.
MichaelW, you have touched my funny bone with that one and my appreciation. You guys that know this stuff have a clear advantage on us who do it the hard way. I wish I had a tenth of your ability. Your first remark in the .asm clears up a bunch, I will go in and modify it.
Quote; The DLGTEMPLATE structure is declared incorrectly in windows.inc,
; causing the structure size to be 20 bytes instead of the 18 bytes
; that the Windows API expects:
hotrod,
You can use more "pure" assembly too... without proc,endproc, uses,call, ret etc. blah-bla-bla.. :bdg
.686
.xmm
.model flat, stdcall
option casemap:none,language:stdcall,dotname
assume fs:nothing
include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib
.code
Def_0:
db 33h,0C0h,0Ebh,5,0B8h,1,0,0,0,83h,0C4h,14h,0FFh,64h,24h,0ECh
dd ExitProcess, 400000h, DlgTempl,0,Start+39,0,0,0
dd L_WM_INITDIALOG+3Eh, 0, IDI_APPLICATION, LoadMenuIndirect
dd 0, WM_SETICON,ICON_SMALL,0,L_WM_INITDIALOG+48h, MenuTempl,Def_0+4,0
MyMsg db "Hi there",0
MyTitle db "Hi from Lingo!",0
DlgTempl db 0,8,200,16,0,0,0,0,2,0,20,0,10,0,186,0
db 94,0,0,0,0,0,72,0,105,0,0,0,0,0,1,80
db 0,0,0,0,64,0,12,0,50,0,21,0,110,0,255,255
db 128,0,38,0,72,0,105,0,0,0,0,0,0,0,1,80
db 0,0,0,0,64,0,42,0,50,0,21,0,120,0,255,255
db 128,0,38,0,69,0,120,0,105,0,116,0,0,0,0,0
MenuTempl db 0,0,0,0,144,0,38,0,70,0,105,0,108,0,101,0
db 0,0,0,0,11,0,38,0,83,0,97,0,121,0,32,0
db 104,0,101,0,108,0,108,0,111,0,0,0,128,0,12,0
db 38,0,69,0,120,0,105,0,116,0,0,0
Start db 83h, 0C4h, 0D1h, 83h, 0E4h, 0F0h
movdqa xmm1, oword ptr [Def_0+16]
movdqa xmm2, oword ptr [Def_0+32]
movdqa [esp+0*16], xmm1
movdqa [esp+1*16], xmm2
jne DialogBoxIndirectParam ; call API
mov ecx,[esp+4*4] ; lParam-> Is it menu?
mov eax,-10h ; - WM_CLOSE
add eax,[esp+2*4] ; eax->msg
je L_WM_CLOSE
sub eax,100h ; WM_INITDIALOG
je L_WM_INITDIALOG
sub eax,1 ; WM_COMMAND
jne Def_0
mov edx, [esp+3*4] ; edx->wParam
test ecx,ecx ; ecx->lParam-> Is it menu?
jne @f
sub edx,11 ; HELLO from Menu = 11
je L_IDC_HELLO
sub edx,1 ; EXIT from Menu = 12
jne Def_0
L_WM_CLOSE:
mov eax,[esp+1*4] ; eax->hwnd
add esp,-3*4 ; loading the stack
mov [esp], offset Def_0+4 ; return address
mov [esp+1*4], eax ; parameter for EndDialog API
mov dword ptr [esp+2*4], 0 ; parameter for EndDialog API
jne EndDialog ; call API
@@:
sub edx, 120 ; EXIT from button = 120
je L_WM_CLOSE
add edx, 10 ; HELLO from button = 110
jne Def_0+9
L_IDC_HELLO:
add esp, -5*4
mov [esp], offset Def_0+4 ; return address
mov dword ptr [esp+1*4], 0 ; parameter for MessageBox API
mov [esp+2*4], offset MyMsg ; parameter for MessageBox API
mov [esp+3*4], offset MyTitle ; parameter for MessageBox API
mov dword ptr [esp+4*4], MB_OK ; parameter for MessageBox API
jne MessageBox ; call API
L_WM_INITDIALOG:
mov ecx,[esp+1*4] ; ecx->hwnd
add esp,-13*4
movdqa xmm1, oword ptr [Def_0+48]
movdqa xmm2, oword ptr [Def_0+64]
movdqa xmm3, oword ptr [Def_0+80]
movdqu [esp+0*16], xmm1
movdqu [esp+1*16], xmm2
mov [esp+1*16], ecx
movdqu [esp+2*16], xmm3
mov [esp+2*16+12], ecx
jne LoadIcon ; call API
add [esp+4*4], eax ; change stack; eax->hIcon
jne SendMessage ; call API
mov [esp+2*4], eax ; change stack; eax->hMenu
jno SetMenu ; call API
End Start
lingo, where are the templates documented; I could eventually figure them out, but it would take awhile? As a matter of fact, I have never seen this approach before. Are you trying to be a trouble maker???
:bg
No need to get revved up, Lingo has just shown you another way to write the code. If it does not suite you, use another technique.
hotrod - i bet lingo's code is fast :U
Hutch, not reved up, just kidding - got to have a since of humor or you will die from the pressure.
dedndave, yep, lingo has got it together, you people are killing me with education.