Hi all,

I have to use a dialog template in memory for a little sample code I am working on and since I haven't ever really done this that I can remember I am having a bit of trouble. The dialog will show correctly until I add a control, at which point it returns "Error 1407 > Cannot find window class.". Since the class is "Edit" I think I must have an alignment problem but I can't find it...

NEWITEMTEMPLATEEX struct
dlgVer DW 1
signature DW 0FFFFh
helpID DD 0
exStyle DD WS_EX_TOOLWINDOW
style DD WS_VISIBLE + WS_SYSMENU + WS_CAPTION + DS_SETFONT
cDlgItems DW 1
x DW 6
y DW 6
cx DW 208
cy DW 212
menu DW 0 ;IDD_NEWITEMDLG
windowClass DW 0
title DUS "New/edit item",0
pointsize DW 8
weight DW 400
italic DB 0
charset DB 0
typeface DUS "MS Sans Serif",0
ENDS

CONTROL1 STRUCT
helpID DD 0
exStyle DD 0x00000200
style DD 0x50010000
x DW 56
y DW 70
cx DW 120
cy DW 13
id DW IDC_STARTIN
windowClass DUS "Edit",0
title DW 0
extraCount DW 0
ENDS

DATA SECTION

ALIGN 4
NewItemDlg NEWITEMTEMPLATEEX <>
ALIGN 4
Ctrl1 CONTROL1 <>
ALIGN 4
EndDlgTemplate: // Provides padding to the next DWORD boundary

CODE SECTION

invoke DialogBoxIndirectParam,,offset NewItemDlg,,offset DlgProc2,0


Ofcourse the DialogBoxIndirectParam is in my main message loop and the and parameters are filled and correct at the time of the call. Thanks in advance for any help.

Donkey
Posted on 2006-10-22 15:00:03 by donkey
hi donkey,

your class definition is wrong, check this out:


;-----------------------------------------------------------
.const ; DialogEx Memory templates by drizz
;-----------------------------------------------------------
BUTTTON_CLASS equ 80h
EDIT_CLASS    equ 81h
STATIC_CLASS  equ 82h

dup_unicode macro ustr:vararg; pass nothing for nil ustring
  IFNB <ustr>
      FORC arg,<ustr>
          IFDIFI <arg>, <!'> 
                    IFDIFI <arg>, <!"> 
                        db "&arg",0
                    ENDIF 
          ENDIF 
      ENDM
  ENDIF   
        db 0,0
endm

; Dialog ;-----------------------------------------------------------
DLGT_START macro Name:req,title:req,font:req,fontsize:req,exStyle:req,Style:req,itemCnt:req,l:req,t:req,w:req,h:req
ALIGN 4
Name dw 1,-1;dlgVer,signature
dd 0;helpID
dd exStyle
dd WS_VISIBLE or DS_SETFONT or Style
dw itemCnt
dw l,t,w,h; x,y,cx,cy
dw 0,0;menu,class
dup_unicode title; caption
dw fontsize
dw 0
dw 0
dup_unicode font; font face
endm
; Edit ;-----------------------------------------------------------
DLGT_EDIT macro exStyle:req,Style:req,itemID:req,l:req,t:req,w:req,h:req
ALIGN 4
dd 0
    dd exStyle
    dd WS_VISIBLE or WS_CHILD or ES_LEFT or Style
    dw l,t,w,h; x,y,cx,cy
    dd itemID; ctlID
    dw 0ffffh,EDIT_CLASS; -1,class
    dw 0
endm
; Static ;-----------------------------------------------------------
DLGT_STATIC macro caption:req,exStyle:req,Style:req,itemID:req,l:req,t:req,w:req,h:req
ALIGN 4
dd 0
    dd exStyle
    dd WS_VISIBLE or WS_CHILD or SS_LEFT or Style
    dw l,t,w,h;x,y,cx,cy
    dd itemID;ctlID
    dw 0ffffh,STATIC_CLASS;-1,class
    dup_unicode caption
ALIGN 2
    dw 0
