/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 13 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2001 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #define STRICT #include #include #include #include #include #include #include #include #include "../../../include/l_bitmap.h" #include "../../../include/l_error.h" #include "demo.h" static L_INT nStatusPercent; /*====(StatusCallBack)====================================================== Description: Performs as a callback for the Progress Bar. Syntax : STATUSCALLBACK L_EXPORT StatusCallBack( L_INT nPercent ); Prototype : demo.h Parameters : nPercent Percent of operation complete. Return Value: SUCCESS The function was successful. ERROR_USER_ABORT User wants to cancel the operation. ==========================================================================*/ L_INT L_FAR L_EXPORT StatusCallBack (L_INT nPercent, L_VOID L_FAR*pUserData) { MSG msg; while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage (&msg); DispatchMessage (&msg); } SetStatusBarProgress(nPercent); if (fKillProgress) return (ERROR_USER_ABORT); else return (SUCCESS); } /*====(ProgressBarProc)==================================================== Description: Processes messages for the Progress Bar. Syntax : LRESULT CALLBACK L_EXPORT ProgressBarProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hWnd Window handle. message Windows message to process. wParam Windows word parameter. lParam Windows long parameter. Return Value: 0 WM_PAINT message processed. DefWindowProc A different message processed. ==========================================================================*/ LRESULT CALLBACK L_EXPORT ProgressBarProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; L_TCHAR szPercent[5]; RECT rcClient; RECT rcClip; L_INT nLen; L_INT xCenter; HRGN hRgn; switch (message) { case WM_PAINT: BeginPaint (hWnd, &ps); SaveDC(ps.hdc); GetClientRect (hWnd, &rcClient); nLen = strprintf (szPercent, TEXT("%d%%"), nStatusPercent); SetTextAlign(ps.hdc, TA_CENTER); SetTextColor(ps.hdc, RGB(255, 255, 255)); SetBkColor(ps.hdc, RGB(0, 0, 255)); hRgn = CreateRectRgnIndirect(&rcClient); SelectObject(ps.hdc, hRgn); SetRect(&rcClip, 0, 0, MulDiv(nStatusPercent, RECTWIDTH(&rcClient), 100), RECTHEIGHT(&rcClient)); OffsetRect(&rcClip, rcClient.left, rcClient.top); xCenter = (rcClient.left + rcClient.right + 1) / 2; IntersectClipRect(ps.hdc, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); ExtTextOut(ps.hdc, xCenter, 0, ETO_OPAQUE, &rcClient, szPercent, nLen, NULL); SetTextColor(ps.hdc, RGB(0, 0, 255)); SetBkColor(ps.hdc, RGB(255, 255, 255)); SelectObject(ps.hdc, hRgn); ExcludeClipRect(ps.hdc, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); ExtTextOut(ps.hdc, xCenter, 0, ETO_OPAQUE, &rcClient, szPercent, nLen, NULL); DeleteObject(hRgn); RestoreDC(ps.hdc, -1); EndPaint (hWnd, &ps); return (0); } return (DefWindowProc (hWnd, message, wParam, lParam)); } /*====(EnableStatusBarProgress)============================================ Description: Hides/Displays various controls on the Status Bar of the Frame. Syntax : L_VOID EnableStatusBarProgress(L_BOOL fEnable) Prototype : demo.h Parameters : fEnable Flag to enable the status bar. Return Value: None. ==========================================================================*/ L_VOID EnableStatusBarProgress(L_BOOL fEnable) { HWND hWnd; L_BOOL fHaveFrames; #ifdef WIN32 L_UINT32 dwVersion; #endif #ifdef WIN32 dwVersion = GetVersion(); if(LOBYTE(LOWORD(dwVersion)) < 4) fHaveFrames = FALSE; else fHaveFrames = TRUE; #else fHaveFrames = TRUE; #endif hWnd = GetDlgItem (hWndStatus, IDC_PROGRESSBARFRAME); ShowWindow(hWnd, fEnable ? SW_SHOW : SW_HIDE); if(fHaveFrames) { hWnd = GetDlgItem (hWndStatus, IDC_PRESSESCFRAME); ShowWindow(hWnd, fEnable ? SW_SHOW : SW_HIDE); } hWnd = GetDlgItem (hWndStatus, IDC_PROGRESSBAR); ShowWindow(hWnd, fEnable ? SW_SHOW : SW_HIDE); hWnd = GetDlgItem (hWndStatus, IDC_PRESSESC); ShowWindow(hWnd, fEnable ? SW_SHOW : SW_HIDE); if(fHaveFrames) { hWnd = GetDlgItem (hWndStatus, IDC_TITLEFRAME); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_DIMENSIONSFRAME); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_BITSPIXELFRAME); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_ZOOMFRAME); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_MEMORYFRAME); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_REGIONBOUNDSFRAME); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); } hWnd = GetDlgItem (hWndStatus, IDC_TITLE); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_DIMENSIONS); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_BITSPIXEL); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_ZOOM); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_MEMORY); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); hWnd = GetDlgItem (hWndStatus, IDC_REGIONBOUNDS); ShowWindow(hWnd, fEnable ? SW_HIDE : SW_SHOW); return; } /*====(SetStatusBarText)=================================================== Description: Sets text into various controls on the Status Bar of the Frame. Syntax : L_VOID SetStatusBarText(LPSTR pTitle, pBITMAPHANDLE pBitmap, L_INT nZoom) Prototype : demo.h Parameters : pTitle Text for the Title control. pBitmap Bitmap currently being processed. nZoom Zoom factor the image is displayed as. Return Value: None. ==========================================================================*/ L_VOID SetStatusBarText(L_TCHAR* pTitle, pBITMAPHANDLE pBitmap, L_INT nZoom, L_BOOL fClipRegion) { L_TCHAR szText[80]; RECT rc; RGNXFORM XForm; L_TCHAR L_FAR*p; if(pTitle) { #ifdef UNICODE ChangeFont (hWndStatus); #endif SetDlgItemText(hWndStatus, IDC_TITLE, pTitle); strprintf( szText, TEXT("%ux%u,%s"), pBitmap->Width, pBitmap->Height, (pBitmap->ViewPerspective == TOP_LEFT ? TEXT("TOP_LEFT") : pBitmap->ViewPerspective == TOP_LEFT90 ? TEXT("TOP_LEFT90") : pBitmap->ViewPerspective == TOP_LEFT180? TEXT("TOP_LEFT180") : pBitmap->ViewPerspective == TOP_LEFT270? TEXT("TOP_LEFT270") : pBitmap->ViewPerspective == BOTTOM_LEFT? TEXT("BOTTOM_LEFT") : pBitmap->ViewPerspective == BOTTOM_LEFT90? TEXT("BOTTOM_LEFT90") : pBitmap->ViewPerspective == BOTTOM_LEFT180?TEXT("BOTTOM_LEFT180") : TEXT("BOTTOM_LEFT270")) ); SetDlgItemText(hWndStatus, IDC_DIMENSIONS, szText); strprintf(szText, TEXT("%u BPP"), pBitmap->BitsPerPixel); SetDlgItemText(hWndStatus, IDC_BITSPIXEL, szText); if(nZoom != -1) { strprintf(szText, TEXT("%u%%"), nZoom); SetDlgItemText(hWndStatus, IDC_ZOOM, szText); } else { SetDlgItemText(hWndStatus, IDC_ZOOM, TEXT("FITTED")); } p = (pBitmap->Flags.Compressed ? TEXT("COMP") : pBitmap->Flags.SuperCompressed ? TEXT("SUP.CMP") : pBitmap->Flags.Tiled ? TEXT("TILED") : (pBitmap->Flags.DiskMemory ? TEXT("DISK") : TEXT("MEMORY"))); // bitmap size < 10MB ? if(pBitmap->Size < 10000000) strprintf(szText, TEXT("%lu bytes, %s"), pBitmap->Size, p); else // > 100MB strprintf(szText, TEXT("%lu KB, %s"), pBitmap->Size >> 10, p); SetDlgItemText(hWndStatus, IDC_MEMORY, szText); if(fClipRegion) { XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; L_GetBitmapRgnBounds(pBitmap, &XForm, &rc); strprintf(szText, TEXT("(%d, %d)-(%d, %d)"), rc.left, rc.top, rc.right, rc.bottom); } else { strprintf(szText, TEXT("NO REGION")); } SetDlgItemText(hWndStatus, IDC_REGIONBOUNDS, szText); } else { SetDlgItemText(hWndStatus, IDC_TITLE, TEXT("")); SetDlgItemText(hWndStatus, IDC_DIMENSIONS, TEXT("")); SetDlgItemText(hWndStatus, IDC_BITSPIXEL, TEXT("")); SetDlgItemText(hWndStatus, IDC_ZOOM, TEXT("")); SetDlgItemText(hWndStatus, IDC_MEMORY, TEXT("")); SetDlgItemText(hWndStatus, IDC_REGIONBOUNDS, TEXT("")); } return; } L_VOID SetStatusBarRegion(pBITMAPHANDLE pBitmap, L_INT left, L_INT top, L_INT right, L_INT bottom, RECT L_FAR *pRect) { HWND hWnd; L_TCHAR szText[80]; left -= pRect->left; top -= pRect->top; right -= pRect->left; bottom -= pRect->top; left = (L_INT) ((L_INT32) left * pBitmap->Width / RECTWIDTH(pRect)); top = (L_INT) ((L_INT32) top * pBitmap->Height / RECTHEIGHT(pRect)); right = (L_INT) ((L_INT32) right * pBitmap->Width / RECTWIDTH(pRect)); bottom = (L_INT) ((L_INT32) bottom * pBitmap->Height / RECTHEIGHT(pRect)); strprintf(szText, TEXT("(%d, %d)-(%d, %d)"), left, top, right, bottom); SetDlgItemText(hWndStatus, IDC_REGIONBOUNDS, szText); hWnd = GetDlgItem (hWndStatus, IDC_PROGRESSBAR); InvalidateRect (hWnd, NULL, FALSE); UpdateWindow (hWnd); return; } /*====(SetStatusBarProgress)=============================================== Description: Paints the Progress Bar. Syntax : L_VOID SetStatusBarProgress(L_INT nPercent) Prototype : demo.h Parameters : nPercent Percent of processing complete. Return Value: None. ==========================================================================*/ L_VOID SetStatusBarProgress(L_INT nPercent) { HWND hWnd; nStatusPercent = nPercent; hWnd = GetDlgItem (hWndStatus, IDC_PROGRESSBAR); InvalidateRect (hWnd, NULL, FALSE); UpdateWindow (hWnd); return; } /*====(StatusBarProc)====================================================== Description: Processes messages for the Status Bar. Syntax : L_BOOL CALLBACK L_EXPORT StatusBarProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hDlg Window handle. message Windows message to process. wParam Windows word parameter. lParam Windows long parameter. Return Value: TRUE WM_INITDIALOG or WM_PAINT message processed. FALSE A different message processed. ==========================================================================*/ L_BOOL CALLBACK L_EXPORT StatusBarProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { RECT rc; PAINTSTRUCT ps; HPEN hPen; HBRUSH hBrush; L_INT cxBorder; L_INT cyBorder; UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(lParam); switch(message) { case WM_INITDIALOG: hWndStatus = hDlg; EnableStatusBarProgress(FALSE); SetStatusBarText(NULL, NULL, 0, FALSE); return(TRUE); case WM_PAINT: BeginPaint (hDlg, &ps); cxBorder = GetSystemMetrics(SM_CXBORDER); cyBorder = GetSystemMetrics(SM_CYBORDER); hPen = SelectObject(ps.hdc, CreatePen(PS_INSIDEFRAME, cxBorder, RGB(0, 0, 0))); hBrush = SelectObject(ps.hdc, GetStockObject(NULL_BRUSH)); GetClientRect(hDlg, &rc); Rectangle(ps.hdc, rc.left - cxBorder, rc.top, rc.right + cxBorder, rc.bottom + cyBorder); SelectObject(ps.hdc, hBrush); DeleteObject(SelectObject(ps.hdc, hPen)); EndPaint (hDlg, &ps); return(TRUE); } return (FALSE); }