void CSettings::SaveCalibration() { FILEINFO f; if ( !BIOS::DSK::Open(&f, "CALIB DAT", BIOS::DSK::IoWrite) ) { _ASSERT( 0 ); return; } ui8* pSharedBuffer = (ui8*)BIOS::DSK::GetSharedBuffer(); memset( pSharedBuffer, 0, FILEINFO::SectorSize ); ui32 dwId = ToDword('C', 'A', 'L', '1'); CStream bufStream( pSharedBuffer, FILEINFO::SectorSize ); bufStream << dwId << CStream(&DacCalib, sizeof(DacCalib)); _ASSERT_VALID( BIOS::DSK::Write(&f, pSharedBuffer) ); memset( pSharedBuffer, 0, FILEINFO::SectorSize ); bufStream.Reset(); bufStream << CStream(&CH1Calib, sizeof(CH1Calib)); _ASSERT_VALID( BIOS::DSK::Write(&f, pSharedBuffer) ); memset( pSharedBuffer, 0, FILEINFO::SectorSize ); bufStream.Reset(); bufStream << CStream(&CH2Calib, sizeof(CH1Calib)); _ASSERT_VALID( BIOS::DSK::Write(&f, pSharedBuffer) ); BIOS::DSK::Close(&f); }
// Get object data. int ClsGdiObject::GetObject( int cbSize, LPVOID pStorage ) const { _ASSERT_VALID( m_hGdiObject ); // Object must be valid. _ASSERT_VALID( pStorage ); // Storage pointer must be valid. return ::GetObject( m_hGdiObject, cbSize, pStorage ); }
// Refresh page contents. void KeyboardPage::RefreshData( LPPARSER pParser ) { _ASSERT_VALID( pParser ); // Save parser. m_pParser = pParser; // Reset list box. m_Keys.SetRedraw( FALSE ); m_Keys.ResetContent(); // Go through the key hashes. LPHASH lpHash, lpNext; TCHAR szKeyString[ 256 ]; for ( int i = 0; i < HASHSIZE; i++ ) { for ( lpHash = pParser->aHash[ i ]; lpHash; lpHash = lpNext ) { // Pick up next hash in this chain. lpNext = lpHash->lpNext; // Convert code and qualifier into // a string. ::CodeQual2Str( lpHash->cCode, lpHash->cQual, szKeyString, 256 ); // Add the string to the list. m_Keys.AddString( szKeyString ); } } m_Keys.SetRedraw(); // Setup the GUI. SetupControls(); }
// Show or hide members. void ClsLayoutEngine::ShowMembers( BOOL bShow /* = TRUE */ ) { _ASSERT_VALID( GetSafeHWND()); // Call the show window message. SendMessage( WM_SHOWMEMBERS, bShow ); }
// Obtain a mask bitmap. A mask bitmap is a bitmap which has // all pixels with the color "crColor" set to white and all // other pixels set to black. HBITMAP ClsBitmap::GetMaskBitmap( COLORREF crColor, int nXPos /* = 0 */, int nYPos /* = 0 */ ) const { _ASSERT_VALID( m_hGdiObject ); // Must be valid. // Preset result. BOOL bResult = FALSE; HBITMAP hMaskBM = NULL; // Create the necessary device contexts. ClsDC dcSrc, dcDst; if ( dcSrc.CreateCompatibleDC( NULL ) && dcDst.CreateCompatibleDC( NULL )) { // Get source bitmap information. BITMAP bm; if ( GetBitmap( &bm )) { // Create a monochrome bitmap of the same size. hMaskBM = ::CreateBitmap( bm.bmWidth, bm.bmHeight, 1, 1, NULL ); if ( hMaskBM ) { // Select both the source and destination bitmaps. HGDIOBJ hOldSrc = dcSrc.SelectObject( m_hGdiObject ); HGDIOBJ hOldDst = dcDst.SelectObject( hMaskBM ); _ASSERT( hOldSrc && hOldDst ); // Obtain the color used to create the mask bitmap. if ( crColor == CLR_DEFAULT ) crColor = dcSrc.GetPixel( nXPos, nYPos ); // Change the background color to the masked color. COLORREF crOldBkCol = dcSrc.SetBkColor( crColor ); // Copy the source into the destination which creates // the mask. if ( dcDst.BitBlt( 0, 0, bm.bmWidth, bm.bmHeight, &dcSrc, 0, 0, SRCCOPY )) // Success... bResult = TRUE; // Restore background color. dcSrc.SetBkColor( crOldBkCol ); // Restore old bitmaps. dcSrc.SelectObject( hOldSrc ); dcDst.SelectObject( hOldDst ); // Destroy it if no successful. if ( bResult == FALSE ) ::DeleteObject( hMaskBM ); } } } // Destroy DCs if ( dcSrc.IsValid()) dcSrc.DeleteDC(); if ( dcDst.IsValid()) dcDst.DeleteDC(); return bResult == TRUE ? hMaskBM : NULL; }
// Constructor. Set's search string and case mode. BoyerMoore::BoyerMoore( LPCSTR pszSearchString, BOOL bCaseOn /* = FALSE */ ) { _ASSERT_VALID( pszSearchString ); // Setup data. m_strSearchString = pszSearchString; m_bCaseOn = bCaseOn; SetSearchString(); }
const BoyerMoore& BoyerMoore::operator=( LPCSTR pszSearchString ) { _ASSERT_VALID( pszSearchString ); // Setup data. m_strSearchString = pszSearchString; SetSearchString(); return *this; }
// Hook procedure. This will attach the dialog // to the object. UINT CALLBACK ClsFontDialog::HookProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { // The lParam parameter of the WM_INITDIALOG message holds a pointer // to the CHOOSEFONT structure. This structure holds in the "lCustData" // field the pointer to the object we need to get attached to. if ( uMsg == WM_INITDIALOG ) { _ASSERT_VALID( lParam ); // Must be valid. ClsFontDialog *pFontDialog = ( ClsFontDialog * )(( LPCHOOSEFONT )lParam )->lCustData; _ASSERT_VALID( pFontDialog ); // Must be valid. // Attach us to the object. pFontDialog->Attach( hWnd ); // Re-position dialog if necessary. pFontDialog->RePositionDialog( pFontDialog ); } return 0; }
ClsBitmap *ClsDC::GetCurrentBitmap() const { _ASSERT_VALID( m_hDC ); // Must be valid. // Get the device context bitmap. HBITMAP hBitmap = ( HBITMAP )::GetCurrentObject( m_hDC, OBJ_BITMAP ); // If it is valid we create a temporary object of // it. return ClsBitmap::FromHandle( hBitmap ); }
ClsPalette *ClsDC::GetCurrentPalette() const { _ASSERT_VALID( m_hDC ); // Must be valid. // Get the device context palette. HPALETTE hPalette = ( HPALETTE )::GetCurrentObject( m_hDC, OBJ_PAL ); // If it is valid we create a temporary object of // it. return ClsPalette::FromHandle( hPalette ); }
// Set splitter rectangle. void ClsSplitter::SetSplitRect( LPRECT lpRect ) { _ASSERT_VALID( lpRect ); // Must be valid. // Copy the rectangle. m_SplitRect = *lpRect; // Adjust the splitter control size. if ( m_bIsHorizontal ) MoveWindow( m_SplitRect.Left() + m_nPosition, m_SplitRect.Top(), SPLITTER_SIZE, m_SplitRect.Height(), TRUE ); else MoveWindow( m_SplitRect.Left(), m_SplitRect.Top() + m_nPosition, m_SplitRect.Width(), SPLITTER_SIZE, TRUE ); }
ClsPen *ClsDC::GetCurrentPen() const { _ASSERT_VALID( m_hDC ); // Must be valid. // Get the device context pen. HPEN hPen = ( HPEN )::GetCurrentObject( m_hDC, OBJ_PEN ); // If it is valid we create a temporary object of // it. return ClsPen::FromHandle( hPen ); }
ClsFont *ClsDC::GetCurrentFont() const { _ASSERT_VALID( m_hDC ); // Must be valid. // Get the device context font. HFONT hFont = ( HFONT )::GetCurrentObject( m_hDC, OBJ_FONT ); // If it is valid we create a temporary object of // it. return ClsFont::FromHandle( hFont ); }
ClsBrush *ClsDC::GetCurrentBrush() const { _ASSERT_VALID( m_hDC ); // Must be valid. // Get the device context brush. HBRUSH hBrush = ( HBRUSH )::GetCurrentObject( m_hDC, OBJ_BRUSH ); // If it is valid we create a temporary object of // it. return ClsBrush::FromHandle( hBrush ); }
// Detach the handle. HDC ClsDC::Detach() { _ASSERT_VALID( m_hDC ); // Save handle. HDC hDC = m_hDC; // Set it to NULL. m_hDC = NULL; // Return the handle. return hDC; }
// Constructor. Initializes to a handle. ClsDC::ClsDC( HDC hDC ) { _ASSERT_VALID( hDC ); // Must be valid. // Clear handle. m_hDC = NULL; // Attach the handle. Attach( hDC ); // Add us to the global list. global_dc_list.AddHead( this ); }
ClsPalette *ClsDC::SelectPalette( ClsPalette *pPalette, BOOL bForceBackground ) { _ASSERT_VALID( m_hDC ); // Must be valid. // Select the palette. HPALETTE hPal = ::SelectPalette( m_hDC, *pPalette, bForceBackground ); // OK? if ( hPal ) // Create temp object. return ClsPalette::FromHandle( hPal ); return NULL; }
// Attach a handle to this object. Only works // if the object is empty. BOOL ClsDC::Attach( HDC hDC ) { _ASSERT( m_hDC == NULL ); // The object must be empty. _ASSERT_VALID( hDC ); // Can we attach the handle? if ( m_hDC == NULL ) { // Attach it. m_hDC = hDC; return TRUE; } return FALSE; }
// GradientFill() API. BOOL ClsDC::GradientFill( TRIVERTEX* pVertices, ULONG nVertices, void* pMesh, ULONG nMeshElements, DWORD dwMode ) { _ASSERT_VALID( m_hDC ); // Must be valid. // Function known? if ( StaticGradientFill ) return ( *StaticGradientFill )( m_hDC, pVertices, nVertices, pMesh, nMeshElements, dwMode ); // Get the procedure address. StaticGradientFill = ( GRADIENTFILL )GetProcAddress( GetModuleHandle( _T( "msimg32.dll" )), "GradientFill" ); if ( StaticGradientFill ) return ( *StaticGradientFill )( m_hDC, pVertices, nVertices, pMesh, nMeshElements, dwMode ); return FALSE; }
// Render an outlined rectangle. void ClsDC::OutlinedRectangle( LPCRECT pRect, COLORREF crOuter, COLORREF crInner ) { _ASSERT_VALID( m_hDC ); // Create GDI objects. ClsBrush inner( crInner ); ClsPen outer( PS_SOLID, 1, crOuter ); // Select them into the DC. ClsSelector bsel( this, inner ); ClsSelector psel( this, outer ); // Render rectangle. Rectangle( pRect ); }
// Write a number of bytes to a file. DWORD ClsFile::Write( LPCVOID lpBuffer, DWORD dwNumBytes ) { _ASSERT( m_hFile != INVALID_HANDLE_VALUE ); // Must be valid. _ASSERT_VALID( lpBuffer ); // Should be valid. // Any bytes to write? DWORD dwBytesWritten = 0L; if ( dwNumBytes ) { // Write the bytes to the file. if ( ! ::WriteFile( m_hFile, lpBuffer, dwNumBytes, &dwBytesWritten, NULL )) throw ClsFileException(); } return dwBytesWritten; }
bool CSettings::LoadCalibration() { FILEINFO f; if ( !BIOS::DSK::Open(&f, "CALIB DAT", BIOS::DSK::IoRead) ) { return false; } ui8* pSharedBuffer = (ui8*)BIOS::DSK::GetSharedBuffer(); _ASSERT_VALID( BIOS::DSK::Read(&f, pSharedBuffer) ); CStream bufStream( pSharedBuffer, FILEINFO::SectorSize ); ui32 dwId = 0; bufStream >> dwId; if ( dwId != ToDword('C', 'A', 'L', '1') ) { _ASSERT(0); return false; } bufStream >> CStream(&DacCalib, sizeof(DacCalib)); bufStream.Reset(); _ASSERT_VALID( BIOS::DSK::Read(&f, pSharedBuffer) ); bufStream >> CStream(&CH1Calib, sizeof(CH1Calib)); bufStream.Reset(); _ASSERT_VALID( BIOS::DSK::Read(&f, pSharedBuffer) ); bufStream >> CStream(&CH2Calib, sizeof(CH2Calib)); BIOS::DSK::Close(&f); return true; }
// Read a number of bytes from the file. DWORD ClsFile::Read( LPVOID lpBuffer, DWORD dwNumBytes ) { _ASSERT( m_hFile != INVALID_HANDLE_VALUE ); // Must be valid. _ASSERT_VALID( lpBuffer ); // Should be valid. // Any bytes to read? DWORD dwBytesRead = 0L; if ( dwNumBytes ) { // Read the bytes from the file. if ( ! ::ReadFile( m_hFile, lpBuffer, dwNumBytes, &dwBytesRead, NULL )) throw ClsFileException(); } return dwBytesRead; }
// Finds a device context object in the list by it's handle // value. static ClsDC *ClsFindObjectByHandle( ClsLinkedList<ClsDC>& list, HDC hDC ) { _ASSERT_VALID( hDC ); // This must be valid. // Iterate the nodes. for ( ClsDC *pDC = list.GetFirst(); pDC; pDC = list.GetNext( pDC )) { // Is the handle wrapped by this object // the one we are looking for? if ( *pDC == hDC ) // Yes. Return a pointer to the object. return pDC; } // Object not in the list. return NULL; }
// Finds a gdi object in the list by it's handle // value. static ClsGdiObject *ClsFindObjectByHandle( ClsLinkedList<ClsGdiObject>& list, HGDIOBJ hGdiObject ) { _ASSERT_VALID( hGdiObject ); // This must be valid. // Iterate the nodes. for ( ClsGdiObject *pGdiObject = list.GetFirst(); pGdiObject; pGdiObject = list.GetNext( pGdiObject )) { // Is the handle wrapped by this object // the one we are looking for? if ( *pGdiObject == hGdiObject ) // Yes. Return a pointer to the object. return pGdiObject; } // Object not in the list. return NULL; }
void CSettings::Save() { FILEINFO f; if ( !BIOS::DSK::Open(&f, "CONFIG DAT", BIOS::DSK::IoWrite) ) { _ASSERT( 0 ); return; } ui8* pSharedBuffer = (ui8*)BIOS::DSK::GetSharedBuffer(); memset( pSharedBuffer, 0, FILEINFO::SectorSize ); CStream bufStream( pSharedBuffer, FILEINFO::SectorSize ); bufStream << *this; _ASSERT_VALID( BIOS::DSK::Write(&f, pSharedBuffer) ); BIOS::DSK::Close(&f, bufStream.GetLength()); }
void CSettings::Load() { FILEINFO f; if ( !BIOS::DSK::Open(&f, "CONFIG DAT", BIOS::DSK::IoRead) ) { return; } ui8* pSharedBuffer = (ui8*)BIOS::DSK::GetSharedBuffer(); _ASSERT_VALID( BIOS::DSK::Read(&f, pSharedBuffer) ); CStream bufStream( pSharedBuffer, FILEINFO::SectorSize ); bufStream >> *this; BIOS::DSK::Close(&f); }
// Attach a handle to the current object. void ClsGdiObject::Attach( HGDIOBJ hGdiObject, BOOL bDestroy /* = TRUE */ ) { _ASSERT_VALID( hGdiObject ); // Passed handle must be valid. _ASSERT( hGdiObject != m_hGdiObject ); // Can't attach to ourselves. // Delete the current handle. Delete(); #ifdef _DEBUG // Increase object counter. if ( bDestroy ) nGDIObjects++; #endif // Setup the new handle. m_hGdiObject = hGdiObject; m_bDestroy = bDestroy; }
// Refresh page contents. void SyntaxPage::RefreshData( LPPARSER pParser ) { _ASSERT_VALID( pParser ); // Save parser. m_pParser = pParser; // Setup lists. m_Blocks.SetParser( pParser ); m_Common.SetParser( pParser ); m_Blocks.SetBlockList(); m_Common.SetCommonList(); // Setup other controls. m_Escape.SetWindowText( pParser->cEscape ? ( LPCTSTR )ClsString( pParser->cEscape ) : NULL ); m_Syntax.SetCheck( pParser->bSyntaxColoring ? BST_CHECKED : BST_UNCHECKED ); // Setup the toolbar. SetupToolbar(); }
BOOL ClsDC::DeleteDC() { _ASSERT_VALID( m_hDC ); // Object must be valid. // Delete the device context. BOOL bRC = ::DeleteDC( m_hDC ); // OK? if ( bRC ) { #ifdef _DEBUG nDCObjects--; #endif // Clear handle. m_hDC = NULL; } // Return error flag. return bRC; }