📄 mdichild.c
字号:
}
}
break; // End WM_COMMAND -> ID_EDIT_COPY
// The filename has changed, update the window title
case ID_UPDATETITLE:
{
TCHAR szFileTitle[MAX_PATH];
LPCHILDWINDOWDATA lpcwd;
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data
if( lpcwd != NULL )
{
// including an icon resource
if( lpcwd->lpIR != NULL )
{
// The calculate and set the new title
if( GetFileTitle( lpcwd->lpIR->szOriginalICOFileName, szFileTitle, MAX_PATH ) == 0 )
{
SetWindowText( hWnd, szFileTitle );
}
}
}
}
break; // End WM_COMMAND -> ID_UPDATETITLE
// How many image formats in the icon resource? (return that number)
case ID_GETNUMFORMATS:
{
LPCHILDWINDOWDATA lpcwd;
UINT nNum = 0;
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data
if( lpcwd != NULL )
{
// If we have a listbox, get its count, else 0
if( lpcwd->hWndFormatListBox != NULL )
nNum = (UINT)SendMessage( lpcwd->hWndFormatListBox, CB_GETCOUNT, 0, 0 );
else
nNum = 0;
// If an error occurred, default to 0
if( nNum == (UINT)CB_ERR )
nNum = 0;
}
// Send it back
return nNum;
}
break; // End WM_COMMAND -> ID_GETNUMFORMATS
// Has this icon resource changed? return TRUE=yes, FALSE=no
case ID_HASFILECHANGED:
{
LPCHILDWINDOWDATA lpcwd;
UINT nRet = 0;
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data
if( lpcwd != NULL )
// And it includes an icon resource
if( lpcwd->lpIR != NULL )
// then check whether it has changed
return lpcwd->lpIR->bHasChanged == TRUE;
// Otherwise, return FALSE
return nRet;
}
break; // End WM_COMMAND -> ID_HASFILECHANGED
// Handle selection changes, etc from listbox
case ID_FORMAT_BOX:
switch( HIWORD(wParam) )
{
// If a selection is made, or changes, repaint
case CBN_SELCHANGE:
case CBN_SELENDOK:
InvalidateRect( hWnd, NULL, TRUE );
break;
}
break; // End WM_COMMAND -> ID_FORMAT_BOX
// User wants to save the ICO file
case ID_FILE_SAVEAS:
case ID_FILE_SAVE:
{
TCHAR szFileName[MAX_PATH];
LPCHILDWINDOWDATA lpcwd;
// Get the data associated this window
if( ( lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA ) ) != NULL )
{
// See if it includes an icon resource
if( lpcwd->lpIR != NULL )
{
HCURSOR hOldCursor;
// This might take a while :(
hOldCursor = SetCursor( LoadCursor(NULL,IDC_WAIT) );
// If we have an original filename, and user did *NOT* 'Save As'
if( ( lstrlen(lpcwd->lpIR->szOriginalICOFileName) > 0 ) && (LOWORD(wParam)!=ID_FILE_SAVEAS) )
{
// The just write it out
WriteIconToICOFile( lpcwd->lpIR, lpcwd->lpIR->szOriginalICOFileName );
// which, of course, brings it up to date
lpcwd->lpIR->bHasChanged = FALSE;
}
else
{
// Either we have no name, or user hit 'Save As'
if( GetSaveIconFileName( szFileName, IDS_FILTERSTRING, LOWORD(wParam)==ID_FILE_SAVE?"Save Icon File":"Save Icon File As" ) )
{
// So, write it out
WriteIconToICOFile( lpcwd->lpIR, szFileName );
// Update the name associated with the resource
lstrcpy( lpcwd->lpIR->szOriginalICOFileName, szFileName );
// Inform window to update title
SendMessage( hWnd, WM_COMMAND, ID_UPDATETITLE, 0 );
// and, of course, it is now up to date
lpcwd->lpIR->bHasChanged = FALSE;
}
}
SetCursor( hOldCursor );
}
else
MessageBox( hWnd, "Error Getting Icon Info - File Not Saved", "Error", MB_OK );
}
}
break; // End WM_COMMAND -> ID_FILE_SAVE/ID_FILE_SAVEAS
}
break; // End WM_COMMAND
}
return DefMDIChildProc( hWnd, Msg, wParam, lParam );
}
/* End IconChildWndProc() **************************************************/
/****************************************************************************
*
* FUNCTION: Draw3DRect
*
* PURPOSE: draws a rectangle in 3d colors
*
* PARAMS: HDC hDC - The DC on which to draw
* RECT Rect - The rectangle itself
* BOOL bSunken - TRUE = rect should look sunken
* FALSE = rect should look raised
*
* RETURNS: BOOL - TRUE for success, FALSE for failure
*
* History:
* July '95 - Created
*
\****************************************************************************/
BOOL Draw3DRect( HDC hDC, RECT Rect, BOOL bSunken )
{
HBRUSH hBrush;
HPEN hPen, hOldPen;
// Get the color for the main foreground
hBrush = CreateSolidBrush( GetSysColor(COLOR_3DFACE) );
// paint it
FillRect( hDC, &Rect, hBrush );
DeleteObject( hBrush );
// Get the pen for the top and left sides
if( bSunken )
hPen = CreatePen( PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW) );
else
hPen = CreatePen( PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT) );
hOldPen = SelectObject( hDC, hPen);
// Draw the top and left sides
MoveToEx( hDC, Rect.right, Rect.top, NULL );
LineTo( hDC, Rect.left, Rect.top );
LineTo( hDC, Rect.left, Rect.bottom );
SelectObject( hDC, hOldPen);
DeleteObject( hPen );
// Get the pen for the bottom and right sides
if( bSunken )
hPen = CreatePen( PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT) );
else
hPen = CreatePen( PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW) );
hOldPen = SelectObject( hDC, hPen);
// Draw the bottom and right sides
LineTo( hDC, Rect.right, Rect.bottom );
LineTo( hDC, Rect.right, Rect.top );
SelectObject( hDC, hOldPen);
DeleteObject( hPen );
return TRUE;
}
/* End Draw3DRect() *******************************************************/
/****************************************************************************
*
* FUNCTION: EraseBackground
*
* PURPOSE: Draws the background for the MDI child
*
* PARAMS: HWND hWnd - The MDI window of interest
* HDC hDC - The DC on which to draw
*
* RETURNS: void
*
* History:
* July '95 - Created
*
\****************************************************************************/
void EraseBackground( HWND hWnd, HDC hDC )
{
RECT Rect;
LPCHILDWINDOWDATA lpcwd;
HBRUSH hBrush;
SIZE TextSize;
// Just how big is this window?
GetClientRect( hWnd, &Rect );
// Paint the background
Draw3DRect( hDC, Rect, FALSE );
// If there is no icon resource yet, bail out
if( ( lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA ) ) == NULL )
return;
// Draw 3d rectangles around areas of interest
Draw3DRect( hDC, lpcwd->WhiteRect, TRUE );
Draw3DRect( hDC, lpcwd->WhiteTextRect, TRUE );
Draw3DRect( hDC, lpcwd->BlackRect, TRUE );
Draw3DRect( hDC, lpcwd->BlackTextRect, TRUE );
Draw3DRect( hDC, lpcwd->XORRect, TRUE );
Draw3DRect( hDC, lpcwd->XORTextRect, TRUE );
Draw3DRect( hDC, lpcwd->ANDRect, TRUE );
Draw3DRect( hDC, lpcwd->ANDTextRect, TRUE );
// Fill in the white area
hBrush = GetStockObject( WHITE_BRUSH );
SelectObject( hDC, hBrush );
Rectangle( hDC, lpcwd->WhiteRect.left, lpcwd->WhiteRect.top, lpcwd->WhiteRect.right, lpcwd->WhiteRect.bottom );
// Fill in the black area
hBrush = GetStockObject( BLACK_BRUSH );
SelectObject( hDC, hBrush );
Rectangle( hDC, lpcwd->BlackRect.left, lpcwd->BlackRect.top, lpcwd->BlackRect.right, lpcwd->BlackRect.bottom );
// Set texts for the various sections
SetBkMode( hDC, TRANSPARENT );
GetTextExtentPoint32( hDC, "Icon On Black", 13, &TextSize );
TextOut( hDC, lpcwd->BlackTextRect.left + ((RectWidth(lpcwd->BlackTextRect)-TextSize.cx)/2),
lpcwd->BlackTextRect.top + ((RectHeight(lpcwd->BlackTextRect)-TextSize.cy)/2), "Icon On Black", 13 );
GetTextExtentPoint32( hDC, "Icon On White", 13, &TextSize );
TextOut( hDC, lpcwd->WhiteTextRect.left + ((RectWidth(lpcwd->WhiteTextRect)-TextSize.cx)/2),
lpcwd->WhiteTextRect.top + ((RectHeight(lpcwd->WhiteTextRect)-TextSize.cy)/2), "Icon On White", 13 );
GetTextExtentPoint32( hDC, "XOR Mask", 8, &TextSize );
TextOut( hDC, lpcwd->XORTextRect.left + ((RectWidth(lpcwd->XORTextRect)-TextSize.cx)/2),
lpcwd->XORTextRect.top + ((RectHeight(lpcwd->XORTextRect)-TextSize.cy)/2), "XOR Mask", 8 );
GetTextExtentPoint32( hDC, "AND Mask", 8, &TextSize );
TextOut( hDC, lpcwd->ANDTextRect.left + ((RectWidth(lpcwd->ANDTextRect)-TextSize.cx)/2),
lpcwd->ANDTextRect.top + ((RectHeight(lpcwd->ANDTextRect)-TextSize.cy)/2), "AND Mask", 8 );
}
/* End EraseBackground() ***************************************************/
/****************************************************************************
*
* FUNCTION: CreateChildren
*
* PURPOSE: Create the listbox, fills it with entries
*
* PARAMS: HWND hWnd - The MDI window of interest
*
* RETURNS: BOOL - TRUE for success, FALSE for failure
*
* History:
* July '95 - Created
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -