/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 13 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2001 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #include "ImgPF.h" /*--------------------Handle Message function decleration ---------------------*/ static L_BOOL Child_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct); static L_VOID Child_OnPaint (HWND hWnd); static L_VOID Child_OnCommand (HWND hWnd, L_INT nID, HWND hwndCtl, L_UINT codeNotify); L_VOID Child_OnSize (HWND hWnd, L_UINT nState, L_INT nCx, L_INT nCy); static L_VOID Child_OnMDIActivate (HWND hWnd, L_BOOL fActive, HWND hWndActivate, HWND hWndDeactivate); static L_VOID Child_OnClose (HWND hWnd); static L_VOID Child_OnDestroy (HWND hWnd); static L_VOID Child_OnHScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos); static L_VOID Child_OnVScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos); static L_BOOL Child_OnEraseBkgnd (HWND hWnd, HDC hDC); static L_VOID Child_OnPaletteChanged (HWND hWnd, HWND hWndPaletteChange); static L_BOOL Child_OnQueryNewPalette (HWND hWnd); static L_VOID Child_OnTimer (HWND hWnd, L_UINT nID); static L_VOID Child_OnLButtonDown (HWND hWnd, L_BOOL bDoubleClick, L_INT x, L_INT y, L_UINT keyFlags); static L_VOID Child_OnMouseMove (HWND hWnd, L_INT x, L_INT y, L_UINT keyFlags); static L_VOID Child_OnRButtonup (HWND hWnd, L_INT nX, L_INT nY, L_UINT ukeyFlags); static L_VOID Child_OnLButtonUp (HWND hWnd, L_INT x, L_INT y, L_UINT keyFlags); static L_VOID Child_OnSetFocus (HWND hWnd, HWND hWndOldFocus); static L_VOID Child_OnKillFocus (HWND hWnd, HWND hWndNewFocus); /*-----------------------functions decleration---------------------------------*/ L_INT PasteBitmapRgn (HWND hWnd); L_INT SaveBitmapFile (HWND hWnd); static L_INT CancelRgn (HWND hWnd, L_BOOL bAddUndoBitmap); L_VOID OutlineBitmapRgn (HWND hWnd, HDC hdc); /*--------global variable -----*/ COLORREF crColor = 0; L_BOOL bInScroll = FALSE; static L_INT nCount = 0; static LPPOINT pptRegion; #define MAXPOINTS 0x4000 /* maximum number of points allowed in freehand */ static L_INT nNextPt; extern L_BOOL bRefDlg2; extern L_BOOL bRefDlg1; /*-----------------------------*/ /*====(ChildWindowProc)==================================================== Description: Processes child window messages. Syntax : LRESULT CALLBACK L_EXPORT ChildWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hWnd Handle of a window. Msg Message to be processed. wParam First message parameter. lParam Second message parameter. Return Value: Depends on the message. ==========================================================================*/ LRESULT CALLBACK ChildWndProc (HWND hwnd, L_UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { HANDLE_MSG (hwnd, WM_CREATE, Child_OnCreate); HANDLE_MSG (hwnd, WM_PAINT, Child_OnPaint); HANDLE_MSG (hwnd, WM_SIZE, Child_OnSize); HANDLE_MSG (hwnd, WM_MDIACTIVATE, Child_OnMDIActivate); HANDLE_MSG (hwnd, WM_HSCROLL, Child_OnHScroll); HANDLE_MSG (hwnd, WM_VSCROLL, Child_OnVScroll); HANDLE_MSG (hwnd, WM_ERASEBKGND, Child_OnEraseBkgnd); HANDLE_MSG (hwnd, WM_PALETTECHANGED, Child_OnPaletteChanged); HANDLE_MSG (hwnd, WM_QUERYNEWPALETTE, Child_OnQueryNewPalette); HANDLE_MSG (hwnd, WM_TIMER, Child_OnTimer); HANDLE_MSG (hwnd, WM_LBUTTONDOWN, Child_OnLButtonDown); HANDLE_MSG (hwnd, WM_MOUSEMOVE, Child_OnMouseMove); HANDLE_MSG (hwnd, WM_LBUTTONUP, Child_OnLButtonUp); HANDLE_MSG (hwnd, WM_SETFOCUS, Child_OnSetFocus); HANDLE_MSG (hwnd, WM_KILLFOCUS, Child_OnKillFocus); HANDLE_MSG (hwnd, WM_RBUTTONUP, Child_OnRButtonup); HANDLE_MSG (hwnd, WM_COMMAND, Child_OnCommand); HANDLE_MSG (hwnd, WM_CLOSE, Child_OnClose); HANDLE_MSG (hwnd, WM_DESTROY, Child_OnDestroy); case WM_USER_CHANGECURSOR: SetCursor(LoadCursor((HINSTANCE)wParam, (LPTSTR)lParam)); break; } return DefMDIChildProc(hwnd, message, wParam, lParam); } /*====(Child_OnCreate)===================================================== Description: Creates an MDI child window. The image can come from a file or the clipboard. Syntax : BOOL Child_OnCreate(HWND hWnd, CREATESTRUCT FAR* lpCreateStruct) Parameters : hWnd Handle of a window. lpCreateStruct Pointer to CREATESTRUCT Return Value: TRUE The function was successful. FALSE The function was not successful. ==========================================================================*/ static L_BOOL Child_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct) { HANDLE hMem; HDC hdcCompatibile; pCHILDDATA pData; LPCREATEDATA pCreateData; //Allocate memory for window private data pCreateData = (LPCREATEDATA) CHILDCREATELPARAM(lpCreateStruct); if(!pCreateData) return FALSE; hMem = GlobalAlloc (GHND, sizeof (CHILDDATA)); SETCHILDDATA (hWnd, hMem); if(!hMem) return(FALSE); pData = LOCKCHILDDATA (hWnd); SetRect(&pData->rcFrame, 0, 0, 0, 0); SetRect(&pData->rcRgn, 0, 0, 0, 0); pData->nVScrollPos = 0; pData->nVScrollMax = 0; pData->nVScrollStep = 0; pData->nHScrollPos = 0; pData->nHScrollMax = 0; pData->nHScrollStep = 0; pData->cxClient = 0; pData->cyClient = 0; pData->bMovingFloater = FALSE; pData->bDrawShape = FALSE; pData->bDrawFrame = FALSE; pData->nPtCount = 0; pData->pPolyPt = NULL; pData->uTimerID = 0; pData->bCapWnd = FALSE; pData->pszTitle = GlobalAllocPtr(GHND, ((lstrlen(pCreateData->pszTitle) + 1 ) *sizeof(L_TCHAR))); pData->bCross = FALSE; pData->hBitmapWnd = hWnd; pData->uCombineMode = L_RGN_SET; pData->hMagicWand = NULL; pData->hMagicWandEx = NULL; pData->crLowerTolerance = RGB(0, 0, 0); pData->crUpperTolerance = RGB(255, 255, 255); pData->bDetected = FALSE; pData->bApplyTrans = FALSE; pData->bFrameMenu = FALSE; pData->bHasBeenApplied = FALSE; if(pData->pszTitle) lstrcpy(pData->pszTitle, pCreateData->pszTitle); pszTitle1[nCount++] = pData->pszTitle; L_CopyBitmapHandle(&pData->LeadBitmap, pCreateData->pBitmap, sizeof(BITMAPHANDLE)); pData->nBitmapFormat = pCreateData->nBitmapFormat; L_InitBitmap(&pData->bmFloater, sizeof(BITMAPHANDLE), 0, 0, 0); L_InitBitmap(&pData->bmSave, sizeof(BITMAPHANDLE), 0, 0, 0); L_InitBitmap(&pData->UndoBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); hdcCompatibile = GetDC(hWnd); pData->hPalette = L_CreatePaintPalette(hdcCompatibile, &pData->LeadBitmap); ReleaseDC(hWnd, hdcCompatibile); SetRect(&pData->rcView, 0, 0, BITMAPWIDTH(&pData->LeadBitmap), BITMAPHEIGHT(&pData->LeadBitmap)); SetWindowLong(hWnd, GWL_USERDATA, (long) pData); if(L_BitmapHasRgn(&pData->LeadBitmap)) L_GetBitmapRgnHandle(&pData->LeadBitmap, NULL, &pData->hrgnRegion); // Save some window handles hWndClient = GetParent(hWnd); hWndFrame = GetParent(hWndClient); pData->hbmSave = (HBITMAP)NULL; pData->hbmFloater = (HBITMAP)NULL; pData->uThreshold = 25; bMagicWndDlg = FALSE; FileInit(hWnd); Child_OnQueryNewPalette(hWnd); UNLOCKCHILDDATA(hWnd); //UNDOLIST// L_UndoList_Init (hWnd, FreeFun, 20); SetStatusBarText(TEXT(""), &pData->LeadBitmap, szPos, szColor); return TRUE; } /*====(Child_OnPaint)====================================================== Description: Paints the child window. Syntax : VOID Child_OnPaint(HWND hWnd) Parameters : hWnd Handle of the child window. Return Value: None. ==========================================================================*/ static L_VOID Child_OnPaint (HWND hWnd) { HDC hdc; HPALETTE hSavedPalette = NULL; HPALETTE hPalette = NULL; PAINTSTRUCT ps; pCHILDDATA pData; BITMAPHANDLE TmpBitmapHandle; RECT rcView; HBITMAP hBitmap; L_INT Rop; L_INT nAngle; L_DOUBLE dTheta; pData = LOCKCHILDDATA (hWnd); if (!pData->LeadBitmap.Flags.Allocated) return; hdc = BeginPaint(hWnd, &ps); hPalette = L_CreatePaintPalette(hdc, &pData->LeadBitmap); if (hPalette) { hSavedPalette = SelectPalette (hdc, hPalette, FALSE); RealizePalette (hdc); } L_PaintDC(hdc, &pData->LeadBitmap, NULL, NULL, &pData->rcView, NULL, SRCCOPY); if (pData->bCross) { hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_CROSS)); L_ConvertFromDDB(hdc, &TmpBitmapHandle, sizeof(BITMAPHANDLE), hBitmap, NULL); rcView.left = pData->ptCenter.x + pData->rcView.left - 15; rcView.top = pData->ptCenter.y + pData->rcView.top - 15; rcView.right = pData->ptCenter.x + pData->rcView.left + 15; rcView.bottom = pData->ptCenter.y + pData->rcView.top + 15; L_PaintDC(hdc, &TmpBitmapHandle, NULL, NULL, &rcView, NULL, SRCINVERT); L_FreeBitmap(&TmpBitmapHandle); DeleteBitmap(hBitmap); } if (pData->bLineHistogram) { Rop = SetROP2(hdc, R2_NOT); MoveToEx(hdc, pData->ptBegLn.x + pData->rcView.left, pData->ptBegLn.y + pData->rcView.top, NULL); LineTo(hdc, pData->ptEndLn.x + pData->rcView.left, pData->ptEndLn.y + pData->rcView.top); SetROP2(hdc, Rop); if (pData->bDetails) { dTheta = atan2(((pData->ptBegLn.y + pData->rcView.top) - (pData->ptEndLn.y + pData->rcView.top)), ((pData->ptBegLn.x + pData->rcView.left) - (pData->ptEndLn.x + pData->rcView.left))); nAngle = (360 - (L_INT)((180 * dTheta)/3.14)) % 360; hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_CROSS)); L_ConvertFromDDB(hdc, &TmpBitmapHandle, sizeof(BITMAPHANDLE), hBitmap, NULL); rcView.left = pData->ptBegLn.x + pData->rcView.left - 15; rcView.top = pData->ptBegLn.y + pData->rcView.top - 15; rcView.right = pData->ptBegLn.x + pData->rcView.left + 15; rcView.bottom = pData->ptBegLn.y + pData->rcView.top + 15; L_RotateBitmap(&TmpBitmapHandle, 4500 - nAngle * 100, ROTATE_RESAMPLE, RGB(0, 0, 0)); L_PaintDC(hdc, &TmpBitmapHandle, NULL, NULL, &rcView, &pData->rcView, SRCINVERT); rcView.left = pData->ptEndLn.x + pData->rcView.left - 15; rcView.top = pData->ptEndLn.y + pData->rcView.top - 15; rcView.right = pData->ptEndLn.x + pData->rcView.left + 15; rcView.bottom = pData->ptEndLn.y + pData->rcView.top + 15; L_PaintDC(hdc, &TmpBitmapHandle, NULL, NULL, &rcView, &pData->rcView, SRCINVERT); L_FreeBitmap(&TmpBitmapHandle); DeleteBitmap(hBitmap); } } if (hSavedPalette) SelectPalette (hdc, hSavedPalette, FALSE); if(hPalette) DeleteObject (hPalette); EndPaint(hWnd,&ps); UNLOCKCHILDDATA(hWnd); } /*====(Child_OnPaletteChanged)============================================== Description: Processes WM_PALETTECHANGED message for a child window. Syntax : VOID Child_OnPaletteChanged(HWND hWnd, HWND hWndPaletteChange) Parameters : hWnd Handle of a window. hWndPaletteChange Handle of the window that has the palette realized. Return Value: None. ==========================================================================*/ static L_VOID Child_OnPaletteChanged (HWND hWnd, HWND hWndPaletteChange) { HDC hDC; HPALETTE hOldPal; pCHILDDATA pData; if(hWnd == hWndPaletteChange) return; pData = LOCKCHILDDATA (hWnd); if(pData->hPalette) { hDC = GetDC(hWnd); hOldPal = SelectPalette(hDC, pData->hPalette, TRUE); RealizePalette(hDC); InvalidateRect(hWnd, NULL, FALSE); SelectPalette(hDC, hOldPal, TRUE); ReleaseDC(hWnd, hDC); } UNLOCKCHILDDATA(hWnd); } /*====(BmpWnd_OnVScroll)==================================================== Description: Scrolls the child window vertically. Syntax : VOID BmpWnd_OnVScroll(HWND hWnd, HWND hWndCtl, UINT nCode, int nPos) Parameters : hWnd Handle of a window. hWndCtl Not used. nCode Amount/Direction to be scrolled. npos The new position of the thumb. Return Value: None. ==========================================================================*/ static L_VOID Child_OnVScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos) { L_INT nScrollInc; pCHILDDATA pData; UNREFERENCED_PARAMETER(hWndCtl); pData = LOCKCHILDDATA (hWnd); bInScroll = TRUE; switch (nCode) { case SB_BOTTOM: nScrollInc = pData->nVScrollMax - pData->nVScrollPos; break; case SB_TOP: nScrollInc = -pData->nVScrollPos; break; case SB_LINEDOWN: nScrollInc = pData->nVScrollStep; break; case SB_LINEUP: nScrollInc = -pData->nVScrollStep; break; case SB_PAGEDOWN: nScrollInc = max (pData->nVScrollStep, (pData->cyClient - pData->nVScrollStep)); break; case SB_PAGEUP: nScrollInc = -max (pData->nVScrollStep, (pData->cyClient - pData->nVScrollStep)); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: nScrollInc = nPos - pData->nVScrollPos; break; default: nScrollInc = 0; break; } nScrollInc = max(-pData->nVScrollPos, min(nScrollInc, (pData->nVScrollMax - pData->nVScrollPos))); if(nScrollInc) { pData->nVScrollPos += nScrollInc; OffsetRect(&pData->rcView, 0, -nScrollInc); ScrollWindow(hWnd, 0, -nScrollInc, NULL, NULL); SetScrollPos(hWnd, SB_VERT, pData->nVScrollPos, TRUE); UpdateWindow(hWnd); } bInScroll = FALSE; UNLOCKCHILDDATA(hWnd); } /*====(BmpWnd_OnHScroll)==================================================== Description: Scrolls the child window horizontally. Syntax : VOID BmpWnd_OnHScroll(HWND hWnd, HWND hWndCtl, UINT nCode, int npos) Parameters : hWnd Handle of a window. hWndCtl Not used. nCode Amount/Direction to be scrolled. npos The new position of the thumb. Return Value: None. ==========================================================================*/ static L_VOID Child_OnHScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos) { L_INT nHScrollInc; pCHILDDATA pData; UNREFERENCED_PARAMETER(hWndCtl); pData = LOCKCHILDDATA (hWnd); if(!pData) return; bInScroll = TRUE; switch (nCode) { case SB_LEFT: nHScrollInc = -pData->nHScrollPos; break; case SB_RIGHT: nHScrollInc = pData->nHScrollMax - pData->nHScrollPos; break; case SB_LINELEFT: nHScrollInc = -pData->nHScrollStep; break; case SB_LINERIGHT: nHScrollInc = pData->nHScrollStep; break; case SB_PAGELEFT: nHScrollInc = -max(pData->nHScrollStep, (pData->cxClient - pData->nHScrollStep)); break; case SB_PAGERIGHT: nHScrollInc = max(pData->nHScrollStep, (pData->cxClient - pData->nHScrollStep)); break; case SB_THUMBPOSITION: case SB_THUMBTRACK: nHScrollInc = nPos - pData->nHScrollPos; break; default: nHScrollInc = 0; break; } nHScrollInc = max (-pData->nHScrollPos, min (nHScrollInc, (pData->nHScrollMax - pData->nHScrollPos))); if (nHScrollInc) { pData->nHScrollPos += nHScrollInc; OffsetRect(&pData->rcView, -nHScrollInc, 0); ScrollWindow(hWnd, -nHScrollInc, 0, NULL, NULL); SetScrollPos(hWnd, SB_HORZ, pData->nHScrollPos, TRUE); UpdateWindow(hWnd); } bInScroll = FALSE; UNLOCKCHILDDATA(hWnd); } /*====(BmpWnd_OnEraseBkgnd)================================================= Description: Erases the background of a child window. Syntax : BOOL BmpWnd_OnEraseBkgnd(HWND hWnd, HDC hDC) Parameters : hWnd Handle to the child window. hDC Handle to the device context. Return Value: TRUE The function was successful. ==========================================================================*/ static L_BOOL Child_OnEraseBkgnd (HWND hWnd, HDC hDC) { HRGN hClientRgn, hFillRgn; RECT rcView, rcClient; HGDIOBJ hBrush; pCHILDDATA pData; pData = LOCKCHILDDATA (hWnd); if(IsIconic(hWnd)) hBrush = GetStockObject(BLACK_BRUSH); else hBrush = GETHBRBACKGROUND(hWnd); GetClientRect(hWnd, &rcClient); GetUpdateRect(hWnd, &rcView, 0); if(bInScroll || pData->LeadBitmap.Flags.Allocated) { IntersectRect(&rcView, &pData->rcView, &rcClient); hClientRgn = CreateRectRgnIndirect(&rcClient); hFillRgn = CreateRectRgnIndirect(&rcView); CombineRgn(hFillRgn, hClientRgn, hFillRgn, RGN_DIFF); FillRgn(hDC, hFillRgn, hBrush); DeleteObject(hFillRgn); DeleteObject(hClientRgn); } else FillRect(hDC, &rcClient, hBrush); UNLOCKCHILDDATA(hWnd); return TRUE; } /*====(Child_OnSize)======================================================= Description: Responds to WM_SIZE message and sets the internal data accordingly. Also forwards the message to DefMDIChildProc. Syntax : VOID Child_OnSize(HWND hWnd, UINT nState, int nCx, int nCy) Parameters : hWnd Handle to the child window. nState State of resizing requested. nCx Size to be used for the "x" direction. nCy Size to be used for the "y" direction. Return Value: None. ==========================================================================*/ L_VOID Child_OnSize (HWND hWnd, L_UINT nState, L_INT nCx, L_INT nCy) { static L_BOOL fSizeInUse = FALSE; L_INT nWidth; L_INT nHeight; L_INT nVScroll; L_INT nHScroll; DWORD dwStyle; pCHILDDATA pData; pData = LOCKCHILDDATA (hWnd); if(!pData) return; if (!fSizeInUse) { fSizeInUse = TRUE; if (!IsIconic(hWnd))// if window is normal { if (!pData->LeadBitmap.Flags.Allocated) { /* if bitmap is not allocated then set width and height to ZERO */ nWidth = 0; nHeight = 0; } else // if bitmap is allocated, then set the width and height to bitmap width and height { nWidth = BITMAPWIDTH(&pData->LeadBitmap); nHeight= BITMAPHEIGHT(&pData->LeadBitmap); } // Set client dimensions to current width and height pData->cxClient = nCx; pData->cyClient = nCy; dwStyle = GetWindowLong (hWnd, GWL_STYLE); nVScroll = GetSystemMetrics (SM_CXVSCROLL); // Get Vertical scroll arrow width nHScroll = GetSystemMetrics (SM_CXHSCROLL); // Get Horizontal scroll arrow width if (WS_VSCROLL & dwStyle) // if Vertical scroll pData->cxClient += nVScroll; if (WS_HSCROLL & dwStyle) // if Horizontal scroll pData->cyClient += nHScroll; if (pData->cxClient < nWidth) // if client width < current width { pData->cyClient -= nHScroll; if (pData->cyClient < nHeight) pData->cxClient -= nVScroll; } else if (pData->cyClient < nHeight) // if client height < current height { pData->cxClient -= nVScroll; if (pData->cxClient < nWidth) pData->cyClient -= nHScroll; } pData->nVScrollStep = max (1, pData->cyClient / SCROLL_RATIO); pData->nHScrollStep = max (1, pData->cxClient / SCROLL_RATIO); pData->nVScrollMax = max (0, (nHeight - pData->cyClient - 1)); pData->nHScrollMax = max (0, (nWidth - pData->cxClient - 1)); pData->nVScrollPos = max (0, min (pData->nVScrollPos, pData->nVScrollMax)); pData->nHScrollPos = max (0, min (pData->nHScrollPos, pData->nHScrollMax)); if (pData->LeadBitmap.Flags.Allocated) { SetRect (&pData->rcView, 0, 0, nWidth, nHeight); OffsetRect (&pData->rcView, -pData->nHScrollPos, -pData->nVScrollPos); } SetScrollRange (hWnd, SB_HORZ, 0, pData->nHScrollMax, TRUE); SetScrollRange (hWnd, SB_VERT, 0, pData->nVScrollMax, TRUE); SetScrollPos (hWnd, SB_HORZ, pData->nHScrollPos, TRUE); SetScrollPos (hWnd, SB_VERT, pData->nVScrollPos, TRUE); } else // if window is iconized { // Retain the x-client and y-client area pData->cxClient = nCx; pData->cyClient = nCy; // set client area SetRect (&pData->rcView, 0, 0, pData->cxClient, pData->cyClient); } fSizeInUse = FALSE; } UNLOCKCHILDDATA(hWnd); FORWARD_WM_SIZE(hWnd,nState, nCx, nCy, DefMDIChildProc); } /*====(Child_OnQueryNewPalette)============================================ Description: Processes WM_QUERYNEWPALETTE message for a child window. Syntax : BOOL Child_OnQueryNewPalette(HWND hWnd) Parameters : hWnd Handle of a window. Return Value: nNoColors Number of colors changed in the palette. ==========================================================================*/ static L_BOOL Child_OnQueryNewPalette (HWND hWnd) { HDC hDC; L_INT nNoColors = 0; HPALETTE hOldPal; pCHILDDATA pData; pData = LOCKCHILDDATA (hWnd); if(pData->hPalette) { DeleteObject(pData->hPalette); pData->hPalette = NULL; } if(pData->LeadBitmap.Flags.Allocated) { hDC = GetDC(hWnd); pData->hPalette = L_CreatePaintPalette(hDC, &pData->LeadBitmap); if(pData->hPalette) { hOldPal = SelectPalette(hDC, pData->hPalette, FALSE); nNoColors = RealizePalette(hDC); if(nNoColors) InvalidateRect(hWnd, NULL, FALSE); SelectPalette(hDC, hOldPal, TRUE); } ReleaseDC(hWnd, hDC); } UNLOCKCHILDDATA(hWnd); return nNoColors; } /* L_INT GetDialogFilter(L_INT ID) { return 0; } */ /*====(Child_OnCommand)==================================================== Description: Processes the WM_COMMAND for a child window. Syntax : VOID Child_OnCommand(HWND hWnd, int nID, HWND hWndCtl, UINT codeNotify) Parameters : hWnd Handle to the child window. nID Value of the command to be processed. hWndCtl Not used. codeNotify Not used. Return Value: None. ==========================================================================*/ static L_VOID Child_OnCommand (HWND hWnd, L_INT nID, HWND hwndCtl, L_UINT codeNotify) { pCHILDDATA pData; L_INT nRet; L_CHAR szOpenFileFilter[] = {"ALL\0""*.*\0"}; L_CHAR szFileName[MAX_PATH] = "\0"; L_CHAR szImageDir[1024] = "\0"; static REFDATADLG RefDataDlg = {0, 90, 110, 31, 29, NULL, NULL, NULL, NULL, 0, 0}; HWND hDlgWnd; L_UINT i; POINT TmpPoints[3]={0}; static L_INT nAngle; static L_UINT uXScale; static L_UINT uYScale; static L_INT nXTrans; static L_INT nYTrans; L_TCHAR pcText[512]={0}; BITMAPHANDLE TempBitmap; StatusProc.hwndCtl = hwndCtl; pData = LOCKCHILDDATA (hWnd); switch(nID) { case IDM_FILE_SAVE: SaveBitmapFile (hWnd); break; case IDM_EDIT_REDO://UNDOLIST// L_UndoList_Redo (hWnd); break; case IDM_EDIT_UNDO://UNDOLIST// L_UndoList_Undo (hWnd); break; case IDM_EDIT_COPY: L_CopyToClipboard(hWnd, &pData->LeadBitmap, 0x1f); break; case IDM_EDIT_COPYRGN: { RECT rcRgn; BITMAPHANDLE bmpRgn; HRGN hRgn=NULL; pData = LOCKCHILDDATA (hWnd); L_GetBitmapRgnBounds(&pData->LeadBitmap, NULL, &rcRgn); L_InitBitmap(&bmpRgn, sizeof(BITMAPHANDLE), 0, 0, 0); L_CopyBitmapRect(&bmpRgn, &pData->LeadBitmap, sizeof(BITMAPHANDLE), rcRgn.left, rcRgn.top, RECTWIDTH(&rcRgn), RECTHEIGHT(&rcRgn)); L_GetBitmapRgnHandle(&bmpRgn, NULL, &hRgn); L_SetBitmapRgnHandle(&bmpRgn, NULL, hRgn, L_RGN_SETNOT); L_FillBitmap(&bmpRgn, RGB(0,0,0)); L_SetBitmapRgnHandle(&bmpRgn, NULL, hRgn, L_RGN_SET); DeleteObject(hRgn); L_CopyToClipboard (hWnd, &bmpRgn, 0x1f); L_FreeBitmap(&bmpRgn); UNLOCKCHILDDATA (hWnd); } break; case IDM_EDIT_PASTE: PasteBitmap(hWnd); break; case IDM_EDIT_CANCELREGION: nRgn =0; CancelRgn(hWnd, TRUE); SetCursor(LoadCursor(NULL, IDC_ARROW)); InvalidateRect(hWnd, NULL, FALSE); break; case IDM_IMAGE_REF_DATA: if(codeNotify == 132 && (L_UINT)hwndCtl==131) { nRet = DoDialogBoxParam(IDD_IMAGE_REF_DATA, hWnd, (DLGPROC) RefDataDlgProc, (LONG)&RefDataDlg); if(nRet) { hDlgWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_IMAGE_REF_NEXT_DLG), hWnd, RefNextDataDlgProc, (LONG)&RefDataDlg); UpdateWindow(hWnd); ShowWindow(hDlgWnd, SW_SHOW); } } else { if(codeNotify == 133 && (L_UINT)hwndCtl==131) { ////////////////////////////////// ////////For registration marks ////////////////////////////////// ////////////Start if(gpSearchData) { for(i = 0; i < guNumberOfMarks; i++) { if(gpSearchData[i].pMarkDetectedPoints) free(gpSearchData[i].pMarkDetectedPoints); } free(gpSearchData); gpSearchData = NULL; } guNumberOfMarks = RefDataDlg.uNumber; ////////////////////////////////// ////////////End ////////////////////////////////// ////////////////////////////////// ////////For registration marks ////////////////////////////////// ////////////Start gpSearchData = (LPSEARCHMARKS)malloc(guNumberOfMarks * sizeof(SEARCHMARKS)); for(i = 0; i < guNumberOfMarks; i++) { gpSearchData[i].uStructSize = sizeof(SEARCHMARKS); gpSearchData[i].uType = RefDataDlg.uTypeIndex; gpSearchData[i].rcRect= RefDataDlg.pRects[i]; gpSearchData[i].uHeight= RefDataDlg.uHeight; gpSearchData[i].uWidth= RefDataDlg.uWidth; gpSearchData[i].uMaxScale = RefDataDlg.uMaxRatio; gpSearchData[i].uMinScale = RefDataDlg.uMinRatio; gpSearchData[i].uSearchMarkCount = 1; gpSearchData[i].pMarkDetectedPoints = (POINT L_FAR *) malloc(sizeof(POINT) * gpSearchData[i].uSearchMarkCount); } ////////////////////////////////// ////////////End ////////////////////////////////// ////////////////////////////////// ////////For registration marks ////////////////////////////////// ////////////Start nRet = L_GetMarksCenterMassBitmap(&pData->LeadBitmap, RefDataDlg.pPoints, RefCMPoints, guNumberOfMarks); if(nRet == SUCCESS) { bRefDone = TRUE; pData->bDetected = FALSE; pData->bApplyTrans = FALSE; } ////////////////////////////////// ////////////End ////////////////////////////////// } else { if(RefDataDlg.uNumber) { if(RefDataDlg.pFilled) free(RefDataDlg.pFilled); RefDataDlg.pFilled = NULL; if(RefDataDlg.pPoints) free(RefDataDlg.pPoints); RefDataDlg.pPoints = NULL; if(RefDataDlg.pRects) free(RefDataDlg.pRects); RefDataDlg.pRects = NULL; if(RefDataDlg.pMarkRects) free(RefDataDlg.pMarkRects); RefDataDlg.pMarkRects = NULL; } RefDataDlg.uIndex = 0; RefDataDlg.uNumber = 0; if(L_BitmapHasRgn(&pData->LeadBitmap)) L_FreeBitmapRgn(&pData->LeadBitmap); nRet = DoDialogBoxParam(IDD_IMAGE_REF_DATA, hWnd, (DLGPROC) RefDataDlgProc, (LONG)&RefDataDlg); if(nRet) { hDlgWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_IMAGE_REF_NEXT_DLG), hWnd, RefNextDataDlgProc, (LONG)&RefDataDlg); ShowWindow(hDlgWnd, SW_SHOW); } } } break; case IDM_IMAGE_DETC_DATA: TransToStatusBar(&TempBitmap, &pData->LeadBitmap); nRet = L_SearchRegMarksBitmap(&pData->LeadBitmap, gpSearchData, guNumberOfMarks); TransBack (&TempBitmap, &pData->LeadBitmap, nRet); if(nRet != SUCCESS) { MessageBox(hWnd, TEXT("Registration marks were not detected"),TEXT("ERROR"), MB_OK); pData->bDetected = FALSE; pData->bApplyTrans = FALSE; pData->bHasBeenApplied = FALSE; break; } nRet = 0; for(i = 0; i < guNumberOfMarks; i++) { if(gpSearchData[i].uMarkDetectedCount == 1) nRet += gpSearchData[i].uMarkDetectedCount; } if(nRet != (L_INT)guNumberOfMarks) { MessageBox(hWnd, TEXT("Not all registration marks were detected"),TEXT("ERROR"), MB_OK); pData->bDetected = FALSE; pData->bApplyTrans = FALSE; pData->bHasBeenApplied = FALSE; } else { SetTimer((hWnd), 1, 100, NULL); for(i = 0; i < guNumberOfMarks; i++) { TmpPoints[i] = gpSearchData[i].pMarkDetectedPoints[0]; if(i) { L_SetBitmapRgnMagicWand(&pData->LeadBitmap,TmpPoints[i].x, TmpPoints[i].y, RGB(50,50,50),RGB(50,50,50), L_RGN_OR); } else { L_SetBitmapRgnMagicWand(&pData->LeadBitmap,TmpPoints[i].x, TmpPoints[i].y, RGB(50,50,50),RGB(50,50,50), L_RGN_SET); } } InvalidateRect(hWnd, NULL, FALSE); MessageBox(hWnd, TEXT("All registration marks were detected"),TEXT("SUCCESS"), MB_OK); nRet = L_GetMarksCenterMassBitmap(&pData->LeadBitmap, TmpPoints, pData->pDetcCMPoints, guNumberOfMarks); if(nRet == SUCCESS) { pData->bDetected = TRUE; pData->bHasBeenApplied = FALSE; } SetTimer((hWnd), 1, 100, NULL); for(i = 0; i < guNumberOfMarks; i++) { TmpPoints[i] = gpSearchData[i].pMarkDetectedPoints[0]; if(i) { L_SetBitmapRgnMagicWand(&pData->LeadBitmap,TmpPoints[i].x, TmpPoints[i].y, RGB(50,50,50),RGB(50,50,50), L_RGN_OR); } else { L_SetBitmapRgnMagicWand(&pData->LeadBitmap,TmpPoints[i].x, TmpPoints[i].y, RGB(50,50,50),RGB(50,50,50), L_RGN_SET); } } InvalidateRect(hWnd, NULL, FALSE); } break; case IDM_IMAGE_COMP_DATA: nRet = L_GetTransformationParameters(&pData->LeadBitmap, RefCMPoints, pData->pDetcCMPoints, &nXTrans, &nYTrans, &nAngle, &uXScale, &uYScale); if(nRet == SUCCESS) { if(pData->bHasBeenApplied) pData->bApplyTrans = FALSE; else pData->bApplyTrans = TRUE; memset(pcText, 0, 512); wsprintf(pcText,TEXT("Rotation angle = %d \n X scale = %d \n Y scale = %d \n X translation = %d \n Y translation = %d"), nAngle, uXScale, uYScale, nXTrans, nYTrans); MessageBox(hWnd, pcText,TEXT("SUCCESS"), MB_OK); if(L_BitmapHasRgn(&pData->LeadBitmap)) L_FreeBitmapRgn(&pData->LeadBitmap); } else { MessageBox(hWnd, TEXT("Can not compute parameters"),TEXT("ERROR"), MB_OK); } break; case IDM_REFDATA_SAVE: if(bRefDone) { if(MessageBox(hWnd,TEXT("Are you sure you want to save data?"),TEXT("Save Data"),MB_YESNO)==IDYES) SaveRefData(hWnd); } else MessageBox(hWnd, TEXT("No Data to be saved"), TEXT("ERROR"), MB_OK); break; case IDM_REFDATA_LOAD: if(MessageBox(hWnd,TEXT("Are you sure you want to load data?"),TEXT("Load Data"),MB_YESNO)==IDYES) LoadRefData(hWnd); break; case IDM_IMAGE_APPLY_TRANS: TransToStatusBar(&TempBitmap, &pData->LeadBitmap); MemorizeBitmap (hWnd); //MEMDISK nRet = L_ApplyTransformationParameters(&pData->LeadBitmap, nXTrans, nYTrans, nAngle,uXScale,uYScale,RGS_SIZE_NORMAL|RGS_SIZE_FAVORWHITE); if(nRet == SUCCESS) { L_UndoList_AddBitmap (hWnd); //UNDOLIST// pData->bHasBeenApplied = TRUE; pData->bApplyTrans = FALSE; } TransBack (&TempBitmap, &pData->LeadBitmap, nRet); InvalidateRect(hWnd, NULL, FALSE); break; case IDM_EDIT_INVERTIMAGE: TransToStatusBar(&TempBitmap, &pData->LeadBitmap); MemorizeBitmap (hWnd); //MEMDISK nRet = L_InvertBitmap(&pData->LeadBitmap); if(nRet == SUCCESS) L_UndoList_AddBitmap (hWnd); //UNDOLIST// TransBack (&TempBitmap, &pData->LeadBitmap, nRet); InvalidateRect(hWnd, NULL, FALSE); break; } UNLOCKCHILDDATA(hWnd); } /*====(SaveBitmapFile)========================================================= Description: Save the image to file. Syntax : L_INT SaveBitmapFile (HWND hWnd) Parameters : hWnd Handle of a window. Return Value: None. ==========================================================================*/ L_INT SaveBitmapFile (HWND hWnd) { SAVEDLGPARAMS DlgParams; OPENFILENAME OpenFileName; SAVEFILEOPTION SaveFileOption; FILEJ2KOPTIONS FileJ2KOptions; pCHILDDATA pData; L_INT nRet; L_TCHAR szFile[1024] = TEXT(""); L_TCHAR szBuffer[1024]; pData = LOCKCHILDDATA (hWnd); memset(&DlgParams, 0, sizeof(SAVEDLGPARAMS)); memset(&OpenFileName, 0, sizeof(OPENFILENAME)); memset(&FileJ2KOptions, 0, sizeof(FILEJ2KOPTIONS)); OpenFileName.lStructSize = sizeof ( OPENFILENAME ) ; OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = TEXT("Save a File"); DlgParams.uFileTypeIndex = 0; DlgParams.uStructSize = sizeof ( SAVEDLGPARAMS ) ; DlgParams.nQFactor = 2; DlgParams.nPageNumber = 1; DlgParams.nBitsPerPixel = pData->LeadBitmap.BitsPerPixel; DlgParams.uSaveMulti = MULTIPAGE_OPERATION_REPLACE ; DlgParams.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_STAMP | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR | DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS ; nRet = L_DlgSave ( hWnd, &OpenFileName, &DlgParams ); if (nRet == SUCCESS_DLG_OK) { L_GetDefaultSaveFileOption(&SaveFileOption, sizeof(SAVEFILEOPTION)); SaveFileOption.Flags = 0; SaveFileOption.PageNumber = DlgParams.nPageNumber; SaveFileOption.Passes = DlgParams.nPasses; SaveFileOption.Flags |= ESO_JPEGSTAMP; /* force compressed stamps */ switch(DlgParams.uSaveMulti) { case MULTIPAGE_OPERATION_OVERWRITE: SaveFileOption.PageNumber = 1; break; case MULTIPAGE_OPERATION_APPEND: SaveFileOption.PageNumber = 2; break; case MULTIPAGE_OPERATION_REPLACE: SaveFileOption.Flags |= ESO_REPLACEPAGE; break; case MULTIPAGE_OPERATION_INSERT: SaveFileOption.Flags |= ESO_INSERTPAGE; break; } if(DlgParams.bSaveWithStamp) { SaveFileOption.Flags |= ESO_SAVEWITHSTAMP; SaveFileOption.StampWidth = DlgParams.nStampWidth; SaveFileOption.StampHeight = DlgParams.nStampHeight; SaveFileOption.StampBits = DlgParams.nStampBits; } if((DlgParams.nFormat == FILE_J2K)|| (DlgParams.nFormat == FILE_JP2)|| (DlgParams.nFormat == FILE_CMW)|| (DlgParams.nFormat == FILE_TIF_J2K)|| (DlgParams.nFormat == FILE_TIF_CMW)) { /*Restore the old J2K Options*/ L_GetJ2KOptions(&FileJ2KOptions,sizeof(FILEJ2KOPTIONS)); L_SetJ2KOptions(&DlgParams.FileJ2KOptions); } nRet = L_SaveBitmap(DlgParams.szFileName, &pData->LeadBitmap, DlgParams.nFormat, DlgParams.nBitsPerPixel, DlgParams.nQFactor, &SaveFileOption); if((DlgParams.nFormat == FILE_J2K)|| (DlgParams.nFormat == FILE_JP2)|| (DlgParams.nFormat == FILE_CMW)|| (DlgParams.nFormat == FILE_TIF_J2K)|| (DlgParams.nFormat == FILE_TIF_CMW)) { /*Restore the old J2K Options*/ L_SetJ2KOptions(&FileJ2KOptions); } if (nRet != SUCCESS) { wsprintf (szBuffer, TEXT("ERROR %d saving the file %s."), nRet, (LPTSTR)szFile); MessageBox(hWnd, szBuffer, TEXT("ERROR"), MB_OK); } else { UNLOCKCHILDDATA(hWnd); return (TRUE); } } UNLOCKCHILDDATA(hWnd); return (FALSE); } /*====(Child_OnClose)==================================================== Description: Performs cleanup for the child window. Syntax : VOID Child_OnClose(HWND hWnd) Parameters : hWnd Handle of a window. Return Value: None. ==========================================================================*/ static L_VOID Child_OnClose (HWND hWnd) { if(bRefDlg1 || bRefDlg2) return; FORWARD_WM_CLOSE(hWnd, DefMDIChildProc); } /*====(Child_OnDestroy)==================================================== Description: Performs cleanup for the child window. Syntax : VOID Child_OnDestroy(HWND hWnd) Parameters : hWnd Handle of a window. Return Value: None. ==========================================================================*/ static L_VOID Child_OnDestroy (HWND hWnd) { pCHILDDATA pData; //MEMDISK...// L_BOOL bDel = TRUE; L_UINT uMem; //...MEMDISK// L_BOOL bBmSaveDel; pData = LOCKCHILDDATA (hWnd); //MEMDISK...// L_GetBitmapMemoryInfo (&pData->LeadBitmap, &uMem, NULL, NULL, NULL, NULL, NULL); if (uMem == TYPE_DISK) bDel = FALSE; //...MEMDISK// L_GetBitmapMemoryInfo (&pData->bmSave, &uMem, NULL, NULL, NULL, NULL, NULL); if (uMem == TYPE_DISK) bBmSaveDel = FALSE; //...MEMDISK// L_UndoList_DestroyList (hWnd);//UNDOLIST// if(pData) { nCount--; if(L_BitmapHasRgn(&pData->LeadBitmap)) KillTimer(hWnd, pData->uTimerID); else KillTimer(hWnd, pData->uTimerID); if(pData->LeadBitmap.Flags.Allocated) { if (bDel) L_FreeBitmap(&pData->LeadBitmap); L_InitBitmap(&pData->LeadBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); } if(pData->bmFloater.Flags.Allocated) { L_FreeBitmap(&pData->bmFloater); L_InitBitmap(&pData->bmFloater, sizeof(BITMAPHANDLE), 0, 0, 0); } if(pData->bmSave.Flags.Allocated) { if (bBmSaveDel) L_FreeBitmap(&pData->bmSave); L_InitBitmap(&pData->bmSave, sizeof(BITMAPHANDLE), 0, 0, 0); } if (pData->UndoBitmap.Flags.Allocated) { L_FreeBitmap(&pData->UndoBitmap); L_InitBitmap(&pData->UndoBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); } if(pData->pszTitle) { GlobalFreePtr(pData->pszTitle); pData->pszTitle = NULL; } if(pData->hPalette) DeletePalette(pData->hPalette); if(pData->hrgnRegion) { DeleteRgn(pData->hrgnRegion); pData->hrgnRegion = NULL; } if(pData->hrgnFloater) { DeleteRgn(pData->hrgnFloater); pData->hrgnFloater = NULL; } UNLOCKCHILDDATA(hWnd); } } /*====(Child_OnMDIActivate)================================================ Description: Informs the child window it is going to receive the focus. Syntax : VOID Child_OnMDIActivate(HWND hWnd, BOOL fActive, HWND hWndActivate, HWND hWndDeactivate) Parameters : hWnd Handle of a window. fActive Truth of "Is the window active". hWndActivate Handle to the window to be activated. hWndDeactivate Handle to the window to be deactivated. Return Value: None. ==========================================================================*/ static L_VOID Child_OnMDIActivate (HWND hWnd, L_BOOL fActive, HWND hWndActivate, HWND hWndDeactivate) { pCHILDDATA pData; pData = LOCKCHILDDATA (hWnd); if(hWnd == GetCapture()) ReleaseCapture(); if(hWndActivate) { if(bRefDlg2) SendMessage(hWndClient, WM_MDISETMENU, (WPARAM) hMenuDisChild, (LPARAM) hMenuChildWindow); else SendMessage(hWndClient, WM_MDISETMENU, (WPARAM) hMenuChild, (LPARAM) hMenuChildWindow); pData->bFrameMenu = FALSE; Child_OnQueryNewPalette(hWnd); } else { SendMessage(hWndClient, WM_MDISETMENU, (WPARAM) hMenuInit, (LPARAM) hMenuInitWindow); pData->bFrameMenu = TRUE; } DrawMenuBar(hWndFrame); UNLOCKCHILDDATA(hWnd); } static VOID FreeRegionBitmaps (pCHILDDATA pData) { if( pData->bmSave.Flags.Allocated ) L_FreeBitmap( &pData->bmSave ); if( pData->bmFloater.Flags.Allocated ) L_FreeBitmap( &pData->bmFloater ); if( pData->hbmFloater ) { DeleteObject( pData->hbmFloater ); pData->hbmFloater = NULL; } if( pData->hbmSave ) { DeleteObject( pData->hbmSave ); pData->hbmSave = NULL; } if( pData->hrgnRegion ) { DeleteObject( pData->hrgnRegion ); pData->hrgnRegion = NULL; } if( pData->hrgnFloater ) { DeleteObject( pData->hrgnFloater ); pData->hrgnFloater = NULL; } } static HBITMAP ResizeToDDB( pCHILDDATA pData, HDC hDisplay, pBITMAPHANDLE pBitmap, int xSrcLeft, int ySrcTop, int nNewWidth, int nNewHeight, int nClientWidth, int nClientHeight ) { HDC hDisplayMem; HDC hdcDevice; HBITMAP hBitmap; HBITMAP hbmSave; L_UINT32 ulFlags; RECT rcDest, rcDestClip; HPALETTE hpalSave = NULL; hdcDevice = (hDisplay) ? hDisplay : GetDC (NULL); hDisplayMem = CreateCompatibleDC (hdcDevice); if ((hBitmap = CreateCompatibleBitmap (hdcDevice, nNewWidth, nNewHeight)) == 0) { if (!hDisplay) ReleaseDC (NULL, hdcDevice); return (NULL); } hbmSave = SelectObject(hDisplayMem, hBitmap); if (pData->hPalette) { hpalSave = SelectPalette (hDisplayMem, pData->hPalette, TRUE); RealizePalette(hDisplayMem); } ulFlags = L_GetDisplayMode (); L_SetDisplayMode (DISPLAYMODE_INDEXEDPAINT, 0); SetRect(&rcDestClip, 0, 0, nNewWidth, nNewHeight); SetRect(&rcDest, - xSrcLeft, - ySrcTop, nClientWidth - xSrcLeft, nClientHeight - ySrcTop); L_PaintDC (hDisplayMem, pBitmap, NULL, NULL, &rcDest, &rcDestClip, SRCCOPY); L_SetDisplayMode (DISPLAYMODE_RESETPOSITIONS, ulFlags); if (hpalSave) SelectPalette (hDisplayMem, hpalSave, TRUE); SelectObject(hDisplayMem, hbmSave); DeleteDC(hDisplayMem); if (!hDisplay) ReleaseDC (NULL, hdcDevice); return (hBitmap); } /*====(OutlineBitmapRgn)====================================================== Description: Draws a frame around the current region Syntax : L_VOID OutlineBitmapRgn(HWND hWnd, HDC hdc) Parameters : hWnd Handle of the child window. HDC DC to use for drawing (may be null) Return Value: None. ==========================================================================*/ L_VOID OutlineBitmapRgn(HWND hWnd, HDC hdc) { pCHILDDATA pData; HDC hdcDraw; RGNXFORM XForm; pData = LOCKCHILDDATA(hWnd); if(L_BitmapHasRgn(&pData->LeadBitmap)) { if(hdc) hdcDraw = hdc; else hdcDraw = GetDC(pData->hBitmapWnd); XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = RECTWIDTH(&pData->rcView); XForm.nXScalarDen = BITMAPWIDTH(&pData->LeadBitmap); XForm.nYScalarNum = RECTHEIGHT(&pData->rcView); XForm.nYScalarDen = BITMAPHEIGHT(&pData->LeadBitmap); XForm.nXOffset = pData->rcView.left; XForm.nYOffset = pData->rcView.top; L_FrameBitmapRgn(hdcDraw, &pData->LeadBitmap, &XForm, pData->uFrameType); if(!hdc) ReleaseDC(pData->hBitmapWnd, hdcDraw); } UNLOCKCHILDDATA(hWnd); } static int SafeCopyBitmapRect( pBITMAPHANDLE pBitmapDst, pBITMAPHANDLE pBitmapSrc, L_INT L_FAR *nXSrc, L_INT L_FAR *nYSrc, L_INT L_FAR *nWidth, L_INT L_FAR *nHeight ) { RECT rc; /* check the input parameters */ if( *nXSrc < 0 ) { *nWidth += *nXSrc; *nXSrc = 0; } else if(*nXSrc >= pBitmapSrc->Width) { *nXSrc = pBitmapSrc->Width; *nWidth = 0; } if( *nYSrc < 0 ) { *nHeight += *nYSrc; *nYSrc = 0; } else if(*nYSrc >= pBitmapSrc->Height) { *nYSrc = pBitmapSrc->Height; *nHeight = 0; } if( *nXSrc + *nWidth > pBitmapSrc->Width ) *nWidth = pBitmapSrc->Width - *nXSrc; if( *nYSrc + *nHeight > pBitmapSrc->Height ) *nHeight = pBitmapSrc->Height - *nYSrc; if( pBitmapDst->Flags.Allocated ) L_FreeBitmap( pBitmapDst ); L_InitBitmap(pBitmapDst, sizeof(BITMAPHANDLE), *nWidth, *nHeight, pBitmapSrc->BitsPerPixel); pBitmapDst->ViewPerspective = pBitmapSrc->ViewPerspective; pBitmapDst->Order = pBitmapSrc->Order; if( L_AllocateBitmap(pBitmapDst, TYPE_CONV) != SUCCESS ) return FAILURE; if( pBitmapSrc->BitsPerPixel <= 8 ) L_CopyBitmapPalette(pBitmapDst, pBitmapSrc); SetRect(&rc, *nXSrc, *nYSrc, *nXSrc + *nWidth, *nYSrc + *nHeight); L_RectFromBitmap(pBitmapSrc, TOP_LEFT, &rc); L_CombineBitmap( pBitmapDst, 0, 0, RECTWIDTH(&rc), RECTHEIGHT(&rc), pBitmapSrc, rc.left, rc.top, L_SRCCOPY ); return SUCCESS; } /*====(HiliteMark)====================================================== Description: Performs the inversion of the region being marked Syntax : L_VOID HiliteMark(HWND hWnd, L_BOOL fUpdate) Parameters : hWnd Handle of the child window. fUpdate Hilite the new points only Return Value: None. ==========================================================================*/ static L_VOID HiliteMark(HWND hWnd, L_BOOL fUpdate) { HDC hdc; HBRUSH hBrush; HPEN hPen; L_INT nDrawMode; pCHILDDATA pData; HRGN hRgn; RECT rcScreen; pData = LOCKCHILDDATA(hWnd); if(nNextPt <= 1) return; hdc = GetDC(pData->hBitmapWnd); hBrush = SelectObject (hdc, GetStockObject (NULL_BRUSH)); hPen = SelectObject (hdc, GetStockObject(WHITE_PEN)); // create a region based on the visible area SetRect(&rcScreen, 0, 0, GetDeviceCaps(hdc, HORZRES), GetDeviceCaps(hdc, VERTRES)); IntersectRect(&rcScreen, &rcScreen, &pData->rcView); hRgn = CreateRectRgnIndirect(&rcScreen); SelectObject(hdc, hRgn); DeleteObject(hRgn); nDrawMode = GetROP2 (hdc); SetROP2 (hdc, R2_NOT); switch(nRgnType) { case 1: Rectangle(hdc, min(pptRegion[0].x, pptRegion[1].x), min(pptRegion[0].y, pptRegion[1].y), max(pptRegion[0].x, pptRegion[1].x), max(pptRegion[0].y, pptRegion[1].y)); break; case 2: RoundRect(hdc, pptRegion[0].x, pptRegion[0].y, pptRegion[1].x, pptRegion[1].y, abs(pptRegion[0].x - pptRegion[1].x) / 4, abs(pptRegion[0].y - pptRegion[1].y) / 4); break; case 3: Ellipse(hdc, pptRegion[0].x, pptRegion[0].y, pptRegion[1].x, pptRegion[1].y); break; case 4: if(fUpdate) Polyline(hdc, &pptRegion[nNextPt - 2], 2); else Polyline(hdc, pptRegion, nNextPt); break; } SetROP2 (hdc, nDrawMode); SelectObject(hdc, hBrush); SelectObject(hdc, hPen); ReleaseDC(pData->hBitmapWnd, hdc); UNLOCKCHILDDATA(hWnd); } /*====(MoveFloater)======================================================== Description: Moves the floater when you drag it with the mouse. Syntax : VOID MoveFloater(HWND hWnd, LPCHILDDATA pData, int x, int y) Parameters : hWnd Handle of the child window. pData Child MDI window's data. x, y New position of the mouse cursor in client coordinates. Return Value: None. ==========================================================================*/ static VOID MoveFloater(HWND hWnd, pCHILDDATA pData, int x, int y) { HDC hdc; HDC hdcUnion; HDC hdcRegion; HBITMAP hbmUnion = 0, holdUnion, holdRegion; RECT rcSave; RECT rcUnion; RECT rcRegion; L_INT nUnionWidth = 0; L_INT nUnionHeight = 0; hdc = GetDC (pData->hBitmapWnd); /* All the x values are relative to the client window; viewport of the DC matches that already */ IntersectClipRect (hdc, 0, 0, RECTWIDTH(&pData->rcView), RECTHEIGHT(&pData->rcView)); SetRect (&rcSave, 0, 0, pData->nFloaterWidth, pData->nFloaterHeight); rcRegion = rcSave; OffsetRect (&rcSave, pData->xFloaterDest, pData->yFloaterDest); pData->deltaX += x - pData->xAnchor; pData->deltaY += y - pData->yAnchor; pData->xFloaterDest = pData->xFloaterDest + x - pData->xAnchor; pData->yFloaterDest = pData->yFloaterDest + y - pData->yAnchor; pData->xAnchor = x; pData->yAnchor = y; OffsetRect (&rcRegion, pData->xFloaterDest, pData->yFloaterDest); if (IntersectRect (&rcUnion, &rcSave, &rcRegion)) { UnionRect (&rcUnion, &rcSave, &rcRegion); /* create a DDB from the origial bitmap the size of the union */ nUnionWidth = rcUnion.right - rcUnion.left; nUnionHeight = rcUnion.bottom - rcUnion.top; hbmUnion = CreateCompatibleBitmap(hdc, nUnionWidth, nUnionHeight ); OffsetRect (&rcRegion, -rcUnion.left, -rcUnion.top); OffsetRect (&rcSave, -rcUnion.left, -rcUnion.top); hdcUnion = CreateCompatibleDC (hdc); holdUnion = SelectObject (hdcUnion, hbmUnion); hdcRegion = CreateCompatibleDC (hdc); holdRegion = SelectObject (hdcRegion, pData->hbmSave); /* copy to the union DDB what's on the screen */ BitBlt( hdcUnion, 0, 0, nUnionWidth, nUnionHeight, hdc, rcUnion.left, rcUnion.top, SRCCOPY ); /* restore the background into the union. Now the union bitmap should contain what should on the screen without the floating bitmap */ BitBlt( hdcUnion, rcSave.left, rcSave.top, pData->nFloaterWidth, pData->nFloaterHeight, hdcRegion, 0, 0, SRCCOPY ); /* get the new background into hbmSave */ BitBlt (hdcRegion, 0, 0, pData->nFloaterWidth, pData->nFloaterHeight, hdcUnion, rcRegion.left, rcRegion.top, SRCCOPY); /* Paint only what's is inside the region using Windows's ability to do clipping. Select the region into the union DC */ SelectObject( hdcUnion, pData->hrgnFloater ); OffsetClipRgn( hdcUnion, rcRegion.left, rcRegion.top ); /* select the floater DDB */ SelectObject( hdcRegion, pData->hbmFloater ); /* Now the union DDB is what should be on the screen */ BitBlt (hdcUnion, rcRegion.left, rcRegion.top, pData->nFloaterWidth, pData->nFloaterHeight, hdcRegion, 0, 0, SRCCOPY); /* blast the whole thing to the screen */ BitBlt( hdc, rcUnion.left, rcUnion.top, nUnionWidth, nUnionHeight, hdcUnion, 0, 0, SRCCOPY ); SelectObject( hdcUnion, holdUnion ); DeleteDC(hdcUnion); SelectObject( hdcRegion, holdRegion ); DeleteDC(hdcRegion); DeleteObject( hbmUnion ); } else { hdcRegion = CreateCompatibleDC (hdc); holdRegion = SelectObject (hdcRegion, pData->hbmSave); /* restore the background */ BitBlt( hdc, rcSave.left, rcSave.top, pData->nFloaterWidth, pData->nFloaterHeight, hdcRegion, 0, 0, SRCCOPY ); /* save the background */ BitBlt (hdcRegion, 0, 0, pData->nFloaterWidth, pData->nFloaterHeight, hdc, pData->xFloaterDest, pData->yFloaterDest, SRCCOPY); /* Paint only what's is inside the region using Windows's ability to do clipping. Select the floater into the union DC */ SelectObject( hdc, pData->hrgnFloater ); OffsetClipRgn( hdc, pData->xFloaterDest, pData->yFloaterDest ); IntersectClipRect (hdc, 0, 0, RECTWIDTH(&pData->rcView), RECTHEIGHT(&pData->rcView)); /* paint only what's INSIDE the region */ SelectObject( hdcRegion, pData->hbmFloater ); BitBlt (hdc, pData->xFloaterDest, pData->yFloaterDest, pData->nFloaterWidth, pData->nFloaterHeight, hdcRegion, 0, 0, SRCCOPY); SelectObject( hdcRegion, holdRegion ); DeleteDC(hdcRegion); } ReleaseDC (pData->hBitmapWnd, hdc); } /*====(YClientToBitmap)=================================================== Description: Helps find the corresponding pixel in the bitmap for a point on the screen. Syntax : int YClientToBitmap(LPCHILDDATA pData, int y) Parameters : pData Child window's data x X coordinate of a point in the client window y Y coordinate of a point in the client window Return Value: The corresponding Y coordinate in bitmap coordinates ==========================================================================*/ static int YClientToBitmap(pCHILDDATA pData, int x, int y) { x = (L_INT)((L_INT32)(x - pData->rcView.left)*BITMAPWIDTH(&pData->LeadBitmap)/RECTWIDTH(&pData->rcView)); y = (L_INT)((L_INT32)(y - pData->rcView.top) *BITMAPHEIGHT(&pData->LeadBitmap)/RECTHEIGHT(&pData->rcView)); L_PointToBitmap(&pData->LeadBitmap, TOP_LEFT, &x, &y); return y; } /*====(XClientToBitmap)=================================================== Description: Helps find the corresponding pixel in the bitmap for a point on the screen. Syntax : int XClientToBitmap(LPCHILDDATA pData, int x) Parameters : pData Child window's data x X coordinate of a point in the client window y Y coordinate of a point in the client window Return Value: The corresponding X coordinate in bitmap coordinates ==========================================================================*/ static int XClientToBitmap(pCHILDDATA pData, int x, int y) { x = (L_INT)((L_INT32)(x - pData->rcView.left)*BITMAPWIDTH(&pData->LeadBitmap)/RECTWIDTH(&pData->rcView)); y = (L_INT)((L_INT32)(y - pData->rcView.top)*BITMAPHEIGHT(&pData->LeadBitmap)/RECTHEIGHT(&pData->rcView)); L_PointToBitmap(&pData->LeadBitmap, TOP_LEFT, &x, &y); return x; } /*----[CreateRegionBitmaps]------------------------------------------------- Syntax: L_INT CreateRegionBitmaps( HWND hWnd ) Parameters: hWnd The window where the bitmap is drawn. Notes: This function will allocate the bitmaps and DDBs used to move the floater bitmap around. --------------------------------------------------------------------------*/ static L_INT CreateRegionBitmaps( HWND hWnd ) { HDC hdc; RGNXFORM XForm; RECT rcRegion; RECT rcFloater; pCHILDDATA pData; RECT rc; pData = LOCKCHILDDATA(hWnd); hdc = GetDC(pData->hBitmapWnd); /* get the position of the region in bitmap coordinates */ XForm.uViewPerspective = pData->LeadBitmap.ViewPerspective; XForm.nXScalarNum = XForm.nXScalarDen = XForm.nYScalarNum = XForm.nYScalarDen = 1; XForm.nXOffset = XForm.nYOffset = 0; L_GetBitmapRgnBounds(&pData->LeadBitmap,&XForm,&rcRegion); pData->xMoveSrc = rcRegion.left; pData->yMoveSrc = rcRegion.top; pData->nMoveWidth = RECTWIDTH(&rcRegion); pData->nMoveHeight = RECTHEIGHT(&rcRegion); /* delete the previous region */ if( pData->hrgnRegion ) DeleteObject( pData->hrgnRegion ); /* get the Windows region handle from original bitmap. Current offset is xMoveSrc,yMoveSrc and I want it at 0,0 */ XForm.nXOffset = - pData->xMoveSrc; XForm.nYOffset = - pData->yMoveSrc; L_GetBitmapRgnHandle( &pData->LeadBitmap, &XForm, &pData->hrgnRegion ); /* get the position of the region in client coordinates. This is how we find out the size of the floater. We have to to it here in case the zoom factor has changed since the creation of the region. I want these coordinates to be TOP_LEFT, like the screen! */ XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = RECTWIDTH(&pData->rcView); XForm.nYScalarNum = RECTHEIGHT(&pData->rcView); XForm.nXScalarDen = BITMAPWIDTH(&pData->LeadBitmap); XForm.nYScalarDen = BITMAPHEIGHT(&pData->LeadBitmap); XForm.nXOffset = pData->rcView.left; XForm.nYOffset = pData->rcView.top; L_GetBitmapRgnBounds(&pData->LeadBitmap,&XForm,&rcFloater); pData->xFloaterDest = rcFloater.left; pData->yFloaterDest = rcFloater.top; pData->nFloaterWidth = RECTWIDTH(&rcFloater); pData->nFloaterHeight = RECTHEIGHT(&rcFloater); /* delete the previous floater region */ if( pData->hrgnFloater ) DeleteObject( pData->hrgnFloater ); /* get the Windows region handle for the floater. I want it at 0,0 */ XForm.uViewPerspective = TOP_LEFT; XForm.nXOffset -= rcFloater.left; XForm.nYOffset -= rcFloater.top; L_GetBitmapRgnHandle( &pData->LeadBitmap, &XForm, &pData->hrgnFloater ); /* clear the region from the source bitmap */ L_FreeBitmapRgn(&pData->LeadBitmap); /* --------------- START CREATING THE FLOATING BITMAPS --------- */ /* free the previous floater bitmap */ if( pData->bmFloater.Flags.Allocated ) L_FreeBitmap( &pData->bmFloater ); /* create the floater bitmap */ L_CopyBitmapRect( &pData->bmFloater, &pData->LeadBitmap, sizeof(BITMAPHANDLE), pData->xMoveSrc, pData->yMoveSrc, pData->nMoveWidth, pData->nMoveHeight ); /* create the floater DDB */ if( pData->hbmFloater ) DeleteObject( pData->hbmFloater ); pData->hbmFloater = ResizeToDDB( pData, hdc, &pData->LeadBitmap, pData->xFloaterDest - pData->rcView.left, pData->yFloaterDest - pData->rcView.top, pData->nFloaterWidth, pData->nFloaterHeight, RECTWIDTH(&pData->rcView), RECTHEIGHT(&pData->rcView) ); /* --------------- the floating bitmaps are created ------------- */ /* ------- START CREATING THE BACKGROUND BITMAPS ------- */ /* create the background bitmap if it doesn't exist already */ if( pData->bmSave.Flags.Allocated ) { //SetRect(&rc, pData->xMoveSrc, pData->yMoveSrc, SetRect(&rc, pData->xSaveSrc, pData->ySaveSrc, pData->xMoveSrc + pData->nMoveWidth, pData->yMoveSrc + pData->nMoveHeight); L_RectFromBitmap(&pData->LeadBitmap, TOP_LEFT, &rc); /* restore the background in the big bitmap */ L_CombineBitmap( &pData->LeadBitmap, rc.left, rc.top, RECTWIDTH(&rc), RECTHEIGHT(&rc), &pData->bmSave, 0, 0, L_SRCCOPY ); } else /* create the save bitmap. Now, it is exactly as the floater */ L_CopyBitmap( &pData->bmSave, &pData->bmFloater, sizeof(BITMAPHANDLE)); /* create the save DDB */ if( pData->hbmSave ) DeleteObject( pData->hbmSave ); pData->hbmSave = ResizeToDDB( pData, hdc, &pData->LeadBitmap, pData->xFloaterDest - pData->rcView.left, pData->yFloaterDest - pData->rcView.top, pData->nFloaterWidth, pData->nFloaterHeight, RECTWIDTH(&pData->rcView), RECTHEIGHT(&pData->rcView) ); /* ------- the background bitmaps are created --------- */ if( !pData->hbmFloater || !pData->hbmSave || !pData->bmFloater.Flags.Allocated || !pData->bmSave.Flags.Allocated || !pData->hrgnRegion || !pData->hrgnFloater ) MessageBox( hWnd, TEXT("Error allocating bitmaps"), TEXT(""), MB_OK ); /* create the background DDB */ ReleaseDC(pData->hBitmapWnd, hdc ); UNLOCKCHILDDATA(hWnd); return SUCCESS; } L_VOID Child_OnRButtonup (HWND hWnd, L_INT nX, L_INT nY, L_UINT ukeyFlags) { HMENU hSubMenu; POINT pt; L_BOOL bClipboardReady; pCHILDDATA pData; pt.x = nX; pt.y = nY; pData = LOCKCHILDDATA (hWnd); if(!pData) return; ClientToScreen(hWnd, &pt); hSubMenu = GetSubMenu(hMenuChild, IsMaximized(hWnd)? 2 : 1); bClipboardReady = L_ClipboardReady(); CheckMenuItem(hMenuChild, IDM_EDIT_SETREGION_NONE, MF_BYCOMMAND | (nRgnType == 0) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_SETREGION_RECTANGLE, MF_BYCOMMAND | (nRgnType == 1) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_SETREGION_ROUNDEDRECTANGLE, MF_BYCOMMAND | (nRgnType == 2) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_SETREGION_ELLIPSE, MF_BYCOMMAND | (nRgnType == 3) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_SETREGION_FREEHAND, MF_BYCOMMAND | (nRgnType == 4) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_SETREGION_MAGICWAND, MF_BYCOMMAND | (nRgnType == 5) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_SINGLE, MF_BYCOMMAND | (pData->uCombineMode == L_RGN_SET) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_MULTI, MF_BYCOMMAND | (pData->uCombineMode == L_RGN_OR) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_INTERSECT, MF_BYCOMMAND | (pData->uCombineMode == L_RGN_AND) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_INVERT, MF_BYCOMMAND | (pData->uCombineMode == L_RGN_SETNOT) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_OLDANDNOTNEW, MF_BYCOMMAND | (pData->uCombineMode == L_RGN_ANDNOTRGN) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_NEWANDNOTOLD, MF_BYCOMMAND | (pData->uCombineMode == L_RGN_ANDNOTBITMAP) ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(hMenuChild, IDM_EDIT_OLDXORNEW, MF_BYCOMMAND | (pData->uCombineMode == L_RGN_XOR) ? MF_CHECKED : MF_UNCHECKED); EnableMenuItem(hMenuChild, IDM_EDIT_PASTE, MF_BYCOMMAND | ((bClipboardReady) ? MF_ENABLED : MF_GRAYED)); if (L_BitmapHasRgn(&(pData->LeadBitmap))) EnableMenuItem(hMenuChild, IDM_EDIT_CANCELREGION, MF_ENABLED); else EnableMenuItem(hMenuChild, IDM_EDIT_CANCELREGION, MF_GRAYED); EnableMenuItem (hMenuChild, IDM_EDIT_UNDO, (L_UndoList_UndoExists (hWnd)) ? MF_ENABLED : MF_GRAYED); EnableMenuItem (hMenuChild, IDM_EDIT_REDO, (L_UndoList_RedoExists (hWnd)) ? MF_ENABLED : MF_GRAYED); if (L_BitmapHasRgn(&(pData->LeadBitmap))) EnableMenuItem(hMenuChild, IDM_EDIT_COPYRGN, MF_ENABLED); else EnableMenuItem(hMenuChild, IDM_EDIT_COPYRGN, MF_GRAYED); if(!bRefDlg2) TrackPopupMenu(hSubMenu, 0, pt.x, pt.y, 0, hWnd, NULL); UNLOCKCHILDDATA(hWnd); } /*====( `)====================================================== Description: Called when the timer value expires Syntax : L_VOID Child_OnTimer(HWND hWnd, UINT nID) Parameters : hWnd Handle of the child window. nID Timer nID supplied in SetTimr Return Value: None. ==========================================================================*/ static L_VOID Child_OnTimer(HWND hWnd, UINT nID) { pCHILDDATA pData; pData = LOCKCHILDDATA(hWnd); switch(nID) { case 1: pData->uFrameType = (pData->uFrameType + 1) % 8; OutlineBitmapRgn(hWnd, NULL); break; } UNLOCKCHILDDATA(hWnd); } /*====(Child_OnSetFocus)====================================================== Description: Indicates when the window is getting the input focus Syntax : VOID Child_OnSetFocus(HWND hWnd) Parameters : hWnd Handle of the child window. hWndOldFocus Previous window that had the focus Return Value: None. ==========================================================================*/ static VOID Child_OnSetFocus(HWND hWnd, HWND hWndOldFocus) { pCHILDDATA pData; pData = LOCKCHILDDATA (hWnd); if (!pData) return; if(bRefDlg2) SendMessage(hWndClient, WM_MDISETMENU, (WPARAM) hMenuDisChild, (LPARAM) hMenuChildWindow); else SendMessage(hWndClient, WM_MDISETMENU, (WPARAM) hMenuChild, (LPARAM) hMenuChildWindow); DrawMenuBar(hWndFrame); if(L_BitmapHasRgn(&pData->LeadBitmap)) pData->uTimerID = SetTimer(hWnd, 1, 100, NULL); UNLOCKCHILDDATA(hWnd); } /*====(Child_OnSetFocus)====================================================== Description: Indicates when the window is getting the input focus Syntax : VOID Child_OnSetFocus(HWND hWnd) Parameters : hWnd Handle of the child window. hWndOldFocus Previous window that had the focus Return Value: None. ==========================================================================*/ static VOID Child_OnKillFocus(HWND hWnd, HWND hWndNewFocus) { pCHILDDATA pData; pData = LOCKCHILDDATA (hWnd); if (!pData) return; if(bRefDlg2) SendMessage(hWndClient, WM_MDISETMENU, (WPARAM) hMenuDisChild, (LPARAM) hMenuChildWindow); else { if(pData->bFrameMenu) SendMessage(hWndClient, WM_MDISETMENU, (WPARAM) hMenuInit, (LPARAM) hMenuInitWindow); else SendMessage(hWndClient, WM_MDISETMENU, (WPARAM) hMenuChild, (LPARAM) hMenuChildWindow); } DrawMenuBar(hWndFrame); if(L_BitmapHasRgn(&pData->LeadBitmap)) KillTimer(hWnd, 1); UNLOCKCHILDDATA(hWnd); } L_VOID FitImageToWindow(RECT rcImage, pBITMAPHANDLE pBitmap, RECT L_FAR * Rect) { L_INT Dy, Dx; L_INT nOffsetx, nOffsety; if(pBitmap->Height >= pBitmap->Width) { Dy = rcImage.bottom - rcImage.top; Dx = MulDiv ( Dy, pBitmap->Width, pBitmap->Height ) ; nOffsety = 0; nOffsetx = (rcImage.right - rcImage.left - Dx)/2; } else { Dx = rcImage.right- rcImage.left; Dy = MulDiv ( Dx, pBitmap->Height, pBitmap->Width ) ; nOffsety = (rcImage.bottom- rcImage.top - Dy)/2; nOffsetx = 0; } SetRect(Rect, 0, 0,Dx, Dy); OffsetRect(Rect, nOffsetx, nOffsety); } /* +--------------------------------------------------------------------------+ | Function :Child_OnLButtonDown | | Desc :starts the dragging of the splitter | | Return :void | | Notes : | +--------------------------------------------------------------------------+ */ static L_VOID Child_OnLButtonDown (HWND hWnd, L_BOOL bDoubleClick, L_INT x, L_INT y, L_UINT keyFlags) { RECT rcClient; POINT pt; pCHILDDATA pData; pData = LOCKCHILDDATA(hWnd); if(!GetCapture() && nRgnType != 0 && !IsIconic(hWnd) && pData->LeadBitmap.Flags.Allocated) { if (pData->bLineHistogram) { SetCapture(hWnd); return; } GetClientRect(hWnd, &rcClient); IntersectRect(&rcClient, &rcClient, &pData->rcView); pt.x = x; pt.y = y; if(PtInRect(&rcClient, pt)) { MemorizeBitmap (hWnd); //...MEMDISK// /* If we click inside the existing region, allow its dragging */ /* x is in client coordinates and L_IsPtInBitmapRgn uses bitmap coordinates */ if(L_BitmapHasRgn(&pData->LeadBitmap) && L_IsPtInBitmapRgn (&pData->LeadBitmap, YClientToBitmap(pData,x,y), XClientToBitmap(pData,x,y)) &&(pData->uCombineMode == L_RGN_SET)) { /* stop displaying the frame while dragging the region */ KillTimer(hWnd, 1); /* create the bitmaps needed to move the floater around If the floater was moved here, restore the background as well */ CreateRegionBitmaps(hWnd); pData->deltaX = pData->deltaY = 0; pData->xAnchor = x; pData->yAnchor = y; pData->bMovingFloater = TRUE; SetCursor(LoadCursor(NULL, IDC_SIZEALL)); SetCapture(hWnd); } else { BOOL bBitmapHasRgn = L_BitmapHasRgn(&pData->LeadBitmap) && (pData->uCombineMode == L_RGN_SET); if(bBitmapHasRgn) FreeRegionBitmaps(pData); if(nRgnType == 4) pptRegion = (LPPOINT) GlobalAllocPtr(GHND, (L_UINT32) sizeof(POINT) * MAXPOINTS); else pptRegion = (LPPOINT) GlobalAllocPtr(GHND, (L_UINT32) sizeof(POINT) * 2); if(pptRegion) { if(pData->uCombineMode == L_RGN_SET) { KillTimer(hWnd, 1); L_FreeBitmapRgn(&pData->LeadBitmap); } InvalidateRect(hWnd, NULL, FALSE); UpdateWindow(hWnd); nNextPt = 0; pptRegion[nNextPt].x = x; pptRegion[nNextPt].y = y; nNextPt++; SetCapture(hWnd); } InvalidateRect(hWnd, NULL, FALSE); } } } else if (nRgnType == 0) { pData->bMoveView = TRUE; pData->ptMovePnt.x = x; pData->ptMovePnt.y = y; SetCapture(hWnd); } UNLOCKCHILDDATA(hWnd); return; } L_VOID SetStatusColorAndPixel(HWND hWnd) { pCHILDDATA pData = LOCKCHILDDATA (hWnd); POINT TmpPoint; GetCursorPos(&TmpPoint); ScreenToClient(hWnd, &TmpPoint); if (!((TmpPoint.x >= pData->LeadBitmap.Width) || (TmpPoint.y >= pData->LeadBitmap.Height))) { wsprintf(szPos, TEXT("%d, %d"), TmpPoint.x + pData->nHScrollPos, TmpPoint.y + pData->nVScrollPos); SetDlgItemText(hStatusWnd, IDC_STATUS_MOUSEPOS, szPos); } } /*--------------------------------------------------------------------------+ | Function :Child_OnMouseMove | Desc :continues dragging the splitter | Return :void | Notes : +--------------------------------------------------------------------------*/ static L_VOID Child_OnMouseMove (HWND hWnd, L_INT x, L_INT y, L_UINT keyFlags) { pCHILDDATA pData; POINT TmpPoint; RECT TmpRect; L_INT nMin, nMax; SetStatusColorAndPixel(hWnd); pData = LOCKCHILDDATA (hWnd); TmpPoint.x = x; TmpPoint.y = y; if (L_BitmapHasRgn(&pData->LeadBitmap)) { if ((L_IsPtInBitmapRgn(&pData->LeadBitmap, TmpPoint.y + pData->nVScrollPos, TmpPoint.x + pData->nHScrollPos) || pData->bMovingFloater) && nRgnType != 0) SetCursor(LoadCursor(NULL, IDC_SIZEALL)); else SetCursor(LoadCursor(NULL, IDC_ARROW)); } if (nRgnType == 0) { GetScrollRange(hWnd, SB_HORZ, &nMin, &nMax); if (nMin < nMax) { SetCursor(LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURS11))); } else { GetScrollRange(hWnd, SB_VERT, &nMin, &nMax); if (nMin < nMax) SetCursor(LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURS11))); else SetCursor(LoadCursor(NULL, IDC_ARROW)); } } GetClientRect(hWnd, &TmpRect); IntersectRect(&TmpRect , &TmpRect, &pData->rcView); if(pData->bMoveView) { OffsetRect(&pData->rcView, -(pData->ptMovePnt.x - TmpPoint.x), -(pData->ptMovePnt.y - TmpPoint.y)); if(pData->rcView.left > 0) OffsetRect(&pData->rcView, -pData->rcView.left, 0); if(pData->rcView.right < TmpRect.right) OffsetRect(&pData->rcView, TmpRect.right - pData->rcView.right, 0); if(pData->rcView.top > 0) OffsetRect(&pData->rcView, 0, -pData->rcView.top); if(pData->rcView.bottom < TmpRect.bottom) OffsetRect(&pData->rcView, 0, TmpRect.bottom - pData->rcView.bottom); pData->nHScrollPos = min(pData->nHScrollMax, -(pData->rcView.left)); pData->nVScrollPos = min(pData->nVScrollMax, -(pData->rcView.top)); SetScrollPos(hWnd, SB_HORZ, pData->nHScrollPos, TRUE); SetScrollPos(hWnd, SB_VERT, pData->nVScrollPos, TRUE); pData->ptMovePnt = TmpPoint; InvalidateRect(hWnd, &pData->rcView, FALSE); return; } if( (GetCapture() == hWnd) && (!pData->bMagGlass)) { if( pData->bMovingFloater ) { SetCursor(LoadCursor(NULL, IDC_SIZEALL)); MoveFloater(hWnd, pData, x, y); } else { switch(nRgnType) { case 4: if(nNextPt < MAXPOINTS) { pptRegion[nNextPt].x = x; pptRegion[nNextPt].y = y; nNextPt++; } break; default: HiliteMark(hWnd, FALSE); pptRegion[1].x = x; pptRegion[1].y = y; nNextPt = 2; break; } HiliteMark(hWnd, TRUE); } } UNLOCKCHILDDATA(hWnd); } /*--------------------------------------------------------------------------+ | Function :Child_OnLButtonUp | Desc :ends the dragging of the splitter | Return :void | Notes : +--------------------------------------------------------------------------*/ static L_VOID Child_OnLButtonUp (HWND hWnd, L_INT x, L_INT y, L_UINT keyFlags) { pCHILDDATA pData; RGNXFORM XForm; L_INT nRet; RECT rc; static RECT rcRef; static POINT pt; HCURSOR hOldCursor; L_INT nOrigX, nOrigY, nOrigWidth, nOrigHeight; L_INT32 dwValue; POINT TmpRgnPt[2]; BITMAPHANDLE TempBitmap; pData = LOCKCHILDDATA(hWnd); pData->uThrPt.x = x + pData->nHScrollPos; pData->uThrPt.y = y + pData->nVScrollPos; if (pData->bLineHistogram) { ReleaseCapture(); return; } if (pData->bMoveView) { pData->bMoveView = FALSE; ReleaseCapture(); } if(GetCapture() == hWnd) { if( pData->bMovingFloater ) { L_UINT uArea; pData->bMovingFloater = FALSE; hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT)); /* get the original rectangle in bitmap coordinates */ SetRect(&rc, pData->xMoveSrc, pData->yMoveSrc, pData->xMoveSrc + pData->nMoveWidth - 1, pData->yMoveSrc + pData->nMoveHeight - 1); /* change it to display coordinates */ L_RectFromBitmap(&pData->LeadBitmap, TOP_LEFT, &rc); /* calculate the position in the bitmap based on the original position and by the distance moved. This helps reduce the approximation errors */ /* Favor the left and up move. */ /* Consider a 7:1 zoomin factor. If you move to the right by 6 pixels on the screen, you don't move in the original bitmap. But if you move 1 pixel to the left, you move 1 pixel to the left in original bitmap */ dwValue = (L_INT32)pData->deltaX * BITMAPWIDTH(&pData->LeadBitmap); if( pData->deltaX < 0 ) /* favor the moving to the left */ dwValue -= RECTWIDTH(&pData->rcView) - 1; OffsetRect(&rc, (L_INT)(dwValue/RECTWIDTH(&pData->rcView)), 0); dwValue = (L_INT32)pData->deltaY * BITMAPHEIGHT(&pData->LeadBitmap); if( pData->deltaY < 0 ) /* favor the moving to the top */ dwValue -= RECTHEIGHT(&pData->rcView) - 1; OffsetRect(&rc, 0, (L_INT)(dwValue / RECTHEIGHT(&pData->rcView))); /* now rc contains the coordinates in TOP_LEFT ViewPerspective. Change them in bitmap's ViewPerspective */ L_RectToBitmap(&pData->LeadBitmap, TOP_LEFT, &rc); /* now I can update pData->xMoveSrc and pData->yMoveSrc */ nOrigX = pData->xMoveSrc = rc.left; /* save these coordinates for the combine later on */ nOrigY = pData->yMoveSrc = rc.top; /* SafeCopyBitmapRect might change them */ nOrigWidth = pData->nMoveWidth; nOrigHeight = pData->nMoveHeight; /* save the background */ SafeCopyBitmapRect( &pData->bmSave, &pData->LeadBitmap, &pData->xMoveSrc, &pData->yMoveSrc, &pData->nMoveWidth, &pData->nMoveHeight ); pData->xSaveSrc=pData->xMoveSrc; pData->ySaveSrc=pData->yMoveSrc; /* set up the transform structure. */ XForm.uViewPerspective = pData->LeadBitmap.ViewPerspective; XForm.nXScalarNum = XForm.nXScalarDen = XForm.nYScalarNum = XForm.nYScalarDen = 1; XForm.nXOffset = nOrigX; XForm.nYOffset = nOrigY; /* set the region in the original bitmap */ L_SetBitmapRgnHandle( &pData->LeadBitmap, &XForm, pData->hrgnRegion, L_RGN_SET ); SetRect(&rc, nOrigX, nOrigY, nOrigX + nOrigWidth, nOrigY + nOrigHeight); L_RectFromBitmap(&pData->LeadBitmap, TOP_LEFT, &rc); /* copy the floater bitmap to the new position */ L_CombineBitmap( &pData->LeadBitmap, rc.left, rc.top, RECTWIDTH(&rc), RECTHEIGHT(&rc), &pData->bmFloater, 0, 0, L_SRCCOPY ); /* and we can still move */ InvalidateRect (hWnd, NULL, FALSE); UpdateWindow (hWnd); SetTimer((hWnd), 1, 100, NULL); /* outline the region without waiting for the WM_TIMER message */ OutlineBitmapRgn(hWnd, NULL); L_GetBitmapRgnArea(&pData->LeadBitmap,&uArea); if(!uArea) { KillTimer(hWnd, 1); FreeRegionBitmaps(pData); L_FreeBitmapRgn(&pData->LeadBitmap); } ReleaseCapture(); SetCursor(hOldCursor); } else { hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT)); HiliteMark(hWnd, FALSE); if(nNextPt > 1 || nRgnType == 5) { XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = BITMAPWIDTH(&pData->LeadBitmap); XForm.nYScalarNum = BITMAPHEIGHT(&pData->LeadBitmap); XForm.nXScalarDen = RECTWIDTH(&pData->rcView); XForm.nYScalarDen = RECTHEIGHT(&pData->rcView); XForm.nXOffset = -pData->rcView.left; XForm.nYOffset = -pData->rcView.top; switch(nRgnType) { case 1: TmpRgnPt[0].x = pptRegion[0].x + pData->nHScrollPos; TmpRgnPt[1].x = pptRegion[1].x + pData->nHScrollPos; TmpRgnPt[0].y = pptRegion[0].y + pData->nVScrollPos; TmpRgnPt[1].y = pptRegion[1].y + pData->nVScrollPos; SetRect(&rc, min(pptRegion[0].x, pptRegion[1].x), min(pptRegion[0].y, pptRegion[1].y), max(pptRegion[0].x, pptRegion[1].x), max(pptRegion[0].y, pptRegion[1].y)); if(pData->bNextArea) { SetRect(&rc, min(TmpRgnPt[0].x, TmpRgnPt[1].x), min(TmpRgnPt[0].y, TmpRgnPt[1].y), max(TmpRgnPt[0].x, TmpRgnPt[1].x), max(TmpRgnPt[0].y, TmpRgnPt[1].y)); if(pData->rcMarkRect.top > rc.top && pData->rcMarkRect.top < rc.bottom && pData->rcMarkRect.bottom > rc.top && pData->rcMarkRect.bottom < rc.bottom && pData->rcMarkRect.left > rc.left && pData->rcMarkRect.left < rc.right && pData->rcMarkRect.right > rc.left && pData->rcMarkRect.right < rc.right) { rcRef = rc; SetRect(&rc, min(pptRegion[0].x, pptRegion[1].x), min(pptRegion[0].y, pptRegion[1].y), max(pptRegion[0].x, pptRegion[1].x), max(pptRegion[0].y, pptRegion[1].y)); nRet = L_SetBitmapRgnRect(&pData->LeadBitmap, &XForm, &rc, L_RGN_SET); PostMessage ( pData->NextDlgWnd , WM_USER_ADDDATA, 0, (LONG)&rcRef); } else { MessageBox(hWnd, TEXT("Mark is outside the search region"),TEXT("Error"), MB_OK); if(pData->bFilled) L_SetBitmapRgnRect(&pData->LeadBitmap, NULL, &pData->rcSearchRect, L_RGN_SET); } } else nRet = L_SetBitmapRgnRect(&pData->LeadBitmap, &XForm, &rc, L_BitmapHasRgn(&(pData->LeadBitmap)) || pData->uCombineMode != L_RGN_OR ? pData->uCombineMode : L_RGN_SET); break; case 2: SetRect(&rc, min(pptRegion[0].x, pptRegion[1].x), min(pptRegion[0].y, pptRegion[1].y), max(pptRegion[0].x, pptRegion[1].x), max(pptRegion[0].y, pptRegion[1].y)); nRet = L_SetBitmapRgnRoundRect(&pData->LeadBitmap, &XForm, &rc, abs(pptRegion[0].x - pptRegion[1].x) / 4, abs(pptRegion[0].y - pptRegion[1].y) / 4, L_BitmapHasRgn(&(pData->LeadBitmap)) || pData->uCombineMode != L_RGN_OR ? pData->uCombineMode : L_RGN_SET); break; case 3: SetRect(&rc, min(pptRegion[0].x, pptRegion[1].x), min(pptRegion[0].y, pptRegion[1].y), max(pptRegion[0].x, pptRegion[1].x), max(pptRegion[0].y, pptRegion[1].y)); nRet = L_SetBitmapRgnEllipse(&pData->LeadBitmap, &XForm, &rc, L_BitmapHasRgn(&(pData->LeadBitmap)) || pData->uCombineMode != L_RGN_OR ? pData->uCombineMode : L_RGN_SET); break; case 4: nRet = L_SetBitmapRgnPolygon(&pData->LeadBitmap, &XForm, pptRegion, nNextPt, L_POLY_WINDING, L_BitmapHasRgn(&(pData->LeadBitmap)) || pData->uCombineMode != L_RGN_OR ? pData->uCombineMode : L_RGN_SET); break; case 5: if(pData->bNextAddPoint) { nRet = L_SetBitmapRgnMagicWand(&pData->LeadBitmap, x + pData->nHScrollPos, y + pData->nVScrollPos, RGB((L_UCHAR)pData->uThreshold,(L_UCHAR)pData->uThreshold,(L_UCHAR)pData->uThreshold),RGB((L_UCHAR)pData->uThreshold,(L_UCHAR)pData->uThreshold,(L_UCHAR)pData->uThreshold), L_RGN_SET); pt.x = x + pData->nHScrollPos; pt.y = y + pData->nVScrollPos; pData->ptCenter.x = pt.x; pData->ptCenter.y = pt.y; pData->bCross = TRUE; InvalidateRect(hWnd, NULL, FALSE); TransToStatusBar(&TempBitmap, &pData->LeadBitmap); if(L_IsRegMarkBitmap(&pData->LeadBitmap, pData->uMarkType, pData->uMarkMinPrc, pData->uMarkMaxPrc, pData->uMarkWidth, pData->uMarkHeight)) { L_GetBitmapRgnBoundsClip(&pData->LeadBitmap, NULL, &rcRef); PostMessage (pData->NextDlgWnd , WM_USER_ADDDATA, (LONG)&pt, (LONG)&rcRef); } else { MessageBox(hWnd, TEXT("Not a registration mark"),TEXT("Error"), MB_OK); L_FreeBitmapRgn(&pData->LeadBitmap); } TransBack(&TempBitmap, &pData->LeadBitmap, SUCCESS); } else nRet = L_SetBitmapRgnMagicWand(&pData->LeadBitmap, x + pData->nHScrollPos, y + pData->nVScrollPos, RGB((L_UCHAR)pData->uThreshold,(L_UCHAR)pData->uThreshold,(L_UCHAR)pData->uThreshold),RGB((L_UCHAR)pData->uThreshold,(L_UCHAR)pData->uThreshold,(L_UCHAR)pData->uThreshold), L_BitmapHasRgn(&(pData->LeadBitmap)) || pData->uCombineMode != L_RGN_OR ? pData->uCombineMode : L_RGN_SET); break; } if(nRet == SUCCESS) { L_GetBitmapRgnBounds(&pData->LeadBitmap, NULL, &rc); if (!rc.left && !rc.top && !rc.right && !rc.bottom) { L_FreeBitmapRgn(&pData->LeadBitmap); ReleaseCapture(); return; } if (pData->bmSave.Flags.Allocated) L_FreeBitmap(&pData->bmSave); L_CopyBitmapRect(&pData->bmSave, &pData->LeadBitmap, sizeof(BITMAPHANDLE), rc.left, rc.top, RECTWIDTH(&rc), RECTHEIGHT(&rc)); pData->xSaveSrc=rc.left; pData->ySaveSrc=rc.top; SetTimer((hWnd), 1, 100, NULL); } } InvalidateRect(hWnd, NULL, FALSE); OutlineBitmapRgn(hWnd, NULL); ReleaseCapture (); GlobalFreePtr(pptRegion); pptRegion = NULL; nNextPt = 0; if(!bRefDlg2) L_UndoList_AddBitmap (hWnd);//UNDOLIST// SetCursor(hOldCursor); } } UNLOCKCHILDDATA(hWnd); } /**************************************************************************************/ /**************************************************************************************/ static L_INT CancelRgn(HWND hWnd, L_BOOL bAddUndoBitmap) { pCHILDDATA pData; RGNXFORM XForm; RECT rcRegion; RECT rc; pData = LOCKCHILDDATA (hWnd); if (!pData) return FAILURE; /* get the region bounds */ XForm.uViewPerspective = pData->LeadBitmap.ViewPerspective; XForm.nXScalarNum = XForm.nXScalarDen = XForm.nYScalarNum = XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; L_GetBitmapRgnBounds(&pData->LeadBitmap, &XForm, &rcRegion ); pData->xMoveSrc = rcRegion.left; pData->yMoveSrc = rcRegion.top; pData->nMoveWidth = RECTWIDTH(&rcRegion); pData->nMoveHeight = RECTHEIGHT(&rcRegion); if(pData->bmSave.Flags.Allocated) { SetRect(&rc, pData->xMoveSrc, pData->yMoveSrc, pData->xMoveSrc + pData->nMoveWidth, pData->yMoveSrc + pData->nMoveHeight); L_RectFromBitmap(&pData->LeadBitmap, TOP_LEFT, &rc); L_CombineBitmap(&pData->LeadBitmap, rc.left, rc.top, RECTWIDTH(&rc), RECTHEIGHT(&rc), &pData->bmSave, 0, 0, L_SRCCOPY ); } L_FreeBitmapRgn(&pData->LeadBitmap); KillTimer(hWnd,1); if (bAddUndoBitmap) L_UndoList_AddBitmap (hWnd); //UNDOLIST// InvalidateRect(hWnd, NULL, FALSE); return SUCCESS; } /*====(StatusCallBack)============================================== Description:Track The Processes witch come from LEADTOOLS API's Syntax : L_INT L_FAR StatusCallBack (L_INT nPercent, L_VOID L_FAR *pUserData) Parameters : nPercent How Much Done From The Process. Return Value: SUCCESS Or 0. ==========================================================================*/ L_INT L_FAR L_EXPORT StatusCallBack (L_INT nPercent, L_VOID L_FAR *pUserData) { MSG msg; HWND hWndParent; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient,SendMessage); if(StatusProc.bProgress) { StatusProc.ProgressValue = nPercent; while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { if ( msg.message == WM_QUIT ) { PostQuitMessage ( 0 ); StatusProc.ProgressValue = 100; return ERROR_USER_ABORT; } else { TranslateMessage ( &msg ) ; DispatchMessage ( &msg ) ; } } if ( StatusProc.bKillProgress ) { StatusProc.bKillProgress = FALSE ; StatusProc.ProgressValue = 100 ; PostMessage ( StatusProc.DlgWnd , WM_USER_UPDATEVIEW, 0, 0 ) ; return ERROR_USER_ABORT ; } if (StatusProc.ProgressValue != 100) { Progress_SetPos(StatusProc.ProgWnd ,StatusProc.ProgressValue); if(StatusProc.bInvalidate) { InvalidateRect(hWndParent,NULL,FALSE); } } return (SUCCESS); } else { return SUCCESS ; } } LRESULT CALLBACK EditWndProc (HWND hEditWnd, L_UINT msg, WPARAM wParam, LPARAM lParam) { static WNDPROC oldWndProc; char keyAscii; TCHAR buff[5] = TEXT("\0"); int num; L_INT nCurPos, nStart; if (!oldWndProc) oldWndProc = (WNDPROC) GetWindowLong (hEditWnd, GWL_USERDATA); switch (msg) { case WM_CHAR: keyAscii = wParam; // As a first step, if the character pressed not a // function key, or not characters from 0-9, and not '+' or '-' // then return if (!(((keyAscii >= '0') && (keyAscii <= '9')) || ((keyAscii >= 0) && (keyAscii <= 29)) || (keyAscii == '-') || (keyAscii == '+'))) return 0; bDoProcess = FALSE; SendMessage(hEditWnd, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)"\0"); GetWindowText(hEditWnd, buff, 5); bDoProcess = TRUE; // Permit - and + only in the begining of the text box if ((keyAscii == '-') || (keyAscii == '+')) { if (buff[0] != '\0') { nCurPos = (L_INT) SendMessage(hEditWnd,EM_GETSEL, 0, 0); nStart = LOBYTE(nCurPos); if (nStart == 0) // Check if cursel is in the first position { if ((buff[0]=='-') || (buff[0]=='+')) return 0; else break; } else return 0; } else break; } // Permit function keys such as backspace if ((keyAscii >= 0) && (keyAscii <= 29)) break; // number should be from 0 to 100 only num = _ttoi (buff); num = abs(num); if (!((num == 10) && (keyAscii == '0'))) if (num > 10) return 0; // Permit 0-9 if ((keyAscii >= '0') && (keyAscii <= '9')) break; return 0; case WM_KEYDOWN: case WM_SYSKEYDOWN: // If user presses Up arrow or Down then this edit box value will increase // or decrease GetWindowText (hEditWnd, buff, 5); num = _ttoi (buff); if (wParam == VK_UP) num = max(-100, min(100, num+1)); else if (wParam == VK_DOWN) num = max(-100, min(100, num-1)); else break; wsprintf(buff, TEXT("%d"), num); _itot(num, buff, 10); SetWindowText (hEditWnd, buff); return 0; } return CallWindowProc (oldWndProc, hEditWnd, msg, wParam, lParam); } L_VOID Dialog_Timer(L_INT nID) { RGNXFORM XForm; pCHILDDATA pData; HDC hDC; HWND hWndParent; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); if (!pData) { MessageBox(hWndParent, TEXT("Error"), NULL, MB_OK); return; } if ((L_INT)pData->uTimerID != nID) return; if(L_BitmapHasRgn(&pData->LeadBitmap)) { hDC = GetDC(hWndParent); if (!hDC) return; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = -GetScrollPos(hWndParent, SB_HORZ); XForm.nYOffset = -GetScrollPos(hWndParent, SB_VERT); pData->uFrameType = (pData->uFrameType + 2) % 8; L_FrameBitmapRgn(hDC, &pData->LeadBitmap, &XForm, pData->uFrameType ); ReleaseDC(hWndParent, hDC); } UNLOCKCHILDDATA(hWndParent); } L_VOID SaveRefData(HWND hWnd) { L_TCHAR lpFileName[MAX_PATH]; L_TCHAR pExeFilename[MAX_PATH]; L_CHAR pNewLin[] = {'\n','\0'}; HANDLE hFile; L_CHAR pStr[80]; L_INT nStrlen, nRet, i; L_INT lpNumberOfBytesWritten; L_TCHAR L_FAR * pExePath; L_TCHAR L_FAR * pTmpStr; L_INT nNewLineSize; memset(pExeFilename, 0, MAX_PATH); memset(lpFileName, 0, MAX_PATH); nNewLineSize = strlen(pNewLin); GetModuleFileName( NULL, pExeFilename, MAX_PATH); pExePath = pExeFilename; while(TRUE) { pTmpStr = _tcschr( pExePath, '\\'); if(pTmpStr == NULL) break; else pExePath = pTmpStr + 1; } memset(pExePath, 0, (MAX_PATH - (L_INT)(pExePath - pExeFilename))); lstrcat(lpFileName, pExeFilename); lstrcat(lpFileName, TEXT("\\RefData.txt")); hFile = CreateFile(lpFileName,GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if(hFile == NULL || hFile == INVALID_HANDLE_VALUE) { MessageBox(hWnd, TEXT("Cannot create or access RefData.txt file"), TEXT("ERROR"), MB_OK); return; } memset(pStr, 0, 80); _gcvt( guNumberOfMarks, 40, pStr ); nStrlen = strlen(pStr); nRet = WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); nRet = WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); for(i = 0; i < (L_INT) guNumberOfMarks; i++) { //save search rect memset(pStr, 0, 80); _gcvt( gpSearchData[i].rcRect.top , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); memset(pStr, 0, 80); _gcvt( gpSearchData[i].rcRect.left , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); memset(pStr, 0, 80); _gcvt( gpSearchData[i].rcRect.right , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); memset(pStr, 0, 80); _gcvt( gpSearchData[i].rcRect.bottom , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); //save mark width and height memset(pStr, 0, 80); _gcvt( gpSearchData[i].uWidth , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); memset(pStr, 0, 80); _gcvt( gpSearchData[i].uHeight , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); //save mark type memset(pStr, 0, 80); _gcvt( gpSearchData[i].uType , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); //save min and max ratios memset(pStr, 0, 80); _gcvt( gpSearchData[i].uMinScale , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); memset(pStr, 0, 80); _gcvt( gpSearchData[i].uMaxScale , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); //save number of marks inside search region memset(pStr, 0, 80); _gcvt( gpSearchData[i].uSearchMarkCount , 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); //save mark reference point memset(pStr, 0, 80); _gcvt( RefCMPoints[i].x, 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); memset(pStr, 0, 80); _gcvt( RefCMPoints[i].y, 40, pStr ); nStrlen = strlen(pStr); WriteFile(hFile, pStr, nStrlen, &lpNumberOfBytesWritten, NULL); WriteFile(hFile, pNewLin, nNewLineSize , &lpNumberOfBytesWritten, NULL); } CloseHandle(hFile); MessageBox(hWnd, TEXT("Data Saved"), TEXT("SUCCESS"), MB_OK); } L_VOID LoadRefData(HWND hWnd) { L_TCHAR lpFileName[MAX_PATH]; L_TCHAR pExeFilename[MAX_PATH]; HANDLE hFile; L_CHAR pStr[80]; L_INT i, j; L_CHAR pByte; L_INT nReadByte; L_TCHAR L_FAR * pExePath; L_TCHAR L_FAR * pTmpStr; pCHILDDATA pData; L_UINT w; memset(pExeFilename, 0, MAX_PATH); memset(lpFileName, 0, MAX_PATH); GetModuleFileName( NULL, pExeFilename, MAX_PATH); pExePath = pExeFilename; while(TRUE) { pTmpStr = _tcschr( pExePath, '\\'); if(pTmpStr == NULL) break; else pExePath = pTmpStr + 1; } memset(pExePath, 0, (MAX_PATH - (L_INT)(pExePath - pExeFilename))); lstrcat(lpFileName, pExeFilename); lstrcat(lpFileName, TEXT("\\RefData.txt")); hFile = CreateFile(lpFileName,GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if(hFile == NULL || hFile == INVALID_HANDLE_VALUE) { MessageBox(hWnd, TEXT("Cannot access RefData.txt file"), TEXT("ERROR"), MB_OK); return; } ////////////////////////////////// ////////For registration marks ////////////////////////////////// ////////////Start if(gpSearchData) { for(i = 0; i < (L_INT)guNumberOfMarks; i++) { if(gpSearchData[i].pMarkDetectedPoints) free(gpSearchData[i].pMarkDetectedPoints); } free(gpSearchData); gpSearchData = NULL; } ////////////////////////////////// ////////////End ////////////////////////////////// i = 0; memset(pStr, 0, 80); while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return; } guNumberOfMarks = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); ////////////////////////////////// ////////For registration marks ////////////////////////////////// ////////////Start gpSearchData = (LPSEARCHMARKS)malloc(guNumberOfMarks * sizeof(SEARCHMARKS)); for(w = 0; w < guNumberOfMarks; w++) gpSearchData[w].uStructSize = sizeof(SEARCHMARKS); ////////////////////////////////// ////////////End ////////////////////////////////// for(j = 0; j < (L_INT) guNumberOfMarks; j++) { //read search rect while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].rcRect.top = (L_INT)atof( pStr ); i = 0; memset(pStr, 0, 80); while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return; } gpSearchData[j].rcRect.left = (L_INT)atof( pStr ); i = 0; memset(pStr, 0, 80); while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].rcRect.right = (L_INT)atof( pStr ); i = 0; memset(pStr, 0, 80); while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].rcRect.bottom = (L_INT)atof( pStr ); i = 0; memset(pStr, 0, 80); //read mark width and height while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].uWidth = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].uHeight = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); //read mark type while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].uType = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); //save min and max ratios while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].uMinScale = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].uMaxScale = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); //save number of marks inside search region while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } gpSearchData[j].uSearchMarkCount = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); gpSearchData[j].pMarkDetectedPoints = (POINT L_FAR *) malloc(sizeof(POINT) * gpSearchData[i].uSearchMarkCount); //read mark reference point while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } RefCMPoints[j].x = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); while(TRUE) { ReadFile(hFile, &pByte, 1, &nReadByte, NULL); if(pByte == '\n') break; if(nReadByte == 0) break; pStr[i] = pByte; i++; if(i > 80) return ; } RefCMPoints[j].y = (L_UINT)atof( pStr ); i = 0; memset(pStr, 0, 80); } CloseHandle(hFile); MessageBox(hWnd, TEXT("Data Loaded"), TEXT("SUCCESS"), MB_OK); pData = LOCKCHILDDATA (hWnd); bRefDone = TRUE; pData->bDetected = FALSE; pData->bApplyTrans = FALSE; } /*====(ProgressBarProc)==================================================== Description: Processes messages for the Progress Bar. Syntax : LRESULT CALLBACK L_EXPORT ProgressBarProc (HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hWnd Window handle. uMessage Windows uMessage to process. wParam Windows word parameter. lParam Windows long parameter. Return Value: 0 WM_PAINT uMessage processed. DefWindowProc A different uMessage processed. ==========================================================================*/ LRESULT CALLBACK L_EXPORT ProgressBarProc (HWND hWnd, L_UINT uMessage, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; L_TCHAR szPercent[5]; RECT rcClient; RECT rcClip; L_INT nLen; L_INT xCenter; HRGN hRgn; switch (uMessage) { case WM_PAINT: BeginPaint (hWnd, &ps); if (StatusProc.ProgressValue > 100) break; SaveDC(ps.hdc); GetClientRect (hWnd, &rcClient); nLen = wsprintf ((LPTSTR) szPercent, TEXT("%d%%"), StatusProc.ProgressValue); 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(StatusProc.ProgressValue, 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, uMessage, wParam, lParam)); } /*====(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; StatusProc.ProgressValue = nPercent; hWnd = GetDlgItem (hStatusWnd, IDC_STATUS_PROG); 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 uMessage, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hDlg Window handle. uMessage Windows uMessage to process. wParam Windows word parameter. lParam Windows long parameter. Return Value: TRUE WM_INITDIALOG or WM_PAINT uMessage processed. FALSE A different uMessage processed. ==========================================================================*/ L_BOOL CALLBACK L_EXPORT StatusBarProc (HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam) { static int x = 0; RECT rcRect; POINT pt; HMENU hColorMenu; HBRUSH hBrush; HDC hDC, hDC1; PAINTSTRUCT ps; switch(uMessage) { case WM_INITDIALOG: hStatusWnd = hDlg; return TRUE; case WM_PAINT: hDC = BeginPaint(hStatusWnd, &ps); EndPaint(hStatusWnd, &ps); if(GetClientRect(GetDlgItem(hDlg, IDC_STATUS_INK), &rcRect)) { hDC1 = GetDC(GetDlgItem(hDlg, IDC_STATUS_INK)); hBrush = CreateSolidBrush(crColor); FillRect(hDC1, &rcRect, hBrush); DeleteBrush(hBrush); ReleaseDC(GetDlgItem(hDlg, IDC_STATUS_INK), hDC1); } return TRUE; case WM_COMMAND: SetFocus(GetDlgItem(hDlg, IDC_STATUS_INK)); GetCursorPos(&pt); hColorMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CSP)); CheckMenuItem(hColorMenu, IDM_COLORSPACEPOPUP_RGB + uColorSpace, MF_CHECKED); TrackPopupMenu(GetSubMenu(hColorMenu, 0), 0, pt.x, pt.y, 0, FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage), NULL); break; case WM_LBUTTONUP: GetClientRect(GetDlgItem(hStatusWnd, IDC_STATUS_COLOR), &rcRect); pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); ClientToScreen(hStatusWnd, &pt); ScreenToClient(GetDlgItem(hStatusWnd, IDC_STATUS_COLOR), &pt); if (PtInRect(&rcRect, pt)) { hColorMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_NUMORDER)); ClientToScreen(GetDlgItem(hStatusWnd, IDC_STATUS_COLOR), &pt); CheckMenuItem(hColorMenu, IDC_STATUS_HEX + IsDecimal, MF_CHECKED); TrackPopupMenu(GetSubMenu(hColorMenu, 0), 0, pt.x, pt.y, 0, FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage), NULL); } return TRUE; } return (FALSE); } /*====(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(LPTSTR pTitle, pBITMAPHANDLE pBitmap, LPTSTR szPos, LPTSTR szColor) { L_TCHAR szText[80]; L_TCHAR L_FAR * p; HDC hDC; RECT rcRect; L_TCHAR szColorSpace[8][6] = {TEXT("RGB"), TEXT("HSV"), TEXT("HLS"), TEXT("XYZ"), TEXT("YCrCb"), TEXT("YUV"), TEXT("LAB"), TEXT("CMY")}; if(pTitle) { wsprintf(szText, TEXT("%u X %u"), pBitmap->Width, pBitmap->Height); SetDlgItemText(hStatusWnd, IDC_STATUS_DIMENSION, szText); wsprintf(szText, TEXT("%u BPP"), pBitmap->BitsPerPixel); SetDlgItemText(hStatusWnd, IDC_STATUS_BITSPIXEL, szText); 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 < 100000) wsprintf(szText, TEXT("%lu bytes, %s"), pBitmap->Size, p); else { if(pBitmap->Size < 10000000) wsprintf(szText, TEXT("%lu KB, %s"), pBitmap->Size >> 10, p); else // > 100MB wsprintf(szText, TEXT("%lu MB, %s"), pBitmap->Size >> 20, p); } SetDlgItemText(hStatusWnd, IDC_STATUS_MEMORY, szText); wsprintf(szText, L_IsGrayScaleBitmap(pBitmap) ? TEXT("GrayScale Bitmap") : TEXT("Colored Bitmap")); SetDlgItemText(hStatusWnd, IDC_STATUS_REGIONBOUNDS, szText); SetDlgItemText(hStatusWnd, IDC_STATUS_SPC, szColorSpace[uColorSpace]); SetDlgItemText(hStatusWnd, IDC_STATUS_COLOR, szColor); SetDlgItemText(hStatusWnd, IDC_STATUS_MOUSEPOS, szPos); } else { SetDlgItemText(hStatusWnd, IDC_STATUS_DIMENSION, TEXT("")); SetDlgItemText(hStatusWnd, IDC_STATUS_BITSPIXEL, TEXT("")); SetDlgItemText(hStatusWnd, IDC_STATUS_MEMORY, TEXT("")); SetDlgItemText(hStatusWnd, IDC_STATUS_REGIONBOUNDS, TEXT("")); SetDlgItemText(hStatusWnd, IDC_STATUS_COLOR, TEXT("")); SetDlgItemText(hStatusWnd, IDC_STATUS_MOUSEPOS, TEXT("")); SetDlgItemText(hStatusWnd, IDC_STATUS_SPC, TEXT("")); GetClientRect(GetDlgItem(hStatusWnd, IDC_STATUS_INK), &rcRect); hDC = GetDC(GetDlgItem(hStatusWnd, IDC_STATUS_INK)); FillRect(hDC, &rcRect, (HBRUSH)COLOR_WINDOW); ReleaseDC(GetDlgItem(hStatusWnd, IDC_STATUS_INK), hDC); } return; } /*====(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 StatusBarProgressCallBack (L_INT nPercent, L_VOID L_FAR * pUserData) { MSG msg; while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { if ((msg.message == WM_CHAR) && (msg.wParam == 27)) { return ERROR_USER_ABORT; } else { TranslateMessage (&msg); if (msg.message == WM_PAINT) DispatchMessage (&msg); } } SetStatusBarProgress(nPercent); return (SUCCESS); } L_VOID TransToStatusBar(pBITMAPHANDLE pTempBitmap, pBITMAPHANDLE pLeadBitmap) { STATUSCALLBACK lpfnOldStatus; if (pTempBitmap->Flags.Allocated) L_FreeBitmap(pTempBitmap); L_CopyBitmap(pTempBitmap, pLeadBitmap, sizeof(BITMAPHANDLE)); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_PROG), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_BITSPIXEL), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_INK), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_COLOR), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_DIMENSION), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_MEMORY), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_MOUSEPOS), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_REGIONBOUNDS), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_SPC), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_ESCAPE), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_PROG), SW_SHOW); lpfnOldStatus = MakeProcInstance (StatusBarProgressCallBack , hInst); L_SetStatusCallBack (lpfnOldStatus, NULL, NULL, NULL); nStatusPercent = 0; } L_VOID TransBack(pBITMAPHANDLE pTempBitmap, pBITMAPHANDLE pLeadBitmap, L_INT nRet) { STATUSCALLBACK lpfnOldStatus ; if (nRet != SUCCESS) { L_FreeBitmap(pLeadBitmap); L_CopyBitmap(pLeadBitmap, pTempBitmap, sizeof(BITMAPHANDLE)); } L_FreeBitmap(pTempBitmap); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_BITSPIXEL), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_INK), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_COLOR), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_DIMENSION), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_MEMORY), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_MOUSEPOS), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_REGIONBOUNDS), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_SPC), SW_SHOW); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_ESCAPE), SW_HIDE); ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_PROG), SW_HIDE); lpfnOldStatus = MakeProcInstance (StatusCallBack, hInst); L_SetStatusCallBack (lpfnOldStatus, NULL, NULL, NULL); StatusProc.bProgress = FALSE; StatusProc.bKillProgress = TRUE; StatusProc.ProgressValue = 100; ShowWindow(GetDlgItem(hStatusWnd, IDC_STATUS_PROG), SW_HIDE); } L_VOID MoveDialogToMiddle(HWND hWnd) { RECT rcDlgPos; RECT rcDlgSize; POINT ptPoint; GetWindowRect(hWndClient, &rcDlgPos); GetWindowRect(hWnd, &rcDlgSize); ptPoint.x = (RECTWIDTH(&rcDlgPos) >> 1) - (RECTWIDTH(&rcDlgSize) >> 1); ptPoint.y = (RECTHEIGHT(&rcDlgPos) >> 1) - (RECTHEIGHT(&rcDlgSize) >> 1); ClientToScreen(hWndFrame, &ptPoint); MoveWindow(hWnd, ptPoint.x , ptPoint.y, RECTWIDTH(&rcDlgSize), RECTHEIGHT(&rcDlgSize), TRUE); }