titanandrews
Programmer
Hi All,
I have an existing app which creates dialogs from an in memory
dialog template using the CreateDialogIndirect function. I have a
working function that generates the controls for the dialog using the
class id for the control instead of the Unicode class name. But I need
to change this function to use the Unicode class name instead, because
I need to be able to create custom controls. I seem to be having some
difficulty with the alignment, because I cannot create the dialog
using the class name. Posted here is my function that creates all the
controls:
Notice that the section marked "//This section works" is the part the
uses the class id. The section I am experimenting with is //Begin new.
If the control id is 0x81, which is an edit field, then I want to use
"Edit".
Does anyone know what I am doing wrong here? Your help is greatly
appreciated.
many thanks,
Barry
I have an existing app which creates dialogs from an in memory
dialog template using the CreateDialogIndirect function. I have a
working function that generates the controls for the dialog using the
class id for the control instead of the Unicode class name. But I need
to change this function to use the Unicode class name instead, because
I need to be able to create custom controls. I seem to be having some
difficulty with the alignment, because I cannot create the dialog
using the class name. Posted here is my function that creates all the
controls:
Notice that the section marked "//This section works" is the part the
uses the class id. The section I am experimenting with is //Begin new.
If the control id is 0x81, which is an edit field, then I want to use
"Edit".
Does anyone know what I am doing wrong here? Your help is greatly
appreciated.
many thanks,
Barry
Code:
void mPageContent::GenerateControls()
{
// The first object in the bag is a frame object
unsigned int panelWidth, panelHeight;
mControlObject *pFrameObj = (mControlObject *)
pBagOfControls->First();
pFrameObj->GetSize( &panelWidth, &panelHeight );
mControlObject *pObj;
while( pObj = ( mControlObject *) pBagOfControls->Next() )
{
unsigned long lDlgStyle;
unsigned int xOrigin;
unsigned int yOrigin;
unsigned int xWidth;
unsigned int yHeight;
unsigned int iCtrlID;
size_t iLongSize = sizeof( long );
size_t iWordSize = sizeof( WORD );
size_t iDWordSize = sizeof( DWORD );
/* --- Set up button control style --- */
lDlgStyle = pObj->GetStyle();
memcpy( pTempBuffer, &lDlgStyle, iLongSize );
pTempBuffer += iLongSize;
pTempBuffer += iLongSize;
/* --- Adjust control position/size for NT coordinate system ---
*/
pObj->ScaleSize( panelHeight );
/* --- Put in coordinates --- */
pObj->GetOrigin( &xOrigin, &yOrigin );
pObj->GetSize( &xWidth, &yHeight );
memcpy( pTempBuffer, &xOrigin, iWordSize );
pTempBuffer += iWordSize;
memcpy( pTempBuffer, &yOrigin, iWordSize );
pTempBuffer += iWordSize;
memcpy( pTempBuffer, &xWidth, iWordSize );
pTempBuffer += iWordSize;
memcpy( pTempBuffer, &yHeight, iWordSize );
pTempBuffer += iWordSize;
iCtrlID = pObj->GetCtrlID();
memcpy( pTempBuffer, &iCtrlID, iWordSize );
//This section works
pTempBuffer += iWordSize;
memset( pTempBuffer, 0xFF, iWordSize );
pTempBuffer += iWordSize;
unsigned int iCtrlType = pObj->GetClassID();
memset( pTempBuffer, iCtrlType, sizeof( char ) );
pTempBuffer += iWordSize;
//Begin new
/*unsigned int iCtrlType = pObj->GetClassID();
if (iCtrlType = 0x81)
{
pTempBuffer += iWordSize;
char* pDateCtrl = "Edit";
AddWideCharText(pDateCtrl);
}
else
{
pTempBuffer += iWordSize;
memset( pTempBuffer, 0xFF, iWordSize );
pTempBuffer += iWordSize;
unsigned int iCtrlType = pObj->GetClassID();
memset( pTempBuffer, iCtrlType, sizeof( char ) );
}
pTempBuffer += iWordSize;*/
//End new
AddWideCharText(pObj->GetText());
}
}
void mPageContent::AddWideCharText(char* pszText)
{
boolean bAlignByte = FALSE;
size_t iWordSize = sizeof( WORD );
size_t iDWordSize = sizeof( DWORD );
int iLen = 0;
if( pszText )
{
wchar_t szWideText[MAX_CTRLTEXT_SIZE];
memset( szWideText, 0x00, MAX_CTRLTEXT_SIZE*sizeof(wchar_t) );
wchar_t *pWide = szWideText;
iLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszText,
strlen( pszText ), pWide,
MAX_CTRLTEXT_SIZE );
if(iLen == 0)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //
Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
GRELOG1(GREERROR, "MultiByteToWideChar: %s\n", (LPTSTR)
lpMsgBuf);
}
// if odd numbered length, then use short form
// if even numbered length, then use long form
if( iLen % 2 == 0 )
bAlignByte = TRUE;
iLen += iLen+2;
memcpy( pTempBuffer, szWideText, iLen );
}
else
{
// null text string, put in unicode null char and move on
iLen = 2;
bAlignByte = TRUE;
}
pTempBuffer += iLen;
if( bAlignByte == TRUE )
pTempBuffer += iDWordSize;
else
pTempBuffer += iWordSize;
}