?? mdichild.c
字號:
GetTextExtentPoint32( hDC, "Unsupported", 11, &Size );
Position.cx = lpcwd->BlackRect.left + ((RectWidth(lpcwd->BlackRect)-Size.cx)/2);
Position.cy = lpcwd->BlackRect.top + (RectHeight(lpcwd->BlackRect)/2) - Size.cy;
TextOut( hDC, Position.cx, Position.cy, "Unsupported", 11 );
GetTextExtentPoint32( hDC, "Format", 6, &Size );
Position.cx = lpcwd->BlackRect.left + ((RectWidth(lpcwd->BlackRect)-Size.cx)/2);
Position.cy = lpcwd->BlackRect.top + (RectHeight(lpcwd->BlackRect)/2) + 1;
TextOut( hDC, Position.cx, Position.cy, "Format", 6 );
// Draw some text in the white rect
SetTextColor( hDC, RGB(0,0,0) );
GetTextExtentPoint32( hDC, "Unsupported", 11, &Size );
Position.cx = lpcwd->WhiteRect.left + ((RectWidth(lpcwd->WhiteRect)-Size.cx)/2);
Position.cy = lpcwd->WhiteRect.top + (RectHeight(lpcwd->WhiteRect)/2) - Size.cy;
TextOut( hDC, Position.cx, Position.cy, "Unsupported", 11 );
GetTextExtentPoint32( hDC, "Format", 6, &Size );
Position.cx = lpcwd->WhiteRect.left + ((RectWidth(lpcwd->WhiteRect)-Size.cx)/2);
Position.cy = lpcwd->WhiteRect.top + (RectHeight(lpcwd->WhiteRect)/2) + 1;
TextOut( hDC, Position.cx, Position.cy, "Format", 6 );
}
else
{
// Draw it on the black background
DrawIconEx( hDC, lpcwd->BlackRect.left + ((RectWidth(lpcwd->BlackRect)-Width)/2),
lpcwd->BlackRect.top + ((RectHeight(lpcwd->BlackRect)-Height)/2),
hIcon, Width, Height, 0, NULL, DI_NORMAL );
// Draw it on the white background
DrawIconEx( hDC, lpcwd->WhiteRect.left + ((RectWidth(lpcwd->WhiteRect)-Width)/2),
lpcwd->WhiteRect.top + ((RectHeight(lpcwd->WhiteRect)-Height)/2),
hIcon, Width, Height, 0, NULL, DI_NORMAL );
}
// Draw just the XOR mask
DrawXORMask( hDC, lpcwd->XORRect, &(lpcwd->lpIR->IconImages[nIndex]) );
// Draw just the AND mask
DrawANDMask( hDC, lpcwd->ANDRect, &(lpcwd->lpIR->IconImages[nIndex]) );
// Kill the icon, we're one with it
if( hIcon != NULL )
DestroyIcon( hIcon );
}
}
}
// Obligtory EndPaint()
EndPaint( hWnd, &ps );
}
break; // End WM_PAINT
// WM_COMMAND - menu options, etc
case WM_COMMAND:
// which one is it?
switch( LOWORD(wParam) )
{
// Edit->Export BMP - write icon image as BMP file
case ID_EDIT_EXPORTBMP:
{
LPCHILDWINDOWDATA lpcwd;
DWORD nIndex;
TCHAR szFileName[MAX_PATH];
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data, including an icon resource
if( (lpcwd != NULL ) && (lpcwd->lpIR != NULL) && (lpcwd->hWndFormatListBox!= NULL) )
{
// Which image is currently selected?
if( (nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_GETCURSEL, 0, 0 )) != CB_ERR )
{
// Get the name of the file from which to import the image
if( GetSaveIconFileName( szFileName, IDS_BMPFILTERSTRING, "Export to BMP File" ) )
{
HCURSOR hOldCursor;
// This might take a while :(
hOldCursor = SetCursor( LoadCursor(NULL,IDC_WAIT) );
IconImageToBMPFile( szFileName, &(lpcwd->lpIR->IconImages[nIndex]) );
SetCursor( hOldCursor );
}
}
}
}
break; // End ID_EDIT_EXPORTBMP
// Edit->Import BMP and Edit->Stretch-Import BMP - convert BMP file to icon
case ID_EDIT_IMPORTBMP:
case ID_EDIT_STRETCHIMPORTBMP:
{
LPCHILDWINDOWDATA lpcwd;
DWORD nIndex;
TCHAR szFileName[MAX_PATH];
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data, including an icon resource
if( (lpcwd != NULL ) && (lpcwd->lpIR != NULL) && (lpcwd->hWndFormatListBox!= NULL) )
{
// Which image is currently selected?
if( (nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_GETCURSEL, 0, 0 )) != CB_ERR )
{
// Get the name of the file from which to import the image
if( GetOpenIconFileName( szFileName, IDS_BMPFILTERSTRING, "Import from BMP File" ) )
{
HCURSOR hOldCursor;
// This might take a while :(
hOldCursor = SetCursor( LoadCursor(NULL,IDC_WAIT) );
// Import the BMP image data
if( IconImageFromBMPFile( szFileName, &(lpcwd->lpIR->IconImages[nIndex]), (LOWORD(wParam)==ID_EDIT_STRETCHIMPORTBMP)?TRUE:FALSE ) )
{
// which, of course, changes things
lpcwd->lpIR->bHasChanged = TRUE;
// Force a repaint
InvalidateRect( hWnd, NULL, TRUE );
}
SetCursor( hOldCursor );
}
}
}
}
break; // End ID_EDIT_IMPORTBMP/ID_EDIT_STRETCHIMPORTBMP
// User wants to add an image format
case ID_EDIT_ADDFORMAT:
{
LPICONIMAGE lpii;
TCHAR szBuffer[256];
// Launch the dialog to ask which size and color depth
if( DialogBoxParam( hInst, MAKEINTRESOURCE(IDD_ADDFORMATDLG), hWndMain, AddFormatDlgProc, (LPARAM)(&lpii) ) )
{
LPCHILDWINDOWDATA lpcwd;
LPICONRESOURCE lpNewIR;
DWORD nIndex, i;
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data, including an icon resource
if( (lpcwd != NULL ) && (lpcwd->lpIR != NULL) && (lpcwd->hWndFormatListBox!= NULL) )
{
// Need to see if the new format already exists in the resource
// We don't want dupes, so check each image for dupe
for(i=0;i<lpcwd->lpIR->nNumImages;i++)
{
// Is it the same as the new one?
if( (lpcwd->lpIR->IconImages[i].Width==lpii->Width) &&
(lpcwd->lpIR->IconImages[i].Height==lpii->Height) &&
(lpcwd->lpIR->IconImages[i].Colors==lpii->Colors) )
{
// Yikes! It is - bail and select the old one
MessageBox( hWnd, "That format already exists - format not added", "Error", MB_OK );
SendMessage( lpcwd->hWndFormatListBox, CB_SETCURSEL, (WPARAM)i, (LPARAM)0 );
break;
}
}
// Need bigger block of memory to hold an extra image format
lpNewIR = malloc( sizeof( ICONRESOURCE ) + ( ( lpcwd->lpIR->nNumImages + 1) * sizeof(ICONIMAGE) ) );
// Of course this changes things
lpNewIR->bHasChanged = TRUE;
// Copy old to new
lstrcpy( lpNewIR->szOriginalICOFileName, lpcwd->lpIR->szOriginalICOFileName );
lstrcpy( lpNewIR->szOriginalDLLFileName, lpcwd->lpIR->szOriginalDLLFileName );
lpNewIR->nNumImages = lpcwd->lpIR->nNumImages + 1;
for(i=0;i<lpcwd->lpIR->nNumImages;i++)
{
memcpy( &(lpNewIR->IconImages[i]), &(lpcwd->lpIR->IconImages[i]), sizeof( ICONIMAGE ) );
}
// Add in the new one
memcpy( &(lpNewIR->IconImages[i]), lpii, sizeof( ICONIMAGE ) );
// Add this new one to the list box
wsprintf( szBuffer, "%dx%d, %d Bit Color", lpii->Width, lpii->Height, lpii->Colors );
nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_ADDSTRING, 0, (LPARAM)szBuffer );
// Select the new one
SendMessage( lpcwd->hWndFormatListBox, CB_SETCURSEL, (WPARAM)i, (LPARAM)0 );
// clean up
free( lpii );
free( lpcwd->lpIR );
lpcwd->lpIR = lpNewIR;
// Create a nice new blank image for this format
CreateBlankNewFormatIcon( &(lpcwd->lpIR->IconImages[i]) );
// force a repaint
InvalidateRect( hWnd, NULL, TRUE );
}
}
}
break; // End WM_COMMAND -> ID_EDIT_ADDFORMAT
// User wants to remove an image format
case ID_EDIT_REMOVEFORMAT:
{
LPCHILDWINDOWDATA lpcwd;
DWORD nIndex, i;
LPICONRESOURCE lpNewIR;
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data, including an icon resource
if( (lpcwd != NULL ) && (lpcwd->lpIR != NULL) && (lpcwd->hWndFormatListBox!= NULL) )
{
// Which image is currently selected?
if( (nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_GETCURSEL, 0, 0 )) != CB_ERR )
{
// Remove the entry from the list box
SendMessage( lpcwd->hWndFormatListBox, CB_DELETESTRING, nIndex, 0 );
// Need less memory now
lpNewIR = malloc( sizeof( ICONRESOURCE ) + ( ( lpcwd->lpIR->nNumImages - 1) * sizeof(ICONIMAGE) ) );
// Of course this changes things
lpNewIR->bHasChanged = TRUE;
// Copy old to new
lstrcpy( lpNewIR->szOriginalICOFileName, lpcwd->lpIR->szOriginalICOFileName );
lstrcpy( lpNewIR->szOriginalDLLFileName, lpcwd->lpIR->szOriginalDLLFileName );
lpNewIR->nNumImages = lpcwd->lpIR->nNumImages - 1;
// Copy the rest of the images from old to new
for(i=0;i<nIndex;i++)
{
memcpy( &(lpNewIR->IconImages[i]), &(lpcwd->lpIR->IconImages[i]), sizeof( ICONIMAGE ) );
}
for(;i<lpcwd->lpIR->nNumImages-1;i++)
{
memcpy( &(lpNewIR->IconImages[i]), &(lpcwd->lpIR->IconImages[i+1]), sizeof( ICONIMAGE ) );
}
// Clean up
free( lpcwd->lpIR );
lpcwd->lpIR = lpNewIR;
// Select a different image
if( --nIndex < 0 ) nIndex = 0;
SendMessage( lpcwd->hWndFormatListBox, CB_SETCURSEL, (WPARAM)nIndex, 0 );
// Force a repaint
InvalidateRect( hWnd, NULL, TRUE );
}
}
}
break; // End WM_COMMAND -> ID_EDIT_REMOVEFORMAT
// User wants to paste CF_DIB from clipboard into current image
case ID_EDIT_STRETCHPASTE:
case ID_EDIT_PASTE:
{
LPCHILDWINDOWDATA lpcwd;
DWORD nIndex;
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data, including an icon resource
if( (lpcwd != NULL ) && (lpcwd->lpIR != NULL) && (lpcwd->hWndFormatListBox!= NULL) )
{
// Which image is currently selected?
if( (nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_GETCURSEL, 0, 0 )) != CB_ERR )
{
HCURSOR hOldCursor;
// This might take a while :(
hOldCursor = SetCursor( LoadCursor(NULL,IDC_WAIT) );
// Paste over it from the clipboard
if( IconImageFromClipBoard( &(lpcwd->lpIR->IconImages[nIndex]), LOWORD(wParam)!=ID_EDIT_PASTE ) )
// which, of course, changes things
lpcwd->lpIR->bHasChanged = TRUE;
// Force a repaint
InvalidateRect( hWnd, NULL, TRUE );
SetCursor( hOldCursor );
}
}
}
break; // End WM_COMMAND -> ID_EDIT_STRETCHPASTE/ID_EDIT_PASTE
// Put current image on the clipboard in CF_DIB format
case ID_EDIT_COPY:
{
LPCHILDWINDOWDATA lpcwd;
DWORD nIndex;
// Get the data associated this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// If we have some data, including an icon resource
if( (lpcwd != NULL ) && (lpcwd->lpIR != NULL) && (lpcwd->hWndFormatListBox!= NULL) )
{
// Which image is currently selected?
if( (nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_GETCURSEL, 0, 0 )) != CB_ERR )
{
// Send this image to the clipboard
IconImageToClipBoard( &(lpcwd->lpIR->IconImages[nIndex]) );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -