?? mdichild.c
字號:
\****************************************************************************/
BOOL CreateChildren( HWND hWnd )
{
RECT ClientRect, TempRect;
LPCHILDWINDOWDATA lpcwd;
HDC hDC;
SIZE size;
// Get the data associated with this window
if( (lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA )) == NULL )
return FALSE;
// Just how big is this window?
GetClientRect( hWnd, &ClientRect );
// Calculate listbox size and position
SetRect( &(lpcwd->BoxRect), 10, ClientRect.bottom-30, (MAX_ICON_WIDTH*2)+14, ClientRect.bottom+50 );
// Create the listbox
if((lpcwd->hWndFormatListBox=CreateChildListBox( hWnd, ID_FORMAT_BOX, &(lpcwd->BoxRect) )) == NULL )
return FALSE;
// If we have an icon resource
if( lpcwd->lpIR != NULL )
{
UINT i, nIndex;
TCHAR szBuffer[256];
// For each image in the resoure
for(i=0;i<lpcwd->lpIR->nNumImages;i++)
{
// Add the type of the image to the listbox
wsprintf( szBuffer, "%dx%d, %d Bit Color", lpcwd->lpIR->IconImages[i].Width,
lpcwd->lpIR->IconImages[i].Height, lpcwd->lpIR->IconImages[i].Colors );
nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_ADDSTRING, 0, (LPARAM)szBuffer );
}
// Select the first entry
SendMessage( lpcwd->hWndFormatListBox, CB_SETCURSEL, (WPARAM)0, (LPARAM)0 );
}
// Adjust the box size based on the listbox's real size
GetClientRect( lpcwd->hWndFormatListBox, &TempRect );
lpcwd->BoxRect.bottom = lpcwd->BoxRect.top + TempRect.bottom;
// How big is text these days?
hDC = GetDC( hWnd );
GetTextExtentPoint32( hDC, "Icon on Black", 13, &size );
ReleaseDC( hWnd, hDC );
// Set the rectangles for the various squares to be drawn later
#define DIVIDER 5
SetRect( &(lpcwd->DrawingRect), 10, 10, (MAX_ICON_WIDTH*2)+14, 20 + (MAX_ICON_HEIGHT*2) + (TempRect.bottom*2) );
SetRect( &(lpcwd->BlackRect), lpcwd->DrawingRect.left, lpcwd->DrawingRect.top, lpcwd->DrawingRect.left + MAX_ICON_WIDTH + 1, lpcwd->DrawingRect.top + MAX_ICON_HEIGHT + 1 );
SetRect( &(lpcwd->BlackTextRect), lpcwd->BlackRect.left, lpcwd->BlackRect.bottom+1, lpcwd->BlackRect.right, lpcwd->BlackRect.bottom + TempRect.bottom + 1 );
SetRect( &(lpcwd->WhiteRect), lpcwd->BlackRect.right+1, lpcwd->BlackRect.top, lpcwd->DrawingRect.right, lpcwd->BlackRect.bottom );
SetRect( &(lpcwd->WhiteTextRect), lpcwd->WhiteRect.left, lpcwd->WhiteRect.bottom+1, lpcwd->WhiteRect.right, lpcwd->WhiteRect.bottom + TempRect.bottom + 1 );
SetRect( &(lpcwd->XORRect), lpcwd->BlackTextRect.left, lpcwd->BlackTextRect.bottom + 1 + DIVIDER, lpcwd->BlackRect.right, lpcwd->BlackTextRect.bottom + 2 + DIVIDER + MAX_ICON_HEIGHT );
SetRect( &(lpcwd->XORTextRect), lpcwd->XORRect.left, lpcwd->XORRect.bottom + 1, lpcwd->XORRect.right, lpcwd->DrawingRect.bottom );
SetRect( &(lpcwd->ANDRect), lpcwd->WhiteTextRect.left, lpcwd->WhiteTextRect.bottom + 1 + DIVIDER, lpcwd->WhiteRect.right, lpcwd->WhiteTextRect.bottom + 2 + DIVIDER + MAX_ICON_HEIGHT );
SetRect( &(lpcwd->ANDTextRect), lpcwd->ANDRect.left, lpcwd->ANDRect.bottom + 1, lpcwd->ANDRect.right, lpcwd->DrawingRect.bottom );
#undef DIVIDER
return TRUE;
}
/* End CreateChildren() ****************************************************/
/****************************************************************************
*
* FUNCTION: CreateChildListBox
*
* PURPOSE: Creates a listbox and shows it
*
* PARAMS: HWND hWndParent - The MDI window to be a parent
* UINT ID - the ID of the new listbox
* LPRECT lpRect - the RECT for the listbox
*
* RETURNS: HWND - handle to listbox window, NULL for failure
*
* History:
* July '95 - Created
*
\****************************************************************************/
HWND CreateChildListBox( HWND hWndParent, UINT ID, LPRECT lpRect )
{
HWND hWnd;
hWnd = CreateWindow( "COMBOBOX", "", CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL | WS_CHILD | WS_VSCROLL,
lpRect->left, lpRect->top,
lpRect->right - lpRect->left + 1, lpRect->bottom - lpRect->top + 1,
hWndParent, (HMENU)ID, hInst, 0 );
if( hWnd != NULL )
ShowWindow( hWnd, SW_SHOW );
return hWnd;
}
/* End CreateChildListBox() ************************************************/
/****************************************************************************
*
* FUNCTION: AddFormatDlgProc
*
* PURPOSE: Dialog Procedure for "Add Format" dialog
*
* PARAMS: HWND hWnd - This dialog's window handle
* UINT Msg - Which Message?
* WPARAM wParam - message parameter
* LPARAM lParam - message parameter
*
* RETURNS: BOOL - TRUE for OK, FALSE for Cancel
*
* History:
* July '95 - Created
*
\****************************************************************************/
BOOL CALLBACK AddFormatDlgProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
// Support all DIB color formats known at this time
#define MAX_COLOR_FORMAT 5
TCHAR ColorFormats[MAX_COLOR_FORMAT+1][20] = { "Monochrome (1bpp)", "16 Color (4bpp)", "256 Color (8bpp)",
"16 Bit Color", "24 Bit Color", "32 Bit Color" };
UINT Bits[MAX_COLOR_FORMAT+1] = { 1, 4, 8, 16, 24, 32 };
static bSquareOnly = TRUE;
static LPARAM lInitParam;
switch( Msg )
{
// Dialog is being initialized
case WM_INITDIALOG:
{
TCHAR szBuffer[100];
// We are passed a pointer to a LPICONIMAGE in lParam, save it
lInitParam = lParam;
// Set the range and position of the sliders
SendDlgItemMessage( hWnd, ID_WIDTHSLIDER, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(MIN_ICON_WIDTH,MAX_ICON_WIDTH) );
SendDlgItemMessage( hWnd, ID_WIDTHSLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)MIN_ICON_WIDTH );
wsprintf( szBuffer, "%d Width", MIN_ICON_WIDTH );
SetDlgItemText( hWnd, ID_WIDTHTEXT, szBuffer );
SendDlgItemMessage( hWnd, ID_HEIGHTSLIDER, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(MIN_ICON_HEIGHT,MAX_ICON_HEIGHT) );
SendDlgItemMessage( hWnd, ID_HEIGHTSLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)MIN_ICON_HEIGHT );
wsprintf( szBuffer, "%d Height", MIN_ICON_HEIGHT );
SetDlgItemText( hWnd, ID_HEIGHTTEXT, szBuffer );
SendDlgItemMessage( hWnd, ID_COLORSLIDER, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0,MAX_COLOR_FORMAT) );
SendDlgItemMessage( hWnd, ID_COLORSLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)2);
SetDlgItemText( hWnd, ID_COLORTEXT, ColorFormats[2] );
CheckDlgButton( hWnd, IDC_SQUAREONLY, bSquareOnly );
}
break; // End WM_INITDIALOG
// Scroll message from the sliders
case WM_HSCROLL:
{
int nPos;
TCHAR szBuffer[100];
// Get the current position
if( ( LOWORD(wParam) == TB_THUMBPOSITION ) || ( LOWORD(wParam) == TB_THUMBTRACK ) )
nPos = HIWORD( wParam );
else
nPos = SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 );
// Was it the width slider?
if( (HWND)lParam == GetDlgItem( hWnd, ID_WIDTHSLIDER) )
{
// Update the text
wsprintf( szBuffer, "%d Width", nPos );
SetDlgItemText( hWnd, ID_WIDTHTEXT, szBuffer );
// If dealing with width=height, adjust height too
if( bSquareOnly )
{
SendDlgItemMessage( hWnd, ID_HEIGHTSLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)nPos );
wsprintf( szBuffer, "%d Height", nPos );
SetDlgItemText( hWnd, ID_HEIGHTTEXT, szBuffer );
}
}
else
{
// Was it the height slider?
if( (HWND)lParam == GetDlgItem( hWnd, ID_HEIGHTSLIDER) )
{
// Update the text
wsprintf( szBuffer, "%d Height", nPos );
SetDlgItemText( hWnd, ID_HEIGHTTEXT, szBuffer );
// If dealing with width=height, adjust width too
if( bSquareOnly )
{
SendDlgItemMessage( hWnd, ID_WIDTHSLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)nPos );
wsprintf( szBuffer, "%d Width", nPos );
SetDlgItemText( hWnd, ID_WIDTHTEXT, szBuffer );
}
}
else
{
// Was it the color slider?
if( (HWND)lParam == GetDlgItem( hWnd, ID_COLORSLIDER) )
{
// Update the text
SetDlgItemText( hWnd, ID_COLORTEXT, ColorFormats[nPos] );
}
}
}
}
break; // End WM_HSCROLL
// Time to say 'goodbye'
case WM_CLOSE:
PostMessage( hWnd, WM_COMMAND, IDCANCEL, 0l );
break; // End WM_CLOSE
// Messages from user items - checkboxes etc
case WM_COMMAND:
switch( LOWORD(wParam) )
{
// Checkbox for width=height restriction
case IDC_SQUAREONLY:
// Is it checked now?
bSquareOnly = IsDlgButtonChecked( hWnd, IDC_SQUAREONLY );
// If it is, set height equal to width
if( bSquareOnly )
{
int nPos;
TCHAR szBuffer[100];
nPos = SendDlgItemMessage( hWnd, ID_WIDTHSLIDER, TBM_GETPOS, 0, 0 );
SendDlgItemMessage( hWnd, ID_HEIGHTSLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)nPos );
wsprintf( szBuffer, "%d Height", nPos );
SetDlgItemText( hWnd, ID_HEIGHTTEXT, szBuffer );
}
break; // End IDC_SQUAREONLY
// Add Format button has been pressed
case IDOK:
{
LPICONIMAGE lpii;
// Were we passed a valid LPICONIMAGE pointer?
if( ((LPICONIMAGE)lInitParam) != NULL )
{
// allocate the new ICONIMAGE
if( (lpii = malloc( sizeof( ICONIMAGE ) )) == FALSE )
EndDialog( hWnd, FALSE );
else
{
// initialize it
ZeroMemory( lpii, sizeof( ICONIMAGE ) );
lpii->Width = SendDlgItemMessage( hWnd, ID_WIDTHSLIDER, TBM_GETPOS, 0, 0 );
lpii->Height = SendDlgItemMessage( hWnd, ID_HEIGHTSLIDER, TBM_GETPOS, 0, 0 );
lpii->Colors = Bits[SendDlgItemMessage( hWnd, ID_COLORSLIDER, TBM_GETPOS, 0, 0 )];
// update the pointer that we were passed
*(LPICONIMAGE *)lInitParam = lpii;
// bail
EndDialog( hWnd, TRUE );
}
}
else
{
// bail
EndDialog( hWnd, FALSE );
}
}
break; // End IDOK
// Time to cancel
case IDCANCEL:
EndDialog( hWnd, FALSE );
break; // End IDCANCEL
}
break;
default:
return FALSE;
break;
}
return TRUE;
#undef MAX_COLOR_FORMAT
}
/* End AddFormatDlgProc() ************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -