// ResFile.cpp: implementation of the CResFile class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ResFile.h" #include "debug.h" extern void GetRCMLVersionNumber( HINSTANCE h, LPTSTR * ppszVersion); ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CResFile::CResFile(BOOL bEnhanced, BOOL bRelative, BOOL bWin32, BOOL bCicero) { m_pszMenu=NULL; m_pszClass=NULL; m_pszTitle=NULL; m_pszFont=NULL; m_pControls=NULL; SetItemCount(0); SetEnhanced( bEnhanced ); SetRelative( bRelative ); SetWin32( bWin32 ); SetCicero( bCicero ); m_pWin32=NULL; m_hwnd=NULL; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CResFile::~CResFile() { if( HIWORD(m_pszMenu) ) delete m_pszMenu; if( HIWORD(m_pszClass) ) delete m_pszClass; delete m_pszTitle; delete m_pszFont; delete m_pWin32; int k=GetItemCount(); for(int i=0;iGetNextControl(); // this is odd. } UnlockResource( hMemDialog ); return TRUE; } } return FALSE; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////// // // Temporary hack - but seems to be working quite well // ////////////////////////////////////////////////////////////////////// BOOL CResFile::LoadWindow(HWND hWnd) { m_hwnd= hWnd; ExtractDlgHeaderInformation(hWnd); HWND hFirstChild=::GetWindow(hWnd, GW_CHILD); // count the number of children. int i=0; while( hFirstChild ) { hFirstChild=::GetWindow( hFirstChild, GW_HWNDNEXT ); i++; } // SetItemCount(i); m_pControls=new CResControl*[i]; hFirstChild=::GetWindow(hWnd, GW_CHILD); i=0; while( hFirstChild ) { m_pControls[i]=new CResControl( hFirstChild, TRUE, GetWin32(), *this ); hFirstChild=::GetWindow( hFirstChild, GW_HWNDNEXT ); i++; } return TRUE; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // void CResFile::ExtractDlgHeaderInformation(HWND hwnd) { HFONT hFont = (HFONT)SendMessage( hwnd , WM_GETFONT, NULL, NULL); if(hFont==NULL) hFont = (HFONT)GetStockObject(SYSTEM_FONT); LOGFONT lf; ::GetObject( hFont, sizeof(lf), &lf ); m_Font.Init(NULL,0,0,0,&lf); WORD wSize= (WORD)(lf.lfHeight<0?-MulDiv(lf.lfHeight, 72, GetDeviceCaps(GetDC(hwnd), LOGPIXELSY) ):lf.lfHeight); SetFontSize( wSize ); // probably need to back map? SetFontWeight( (WORD)lf.lfWeight ); SetFontItalic( lf.lfItalic ); SetFont( lf.lfFaceName ); // // Now we have the font, we can size the dialog correctly. // WINDOWPLACEMENT wp; wp.length = sizeof(wp); GetWindowPlacement( hwnd, &wp ); RECT r; GetClientRect( hwnd, &r); SIZE size; size.cx = wp.rcNormalPosition.right - wp.rcNormalPosition.left; size.cy = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; size.cx = r.right - r.left; size.cy = r.bottom - r.top; size = m_Font.GetDlgUnitsFromPixels( size ); SetWidth( size.cx ); SetHeight( size.cy ); SetStyle( GetWindowLong( hwnd, GWL_STYLE) ); SetStyleEx( GetWindowLong( hwnd, GWL_EXSTYLE) ); SetMenu(NULL); // review SetClass(NULL); // can't get that I don't think, hidden? int cbText = GetWindowTextLength( hwnd )+1; LPTSTR pszTitle=new TCHAR[cbText+1]; GetWindowText( hwnd, pszTitle, cbText ); SetTitle(pszTitle); delete pszTitle; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // DLGITEMTEMPLATE * CResFile::ExtractDlgHeaderInformation(DLGTEMPLATE *pDlgTemplate) { DLGTEMPLATEEX * pDlgEx=(DLGTEMPLATEEX*)pDlgTemplate; // // New or old style dialog template. // if ( pDlgEx->signature == (WORD)-1 ) { // // New dialog format used here. // SetWidth( pDlgEx->cx ); SetHeight( pDlgEx->cy ); SetItemCount( pDlgEx->cDlgItems ); SetStyle( pDlgEx->style ); SetStyleEx( pDlgEx->exStyle ); LPWSTR pszString=(LPWSTR)(&pDlgEx->menu); // // Menu goo. // WORD * pW=(WORD*)pszString; if( *pW == 0 ) { // No menu. pszString++; } else if (*pW==(WORD)-1) { // Menu is a resource - yuck. SetMenu( (LPTSTR)*(pW+1) ); pszString+=2; } else { pszString = SetMenu( pszString ); } // // Class goo. // pW=(WORD*)pszString; if( *pW == 0 ) { // No class. pszString++; } else if (*pW==(WORD)-1) { // Menu is a resource - what does that mean! pszString+=2; } else { pszString = SetClass( pszString ); } // // pszString = SetTitle( pszString ); // // pszString now points at // // short pointsize; // if DS_SETFONT or DS_SHELLFONT is set // short weight; // if DS_SETFONT or DS_SHELLFONT is set // short bItalic; // if DS_SETFONT or DS_SHELLFONT is set // WCHAR font[fontLen]; // if DS_SETFONT or DS_SHELLFONT is set DWORD dwStyle = GetStyle(); if( dwStyle & DS_SETFONT ) { short * pShort=(short *)pszString; // Font Size SetFontSize( *pShort++ ); SetFontWeight( *pShort++ ); SetFontItalic( *pShort++ ); pszString=SetFont( (LPWSTR)pShort ); } DWORD pData=(DWORD)pszString; pData+=3; pData &= ~3; return (DLGITEMTEMPLATE * )pData; } else { SetWidth( pDlgTemplate->cx ); SetHeight( pDlgTemplate->cy ); SetItemCount( pDlgTemplate->cdit ); SetStyle( pDlgTemplate->style ); SetStyleEx( pDlgTemplate->dwExtendedStyle ); LPWSTR pszString=(LPWSTR)(&pDlgTemplate->cy+1); // pszString++; // for some reason, we do this>? // // Followed by 3 variable length arrays (strings) // menu, class, title and then a font name if DS_SETFONT is used. // pszString = SetMenu( pszString ); pszString = SetClass( pszString ); pszString = SetTitle( pszString ); // // Now we go for the FONT. // DWORD dwStyle = GetStyle(); if( dwStyle & DS_SETFONT ) { // Font Size SetFontSize( *((LPWORD)pszString) ); pszString++; pszString=SetFont( pszString ); } DWORD pData=(DWORD)pszString; pData+=3; pData &= ~3; return (DLGITEMTEMPLATE * )pData; } return NULL; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // LPWSTR CResFile::SetMenu ( LPWSTR pszMenu ) { return SetString( &m_pszMenu, pszMenu ); } LPWSTR CResFile::SetClass ( LPWSTR pszClass ) { return SetString( &m_pszClass, pszClass ); } LPWSTR CResFile::SetTitle ( LPWSTR pszTitle ) { UINT cbLen=lstrlenW(pszTitle)+1; LPWSTR newString = FixEntity( pszTitle ); LPWSTR pRes=SetString( &m_pszTitle, newString); delete newString; return pszTitle+cbLen; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Takes an input string, and returns a string fixed up with entities. // LPWSTR CResFile::FixEntity( LPWSTR pszTitle ) { UINT cbLen=lstrlenW(pszTitle)+1; LPWSTR newString=new WCHAR[cbLen*4]; LPWSTR pSource=pszTitle; LPWSTR pDest=newString; while( *pSource!=0) { /* < - (<) > - (>) & - (&) " - (") ' - (') */ int i=0; BOOL bFound=FALSE; while( g_Entity[i].szEntity ) { if( *pSource == g_Entity[i].szChar ) { lstrcpy(pDest, g_Entity[i].szEntity ); pDest += lstrlen( g_Entity[i].szEntity ); bFound=TRUE; break; } i++; } if( !bFound ) *pDest++=*pSource; pSource++; } *pDest=0; return newString; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // LPWSTR CResFile::SetFont ( LPWSTR pszFont ) { return SetString( &m_pszFont, pszFont ); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // LPWSTR CResFile::SetString( LPWSTR * ppszString , LPWSTR pszSource ) { if( HIWORD(*ppszString) != NULL ) { delete *ppszString; *ppszString=NULL; } if(HIWORD(pszSource)) { int len=lstrlenW( pszSource )+1; *ppszString=new WCHAR[len]; lstrcpyW( *ppszString, pszSource ); return pszSource+len; } else { *ppszString=pszSource; return NULL; } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // void CResFile::DumpDialog(LPTSTR pszFilename) { if( m_hFile.CreateFile(pszFilename) ) { DumpProlog(); DumpFormAndCaption(); DumpPage(); // DumpDialogStyles(); DumpTestInfo(pszFilename); DumpLayoutElement(); DumpMenu(); int k=GetItemCount(); CResControl * pLast=NULL; CResControl * pCurrent=NULL; for(int i=0;iGetY() == pLast->GetY() ) { if( pCurrent->GetHeight() == pCurrent->GetHeight() ) { bRelative=TRUE; } } if( pCurrent->GetX() == pLast->GetX( ) ) { if( pCurrent->GetHeight() == pCurrent->GetHeight() ) { bRelative=TRUE; } } } } pCurrent->Dump(bRelative?pLast:NULL); pLast=pCurrent; Write( TEXT("\r\n"), FALSE ); } // DumpEpilog(); m_hFile.CloseFile(); } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // BOOL CResFile::IsExtended(DLGTEMPLATE *pDlgTemplate) { DLGTEMPLATEEX * pDlgEx=(DLGTEMPLATEEX*)pDlgTemplate; // // New or old style dialog template. // return pDlgEx->signature == (WORD)-1 ; } void CResFile::DumpLayoutElement() { TCHAR szBuffer[1024]; Write(TEXT("\t\t\t")); Write(TEXT("\t\t\t\t")); // // Now we dump the style object too. // wsprintf(szBuffer,TEXT("\t\t\t\t