  rem VDS2ASM Converter v1.0
  rem written by Mike Cherry <mike@sterlingpolice.net>
  rem 
  rem converts dialog code into assembly code. NOTE: converts only
  rem dialog code, no functions, callbacks, or anything. the
  rem asm code generated was tested under Masm32 Version 6
  rem with the service pack installed. YOU MUST HAVE THE SERVICE
  rem PACK INSTALLED!
  rem 
  rem Masm32 and the service pack can be obtained from:
  rem 
  rem http://www.pbq.com.au/home/hutch/masm.htm
  rem 
  rem to use, just copy the dialog code from DIALOG CREATE
  rem to DIALOG SHOW, and paste it in the VDS Code text box
  rem then click convert.
  rem 
  rem only converts the following controls:
  rem (anything with a * next to it doesnt currently convert)
  rem 
  rem         single line edit
  rem         multi line edit
  rem         frame
  rem         button
  rem         status
  rem         combo
  rem         list
  rem         checkbox
  rem         text
  rem         progress
  rem         bitmap *
  rem         radio *
  rem         menu *
  rem 
  rem have fun with the code, modify if you want just send me a copy.
  rem a quick way to test it out is to just copy the dialog code below,
  rem then run this program and paste it in the VDS Code section. then
  rem just click Convert

  title VDS2ASM Converter

  option fieldsep,@chr(44)

  dialog CREATE,VDS2ASM Converter,-1,0,500,368,class VDS2ASMMain,resizable
  dialog ADD,STYLE,edtstyle,Courier New,10,B,WHITE,BLACK
  dialog ADD,GROUP,frame1,2,2,496,156,VDS Code
  dialog ADD,EDIT,vdscode,16,8,484,136,,multi,scroll,edtstyle
  dialog ADD,GROUP,frame2,162,2,496,156,ASM Code
  dialog ADD,EDIT,ccode,176,8,484,136,,multi,scroll,edtstyle
  dialog ADD,STATUS,STATUS
  dialog ADD,BUTTON,btnconvert,320,2,64,24,&Convert
  dialog ADD,BUTTON,btnexit,320,434,64,24,E&xit
  dialog SHOW

