?? mdichild.c
字號:
/****************************************************************************\
*
* FILE: MDIChild.C
*
* PURPOSE: IconPro Project MDI Child Window handling c file
*
* COMMENTS: This file contains the MDI Child Window handling code
*
* FUNCTIONS:
* EXPORTS:
* IconChildWndProc - Window Procedure for the MDI children
* LOCALS:
* Draw3DRect - Draws a rectangle using 3D colors
* EraseBackground - Draws the MDI child's background
* CreateChildren - Creates MDI child's child windows
* CreateChildListBox - Creates and shows a list box
* AddFormatDlgProc - Dialog Proc for AddFormat dialog
*
* Copyright 1995 Microsoft Corp.
*
*
* History:
* July '95 - Created
*
\****************************************************************************/
#include <windows.h>
#include <commctrl.h>
#include "Icons.h"
#include "IconPro.h"
#include "Resource.h"
#include "MDIChild.H"
/****************************************************************************/
// External Globals
extern HINSTANCE hInst;
extern HWND hWndMain, hMDIClientWnd;
/****************************************************************************/
/****************************************************************************/
// Prototypes for local functions
BOOL Draw3DRect( HDC hDC, RECT Rect, BOOL bSunken );
void EraseBackground( HWND hWnd, HDC hDC );
BOOL CreateChildren( HWND hWnd );
HWND CreateChildListBox( HWND hWndParent, UINT ID, LPRECT lpRect );
BOOL CALLBACK AddFormatDlgProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
/****************************************************************************/
/****************************************************************************
*
* FUNCTION: IconChildWndProc
*
* PURPOSE: Window Procedure for MDI child window
*
* PARAMS: HWND hWnd - This window handle
* UINT Msg - Which Message?
* WPARAM wParam - message parameter
* LPARAM lParam - message parameter
*
* RETURNS: LRESULT - depends on message
*
* History:
* July '95 - Created
*
\****************************************************************************/
LRESULT CALLBACK IconChildWndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
// Which message is it?
switch( Msg )
{
// User pressed left mouse button
// Should be re-generate the AND mask?
case WM_LBUTTONDOWN:
{
LPCHILDWINDOWDATA lpcwd;
// Get the icon resource data aassociated with this window
if( (lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA )) == NULL )
break;
// Do something only if the CNTRL key is pressed too
if( MK_CONTROL & wParam )
{
POINTS pts = MAKEPOINTS(lParam);
POINT pt;
RECT ImageRect;
DWORD nIndex;
pt.x = pts.x; pt.y = pts.y;
// Do we have some icon resource data?
if( lpcwd->lpIR != NULL )
{
// Which image is selected right now?
if( (nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_GETCURSEL, 0, 0 )) != CB_ERR )
{
// Where is it drawn
ImageRect = GetXORImageRect( lpcwd->XORRect, &(lpcwd->lpIR->IconImages[nIndex]) );
// Is the mouse click in the image?
if( PtInRect( &ImageRect, pt ) )
{
HCURSOR hOldCursor;
// This might take a while :(
hOldCursor = SetCursor( LoadCursor(NULL,IDC_WAIT) );
pt.x -= ImageRect.left;
pt.y -= ImageRect.top;
// generate the new AND mask
MakeNewANDMaskBasedOnPoint( &(lpcwd->lpIR->IconImages[nIndex]), pt );
// force a redraw
InvalidateRect( hWnd, NULL, TRUE );
// Set changed flag
lpcwd->lpIR->bHasChanged = TRUE;
// finally, its over, put the cursor back
SetCursor( hOldCursor );
}
}
}
}
}
break; // End WM_LBUTTONDOWN
// Time to say "Goodbye"
case WM_CLOSE:
{
LPCHILDWINDOWDATA lpcwd;
TCHAR szWindowTitle[MAX_PATH];
// Get the data associated with this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// Is there data associated with this window?
if( lpcwd != NULL )
{
// Does the data include an icon resource
if( lpcwd->lpIR != NULL )
{
// Has the resource changed?
if( lpcwd->lpIR->bHasChanged )
{
// Get the title for the message box
GetWindowText( hWnd, szWindowTitle, MAX_PATH );
if( lstrlen( szWindowTitle ) < 1 )
lstrcpy( szWindowTitle, "UnKnown" );
// User want to save changes?
switch( MessageBox( hWnd, "Icon has Changed, Save Changes?", szWindowTitle, MB_ICONSTOP | MB_YESNOCANCEL ) )
{
case IDYES:
SendMessage( hWnd, WM_COMMAND, ID_FILE_SAVE, 0 );
// Fall through to IDNO and kill window
case IDNO:
DefMDIChildProc( hWnd, Msg, wParam, lParam );
return 0;
break;
case IDCANCEL:
return 1;
break;
}
}
}
}
DefMDIChildProc( hWnd, Msg, wParam, lParam );
return 0;
}
break; // End WM_CLOSE
// We are being created
case WM_CREATE:
{
LPCHILDWINDOWDATA lpcwd;
// Need new data for this new window
lpcwd = malloc( sizeof( CHILDWINDOWDATA ) );
SetWindowLong( hWnd, GWL_USERDATA, (LONG)lpcwd );
lpcwd->lpIR = NULL;
// If a resource was passed in, use it
if( (LPVOID)lParam != NULL )
lpcwd->lpIR = (LPICONRESOURCE)(((MDICREATESTRUCT *)(((CREATESTRUCT *)lParam)->lpCreateParams))->lParam);
// If no resource was passed in, do minimal initialization
if( lpcwd->lpIR == NULL )
{
lpcwd->lpIR = malloc(sizeof(ICONRESOURCE));
lstrcpy( lpcwd->lpIR->szOriginalICOFileName, "Untitled" );
lstrcpy( lpcwd->lpIR->szOriginalDLLFileName, "" );
lpcwd->lpIR->nNumImages = 0;
}
// Nothing has changed
lpcwd->lpIR->bHasChanged = FALSE;
// Create the list box, etc
CreateChildren( hWnd );
return DefMDIChildProc( hWnd, Msg, wParam, lParam );
}
break; // End WM_CREATE
// Won't let window get too small to show our main area
case WM_GETMINMAXINFO:
{
LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
lpmmi->ptMinTrackSize.x = WINDOW_WIDTH;
lpmmi->ptMinTrackSize.y = WINDOW_HEIGHT;
return 0;
}
break; // End WM_GETMINMAXINFO
// Yikes! We're being destroyed!
case WM_DESTROY:
{
LPCHILDWINDOWDATA lpcwd;
// Get the data associated with this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// Is there some?
if( lpcwd != NULL )
{
// Is there a resource?
if( lpcwd->lpIR != NULL )
{
UINT i;
// Free all the bits
for( i=0; i< lpcwd->lpIR->nNumImages; i++ )
{
if( lpcwd->lpIR->IconImages[i].lpBits != NULL )
free( lpcwd->lpIR->IconImages[i].lpBits );
}
free( lpcwd->lpIR );
}
free( lpcwd );
}
SetWindowLong( hWnd, GWL_USERDATA, 0 );
}
break; // End WM_DESTROY
// Draw our background (white and black squares, etc)
case WM_ERASEBKGND:
EraseBackground( hWnd, (HDC)wParam );
return 1;
break; // End WM_ERASEBKGND
// Ok, time to paint
case WM_PAINT:
{
LPCHILDWINDOWDATA lpcwd;
HDC hDC;
PAINTSTRUCT ps;
DWORD nIndex;
HICON hIcon = NULL;
// Obligatory BeginPaint()
hDC = BeginPaint( hWnd, &ps );
// Get the data associated with this window
lpcwd = (LPCHILDWINDOWDATA)GetWindowLong( hWnd, GWL_USERDATA );
// Is there some?
if( lpcwd != NULL )
{
// Is there a resource?
if( lpcwd->lpIR != NULL )
{
// Which image is selected?
if( (nIndex = SendMessage( lpcwd->hWndFormatListBox, CB_GETCURSEL, 0, 0 )) != CB_ERR )
{
int Width, Height;
// Get an HICON for the currently selected image
hIcon = MakeIconFromResource( &(lpcwd->lpIR->IconImages[nIndex]) );
// How big is the icon?
Width = lpcwd->lpIR->IconImages[nIndex].Width;
Height = lpcwd->lpIR->IconImages[nIndex].Height;
// Check to see if the icon is NULL
// If it is, consider it "unsupported"
// In the future, maybe we should look into MakeIconFromResource() and
// see why it is null - it may be for another reason than "unsupported"
if( hIcon == NULL )
{
SIZE Size, Position;
// Draw some text in the black rect
SetTextColor( hDC, RGB(255,255,255) );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -