/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 14 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2004 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #include "ImgPF.h" static L_BOOL PlaneDlg_OnCommand (HWND hWnd, L_INT nID, HWND hWndCtl, L_UINT uCodeNotify); static L_BOOL PlaneDlg_OnHScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos); static L_BOOL PlaneDlg_OnInitDialog (HWND hWnd, HWND hWndFocus, LPARAM lParam); static L_BOOL PlaneDlg_OnPaint (HWND hWnd); static L_VOID PlaneDlg_OnTimer (HWND hWnd, L_INT nID); static L_VOID L_ApplyFilter (HWND hWnd); L_BOOL CALLBACK PlaneDlgProc (HWND hWnd, L_UINT uMessage, WPARAM wParam, LPARAM lParam) { switch(uMessage) { HANDLE_MSG (hWnd, WM_COMMAND, PlaneDlg_OnCommand); HANDLE_MSG (hWnd, WM_INITDIALOG, PlaneDlg_OnInitDialog); HANDLE_MSG (hWnd, WM_HSCROLL, PlaneDlg_OnHScroll); HANDLE_MSG (hWnd, WM_PAINT, PlaneDlg_OnPaint); HANDLE_MSG (hWnd, WM_TIMER, PlaneDlg_OnTimer); case WM_USER_UPDATEVIEW: StatusProc.ProgressValue = 100; L_ApplyFilter(hWnd); break; } return FALSE; } static LRESULT CALLBACK Mouse(L_INT nCode, WPARAM wParam, LPARAM lParam) { LPPLNDLGDATA pPlnDlgData; LPMOUSEHOOKSTRUCT pMouseHook; HWND hWndParent; pCHILDDATA pData; RECT rcRect; POINT TmpPoint; DWORD dwStyle; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient,SendMessage); pData = LOCKCHILDDATA (hWndParent); pPlnDlgData = (LPPLNDLGDATA)GetWindowLong(hGlobalWnd, GWL_USERDATA); pMouseHook = (LPMOUSEHOOKSTRUCT)lParam; GetWindowRect(hGlobalWnd, &rcRect); if (PtInRect(&rcRect, pMouseHook->pt)) return 0; switch(LOWORD(wParam)) { case WM_NCMOUSEMOVE: TmpPoint = pMouseHook->pt; if (PtInRect(&rcRect, TmpPoint)) break; if (pPlnDlgData->bPushed) { PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_CROSS); } else { dwStyle = GetWindowLong (hWndParent, GWL_STYLE); if ((WS_VSCROLL & dwStyle) || (WS_HSCROLL & dwStyle)) PostMessage(hWndParent, WM_USER_CHANGECURSOR, (WPARAM)hInst, (LONG)MAKEINTRESOURCE(IDC_CURS11)); ScreenToClient(hWndParent, &pMouseHook->pt); GetClientRect(hGlobalWnd, &rcRect); if (!PtInRect(&rcRect, pMouseHook->pt)) SendMessage((hWndParent), WM_MOUSEMOVE, wParam, MAKELPARAM((pMouseHook->pt.x), (pMouseHook->pt.y))); } break; case WM_NCLBUTTONDOWN: TmpPoint = pMouseHook->pt; if (PtInRect(&rcRect, TmpPoint)) break; if (pPlnDlgData->bPushed) { PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_CROSS); ScreenToClient(hWndParent, &pMouseHook->pt); GetClientRect(hWndParent, &rcRect); if (PtInRect(&pData->rcView, pMouseHook->pt)) { if (L_BitmapHasRgn(&pData->LeadBitmap)) { L_GetBitmapRgnBounds(&pData->LeadBitmap, NULL, &rcRect); TmpPoint.x = pMouseHook->pt.x + pData->nHScrollPos; TmpPoint.y = pMouseHook->pt.y + pData->nVScrollPos; if (!PtInRect(&rcRect, TmpPoint)) return CallNextHookEx(pPlnDlgData->hMouseHook , nCode, wParam, lParam); } pData->ptCenter.x = pPlnDlgData->ptCenterPoint.x = pMouseHook->pt.x + pData->nHScrollPos; pData->ptCenter.y = pPlnDlgData->ptCenterPoint.y = pMouseHook->pt.y + pData->nVScrollPos; SetDlgItemInt(hGlobalWnd, IDC_PLN_XCT_EDT, pPlnDlgData->ptCenterPoint.x, TRUE); SetDlgItemInt(hGlobalWnd, IDC_PLN_YCT_EDT, pPlnDlgData->ptCenterPoint.y, TRUE); InvalidateRect(hWndParent, NULL, FALSE); L_ApplyFilter(hGlobalWnd); PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_CROSS); } else { PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_ARROW); } } else { dwStyle = GetWindowLong (hWndParent, GWL_STYLE); if ((WS_VSCROLL & dwStyle) || (WS_HSCROLL & dwStyle)) PostMessage(hWndParent, WM_USER_CHANGECURSOR, (WPARAM)hInst, (LONG)MAKEINTRESOURCE(IDC_CURS11)); ScreenToClient(hWndParent, &pMouseHook->pt); SendMessage(hWndParent, WM_LBUTTONDOWN, wParam, MAKELPARAM((pMouseHook->pt.x), (pMouseHook->pt.y))); } break; case WM_NCLBUTTONUP: TmpPoint = pMouseHook->pt; if (PtInRect(&rcRect, TmpPoint)) break; if (pPlnDlgData->bPushed) { PostMessage (hWndParent, WM_USER_CHANGECURSOR, 0, (LONG)IDC_CROSS); } else { dwStyle = GetWindowLong (hWndParent, GWL_STYLE); if ((WS_VSCROLL & dwStyle) || (WS_HSCROLL & dwStyle)) PostMessage(hWndParent, WM_USER_CHANGECURSOR, (WPARAM)hInst, (LONG)MAKEINTRESOURCE(IDC_CURS11)); ScreenToClient(hWndParent, &pMouseHook->pt); GetClientRect(hGlobalWnd, &rcRect); if (!PtInRect(&rcRect, pMouseHook->pt)) SendMessage(hWndParent, WM_LBUTTONUP, wParam, MAKELPARAM((pMouseHook->pt.x), (pMouseHook->pt.y))); } break; } if (pPlnDlgData) { if (LOWORD(wParam) >= WM_NCMOUSEMOVE && LOWORD(wParam) <= WM_NCMBUTTONDBLCLK) return TRUE; else return CallNextHookEx(pPlnDlgData->hMouseHook , nCode, wParam, lParam); } else return FALSE; } static L_BOOL PlaneDlg_OnInitDialog (HWND hWnd, HWND hWndFocus, LPARAM lParam) { LPPLNDLGDATA pPlnDlgData; HWND hWndParent; pCHILDDATA pData; L_INT nRangeMax[] = { 0, 0, 100, 400, 360, 0, 0, 0, 100, 100, 500}; L_INT nRangeMin[] = { 1, 1, -1, 1, -360, 0, 0, 0, 0, 0, 1}; L_INT nPosInit [] = { 0, 0, -1, 100, 0, 0, 0, 0, 0, 100, 50}; L_INT nSlider; RECT rcRgn; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); pPlnDlgData = (LPPLNDLGDATA)lParam; hGlobalWnd = hWnd; pData->bCross = TRUE; MoveDialogToMiddle(hWnd); SetWindowLong(hWnd, GWL_USERDATA, (LONG)pPlnDlgData); StatusProc.bProgress = TRUE; StatusProc.bInvalidate = FALSE; StatusProc.bEnd = FALSE; StatusProc.DlgWnd = hWnd; StatusProc.ProgressValue = 100; StatusProc.ProgWnd = GetDlgItem(hWnd, IDC_PLN_PRG); Progress_SetRange(StatusProc.ProgWnd, 0, 100); Progress_SetPos(StatusProc.ProgWnd, 0); //MEMDISK...// MemorizeAndCopyBitmap (hWndParent, &pPlnDlgData->Bitmap); L_CopyBitmap(&pPlnDlgData->Bitmap, &pData->LeadBitmap, sizeof(BITMAPHANDLE)); L_GetBitmapRgnBoundsClip(&pPlnDlgData->Bitmap, NULL, &rcRgn); pPlnDlgData->nSlideNum = 11; pPlnDlgData->nEdtBaseID = IDC_PLN_OFS_EDT; pPlnDlgData->nSldBaseID = IDC_PLN_OFS_SLD; nRangeMax[0] = max((rcRgn.bottom - rcRgn.top), (rcRgn.right - rcRgn.left)); nRangeMax[1] = max((rcRgn.bottom - rcRgn.top), (rcRgn.right - rcRgn.left)); nRangeMax[5] = 3 * (rcRgn.right - rcRgn.left) / 2 + rcRgn.left; nRangeMin[5] = -3 * (rcRgn.right - rcRgn.left) / 2 + rcRgn.left; nRangeMax[6] = 3 * (rcRgn.bottom - rcRgn.top) / 2 + rcRgn.top; nRangeMin[6] = -3 * (rcRgn.bottom - rcRgn.top) / 2 + rcRgn.top; nRangeMax[7] = max((rcRgn.bottom - rcRgn.top), (rcRgn.right - rcRgn.left)); nPosInit[0] = min((rcRgn.bottom - rcRgn.top), (rcRgn.right - rcRgn.left))/2; nPosInit[1] = min((rcRgn.bottom - rcRgn.top), (rcRgn.right - rcRgn.left))/2; nPosInit[5] = (rcRgn.right + rcRgn.left) / 2; nPosInit[6] = (rcRgn.bottom + rcRgn.top) / 2; pPlnDlgData->uPlaneOffset = nPosInit[0]; pPlnDlgData->nDistance = nPosInit[1]; pPlnDlgData->nRepeat = nPosInit[2]; pPlnDlgData->uStretch = nPosInit[3]; pPlnDlgData->nPyramidAngle = nPosInit[4]; pPlnDlgData->ptCenterPoint.x = pData->ptCenter.x = nPosInit[5]; pPlnDlgData->ptCenterPoint.y = pData->ptCenter.y = nPosInit[6]; pPlnDlgData->uZValue = nPosInit[7]; pPlnDlgData->uStartBright = nPosInit[8]; pPlnDlgData->uEndBright = nPosInit[9]; pPlnDlgData->uBrightLength = nPosInit[10]; pPlnDlgData->crFill = RGB(255, 255, 255); pPlnDlgData->crBright = RGB(255, 255, 255); pPlnDlgData->uFlags = PLANE_UP | PLANE_DOWN | PLANE_RIGHT | PLANE_LEFT ; pPlnDlgData->uColorFlag = PLANE_FILL_CLR; for (nSlider = 0; nSlider < pPlnDlgData->nSlideNum; nSlider++) { Trackbar_SetTheRange(GetDlgItem(hWnd, pPlnDlgData->nSldBaseID + nSlider), TRUE, nRangeMin[nSlider], nRangeMax[nSlider]); SetDlgItemInt(hWnd, pPlnDlgData->nEdtBaseID + nSlider, nPosInit[nSlider], TRUE); SetNumericEditBox(GetDlgItem(hWnd, pPlnDlgData->nEdtBaseID + nSlider), nRangeMin[nSlider], nRangeMax[nSlider], 1, 0, 0); } Button_SetCheck(GetDlgItem(hWnd, IDC_PLN_COL_RAD ), TRUE); Button_SetCheck(GetDlgItem(hWnd, IDC_PLN_UP_CHK ), TRUE); Button_SetCheck(GetDlgItem(hWnd, IDC_PLN_DOWN_CHK), TRUE); Button_SetCheck(GetDlgItem(hWnd, IDC_PLN_LEFT_CHK), TRUE); Button_SetCheck(GetDlgItem(hWnd, IDC_PLN_RIGT_CHK), TRUE); pPlnDlgData->bPushed = FALSE; pPlnDlgData->hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_MOUSE)); SendMessage(GetDlgItem(hWnd, IDC_PLN_POS_BUT), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(HICON)pPlnDlgData->hIcon); pPlnDlgData->hMouseHook = SetWindowsHookEx(WH_MOUSE, Mouse, hInst, GetCurrentThreadId()); pData->uTimerID = SetTimer(hWnd, 1, 100, NULL); UpdateWindow(hWnd); ShowWindow (hWnd, SW_SHOW); L_ApplyFilter(hWnd); return ( TRUE ); } static L_VOID PlaneDlg_OnTimer (HWND hWnd, L_INT nID) { Dialog_Timer(nID); } static L_BOOL PlaneDlg_OnPaint(HWND hWnd) { HDC hDC; PAINTSTRUCT ps; RECT rcRect; HBRUSH hBrush; LPPLNDLGDATA pPlnDlgData; pPlnDlgData = (LPPLNDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); GetClientRect(GetDlgItem(hWnd , IDC_PLN_COL_TXT), &rcRect); hDC = BeginPaint(GetDlgItem(hWnd, IDC_PLN_COL_TXT), &ps); hBrush = CreateSolidBrush(pPlnDlgData->crFill); FillRect(hDC, &rcRect, hBrush); DeleteObject (hBrush); EndPaint(GetDlgItem(hWnd, IDC_PLN_COL_TXT), &ps); GetClientRect(GetDlgItem(hWnd , IDC_PLN_BRG_COL_TXT), &rcRect); hDC = BeginPaint(GetDlgItem(hWnd, IDC_PLN_BRG_COL_TXT), &ps); hBrush = CreateSolidBrush(pPlnDlgData->crBright); FillRect(hDC, &rcRect, hBrush); DeleteObject (hBrush); EndPaint(GetDlgItem(hWnd, IDC_PLN_BRG_COL_TXT), &ps); return FALSE; } static L_BOOL PlaneDlg_OnCommand (HWND hWnd, L_INT nID, HWND hWndCtl, L_UINT uCodeNotify) { LPPLNDLGDATA pPlnDlgData; HWND hWndParent; L_INT nRangeMax[] = { 0, 0, 100, 360, 400, 360 , 0, 0, 0, 100, 100, 500}; L_INT nRangeMin[] = { 1, 1, -1 , -360, 1 , -360, 0, 0, 0, 0 , 0 , 1 }; pCHILDDATA pData; L_INT nValue; L_INT nIndex; COLORREF crColor; RECT rcRgn; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); pPlnDlgData = (LPPLNDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); L_GetBitmapRgnBoundsClip(&pPlnDlgData->Bitmap, NULL, &rcRgn); nRangeMax[0] = max((rcRgn.bottom - rcRgn.top), (rcRgn.right - rcRgn.left)); nRangeMax[1] = max((rcRgn.bottom - rcRgn.top), (rcRgn.right - rcRgn.left)); nRangeMax[6] = 3 * (rcRgn.right - rcRgn.left) / 2 + rcRgn.left; nRangeMin[6] = -3 * (rcRgn.right - rcRgn.left) / 2 + rcRgn.left; nRangeMax[7] = 3 * (rcRgn.bottom - rcRgn.top) / 2 + rcRgn.top; nRangeMin[7] = -3 * (rcRgn.bottom - rcRgn.top) / 2 + rcRgn.top; nRangeMax[8] = max((rcRgn.bottom - rcRgn.top), (rcRgn.right - rcRgn.left)); if (nID >= pPlnDlgData->nEdtBaseID && nID < (pPlnDlgData->nEdtBaseID + pPlnDlgData->nSlideNum)) { if(uCodeNotify == EN_CHANGE) { nValue = GetDlgItemInt(hWnd, nID, NULL, TRUE); nIndex = nID - pPlnDlgData->nEdtBaseID; Trackbar_SetPos(GetDlgItem(hWnd, pPlnDlgData->nSlideNum + nID), TRUE, nValue); switch (nIndex) { case 0: if(pPlnDlgData->uPlaneOffset == (L_UINT)nValue) return TRUE; pPlnDlgData->uPlaneOffset = nValue; break; case 1: if(pPlnDlgData->nDistance == nValue) return TRUE; pPlnDlgData->nDistance = nValue; break; case 2: if(pPlnDlgData->nRepeat == nValue) return TRUE; pPlnDlgData->nRepeat = nValue; break; case 3: if(pPlnDlgData->uStretch == (L_UINT)nValue) return TRUE; pPlnDlgData->uStretch = nValue; break; case 4: if(pPlnDlgData->nPyramidAngle == nValue) return TRUE; pPlnDlgData->nPyramidAngle = nValue; break; case 5: if(pPlnDlgData->ptCenterPoint.x == nValue) return TRUE; pPlnDlgData->ptCenterPoint.x = nValue; pData->ptCenter.x = nValue; break; case 6: if(pPlnDlgData->ptCenterPoint.y == nValue) return TRUE; pPlnDlgData->ptCenterPoint.y = nValue; pData->ptCenter.y = nValue; break; case 7: if(pPlnDlgData->uZValue == (L_UINT)nValue) return TRUE; pPlnDlgData->uZValue = nValue; break; case 8: if(pPlnDlgData->uStartBright == (L_UINT)nValue) return TRUE; pPlnDlgData->uStartBright = nValue; break; case 9: if(pPlnDlgData->uEndBright == (L_UINT)nValue) return TRUE; pPlnDlgData->uEndBright = nValue; break; case 10: if(pPlnDlgData->uBrightLength == (L_UINT)nValue) return TRUE; pPlnDlgData->uBrightLength = nValue; break; } L_ApplyFilter(hWnd); } } switch (nID) { case IDC_PLN_POS_BUT: pPlnDlgData->bPushed = Button_GetCheck(hWndCtl); break; case IDC_PLN_LEFT_CHK: case IDC_PLN_RIGT_CHK: case IDC_PLN_UP_CHK: case IDC_PLN_DOWN_CHK: pPlnDlgData->uFlags ^= 1 << (4 + (nID - IDC_PLN_LEFT_CHK)); L_ApplyFilter(hWnd); break; case IDC_PLN_COL_BUT: crColor = pPlnDlgData->crFill; pPlnDlgData->crFill = ShowColorDialog(hWnd, crColor); if (crColor != pPlnDlgData->crFill) { InvalidateRect(hWnd, NULL, FALSE); L_ApplyFilter(hWnd); } break; case IDC_PLN_BRG_COL_BUT: crColor = pPlnDlgData->crBright; pPlnDlgData->crBright = ShowColorDialog(hWnd, crColor); if (crColor != pPlnDlgData->crBright) { InvalidateRect(hWnd, NULL, FALSE); L_ApplyFilter(hWnd); } break; case IDC_PLN_NOC_RAD: EnableWindow(GetDlgItem(hWnd, IDC_PLN_COL_BUT), FALSE); pPlnDlgData->uColorFlag = PLANE_NO_CHG; L_ApplyFilter(hWnd); break; case IDC_PLN_COL_RAD: EnableWindow(GetDlgItem(hWnd, IDC_PLN_COL_BUT), TRUE); pPlnDlgData->uColorFlag = PLANE_FILL_CLR; L_ApplyFilter(hWnd); break; case IDCANCEL: pData->bCross = FALSE; StatusProc.bProgress = FALSE; StatusProc.bKillProgress = TRUE ; StatusProc.ProgressValue = 100 ; UnhookWindowsHookEx(pPlnDlgData->hMouseHook); DestroyIcon(pPlnDlgData->hIcon); EndDialog(hWnd, FALSE); break; case IDOK: pData->bCross = FALSE; ShowStatusWindow(FALSE); StatusProc.bStillWork = TRUE; StatusProc.bInvalidate = TRUE; StatusProc.bEnd = TRUE; UnhookWindowsHookEx(pPlnDlgData->hMouseHook); DestroyIcon(pPlnDlgData->hIcon); EndDialog(hWnd, TRUE); break; } return TRUE; } static L_BOOL PlaneDlg_OnHScroll (HWND hWnd, HWND hWndCtl, L_UINT nCode, L_INT nPos) { LPPLNDLGDATA pPlnDlgData = (LPPLNDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); SetDlgItemInt(hWnd, GetDlgCtrlID(hWndCtl) - pPlnDlgData->nSlideNum, Trackbar_GetPos(hWndCtl), TRUE); return TRUE; } static L_VOID L_ApplyFilter(HWND hWnd) { pCHILDDATA pData; L_INT nRet = 0; HWND hWndParent; LPPLNDLGDATA pPlnDlgData; if ( 100 != StatusProc.ProgressValue ) { StatusProc.bKillProgress = TRUE ; return ; } pPlnDlgData = (LPPLNDLGDATA) GetWindowLong(hWnd, GWL_USERDATA); hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); FreeMemorizedBitmap (hWndParent); //MEMDISK// L_CopyBitmap(&pData->LeadBitmap, &pPlnDlgData->Bitmap, sizeof(BITMAPHANDLE)); nRet = L_PlaneBitmap(&pData->LeadBitmap, pPlnDlgData->ptCenterPoint, pPlnDlgData->uZValue, pPlnDlgData->nDistance, pPlnDlgData->uPlaneOffset, pPlnDlgData->nRepeat, pPlnDlgData->nPyramidAngle, pPlnDlgData->uStretch, pPlnDlgData->uStartBright, pPlnDlgData->uEndBright, pPlnDlgData->uBrightLength, pPlnDlgData->crBright, pPlnDlgData->crFill, pPlnDlgData->uFlags | pPlnDlgData->uColorFlag); if(nRet == SUCCESS) { InvalidateRect(hWndParent, NULL, FALSE); StatusProc.ProgressValue = 100; Progress_SetPos(StatusProc.ProgWnd , 0); if(StatusProc.bEnd) { StatusProc.bProgress = FALSE; StatusProc.bKillProgress = TRUE ; } } }