//..................................................................................................................... // // Initialization : Implementation file. // // Copyright (C) 1990, 1999 LEAD Technologies, Inc. // All rights reserved. // //..................................................................................................................... #include "StdSDK.h" // Standard application includes #include "Init.h" #include "Frame.h" #include "MDI.h" #include "resource.h" // For resource identifiers #include "paint.h" #define PAINT_SHAPE_INIT_ELLIPSE_WIDTH 25 /* Set the initial value for the shape round rect width */ #define PAINT_SHAPE_INIT_ELLIPSE_HEIGHT 25 /* Set the initial value for the shape round rect height */ #define PAINT_REGION_INIT_ELLIPSE_WIDTH 25 /* Set the initial value for the region round rect height */ #define PAINT_REGION_INIT_ELLIPSE_HEIGHT 25 /* Set the initial value for the region round rect height */ //..................................................................................................................... // Function prototypes for static functions //..................................................................................................................... ATOM InternalRegisterClass ( const LPWNDCLASSEX lpwcex ) ; HWND CreateMainFrameWindow ( HINSTANCE hinst, L_INT nCmdShow ) ; L_BOOL RegisterWindowClasses ( HINSTANCE hinst, L_UINT resPoolID ) ; //..................................................................................................................... // Function prototypes for callback functions //..................................................................................................................... //..................................................................................................................... // Variables. //..................................................................................................................... extern pAUTOMATIONHANDLE g_pAutomation ; extern pTOOLBARHANDLE g_pToolbar ; extern BITMAPHANDLE g_hBackTileBitmap ; extern BITMAPHANDLE g_hPaperTextureBitmap ; extern BITMAPHANDLE g_hBrushBitmap ; extern HBITMAP g_hBorderTileBitmap ; extern PAINTBRUSH g_Paintbrush ; extern PAINTSHAPE g_PaintShape ; extern PAINTREGION g_PaintRegion ; extern PAINTFILL g_PaintFill ; extern PAINTTEXT g_PaintText ; extern HACCEL g_hAccel ; // Current accelerator table in use extern L_TCHAR g_szCurrentText [ 255 ] ; //..................................................................................................................... // Typedefs //..................................................................................................................... typedef ATOM (WINAPI* REGISTERCLASSEXPROC)(const LPWNDCLASSEX lpwcex) ; L_BOOL InitInstance ( HINSTANCE hinst, L_UINT resPoolID, L_INT nCmdShow ) { HWND hwnd ; TCHAR ClassName [ MAX_RESOURCESTRING + 1 ] ; LOGFONT lf ; L_INT nRet ; nRet = LoadString ( hinst, resPoolID, ClassName, DIM ( ClassName ) ) ; VERIFY ( nRet != 0 ) ; // Constrain this application to run single instance hwnd = FindWindow ( ClassName, NULL ) ; if ( hwnd != NULL ) { // A previous instance of this application is running. // Activate the previous instance, tell it what the user // requested this instance to do, then abort initialization // of this instance. if ( IsIconic ( hwnd ) ) { ShowWindow ( hwnd, SW_RESTORE ) ; } SetForegroundWindow ( hwnd ) ; // Send an application-defined message to the previous // instance (or use some other type of IPC mechanism) // to tell the previous instance what to do. // Determining what to do generally depends on how the // user started this instance. // ... // Abort this instance's initialization return FALSE ; } // Register all application-specific window classes if ( ! RegisterWindowClasses ( hinst, resPoolID ) ) { return FALSE ; } // Create the application's main frame window g_hMainFrame = CreateMainFrameWindow ( hinst, nCmdShow ) ; if ( g_hMainFrame == NULL ) { return FALSE ; } g_hMainMenu = GetMenu ( g_hMainFrame ) ; // restore to this when all MDI children gone g_hMainAccel = LoadAccelerators ( hinst, MAKEINTRESOURCE ( IDR_MAINFRAME ) ) ; g_hAccel = g_hMainAccel ; // current accelerators are main accelerators if ( ! Paint_OnInitInstance ( hinst ) ) { return FALSE ; } {//AUTOMATION STUFF if ( L_AutInit ( &g_pAutomation ) ) { if ( SUCCESS != L_AutCreate ( g_pAutomation, AUTOMATION_MODE_PAINT, 0 ) ) { MessageBox ( hwnd, TEXT("Error Initializing Paint Automation"), TEXT("Error:"), MB_ICONSTOP ) ; L_AutFree ( g_pAutomation ) ; return FALSE ; } SendMessage ( g_hMainFrame, UWM_UPDATE_TOOLBAR, 0, 0 ) ; } else { MessageBox ( hwnd, TEXT("Error Initializing Paint Automation"), TEXT("Error:"), MB_ICONSTOP ) ; return FALSE ; } {// INITIATE THE TOOLBAR if ( SUCCESS == L_TBInit ( &g_pToolbar ) ) { L_BOOL fTBVisible ; POINT pt = { 0, 0 } ; RECT rcClient ; GetClientRect ( g_hMainFrame, &rcClient ) ; pt.x = rcClient.left ; pt.y = rcClient.top ; ClientToScreen ( g_hMainFrame, &pt ) ; L_TBCreate ( g_pToolbar, g_hMainFrame, TEXT("Paint Automation"), TOOLBAR_PAINT ) ; L_TBSetPosition ( g_pToolbar, &pt, TOOLBAR_POSITION_TOP | TOOLBAR_POSITION_LEFT ) ; L_TBIsVisible ( g_pToolbar, &fTBVisible ) ; if ( ! fTBVisible ) { L_TBSetVisible ( g_pToolbar, TRUE ) ; } L_TBSetCallback ( g_pToolbar, ProcessToolbarEvents, NULL ) ; } else { return FAILURE ; } L_AutSetToolbar ( g_pAutomation, g_pToolbar ) ; }// INITIATE THE TOOLBAR }//AUTOMATION STUFF {// LOAD BACKGROUND TILE IMAGE HBITMAP hBitmap ; HDC hDC = NULL ; hDC = GetDC ( NULL ) ; hBitmap = ( HBITMAP ) LoadImage ( hinst, MAKEINTRESOURCE ( IDB_TILE_BACK ), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE ) ; memset ( &g_hBackTileBitmap, 0, sizeof ( BITMAPHANDLE ) ) ; L_ConvertFromDDB ( hDC, &g_hBackTileBitmap, sizeof(BITMAPHANDLE), hBitmap, NULL ) ; L_ChangeBitmapViewPerspective ( &g_hBackTileBitmap, &g_hBackTileBitmap, sizeof(BITMAPHANDLE), TOP_LEFT ) ; ReleaseDC ( NULL, hDC ) ; DeleteObject ( hBitmap ) ; }// LOAD BACKGROUND TILE IMAGE // load border tile image. g_hBorderTileBitmap = NULL ; g_hBorderTileBitmap = LoadBitmap ( hinst, MAKEINTRESOURCE ( IDB_TILE_BORDER ) ) ; {// LOAD PAPER TEXTURE IMAGE HBITMAP hBitmap ; HDC hDC = NULL ; hDC = GetDC ( NULL ) ; hBitmap = ( HBITMAP ) LoadImage ( hinst, MAKEINTRESOURCE ( IDB_PAPERTEXTURE ), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE ) ; memset ( &g_hPaperTextureBitmap, 0, sizeof ( BITMAPHANDLE ) ) ; L_ConvertFromDDB ( hDC, &g_hPaperTextureBitmap, sizeof(BITMAPHANDLE), hBitmap, NULL ) ; L_ChangeBitmapViewPerspective ( &g_hPaperTextureBitmap, &g_hPaperTextureBitmap, sizeof(BITMAPHANDLE), TOP_LEFT ) ; ReleaseDC ( NULL, hDC ) ; DeleteObject ( hBitmap ) ; }// LOAD PAPER TEXTURE IMAGE {// LOAD BITMAP G_PAINTBRUSH IMAGE HBITMAP hBitmap ; HDC hDC = NULL ; hDC = GetDC ( NULL ) ; hBitmap = ( HBITMAP ) LoadImage ( hinst, MAKEINTRESOURCE ( IDB_BITMAPBRUSH ), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE ) ; memset ( &g_hBrushBitmap, 0, sizeof ( BITMAPHANDLE ) ) ; L_ConvertFromDDB ( hDC, &g_hBrushBitmap, sizeof(BITMAPHANDLE), hBitmap, NULL ) ; L_ChangeBitmapViewPerspective ( &g_hBrushBitmap, &g_hBrushBitmap, sizeof(BITMAPHANDLE), TOP_LEFT ) ; ReleaseDC ( NULL, hDC ) ; DeleteObject ( hBitmap ) ; }// LOAD BITMAP G_PAINTBRUSH IMAGE // Paintbrush initialization. g_Paintbrush.nSize = sizeof ( PAINTBRUSH ) ; g_Paintbrush.dwMask = PBF_ALL ; g_Paintbrush.Touch.nContentsType = PAINT_TOUCH_CONTENTS_COLOR ; g_Paintbrush.Touch.crColor = RGB ( 0, 0, 0 ) ; g_Paintbrush.Touch.nShape = PAINT_TOUCH_SHAPE_CIRCLE ; g_Paintbrush.Touch.pBitmap = &g_hBrushBitmap ; g_Paintbrush.Touch.crTransparentColor = RGB ( 0, 0, 0 ) ; g_Paintbrush.nDiameter = PAINT_BRUSH_MIN_DIAMETER ; g_Paintbrush.Hardness.nDistributionType = PAINT_HARDNESS_DISTRB_TYPE_0 ; g_Paintbrush.Hardness.nValue = PAINT_BRUSH_MIN_HARDNESS ; g_Paintbrush.nSpacing = 3 ; g_Paintbrush.nDensity = PAINT_BRUSH_MAX_DENSITY ; g_Paintbrush.nOpacity = PAINT_BRUSH_MIN_OPACITY ; g_Paintbrush.nFadeOutRate = PAINT_BRUSH_MIN_FADEOUT ; g_Paintbrush.pTexture = &g_hPaperTextureBitmap ; // PaintShape initialization. g_PaintShape.nSize = sizeof ( PAINTSHAPE ) ; g_PaintShape.dwMask = PSF_ALL ; g_PaintShape.nBackgroundStyle = PAINT_SHAPE_BACK_STYLE_OPAQUE ; g_PaintShape.crBackgroundColor = RGB ( 255, 255, 255 ) ; g_PaintShape.pBackgroundTileBitmap = &g_hBackTileBitmap ; g_PaintShape.nBorderStyle = PAINT_SHAPE_BORDER_STYLE_SOLID ; g_PaintShape.nBorderBrushStyle = PAINT_SHAPE_BORDER_BRUSH_STYLE_COLOR ; g_PaintShape.crBorderColor = RGB ( 0, 0, 0 ) ; g_PaintShape.hBorderTileBitmap = g_hBorderTileBitmap ; g_PaintShape.nBorderWidth = PAINT_SHAPE_MIN_BORDER_WIDTH ; g_PaintShape.nBorderEndCap = PAINT_SHAPE_BORDER_ENDCAP_SQUARE ; g_PaintShape.nGradientStyle = PAINT_SHAPE_GRADIENT_STYLE_RECTANGLE_TO_C ; g_PaintShape.crGradientStartColor = RGB ( 0, 0, 0 ) ; g_PaintShape.crGradientEndColor = RGB ( 255, 255, 255 ) ; g_PaintShape.uGradientSteps = PAINT_SHAPE_MAX_GRADIENT_STEPS ; g_PaintShape.nRoundRectEllipseWidth = PAINT_SHAPE_INIT_ELLIPSE_WIDTH ; g_PaintShape.nRoundRectEllipseHeight = PAINT_SHAPE_INIT_ELLIPSE_HEIGHT ; g_PaintShape.nOpacity = PAINT_SHAPE_MIN_OPACITY ; g_PaintShape.pTexture = &g_hPaperTextureBitmap ; // PaintRegion initialization. g_PaintRegion.nSize = sizeof ( PAINTREGION ) ; g_PaintRegion.dwMask = PRF_ALL ; g_PaintRegion.crLowerTolerance = RGB ( PAINT_REGION_MIN_TOLERANCE, PAINT_REGION_MIN_TOLERANCE, PAINT_REGION_MIN_TOLERANCE ) ; g_PaintRegion.crUpperTolerance = RGB ( PAINT_REGION_MIN_TOLERANCE, PAINT_REGION_MIN_TOLERANCE, PAINT_REGION_MIN_TOLERANCE ) ; g_PaintRegion.nRoundRectEllipseWidth = PAINT_REGION_INIT_ELLIPSE_WIDTH ; g_PaintRegion.nRoundRectEllipseHeight = PAINT_REGION_INIT_ELLIPSE_HEIGHT ; // PaintFill initialization. g_PaintFill.nSize = sizeof ( PAINTFILL ) ; g_PaintFill.dwMask = PFF_ALL ; g_PaintFill.nStyle = PAINT_FILL_STYLE_SOLID ; g_PaintFill.crSolidFillColor = RGB ( 255, 255, 255 ) ; g_PaintFill.pBackgroundTileBitmap = &g_hBackTileBitmap ; g_PaintFill.nGradientStyle = PAINT_SHAPE_GRADIENT_STYLE_RECTANGLE_TO_C ; g_PaintFill.crGradientStartColor = RGB ( 0, 0, 0 ) ; g_PaintFill.crGradientEndColor = RGB ( 255, 255, 255 ) ; g_PaintFill.uGradientSteps = 255 ; g_PaintFill.crUpperTolerance = RGB ( 0, 0, 0 ) ; g_PaintFill.crLowerTolerance = RGB ( 0, 0, 0 ) ; g_PaintFill.nOpacity = PAINT_FILL_MIN_OPACITY ; g_PaintFill.pTexture = &g_hPaperTextureBitmap ; // PaintText initialization. memset ( g_szCurrentText, 0, sizeof ( g_szCurrentText ) ) ; lstrcpy ( g_szCurrentText, TEXT("LEADTOOLS!") ) ; lf.lfHeight = 48 ; lf.lfWidth = 0 ; lf.lfEscapement = 0 ; lf.lfOrientation = 0 ; lf.lfWeight = FW_NORMAL ; lf.lfItalic = FALSE ; lf.lfUnderline = FALSE ; lf.lfStrikeOut = FALSE ; lf.lfCharSet = ANSI_CHARSET ; lf.lfOutPrecision = OUT_DEFAULT_PRECIS ; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS ; lf.lfQuality = DEFAULT_QUALITY ; lf.lfPitchAndFamily = FF_DONTCARE ; lstrcpy(lf.lfFaceName, TEXT("Times New Roman")); g_PaintText.nSize = sizeof ( PAINTTEXT ) ; g_PaintText.dwMask = PTF_ALL ; g_PaintText.pszText = g_szCurrentText ; g_PaintText.hFont = CreateFontIndirect ( &lf ) ; g_PaintText.nBorderBrushStyle = PAINT_TEXT_BORDER_BRUSH_STYLE_COLOR ; g_PaintText.nBorderWidth = PAINT_TEXT_MIN_BORDER_WIDTH ; g_PaintText.crBorderColor = RGB ( 0, 0, 0 ) ; g_PaintText.nBackgroundStyle = PAINT_TEXT_BACK_STYLE_OPAQUE ; g_PaintText.crBackgroundColor = RGB ( 255, 255, 255 ) ; g_PaintText.pBackgroundTileBitmap = &g_hBackTileBitmap ; g_PaintText.nAlignment = ( PAINTALIGNMENT ) ( PAINT_ALIGNMENT_HCENTER | PAINT_ALIGNMENT_VCENTER ) ; g_PaintText.nOpacity = PAINT_TEXT_MIN_OPACITY ; g_PaintText.pTexture = &g_hPaperTextureBitmap ; g_PaintText.TransformInfo.nRotate = PAINT_TEXT_MIN_ROTATE ; g_PaintText.TransformInfo.Scale.cx = 100 ; g_PaintText.TransformInfo.Scale.cy = 100 ; L_AutSetPaintProperty ( g_pAutomation, PAINT_GROUP_BRUSH, &g_Paintbrush ) ; L_AutSetPaintProperty ( g_pAutomation, PAINT_GROUP_SHAPE, &g_PaintShape ) ; L_AutSetPaintProperty ( g_pAutomation, PAINT_GROUP_REGION, &g_PaintRegion ) ; L_AutSetPaintProperty ( g_pAutomation, PAINT_GROUP_FILL, &g_PaintFill ) ; L_AutSetPaintProperty ( g_pAutomation, PAINT_GROUP_TEXT, &g_PaintText ) ; return TRUE ; } L_INT ExitInstance ( MSG* pmsg ) { Paint_OnExitInstance ( ) ; if ( g_PaintText.hFont != NULL ) { DeleteObject ( ( HFONT ) g_PaintText.hFont ) ; } // clean up bitmaps. L_FreeBitmap ( &g_hBackTileBitmap ) ; L_FreeBitmap ( &g_hPaperTextureBitmap ) ; L_FreeBitmap ( &g_hBrushBitmap ) ; DeleteObject ( g_hBorderTileBitmap ) ; {//AUTOMATION STUFF if ( L_AutIsValid ( g_pAutomation ) ) { L_AutFree ( g_pAutomation ) ; } {//DELETE THE TOOLBAR if ( L_TBIsValid ( g_pToolbar ) ) { L_TBFree ( g_pToolbar ) ; } }//DELETE THE TOOLBAR }//AUTOMATION STUFF return pmsg->wParam ; } L_BOOL RegisterWindowClasses ( HINSTANCE hinst, L_UINT resPoolID ) { TCHAR ClassName [MAX_RESOURCESTRING + 1] ; WNDCLASSEX wcex ; VERIFY (LoadString (hinst, resPoolID, ClassName, DIM(ClassName))) ; // Fill in window class structure with parameters that describe // the main window. wcex.cbSize = sizeof (WNDCLASSEX) ; wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ; wcex.lpfnWndProc = MainFrameWndProc ; wcex.cbClsExtra = 0 ; wcex.cbWndExtra = 0 ; wcex.hInstance = hinst ; wcex.hIcon = LoadIcon (hinst, MAKEINTRESOURCE (resPoolID)) ; wcex.hCursor = LoadCursor (NULL, IDC_ARROW) ; wcex.hbrBackground = NULL ; wcex.lpszMenuName = MAKEINTRESOURCE (resPoolID) ; wcex.lpszClassName = ClassName ; wcex.hIconSm = NULL ; // Register the window class and return success/failure code. return InternalRegisterClass ( &wcex ) ; } HWND CreateMainFrameWindow ( HINSTANCE hinst, L_INT nCmdShow ) { HWND hwnd ; TCHAR ClassName [MAX_RESOURCESTRING + 1] ; TCHAR Title [MAX_RESOURCESTRING + 1] ; // Create the main frame window VERIFY ( LoadString ( hinst, IDR_MAINFRAME, ClassName, DIM ( ClassName ) ) ) ; VERIFY ( LoadString ( hinst, IDS_APP_TITLE, Title, DIM ( Title ) ) ) ; hwnd = CreateWindowEx ( 0, // Extended window styles ClassName, // Address of registered class name Title, // Address of window name WS_OVERLAPPEDWINDOW,// Window style CW_USEDEFAULT, // Horizontal position of window CW_USEDEFAULT, // Vertical position of window CW_USEDEFAULT, // Window width CW_USEDEFAULT, // Window height NULL, // Handle of parent or owner window NULL, // Handle of menu for this window hinst, // Handle of application instance NULL ) ; // Address of window-creation data ASSERT ( NULL != hwnd ) ; if ( hwnd == NULL ) { return NULL ; } CenterWindow ( hwnd, NULL ); ShowWindow ( hwnd, nCmdShow ) ; UpdateWindow ( hwnd ) ; return hwnd ; } ATOM InternalRegisterClass ( const LPWNDCLASSEX lpwcex ) { WNDCLASS wc ; #ifndef UNICODE // Get the module handle of the 32-bit USER DLL HANDLE hModule = GetModuleHandle ( TEXT("USER32") ) ; if ( NULL != hModule ) { // If we're running on a Win32 version supporting RegisterClassEx // get the address of the function so we can call it REGISTERCLASSEXPROC proc = ( REGISTERCLASSEXPROC ) GetProcAddress ( ( HINSTANCE ) hModule, "RegisterClassExA" ) ; if ( NULL != proc ) { return ( *proc ) ( lpwcex ) ; } } #endif // Convert the WNDCLASSEX structure to a WNDCLASS structure wc.style = lpwcex->style ; wc.lpfnWndProc = lpwcex->lpfnWndProc ; wc.cbClsExtra = lpwcex->cbClsExtra ; wc.cbWndExtra = lpwcex->cbWndExtra ; wc.hInstance = lpwcex->hInstance ; wc.hIcon = lpwcex->hIcon ; wc.hCursor = lpwcex->hCursor ; wc.hbrBackground = lpwcex->hbrBackground ; wc.lpszMenuName = lpwcex->lpszMenuName ; wc.lpszClassName = lpwcex->lpszClassName ; return RegisterClass (&wc) ; } ATOM RegisterMDIChild ( HINSTANCE hinst, L_UINT resPoolID, WNDPROC wproc, L_UINT extra ) { WNDCLASSEX wcex ; TCHAR ClassName[80] ; HCURSOR cursor ; HICON icon ; if ( LoadString ( hinst, resPoolID, ClassName, DIM ( ClassName ) ) == 0 ) { return ( ( ATOM ) 0 ) ; // failed } cursor = LoadCursor ( NULL, IDC_ARROW ) ; icon = LoadIcon ( hinst, MAKEINTRESOURCE ( IDR_MAINFRAME ) ) ; wcex.cbSize = sizeof (WNDCLASSEX) ; wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ; wcex.lpfnWndProc = wproc ; wcex.cbClsExtra = 0 ; wcex.cbWndExtra = extra ; wcex.hInstance = hinst ; wcex.hIcon = (icon != NULL ? icon : LoadIcon ( NULL, IDI_APPLICATION ) ) ; wcex.hCursor = (cursor != NULL ? cursor : LoadCursor ( NULL, IDC_ARROW ) ) ; wcex.hbrBackground = NULL ; wcex.lpszMenuName = NULL ; // MDI children generally have no menus wcex.lpszClassName = ClassName ; wcex.hIconSm = NULL ; return InternalRegisterClass ( &wcex ) ; }