endm
; GroupBox ;--------------------------------------------------------
DLGT_GRPBOX macro caption:req,exStyle:req,Style:req,itemID:req,l:req,t:req,w:req,h:req
ALIGN 4
dd 0
    dd exStyle
    dd WS_VISIBLE or WS_CHILD or BS_GROUPBOX or Style
    dw l,t,w,h;0,0,200,87;x,y,cx,cy
    dd itemID;-1;667; ctlID
    dw 0ffffh,BUTTTON_CLASS;-1,class
    dup_unicode caption
ALIGN 2
    dw 0
endm
; Button ;-----------------------------------------------------------
DLGT_BUTTON macro caption:req,exStyle:req,Style:req,itemID:req,l:req,t:req,w:req,h:req
ALIGN 4
    dd 0
    dd exStyle
    dd WS_VISIBLE or WS_CHILD or BS_PUSHBUTTON or WS_TABSTOP or Style
    dw l,t,w,h;0,0,200,87;x,y,cx,cy
    dd itemID;-1;667; ctlID
    dw 0ffffh,BUTTTON_CLASS;-1,class
    dup_unicode caption
ALIGN 2
    dw 0
endm
; CheckBox ;-----------------------------------------------------------
DLGT_CHKBOX macro caption:req,exStyle:req,Style:req,itemID:req,l:req,t:req,w:req,h:req
ALIGN 4
    dd 0
    dd exStyle
    dd WS_VISIBLE or WS_CHILD or BS_AUTOCHECKBOX or WS_TABSTOP or Style
    dw l,t,w,h;0,0,200,87;x,y,cx,cy
    dd itemID;-1;667; ctlID
    dw 0ffffh,BUTTTON_CLASS;-1,class
    dup_unicode caption
ALIGN 2
    dw 0
endm
;---------------------------------------------------------------------
DLGT_END macro
    dw 0
endm
;---------------------------------------------------------------------


IDC_BTN1 equ 101
IDC_BTN2 equ 102
DLG_STYLE equ DS_MODALFRAME or DS_CENTER  or WS_CAPTION or WS_SYSMENU
.data
DLGT_START DlgTemplate,'Hello World','Arial',8,WS_EX_DLGMODALFRAME,DLG_STYLE,2,  6,6,194,106
DLGT_BUTTON 'Btn',WS_EX_STATICEDGE,0,IDC_BTN1, 8,7,48,12
DLGT_BUTTON 'Btn',WS_EX_STATICEDGE,0,IDC_BTN2, 8,24,48,15
DLGT_END
Posted on 2006-10-22 16:19:20 by drizz
Thank you very much Drizz, however it was not the class that was the problem though your post did point it out to me, I was missing a parameter (dwitemID). All is fine now (with UNICODE text as the class so I can use common controls and custom classes). Funny that that feild is not in the documentation for the structure.

Donkey
Posted on 2006-10-22 16:27:35 by donkey
of course : >custom classes< doh, either way, you found the error  :)
Posted on 2006-10-22 16:41:21 by drizz
Hi Drizz,

Actually the error was that I had defined the id as a WORD when it should have been a DWORD, dummy me, actually believing the SDK !!!!

typedef struct {
    DWORD helpID;
    DWORD exStyle;
    DWORD style;
    short x;
    short y;
    short cx;
    short cy;
    WORD id;
    sz_Or_Ord windowClass;
    sz_Or_Ord title;
    WORD extraCount;
} DLGITEMTEMPLATEEX;


id should be a DWORD not a WORD then everything is perfect.
Posted on 2006-10-22 16:50:09 by donkey
Hi,

it seems you aren't the only one :)
http://blogs.msdn.com/andypennell/archive/2006/03/29/564231.aspx

check the info in this KB (dword)  :)
http://support.microsoft.com/default.aspx?scid=kb;en-us;141201
Posted on 2006-10-22 17:14:19 by drizz
It seems we ended up with the same solution, define an extra WORD in the structure...

CONTROL1 STRUCT
helpID DD 0
exStyle DD WS_EX_CLIENTEDGE
style DD WS_CHILD+WS_VISIBLE+WS_TABSTOP
x DW 56
y DW 70
cx DW 120
cy DW 13
id DW IDC_STARTIN
unknown DW 0
windowClass DUS "Edit",0
title DW 0
extraCount DW 0
ENDS
Posted on 2006-10-22 17:33:02 by donkey