:Resize
  dialog setpos,frame1,2,2,@fsub(@winpos(#VDS2ASMMain,W),12),156
  dialog setpos,frame2,162,2,@fsub(@winpos(#VDS2ASMMain,W),12),@fsub(@winpos(#VDS2ASMMain,H),240)
  dialog setpos,vdscode,16,8,@fsub(@winpos(#VDS2ASMMain,W),25),136
  dialog setpos,ccode,176,8,@fsub(@winpos(#VDS2ASMMain,W),25),@fsub(@winpos(#VDS2ASMMain,H),260)
  dialog setpos,btnconvert,@fsub(@winpos(#VDS2ASMMain,H),75),2,64,24
  dialog setpos,btnexit,@fsub(@winpos(#VDS2ASMMain,H),75),@fsub(@winpos(#VDS2ASMMain,W),75),64,24

:Evloop
  %e = @event()
  if %e
    goto %e
  end 
  dialog cursor
  goto evloop

:btnconvertBUTTON
  if @null(@dlgtext(vdscode))
    warn "No VDS code to convert."
    goto evloop
  end 
  dialog cursor,wait
  dialog disable,btnconvert
  dialog disable,btnexit
  gosub Sub_ConvertVDSCode
  dialog enable,btnconvert
  dialog enable,btnexit
  goto evloop

:btnexitBUTTON
  goto Close

:Close
  stop 


  rem routines for converting vds code to asm code
:Sub_ConvertVDSCode

  rem define some actual names for the buffer lists
  rem this makes it easier in case the list numbers
  rem have to change
  %%headers = 1
  %%data = 2
  %%main = 3
  %%const = 4
  %%end = 5
  %%vds_code = 6
  %%c_code = 7
  %%temp = 8
  %%u_data = 9

  %%counter = 0

  list create,%%headers
  list create,%%data
  list create,%%main
  list create,%%const
  list create,%%end
  list create,%%vds_code
  list create,%%c_code
  list create,%%temp
  list create,%%u_data



  rem "backup" the contents of the clipboard
  list paste,%%temp

  clipboard set,@dlgtext(vdscode)
  list paste,%%vds_code

  rem preprocess the code
  rem this looks for a status bar so it
  rem can size the window properly
  dialog set,status,"Pre-processing code"
  list seek,%%vds_code,0
  if @match(%%vds_code, "status")
    %%height_add = 20
  else 
    %%height_add = 0
  end 

  list seek,%%vds_code,0
  parse "%%junk;%%title;%%top;%%left;%%width;%%height",@item(%%vds_code)
  %%class = @substr(%%class,7,@len(%%class))


  rem load header info into header list
  dialog set,status,"Generating header"
  list add,%%headers,"; Window and control code generated by VDS2ASM Converter v1.0"
  list add,%%headers,"; VDS2ASM Converter v1.0 written by Mike Cherry <mike@sterlingpolice.net>"
  list add,%%headers,";"
  list add,%%headers,"; Required Files:"
  list add,%%headers,";"
  list add,%%headers,";"@tab()"This file"
  list add,%%headers,";"@tab()"Rsrc.rc"@tab()@tab()"(Resource File)"
  list add,%%headers,";"@tab()"Main.ico"@tab()"(Program Icon)"
  list add,%%headers,";"
  list add,%%headers,"; Put all required files in the same directory, then build the project."
  list add,%%headers,
  list add,%%headers,".386"
  list add,%%headers,".model flat,stdcall"
  list add,%%headers,"option casemap:none"
  list add,%%headers,
  list add,%%headers,"; function prototypes"
  list add,%%headers,"WinMain proto :DWORD, :DWORD, :DWORD, :DWORD"
  list add,%%headers,"TopXY proto :DWORD, :DWORD"
  list add,%%headers,
  list add,%%headers,"; win32 asm includes"
  list add,%%headers,"include \masm32\include\windows.inc"
  list add,%%headers,"include \masm32\include\user32.inc"
  list add,%%headers,"include \masm32\include\kernel32.inc"
  list add,%%headers,"include \masm32\include\comctl32.inc"
  list add,%%headers,"include \masm32\include\comdlg32.inc"
  list add,%%headers,"include \masm32\include\shell32.inc"
  list add,%%headers,"include \masm32\include\gdi32.inc"
  list add,%%headers,
  list add,%%headers,"; win32 asm libraries"
  list add,%%headers,"includelib \masm32\lib\user32.lib"
  list add,%%headers,"includelib \masm32\lib\kernel32.lib"
  list add,%%headers,"includelib \masm32\lib\comctl32.lib"
  list add,%%headers,"includelib \masm32\lib\comdlg32.lib"
  list add,%%headers,"includelib \masm32\lib\shell32.lib"
  list add,%%headers,"includelib \masm32\lib\gdi32.lib"
  list add,%%headers,
  list add,%%headers,"; some macros to make our lives easier"
  list add,%%headers,"varSet MACRO Name, Text:VARARG"
  list add,%%headers,@tab()"LOCAL lbl"
  list add,%%headers,@tab()"jmp lbl"
  list add,%%headers,@tab()"Name db Text,0"
  list add,%%headers,@tab()"lbl:"
  list add,%%headers,"ENDM"
  list add,%%headers,
  list add,%%headers,"return MACRO arg"
  list add,%%headers,@tab()"mov eax, arg"
  list add,%%headers,@tab()"ret"
  list add,%%headers,"ENDM"

  rem initialized data
  dialog set,status,"Generating .data"
  list add,%%data,"; define some variables. you know what ClassName and AppName are"
  list add,%%data,".data"
  list add,%%data,@tab()"ClassName db "@chr(34)"Win_Main"@chr(34)",0"
  list add,%%data,@tab()"AppName db "@chr(34)%%title@chr(34)",0"
  list add,%%data,@tab()"true db "@chr(34)"TRUE"@chr(34)",0"
  list add,%%data,@tab()"false db "@chr(34)"FALSE"@chr(34)",0"
  list add,%%data,
  list add,%%data,@tab()"ButtonClassName db "@chr(34)"button"@chr(34)",0"
  list add,%%data,@tab()"EditClassName db "@chr(34)"edit"@chr(34)",0"
  list add,%%data,@tab()"ComboClassName db "@chr(34)"combobox"@chr(34)",0"
  list add,%%data,@tab()"ListClassName db "@chr(34)"listbox"@chr(34)",0"
  list add,%%data,@tab()"StaticClassName db "@chr(34)"static"@chr(34)",0"
  list add,%%data,@tab()"ProgressClassName db "@chr(34)"msctls_progress32"@chr(34)",0"
  list add,%%data,

  rem uninitialized data
  dialog set,status,"Generating .data"
  list add,%%u_data,
  list add,%%u_data,"; defines for various window objects (windows, controls, ...)"
  list add,%%u_data,".data?"
  list add,%%u_data,@tab()"hInstance HINSTANCE ?"
  list add,%%u_data,@tab()"CommandLine LPSTR ?"

  dialog set,status,"Generating .const"
  list add,%%const,"; constants for controls"
  list add,%%const,".const"

  rem load main window creation code
  dialog set,status,"Generating .code"
  list add,%%main,"; start of main code, making any needed calls to the API"
  list add,%%main,"; so we can create an initial window."
  list add,%%main,"; "@item(%%vds_code)
  list add,%%main,".code"
  list add,%%main,"start:"
  list add,%%main,@tab()"invoke GetModuleHandle, NULL"
  list add,%%main,@tab()"mov    hInstance, eax"
  list add,%%main,@tab()"invoke GetCommandLine"
  list add,%%main,@tab()"mov    CommandLine, eax"
  list add,%%main,@tab()"invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT"
  list add,%%main,@tab()"invoke ExitProcess, eax"
  list add,%%main,
  list add,%%main,@tab()"WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLin:LPSTR, CmdShow:DWORD"
  list add,%%main,@tab()@tab()"LOCAL  wc:WNDCLASSEX"
  list add,%%main,@tab()@tab()"LOCAL  msg:MSG"
  list add,%%main,@tab()@tab()"LOCAL  hwnd:HWND"
  list add,%%main,@tab()@tab()"LOCAL  Wwd:DWORD"
  list add,%%main,@tab()@tab()"LOCAL  Wht:DWORD"
  list add,%%main,@tab()@tab()"LOCAL  Wtx:DWORD"
  list add,%%main,@tab()@tab()"LOCAL  Wty:DWORD"
  list add,%%main,
  list add,%%main,@tab()@tab()"mov    wc.cbSize, SIZEOF WNDCLASSEX"
  list add,%%main,@tab()@tab()"mov    wc.style, CS_HREDRAW or CS_VREDRAW"
  list add,%%main,@tab()@tab()"mov    wc.lpfnWndProc, OFFSET WndProc"
  list add,%%main,@tab()@tab()"mov    wc.cbClsExtra, NULL"
  list add,%%main,@tab()@tab()"mov    wc.cbWndExtra, NULL"
  list add,%%main,@tab()@tab()"push   hInstance"
  list add,%%main,@tab()@tab()"pop    wc.hInstance"
  list add,%%main,@tab()@tab()"mov    wc.hbrBackground, COLOR_WINDOW"
  list add,%%main,@tab()@tab()"mov    wc.lpszMenuName, NULL"
  list add,%%main,@tab()@tab()"mov    wc.lpszClassName, OFFSET ClassName"
  list add,%%main,@tab()@tab()"invoke LoadIcon, hInstance, 500"
  list add,%%main,@tab()@tab()"mov    wc.hIcon, eax"
  list add,%%main,@tab()@tab()"mov    wc.hIconSm, eax"
  list add,%%main,@tab()@tab()"invoke LoadCursor, NULL, IDC_ARROW"
  list add,%%main,@tab()@tab()"mov    wc.hCursor, eax"
  list add,%%main,@tab()@tab()"invoke RegisterClassEx, addr wc"
  list add,%%main,
  list add,%%main,@tab()@tab()"; center window on the screen"
  list add,%%main,@tab()@tab()"mov Wwd, "@fadd(%%width,8)
  list add,%%main,@tab()@tab()"mov Wht, "@fadd(@fadd(%%height,4),%%height_add)
  list add,%%main,
  list add,%%main,@tab()@tab()"invoke GetSystemMetrics, SM_CXSCREEN"
  list add,%%main,@tab()@tab()"invoke TopXY, Wwd, eax"
  list add,%%main,@tab()@tab()"mov Wtx, eax"
  list add,%%main,
  list add,%%main,@tab()@tab()"invoke GetSystemMetrics, SM_CYSCREEN"
  list add,%%main,@tab()@tab()"invoke TopXY, Wht, eax"
  list add,%%main,@tab()@tab()"mov Wty, eax"
  list add,%%main,
  list add,%%main,@tab()@tab()"; create main window"
  list add,%%main,@tab()@tab()"invoke CreateWindowEx, NULL, addr ClassName, addr AppName, WS_OVERLAPPEDWINDOW, Wtx, Wty, Wwd, Wht, NULL, NULL, hInst, NULL"
  list add,%%main,
  list add,%%main,@tab()@tab()"mov    hwnd, eax"
  list add,%%main,@tab()@tab()"invoke ShowWindow, hwnd, SW_SHOWNORMAL"
  list add,%%main,@tab()@tab()"invoke UpdateWindow, hwnd"
  list add,%%main,
  list add,%%main,@tab()@tab()"; main window loop"
  list add,%%main,@tab()@tab()".while true"
  list add,%%main,@tab()@tab()@tab()"invoke GetMessage, addr msg, NULL, 0, 0"
  list add,%%main,@tab()@tab()@tab()".break .if (!eax)
  list add,%%main,@tab()@tab()@tab()"invoke TranslateMessage, addr msg"
  list add,%%main,@tab()@tab()@tab()"invoke DispatchMessage, addr msg"
  list add,%%main,@tab()@tab()".endw"
  list add,%%main,
  list add,%%main,@tab()@tab()"mov    eax, msg.wParam"
  list add,%%main,@tab()@tab()"ret"
  list add,%%main,@tab()"WinMain endp"



  rem load code that comes after control creation
  dialog set,status,"Generating .code"
  list add,%%end,@tab()"; this procedure handles windows messages"
  list add,%%end,@tab()"WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM"
  list add,%%end,
  list add,%%end,@tab()@tab()"LOCAL hFont:DWORD"
  list add,%%end,
  list add,%%end,@tab()@tab()".if uMsg == WM_DESTROY"
  list add,%%end,

  list add,%%end,@tab()@tab()@tab()"invoke PostQuitMessage, NULL"
  list add,%%end,
  list add,%%end,@tab()@tab()".elseif uMsg == WM_CLOSE"
  list add,%%end,
  list add,%%end,@tab()@tab()@tab()"; clicked the windows close button"
  list add,%%end,@tab()@tab()@tab()"varSet Close_Text, "@chr(34)"Insert code here to process Close event."@chr(34)
  list add,%%end,@tab()@tab()@tab()"invoke MessageBox, NULL, addr Close_Text, addr AppName, MB_OK or MB_ICONINFORMATION"
  list add,%%end,@tab()@tab()@tab()"invoke DestroyWindow, hWnd"
  list add,%%end,
  list add,%%end,@tab()@tab()".elseif uMsg == WM_CREATE"
  list add,%%end,
  list add,%%end,@tab()@tab()@tab()"invoke GetStockObject,ANSI_VAR_FONT"
  list add,%%end,@tab()@tab()@tab()"mov hFont, eax"
  list add,%%end,
  list add,%%end,@tab()@tab()@tab()"; window was created, now create controls"

  rem generate control code
  dialog set,status,"Generating control code"
  repeat 
    %%counter = @succ(%%counter)

    list seek,%%vds_code,@succ(@index(%%vds_code))
    %%dialog_code = @trim(@item(%%vds_code))
    %%term_string = %%dialog_code
    parse "%%junk;%%type;%%name;%%top;%%left;%%width;%%height;%%caption;%%edtstyle",%%dialog_code

    %%caption = @chr(34)%%caption@chr(34)

    rem create button
    if @equal(%%type,"button")
      if @equal(%%caption,@chr(34)@chr(34))
        %%caption = "NULL"
      end 

      list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
      list add,%%const,@tab()%%name" equ "%%counter
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
      list add,%%end,@tab()@tab()@tab()"varSet "%%name"_Text, "%%caption
      list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, NULL, addr ButtonClassName, addr "%%name"_Text, WS_CHILD or WS_VISIBLE, "%%left", "%%top", "%%width", "%%height", hWnd, "%%name", hInstance, NULL"
      list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
      list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
    end 

    rem create combo
    if @equal(%%type,"combo")
      if @equal(%%caption,@chr(34)@chr(34))
        %%caption = "NULL"
      end 

      list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
      list add,%%const,@tab()%%name" equ "%%counter
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
      list add,%%end,@tab()@tab()@tab()"varSet "%%name"_Text, "%%caption
      list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr ComboClassName, addr "%%name"_Text, WS_CHILD or WS_BORDER or WS_VISIBLE or CBS_HASSTRINGS or CBS_DROPDOWNLIST or WS_VSCROLL, "%%left", "%%top", "%%width", "%%height", hWnd, "%%name", hInstance, NULL"
      list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
      list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
    end 

    rem create list
    if @equal(%%type,"list")
      if @equal(%%caption,@chr(34)@chr(34))
        %%caption = "NULL"
      end 

      list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
      list add,%%const,@tab()%%name" equ "%%counter
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
      list add,%%end,@tab()@tab()@tab()"varSet "%%name"_Text, "%%caption
      list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr ListClassName, addr "%%name"_Text, WS_VSCROLL or WS_VISIBLE or WS_BORDER or WS_CHILD or LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or LBS_DISABLENOSCROLL, "%%left", "%%top", "%%width", "%%height", hWnd, "%%name", hInstance, NULL"
      list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
      list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
    end 

    rem create checkbox
    if @equal(%%type,"check")
      if @equal(%%caption,@chr(34)@chr(34))
        %%caption = "NULL"
      end 

      list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
      list add,%%const,@tab()%%name" equ "%%counter
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
      list add,%%end,@tab()@tab()@tab()"varSet "%%name"_Text, "%%caption
      list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, NULL, addr ButtonClassName, addr "%%name"_Text, WS_CHILD or WS_VISIBLE or BS_AUTOCHECKBOX, "%%left", "%%top", "%%width", "%%height", hWnd, "%%name", hInstance, NULL"
      list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
      list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
    end 

    rem create text (static)
    if @equal(%%type,"text")
      if @equal(%%caption,@chr(34)@chr(34))
        %%caption = "NULL"
      end 

      list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
      list add,%%const,@tab()%%name" equ "%%counter
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
      list add,%%end,@tab()@tab()@tab()"varSet "%%name"_Text, "%%caption
      list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, NULL, addr StaticClassName, addr "%%name"_Text, WS_CHILD or WS_VISIBLE or SS_LEFT, "%%left", "%%top", "%%width", "%%height", hWnd, "%%name", hInstance, NULL"
      list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
      list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
    end 

    rem create progress bar
    if @equal(%%type,"progress")
      if @equal(%%caption,@chr(34)@chr(34))
        %%caption = "NULL"
      end 

      list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
      list add,%%const,@tab()%%name" equ "%%counter
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
      list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, NULL, addr ProgressClassName, NULL, WS_CHILD or WS_VISIBLE, "%%left", "%%top", "%%width", "%%height", hWnd, "%%name", hInstance, NULL"
      list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
    end 

    rem create group frame
    if @equal(%%type,"group")
      if @equal(%%caption,@chr(34)@chr(34))
        %%caption = "NULL"
      end 

      list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
      list add,%%end,@tab()@tab()@tab()"varSet "%%name"_Text, "%%caption
      list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, NULL, addr ButtonClassName, addr "%%name"_Text, WS_CHILD or WS_VISIBLE or WS_GROUP or BS_GROUPBOX, "%%left", "%%top", "%%width", "%%height", hWnd, 0, hInstance, NULL"
      list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
      list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
    end 

    rem create group status
    if @equal(%%type,"status")
      list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
      list add,%%end,@tab()@tab()@tab()"invoke CreateStatusWindow, WS_CHILD or WS_VISIBLE or SBS_SIZEGRIP, NULL, hWnd, 200"
      list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
      list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
      %%status_name = %%name
    end 

    rem create group edit box (single and multi-line)
    if @equal(%%type,"edit")
      if @equal(%%caption,@chr(34)@chr(34))
        %%caption = "NULL"
      end 

      if @equal(%%edtstyle,"multi")
        list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
        list add,%%end,
        list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
        list add,%%end,@tab()@tab()@tab()"varSet "%%name"_Text, "%%caption
        list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr EditClassName, addr "%%name"_Text, WS_CHILD or WS_VISIBLE or WS_HSCROLL or WS_VSCROLL or ES_MULTILINE or ES_LEFT, "%%left", "%%top", "%%width", "%%height", hWnd, 0, hInstance, NULL"
        list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
        list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
      else 
        list add,%%u_data,@tab()"hwnd_"%%name" HWND ?"
        list add,%%end,
        list add,%%end,@tab()@tab()@tab()"; "%%dialog_code
        list add,%%end,@tab()@tab()@tab()"varSet "%%name"_Text, "%%caption
        list add,%%end,@tab()@tab()@tab()"invoke CreateWindowEx, WS_EX_CLIENTEDGE, addr EditClassName, addr "%%name"_Text, WS_CHILD or WS_VISIBLE or ES_LEFT, "%%left", "%%top", "%%width", "%%height", hWnd, 0, hInstance, NULL"
        list add,%%end,@tab()@tab()@tab()"mov    hwnd_"%%name", eax"
        list add,%%end,@tab()@tab()@tab()"invoke SendMessage, hwnd_"%%name", WM_SETFONT, hFont, 0"
      end 
    end 
  until @equal(%%term_string,"DIALOG SHOW")

  list seek,%%vds_code,0



  rem do we have a status bar? if so size things up
  dialog set,status,"Generating .code"
  if @equal(%%height_add,20)
    list add,%%end,
    list add,%%end,@tab()@tab()".elseif uMsg == WM_SIZE"
    list add,%%end,
    list add,%%end,@tab()@tab()@tab()"; keep the status bar sized to the window"
    list add,%%end,@tab()@tab()@tab()"invoke MoveWindow, hwnd_"%%status_name", 0, 0, 0, 0, true"
  end 

  list add,%%end,
  list add,%%end,@tab()@tab()".elseif uMsg == WM_COMMAND"
  list add,%%end,
  list add,%%end,@tab()@tab()@tab()"; clicked a control on the window"
  list add,%%end,@tab()@tab()@tab()"mov eax, wParam"

  rem generate control callbacks
  dialog set,status,"Generating control callbacks"
  repeat 
    %%counter = @succ(%%counter)

    list seek,%%vds_code,@succ(@index(%%vds_code))
    %%dialog_code = @trim(@item(%%vds_code))
    %%term_string = %%dialog_code
    parse "%%junk;%%type;%%name;%%top;%%left;%%width;%%height;%%caption;%%edtstyle",%%dialog_code

    if @equal(%%type,"button")
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()"; trap the "%%name"BUTTON event"
      list add,%%end,@tab()@tab()@tab()".if ax == "%%name
      list add,%%end,@tab()@tab()@tab()@tab()"shr eax, 16"
      list add,%%end,@tab()@tab()@tab()@tab()".if ax == BN_CLICKED"
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()@tab()@tab()"varSet "%%name"_Message, "@chr(34)"Insert code here to process "%%name" Click event"@chr(34)
      list add,%%end,@tab()@tab()@tab()@tab()@tab()"invoke MessageBox, NULL, addr "%%name"_Message, addr AppName, MB_OK or MB_ICONINFORMATION"
      list add,%%end,
      list add,%%end,@tab()@tab()@tab()@tab()".endif"
      list add,%%end,@tab()@tab()@tab().endif
      list add,%%end,
    end 
  until @equal(%%term_string,"DIALOG SHOW")

  dialog set,status,"Generating .code"
  list add,%%end,@tab()@tab()".else"
  list add,%%end,
  list add,%%end,@tab()@tab()@tab()"invoke DefWindowProc, hWnd, uMsg, wParam, lParam"
  list add,%%end,@tab()@tab()@tab()"ret"
  list add,%%end,
  list add,%%end,@tab()@tab()".endif"
  list add,%%end,@tab()@tab()"xor eax, eax"
  list add,%%end,@tab()@tab()"ret"
  list add,%%end,@tab()"WndProc endp"
  list add,%%end,
  list add,%%end,@tab()"; calculate X and Y coords based on screen resolution"
  list add,%%end,@tab()"TopXY proc wDim:DWORD, sDim:DWORD"
  list add,%%end,
  list add,%%end,@tab()@tab()"shr sDim, 1"
  list add,%%end,@tab()@tab()"shr wDim, 1"
  list add,%%end,@tab()@tab()"mov eax, wDim"
  list add,%%end,@tab()@tab()"sub sDim, eax"
  list add,%%end,
  list add,%%end,@tab()@tab()"return sDim"
  list add,%%end,
  list add,%%end,@tab()"TopXY endp"
  list add,%%end,
  list add,%%end,"end start"

  rem build the final source file
  clipboard set,@text(%%headers)
  clipboard append,@text(%%data)
  clipboard append,@text(%%u_data)
  clipboard append,@text(%%const)
  clipboard append,@text(%%main)
  clipboard append,@text(%%end)
  list paste,%%c_code
  dialog set,ccode,@text(%%c_code)

  rem set the clipboard to what it had before runing this program
  clipboard set,@text(%%temp)

  rem cleanup so we can re-use lists and exit subroutine
  list close,%%headers
  list close,%%data
  list close,%%main
  list close,%%const
  list close,%%end
  list close,%%vds_code
  list close,%%c_code
  list close,%%temp
  list close,%%u_data
  dialog set,status,"Generation complete"
  exit 
