/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(NewPaint)--------------------------------------------------------------- LEAD Functions Used. L_FileInfo L_LoadFile L_SetDisplayMode L_CreatePaintPalette L_PaintDC L_FreeBitmap We have made the assumption that the user has the knowledge of programing in C and Windows. This example will: 1. load the image from a file, whose name is sent through the command line, using L_LoadFile, 2. display the image, 3. pop up a dialog box to set paint rects for displaying. Usage: PAINTDC --------------------------------------------------------------------------*/ #include /* Required for all Windows applications. */ #include /* Needed for message crackers. */ #include "tchar.h" #include #include "..\\..\\..\\include\\l_bitmap.h" /* LEADTOOLS main header file. */ #include "..\\..\\..\\include\\l_error.h" /* LEADTOOLS error definition header file. */ #include "PaintDC.h" /* Application specific header file. */ L_BOOL ExtractCommandData ( ); /*---[WinMain]--------------------------------------------------------------- Syntax: L_INT L_PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, L_INT nCmdShow ) Parameters: hInstance Current instance. hPrevInstance previous instance. lpCmdLine command line. nCmdShow show-window type. Prototype: Windows.h Notes: Windows main function, calls initialization function and processes message loop. --------------------------------------------------------------------------*/ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; /* Message structure, See Windows SDK for more information. */ UNLOCKSUPPORT(); if (!hPrevInstance) /* Other instances of app running? */ if (!InitApplication (hInstance)) /* Initialize shared things. */ return (FALSE); /* Exits if unable to initialize. */ ExtractCommandData ( ); if (!InitInstance (hInstance, nCmdShow)) /* Do instance initializations. */ return (FALSE); /* Acquire and dispatch messages until a WM_QUIT message is received. */ while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); /* Translates virtual key codes. */ DispatchMessage (&msg); /* Dispatches message to window. */ } return (msg.wParam); /* Returns the value from PostQuitMessage. */ } /*---[InitApplication]------------------------------------------------------ Syntax: L_BOOL InitApplication( HANDLE hInstance ) Parameters: hInstance Current instance. Prototype: NewPaint.h Notes: Initializes window class structure and registers window class. --------------------------------------------------------------------------*/ L_BOOL InitApplication (HANDLE hInstance) { WNDCLASS wcWindowClass; wcWindowClass.style = 0; /* Class style(s). */ wcWindowClass.lpfnWndProc = MainWndProc; /* Function to retrieve messages */ /* for windows of this class. */ wcWindowClass.cbClsExtra = 0;/* No per-class extra data. */ wcWindowClass.cbWndExtra = 0;/* No per-window extra data. */ wcWindowClass.hInstance = hInstance; /* Owner. */ wcWindowClass.hIcon = LoadIcon (hInstance, TEXT("LEAD")); wcWindowClass.hCursor = LoadCursor (NULL, IDC_ARROW); wcWindowClass.hbrBackground = GetStockObject (WHITE_BRUSH); wcWindowClass.lpszMenuName = TEXT("MENU_STATUS"); /* Menu name. */ wcWindowClass.lpszClassName = TEXT("LEADWClass"); /* Name. */ /* Register the window class and return the result code. */ return (RegisterClass (&wcWindowClass)); } /*---[InitInstance]---------------------------------------------------------- Syntax: L_BOOL InitInstance( HANDLE hInstance, L_INT nCmdShow ) Parameters: hInstance Current instance. nCmdShow Param for first ShowWindow() call. Prototype: NewPaint.h Notes: Saves instance handle and creates main window. --------------------------------------------------------------------------*/ L_BOOL InitInstance (HANDLE hInstance, L_INT nCmdShow) { hInst = hInstance; /* Get image information. */ Data.FileInfo.uStructSize = sizeof(FILEINFO); if (L_FileInfo (Data.szFilename, &Data.FileInfo, sizeof(FILEINFO), 0, NULL) != SUCCESS) return (FALSE); /* Set up RECT for window sizing. */ rWndSize.top = 0; rWndSize.left = 0; // if (Data.FileInfo.Height + GetSystemMetrics (SM_CYMENU) + 1 > 440) if (INFOHEIGHT(&Data.FileInfo) + GetSystemMetrics (SM_CYMENU) + 1 > 440) rWndSize.bottom = 440; else // rWndSize.bottom = Data.FileInfo.Height + GetSystemMetrics (SM_CYMENU) + 1; rWndSize.bottom = INFOHEIGHT(&Data.FileInfo) + GetSystemMetrics (SM_CYMENU) + 1; // if (Data.FileInfo.Width > 600) if (INFOWIDTH(&Data.FileInfo) > 600) rWndSize.right = 600; else // rWndSize.right = Data.FileInfo.Width; rWndSize.right = INFOWIDTH(&Data.FileInfo); /* Create RECT to size of image plus window frame. */ AdjustWindowRect (&rWndSize, WS_OVERLAPPEDWINDOW, FALSE); /* Create a main window for this application instance. */ MainWnd = CreateWindow ( TEXT("LEADWClass"), TEXT("LEADTOOLS Sample Application"), /* Window title */ WS_OVERLAPPEDWINDOW, /* Window style. */ CW_USEDEFAULT, /* Default horizontal position. */ CW_USEDEFAULT, /* Default vertical position. */ rWndSize.right - rWndSize.left, /* Window width. */ rWndSize.bottom - rWndSize.top, /* Window height. */ NULL,/* Overlapped windows have no parent. */ NULL,/* Use the window class menu. */ hInstance, /* This instance owns this window. */ NULL /* Pointer not needed. */ ); if (MainWnd == NULL) return (FALSE); /* If window could not be created, return "failure". */ ShowWindow (MainWnd, nCmdShow); /* Show the window. */ UpdateWindow (MainWnd); /* Send WM_PAINT message. */ return (TRUE); } /*---[MainWndProc]----------------------------------------------------------- Syntax: L_INT32 EXT_FUNCTION MainWndProc( HWND hWnd, L_UINT message, WPARAM wParam, LPARAM lParam ) Parameters: hWnd Window handle. message Type of message. wParam Additional information. lParam Additional information. Prototype: NewPaint.h Notes: This procedure is responsible for handling window messages. --------------------------------------------------------------------------*/ L_INT32 EXT_FUNCTION MainWndProc (HWND hWnd, L_UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { HANDLE_MSG (hWnd, WM_CREATE, Window_OnCreate); HANDLE_MSG (hWnd, WM_INITMENUPOPUP, Window_OnInitMenuPopup); HANDLE_MSG (hWnd, WM_COMMAND, Window_OnCommand); HANDLE_MSG (hWnd, WM_PALETTECHANGED, Window_OnPaletteChanged); HANDLE_MSG (hWnd, WM_QUERYNEWPALETTE, Window_OnQueryNewPalette); HANDLE_MSG (hWnd, WM_PAINT, Window_OnPaint); HANDLE_MSG (hWnd, WM_DESTROY, Window_OnDestroy); } return DefWindowProc (hWnd, Message, wParam, lParam); } /*---[Window_OnCreate]----------------------------------------------------- Syntax: BOOL Window_OnCreate(HWND hWnd, CREATESTRUCT FAR* lpCreateStruct); Parameters: hWnd Window handle. lpCreateStruct Windows Create Structure. Prototype: NewPaint.h Notes: This procedure is responsible for handling WM_CREATE. --------------------------------------------------------------------------*/ BOOL Window_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct) { HMENU hMenu; L_INT nRet; L_TCHAR buf[1024]; UNREFERENCED_PARAMETER (lpCreateStruct); hMenu = GetMenu (hWnd); EnableMenuItem (hMenu, 0, MF_BYPOSITION | MF_ENABLED); EnableMenuItem (hMenu, 1, MF_BYPOSITION | MF_ENABLED); DrawMenuBar (hWnd); nRet = L_LoadFile (Data.szFilename, &Data.BitmapHandle, sizeof(BITMAPHANDLE), Data.FileInfo.BitsPerPixel, ORDER_BGR, LOADFILE_STORE | LOADFILE_ALLOCATE | LOADFILE_COMPRESSED, NULL, NULL, NULL, NULL); L_SetDisplayMode (DISPLAYMODE_ORDEREDDITHER, DISPLAYMODE_ORDEREDDITHER); if (nRet == SUCCESS) { FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, TRUE); UpdateWindow (hWnd); } else { wsprintf (buf, TEXT("Error %d Loading %s"), nRet, (LPSTR) Data.szFilename); MessageBox (hWnd, buf, TEXT("Error"), MB_OK); nRet = FALSE; } fFirst = TRUE; fNewErase = TRUE; fWindowErase = FALSE; fPaintMode = P_NORMAL; fDisplayFlags = L_GetDisplayMode (); return (nRet); } /*---[Window_OnActivate]----------------------------------------------------- Syntax: VOID Window_OnActivate(HWND hwnd, UINT state, HWND hwndActDeact, BOOL fMinimized) Parameters: hWnd Window handle. state WA_ACTIVE | WA_CLICKACTIVE | WA_INACTIVE hwndActDeact the winodw habdle that deactivate fMinimized Window is minimized Prototype: Color.h Notes: This procedure is responsible for handling WM_ONCOMMAND. --------------------------------------------------------------------------*/ VOID Window_OnActivate(HWND hwnd, UINT state, HWND hwndActDeact, BOOL fMinimized) { if(state!=WA_INACTIVE) Window_OnQueryNewPalette (hwnd); } /*---[Window_OnInitMenuPopup]---------------------------------------------- Description: This function will initialize the main popup menu when the user clicks on one of the menu items. Syntax : VOID Window_OnInitMenuPopup(HWND hWnd, HMENU hMenu, L_INT nItem, BOOL fSystemMenu) Prototype : NewPaint.h Parameters : hWnd Handle to the window using the popup menu. hMenu Handle to the menu to be used. nItem Number of items in the menu. fSystemMenu Truth of "Is the menu a system menu". Return Value: None. --------------------------------------------------------------------------*/ VOID Window_OnInitMenuPopup (HWND hWnd, HMENU hMenu, L_INT nItem, BOOL fSystemMenu) { L_INT i; if (!fSystemMenu && GetSubMenu (GetMenu (hWnd), nItem) == hMenu) { switch (nItem) { case 2: for (i = IDM_SRCCOPY; i <= IDM_WHITENESS; i++) CheckMenuItem (hMenu, i, MF_BYCOMMAND | MF_UNCHECKED); switch (ulROP3Code) { case SRCCOPY: CheckMenuItem (hMenu, IDM_SRCCOPY, MF_BYCOMMAND | MF_CHECKED); break; case SRCPAINT: CheckMenuItem (hMenu, IDM_SRCPAINT, MF_BYCOMMAND | MF_CHECKED); break; case SRCAND: CheckMenuItem (hMenu, IDM_SRCAND, MF_BYCOMMAND | MF_CHECKED); break; case SRCINVERT: CheckMenuItem (hMenu, IDM_SRCINVERT, MF_BYCOMMAND | MF_CHECKED); break; case SRCERASE: CheckMenuItem (hMenu, IDM_SRCERASE, MF_BYCOMMAND | MF_CHECKED); break; case NOTSRCCOPY: CheckMenuItem (hMenu, IDM_NOTSRCCOPY, MF_BYCOMMAND | MF_CHECKED); break; case NOTSRCERASE: CheckMenuItem (hMenu, IDM_NOTSRCERASE, MF_BYCOMMAND | MF_CHECKED); break; case MERGECOPY: CheckMenuItem (hMenu, IDM_MERGECOPY, MF_BYCOMMAND | MF_CHECKED); break; case MERGEPAINT: CheckMenuItem (hMenu, IDM_MERGEPAINT, MF_BYCOMMAND | MF_CHECKED); break; case PATCOPY: CheckMenuItem (hMenu, IDM_PATCOPY, MF_BYCOMMAND | MF_CHECKED); break; case PATPAINT: CheckMenuItem (hMenu, IDM_PATPAINT, MF_BYCOMMAND | MF_CHECKED); break; case PATINVERT: CheckMenuItem (hMenu, IDM_PATINVERT, MF_BYCOMMAND | MF_CHECKED); break; case DSTINVERT: CheckMenuItem (hMenu, IDM_DSTINVERT, MF_BYCOMMAND | MF_CHECKED); break; case BLACKNESS: CheckMenuItem (hMenu, IDM_BLACKNESS, MF_BYCOMMAND | MF_CHECKED); break; case WHITENESS: CheckMenuItem (hMenu, IDM_WHITENESS, MF_BYCOMMAND | MF_CHECKED); break; } } } return; } /*---[Window_OnCommand]----------------------------------------------------- Syntax: VOID Window_OnCommand( HWND hWnd, int id, HWND hwndCtl, UINT codeNotify ) Parameters: hWnd Window handle. id Menu item or Control ID. hwndCtl 0 if menu item selected, else window handle of the control. codeNotify 1 if accelerator keystroke, else notification code, such as BN_CLICKED. Prototype: NewPaint.h Notes: This procedure is responsible for handling WM_ONCOMMAND. --------------------------------------------------------------------------*/ VOID Window_OnCommand (HWND hWnd, int id, HWND hwndCtl, UINT codeNotify) { FARPROC lpfn = NULL; UNREFERENCED_PARAMETER (hwndCtl); UNREFERENCED_PARAMETER (codeNotify); switch (id) { case IDM_QUIT: DestroyWindow (MainWnd); break; case IDM_GO: lpfn = MakeProcInstance ((FARPROC) PaintRectDlgProc, hInst); DialogBox (hInst, MAKEINTRESOURCE (IDD_PAINTRECT), hWnd, (DLGPROC) lpfn); break; case IDM_SRCCOPY: ulROP3Code = SRCCOPY; break; case IDM_SRCPAINT: ulROP3Code = SRCPAINT; break; case IDM_SRCAND: ulROP3Code = SRCAND; break; case IDM_SRCINVERT: ulROP3Code = SRCINVERT; break; case IDM_SRCERASE: ulROP3Code = SRCERASE; break; case IDM_NOTSRCCOPY: ulROP3Code = NOTSRCCOPY; break; case IDM_NOTSRCERASE: ulROP3Code = NOTSRCERASE; break; case IDM_MERGECOPY: ulROP3Code = MERGECOPY; break; case IDM_MERGEPAINT: ulROP3Code = MERGEPAINT; break; case IDM_PATCOPY: ulROP3Code = PATCOPY; break; case IDM_PATPAINT: ulROP3Code = PATPAINT; break; case IDM_PATINVERT: ulROP3Code = PATINVERT; break; case IDM_DSTINVERT: ulROP3Code = DSTINVERT; break; case IDM_BLACKNESS: ulROP3Code = BLACKNESS; break; case IDM_WHITENESS: ulROP3Code = WHITENESS; break; } /* Force repaint */ InvalidateRect (hWnd, NULL, TRUE); return; } /*----(Window_OnPaletteChanged)-------------------------------------------- Syntax: VOID Window_OnPaletteChanged( HWND hWnd, HWND hWndPaletteChange ) Parameters: hwnd Handle to a window. hWndPaletteChange Handle to a window that has the palette realized. Prototype: NewPaint.h Notes: This procedure is responsible for handling WM_PALETTECHANGED. --------------------------------------------------------------------------*/ VOID Window_OnPaletteChanged (HWND hWnd, HWND hWndPaletteChange) { HDC hDC; HPALETTE hPalette; /* If this window initiated the palette change, do nothing. */ if (hWnd == hWndPaletteChange) return; /* Delete the previous palette, if there is one. */ if (Data.hPalette) { DeleteObject (Data.hPalette); Data.hPalette = NULL; } /* Does this window have a bitmap and a palette? */ if (Data.BitmapHandle.Flags.Allocated) { hDC = GetDC (hWnd); /* Generate a new logical palette (if needed) for painting. */ Data.hPalette = L_CreatePaintPalette (hDC, &Data.BitmapHandle); /* Select and Realize the palette. */ hPalette = SelectPalette (hDC, Data.hPalette, TRUE); RealizePalette (hDC); /* Force a repaint. */ InvalidateRect (hWnd, NULL, FALSE); /* Return the old palette. */ SelectPalette (hDC, hPalette, TRUE); ReleaseDC (hWnd, hDC); } return; } /*====(Window_OnPaletteChanging)========================================== Description: Enumerates all child windows and asks them to realize their logical palettes beside the physical palette. Syntax : VOID Window_OnPaletteChanging(HWND hwnd, HWND hWndPaletteChange) Parameters : hwnd Handle to a window. hWndPaletteChange Handle to a window that has the palette realized. Return Value: None. ==========================================================================*/ VOID Window_OnPaletteChanging(HWND hWnd, HWND hWndPaletteChange) { Window_OnPaletteChanged (hWnd, hWndPaletteChange); } /*====(Window_SysColorChange)========================================== Syntax: VOID Window_SysColorChange( HWND hWnd ) Parameters: hWnd Handle to a window. Prototype: Loadsave.h Notes: This procedure is responsible for handling WM_SYSCOLORCHANGE. --------------------------------------------------------------------------*/ VOID Window_SysColorChange(HWND hwnd) { Window_OnQueryNewPalette (hwnd); } /*----(Window_OnQueryNewPalette)-------------------------------------------- Syntax: BOOL Window_OnQueryNewPalette( HWND hWnd ) Parameters: hWnd Handle to a window. Prototype: NewPaint.h Notes: This procedure is responsible for handling WM_QUERYNEWPALETTE. --------------------------------------------------------------------------*/ BOOL Window_OnQueryNewPalette (HWND hWnd) { HDC hDC; HPALETTE hPalette; L_INT nNoColors = 0; /* Delete the previous palette, if there is one. */ if (Data.hPalette) { DeleteObject (Data.hPalette); Data.hPalette = NULL; } if (Data.BitmapHandle.Flags.Allocated) { hDC = GetDC (hWnd); if (Data.BitmapHandle.BitsPerPixel == 1) { L_SetDisplayMode (DISPLAYMODE_RESETPOSITIONS, fDisplayFlags); if (fPaintMode == P_SCALETOGRAY) L_SetDisplayMode (DISPLAYMODE_SCALETOGRAY, DISPLAYMODE_SCALETOGRAY); else if (fPaintMode == P_FAVORBLACK) L_SetDisplayMode (DISPLAYMODE_FAVORBLACK, DISPLAYMODE_FAVORBLACK); } /* Generate a new logical palette (if needed) for painting. */ Data.hPalette = L_CreatePaintPalette (hDC, &Data.BitmapHandle); if (Data.hPalette) /* Is a palette needed? */ { hPalette = SelectPalette (hDC, Data.hPalette, FALSE); nNoColors = RealizePalette (hDC); if (nNoColors) /* If the palette changed, force a WM_PAINT */ InvalidateRect (hWnd, NULL, FALSE); /* Restore the old palette. */ SelectPalette (hDC, hPalette, TRUE); } ReleaseDC (hWnd, hDC); } return (nNoColors); } /*---[Window_OnPaint]------------------------------------------------------- Syntax: VOID Window_OnPaint( HWND hWnd ); Parameters: hWnd Window handle. Prototype: NewPaint.h Notes: This procedure is responsible for handling WM_PAINT. --------------------------------------------------------------------------*/ VOID Window_OnPaint (HWND hWnd) { HDC hdc; PAINTSTRUCT ps; HPALETTE hOldPal = NULL; RECT rc; hdc = BeginPaint (hWnd, &ps);/* Get DC */ if (Data.BitmapHandle.Flags.Allocated) /* Do we have an image? */ { if (Data.hPalette) /* Is there a palette that needs to be selected? */ hOldPal = SelectPalette (hdc, Data.hPalette, TRUE); /* Select it. */ /* Paint it */ if (fFirst) { fFirst = FALSE; GetClientRect (hWnd, &rc); rcSrc.left = 0; rcSrc.top = 0; rcSrc.right = rc.right; rcSrc.bottom = rc.bottom; rcSrcClip.left = 0; rcSrcClip.top = 0; rcSrcClip.right = rc.right; rcSrcClip.bottom = rc.bottom; rcDest.left = ps.rcPaint.left; rcDest.top = ps.rcPaint.top; rcDest.right = ps.rcPaint.right; rcDest.bottom = ps.rcPaint.bottom; rcDestClip.left = ps.rcPaint.left; rcDestClip.top = ps.rcPaint.top; rcDestClip.right = ps.rcPaint.right; rcDestClip.bottom = ps.rcPaint.bottom; } L_PaintDC (hdc, &Data.BitmapHandle, &rcSrc, &rcSrcClip, &rcDest, &rcDestClip, ulROP3Code); if (Data.hPalette) /* Return old palette if there is one. */ SelectPalette (hdc, hOldPal, TRUE); } EndPaint (hWnd, &ps); /* Return DC */ return; } /*---[Window_OnDestroy]---------------------------------------------------- Syntax: VOID Window_OnDestroy( HWND hWnd ); Parameters: hWnd Window handle. Prototype: NewPaint.h Notes: This procedure is responsible for handling WM_DESTROY. --------------------------------------------------------------------------*/ VOID Window_OnDestroy (HWND hWnd) { UNREFERENCED_PARAMETER (hWnd); if (Data.BitmapHandle.Flags.Allocated) /* Do we have an image? */ L_FreeBitmap (&Data.BitmapHandle); if (Data.hPalette) { DeleteObject (Data.hPalette); Data.hPalette = NULL; } PostQuitMessage (0); /* Post WM_QUIT, to end the application. */ return; } /*----(PaintRect)------------------------------------------------------ Description: This function will process Paint Rectangle dialog box messages. Syntax : BOOL CALLBACK __export PaintRectDlgProc(HWND hDlg, UINT message, WPARAM id, LPARAM lParam) Prototype : newpaint.h Parameters : hDlg Handle of the dialog box. message Message to be processed. id First parameter. lParam Second parameter. Return Value: TRUE The function was successful. FALSE The function was not successful. --------------------------------------------------------------------------*/ L_BOOL CALLBACK L_EXPORT PaintRectDlgProc (HWND hDlg, UINT message, WPARAM id, LPARAM lParam) { L_BOOL bTranslated; L_INT i; RECT rcInval; RECT rcWindow; UNREFERENCED_PARAMETER (lParam); switch (message) { case WM_INITDIALOG: CheckDlgButton (hDlg, IDC_NEWERASE, fNewErase); CheckDlgButton (hDlg, IDC_WINDOWERASE, fWindowErase); CheckRadioButton (hDlg, IDC_NORMAL, IDC_FAVORBLACK, IDC_NORMAL + fPaintMode); SetDlgItemInt (hDlg, IDC_WIDTH, Data.BitmapHandle.Width, TRUE); SetDlgItemInt (hDlg, IDC_HEIGHT, Data.BitmapHandle.Height, TRUE); SetDlgItemInt (hDlg, IDC_SRCLEFT, rcSrc.left, TRUE); SetDlgItemInt (hDlg, IDC_SRCTOP, rcSrc.top, TRUE); SetDlgItemInt (hDlg, IDC_SRCRIGHT, rcSrc.right, TRUE); SetDlgItemInt (hDlg, IDC_SRCBOTTOM, rcSrc.bottom, TRUE); SetDlgItemInt (hDlg, IDC_SRCCLIPLEFT, rcSrcClip.left, TRUE); SetDlgItemInt (hDlg, IDC_SRCCLIPTOP, rcSrcClip.top, TRUE); SetDlgItemInt (hDlg, IDC_SRCCLIPRIGHT, rcSrcClip.right, TRUE); SetDlgItemInt (hDlg, IDC_SRCCLIPBOTTOM, rcSrcClip.bottom, TRUE); SetDlgItemInt (hDlg, IDC_DESTLEFT, rcDest.left, TRUE); SetDlgItemInt (hDlg, IDC_DESTTOP, rcDest.top, TRUE); SetDlgItemInt (hDlg, IDC_DESTRIGHT, rcDest.right, TRUE); SetDlgItemInt (hDlg, IDC_DESTBOTTOM, rcDest.bottom, TRUE); SetDlgItemInt (hDlg, IDC_DESTCLIPLEFT, rcDestClip.left, TRUE); SetDlgItemInt (hDlg, IDC_DESTCLIPTOP, rcDestClip.top, TRUE); SetDlgItemInt (hDlg, IDC_DESTCLIPRIGHT, rcDestClip.right, TRUE); SetDlgItemInt (hDlg, IDC_DESTCLIPBOTTOM, rcDestClip.bottom, TRUE); GetWindowRect (hDlg, &rcWindow); MoveWindow (hDlg, 0, 0, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, FALSE); return (TRUE); case WM_COMMAND: switch (id) { case IDOK: i = GetDlgItemInt (hDlg, IDC_SRCLEFT, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_SRCLEFT)); return (TRUE); } else rcSrc.left = i; i = GetDlgItemInt (hDlg, IDC_SRCTOP, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_SRCTOP)); return (TRUE); } else rcSrc.top = i; i = GetDlgItemInt (hDlg, IDC_SRCRIGHT, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_SRCRIGHT)); return (TRUE); } else rcSrc.right = i; i = GetDlgItemInt (hDlg, IDC_SRCBOTTOM, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_SRCBOTTOM)); return (TRUE); } else rcSrc.bottom = i; i = GetDlgItemInt (hDlg, IDC_SRCCLIPLEFT, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_SRCCLIPLEFT)); return (TRUE); } else rcSrcClip.left = i; i = GetDlgItemInt (hDlg, IDC_SRCCLIPTOP, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_SRCCLIPTOP)); return (TRUE); } else rcSrcClip.top = i; i = GetDlgItemInt (hDlg, IDC_SRCCLIPRIGHT, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_SRCCLIPRIGHT)); return (TRUE); } else rcSrcClip.right = i; i = GetDlgItemInt (hDlg, IDC_SRCCLIPBOTTOM, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_SRCCLIPBOTTOM)); return (TRUE); } else rcSrcClip.bottom = i; i = GetDlgItemInt (hDlg, IDC_DESTLEFT, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DESTLEFT)); return (TRUE); } else rcDest.left = i; i = GetDlgItemInt (hDlg, IDC_DESTTOP, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DESTTOP)); return (TRUE); } else rcDest.top = i; i = GetDlgItemInt (hDlg, IDC_DESTRIGHT, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DESTRIGHT)); return (TRUE); } else rcDest.right = i; i = GetDlgItemInt (hDlg, IDC_DESTBOTTOM, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DESTBOTTOM)); return (TRUE); } else rcDest.bottom = i; i = GetDlgItemInt (hDlg, IDC_DESTCLIPLEFT, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DESTCLIPLEFT)); return (TRUE); } else rcDestClip.left = i; i = GetDlgItemInt (hDlg, IDC_DESTCLIPTOP, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DESTCLIPTOP)); return (TRUE); } else rcDestClip.top = i; i = GetDlgItemInt (hDlg, IDC_DESTCLIPRIGHT, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DESTCLIPRIGHT)); return (TRUE); } else rcDestClip.right = i; i = GetDlgItemInt (hDlg, IDC_DESTCLIPBOTTOM, &bTranslated, TRUE); if (!bTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DESTCLIPBOTTOM)); return (TRUE); } else rcDestClip.bottom = i; if (fWindowErase) { GetClientRect (MainWnd, &rcInval); InvalidateRect (MainWnd, &rcInval, TRUE); } else { IntersectRect (&rcInval, &rcDest, &rcDestClip); InvalidateRect (MainWnd, &rcInval, fNewErase); } if (Data.BitmapHandle.BitsPerPixel == 1) { if (IsDlgButtonChecked (hDlg, IDC_NORMAL)) fPaintMode = P_NORMAL; else if (IsDlgButtonChecked (hDlg, IDC_SCALETOGRAY)) fPaintMode = P_SCALETOGRAY; else fPaintMode = P_FAVORBLACK; FORWARD_WM_QUERYNEWPALETTE (MainWnd, SendMessage); } EndDialog (hDlg, TRUE); return (TRUE); case IDC_NEWERASE: fNewErase = !fNewErase; CheckDlgButton (hDlg, IDC_NEWERASE, fNewErase); return (TRUE); case IDC_WINDOWERASE: fWindowErase = !fWindowErase; CheckDlgButton (hDlg, IDC_WINDOWERASE, fWindowErase); return (TRUE); case IDCANCEL: EndDialog (hDlg, FALSE); return (TRUE); } } return (FALSE); } /*---[ExtractCommandData]---------------------------------------------------- Syntax: L_BOOL ExtractCommandData( ); Parameters: None. ProtoType: Paintdc.c Notes: - This procedure is responsible for extracting the file name passed through the command line. - You should call this function only in WinMain function. --------------------------------------------------------------------------*/ L_BOOL ExtractCommandData ( ) { LPTSTR pszFirst = NULL; LPTSTR pszCmdLine = NULL; LPTSTR psz = NULL; L_INT nFirstPos = 0 ; L_INT nStringLen = 0 ; pszCmdLine = GetCommandLine(); nStringLen = lstrlen ( pszCmdLine ) + 1 ; // To specify that it is command line or not. if(( pszCmdLine[1] == ':' ) || // Shortcut case ( pszCmdLine[2] == ':' )) //VS case { // 1- TRY TO EXPOSE THE EXE NAME FROM THE COMMAND LINE psz = _tcschr ( pszCmdLine, ':' ) ; if ( NULL == psz ) { return FALSE ; } } else { psz = pszCmdLine ; } pszFirst = _tcschr ( psz + 1, ':' ) ; if ( NULL == pszFirst ) { return FALSE ; } // Calc the char number to the image file name. nFirstPos = pszFirst - pszCmdLine - 1 ; if ( 0 > nFirstPos ) { return FALSE ; } memset ( Data.szFilename, 0, sizeof ( Data.szFilename ) ); lstrcpyn ( Data.szFilename, pszFirst - 1, ( nStringLen - nFirstPos ) ) ; return TRUE; }