Category : C++ Source Code
Archive   : WICS.ZIP
Filename : DLGTMPLT.CPP

 
Output of file : DLGTMPLT.CPP contained in archive : WICS.ZIP

//==============================================================================================
//
// Windows Interface Construction Set
// Version 1.00
//
// DLGTMPLT.CPP - Dialog Template Class Source File
// Copyright © 1993 by Microdyne Development Technologies.
// All rights reserved.
//==============================================================================================

#include
#include
#include

TDialogTemplate::TDialogTemplate(DWORD lStyle, WORD x, WORD y, WORD cx, WORD cy, LPSTR lpClass, Pchar lpCaption)
{
LPDIALOGBOXHEADER lpDialog ;
LPSTR lpText;
WORD FAR * lpWord;

if ( lpClass )
if ( lpCaption )
wSize = 16 + _fstrlen(lpClass) + strlen(lpCaption) ;
else
wSize = 17 + _fstrlen(lpClass) ;
else
if ( lpCaption )
wSize = 17 + strlen(lpCaption) ;
else
wSize = 18;

lStyle &= (~DS_SETFONT);

// Allocate the structure

hTemplate = GlobalAlloc (GHND, wSize);

lpDialog = (LPDIALOGBOXHEADER) GlobalLock (hTemplate);
lpText = (LPSTR) lpDialog;

*((DWORD FAR *) lpText) = lStyle; lpText += 4;
*lpText++ = 0;
*((WORD FAR *) lpText) = x; lpText += 2;
*((WORD FAR *) lpText) = y; lpText += 2;
*((WORD FAR *) lpText) = cx; lpText += 2;
*((WORD FAR *) lpText) = cy; lpText += 2;

*lpText++ = 0x00 ;

if ( lpClass )
{
_fstrcpy ( lpText, lpClass);
lpText = ( lpText + _fstrlen(lpText) + 1) ;
}
else
*lpText++ = 0x00;

if ( lpCaption )
{
_fstrcpy ( lpText, lpCaption);
lpText = ( lpText + _fstrlen(lpText) + 1) ;
}
else
*lpText++ = 0x00 ;

GlobalUnlock (hTemplate);
}

TDialogTemplate::~TDialogTemplate()
{
GlobalFree (hTemplate);
}

void TDialogTemplate::AssignMenu (Pchar lpMenuName)
{
HGLOBAL hTemp ;
LPDIALOGBOXHEADER lpDialog ;
LPDIALOGBOXHEADER lpSource ;
LPSTR lpText;
LPSTR lpSrcText;
PWORD lpWord;

hTemp = GlobalAlloc (GHND, wSize + strlen(lpMenuName));

lpSource = (LPDIALOGBOXHEADER) GlobalLock(hTemplate);
lpDialog = (LPDIALOGBOXHEADER) GlobalLock(hTemp);

lpSrcText = (LPSTR) (lpSource+1);
lpText = (LPSTR) (lpDialog+1);

_fmemmove ( lpDialog, lpSource, 13);

_fstrcpy (lpText, lpMenuName);
lpText += (strlen(lpMenuName) + 1) ;

_fmemmove ( lpText, lpSrcText, wSize - 13);

GlobalUnlock (hTemplate);
GlobalUnlock (hTemp);
GlobalFree (hTemplate);

wSize += _fstrlen(lpMenuName);
hTemplate = hTemp;
}

void TDialogTemplate::AddControl (DWORD lStyle, WORD id, WORD x, WORD y, WORD cx, WORD cy, LPSTR lpClass, Pchar lpCaption)
{
HGLOBAL hTemp;
WORD wNewSize;
LPDIALOGBOXHEADER lpDialog;
LPDIALOGBOXHEADER lpSource;
LPCONTROLDATA lpControl;
LPSTR lpText;

wNewSize = wSize + sizeof(CONTROLDATA) + 3 ;

if ( FP_SEG(lpClass) != 0 )
wNewSize += _fstrlen(lpClass);

if ( lpCaption )
wNewSize += strlen(lpCaption);

hTemp = GlobalAlloc (GHND, wNewSize);

lpSource = (LPDIALOGBOXHEADER) GlobalLock (hTemplate);
lpDialog = (LPDIALOGBOXHEADER) GlobalLock (hTemp);
lpControl = (LPCONTROLDATA)(((LPSTR) lpDialog) + wSize);
lpText = (LPSTR) lpControl + sizeof(CONTROLDATA) ;

_fmemmove (lpDialog, lpSource, wSize);

lpDialog->bNumberOfItems++;

lpControl->x = x;
lpControl->y = y;
lpControl->cx = cx;
lpControl->cy = cy;
lpControl->wID = id;
lpControl->lStyle = lStyle;

if ( FP_SEG(lpClass) == 0x00 )
*lpText++ = (BYTE) lpClass;
else
{
_fstrcpy (lpText, lpClass);
lpText += (_fstrlen(lpClass) + 1);
}

if ( lpCaption )
{
_fstrcpy ( lpText, lpCaption );
lpText += (strlen(lpCaption) + 1);
}
else
*lpText++ = 0x00;

*lpText++ = 0x00 ;

GlobalUnlock (hTemplate);
GlobalUnlock (hTemp);
GlobalFree (hTemplate);

wSize = wNewSize;
hTemplate = hTemp;
}