/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[] []*/ /*[] draw.c []*/ /*[]=====================================================================[]*/ #include "draw.h" #include "defines.h" #include "windows.h" #include "extern.h" L_VOID ShowDicomImage() { ShowWindow(hTreeKey, SW_HIDE); ShowWindow(hButtonImage, SW_SHOW); InvalidateRect(hButtonImage, NULL, TRUE); } L_VOID HideDicomImage() { ShowWindow(hTreeKey, SW_SHOW); ShowWindow(hButtonImage, SW_HIDE); } L_VOID MatchAspectRatio (LPRECT pRect, L_INT nImageWidth, L_INT nImageHeight) { L_INT cxRect, cyRect; L_INT nRectWidth, nRectHeight; nRectWidth = pRect->right - pRect->left; nRectHeight = pRect->bottom - pRect->top; cyRect = nRectHeight; cxRect = MulDiv (cyRect, nImageWidth, nImageHeight); if (cxRect > nRectWidth) { cxRect = nRectWidth; cyRect = MulDiv (cxRect, nImageHeight, nImageWidth); pRect->top = (pRect->bottom - pRect->top - cyRect) / 2; } else { pRect->left = (pRect->right - pRect->left - cxRect) / 2; } pRect->bottom = pRect->top + cyRect; pRect->right = pRect->left + cxRect; } L_VOID PaintBitmap(HDC hDC, LPRECT pDest, pBITMAPHANDLE pBitmap) { HPALETTE hOldPal; HBRUSH hBrush, hOldBrush; HPEN hPen, hOldPen; RECT rcCenter; L_BOOL bFirstPaint; hBrush = GetStockObject(GRAY_BRUSH); hPen = GetStockObject(BLACK_PEN); hOldBrush = SelectObject(hDC, hBrush); hOldPen = SelectObject(hDC, hPen); //Get a destination rectangle preserving the aspect ratio of the image CopyRect(&rcCenter, pDest); MatchAspectRatio (&rcCenter, BITMAPWIDTH(pBitmap), BITMAPHEIGHT(pBitmap)); bFirstPaint = hPaletteGlobal == NULL; if (hPaletteGlobal == NULL) { hPaletteGlobal = L_CreatePaintPalette(hDC, pBitmap); } if(hPaletteGlobal) { //If first paint, releaize palette as foreground palette hOldPal = SelectPalette(hDC, hPaletteGlobal, !bFirstPaint); RealizePalette(hDC); } L_PaintDC(hDC, pBitmap, NULL, NULL, &rcCenter, NULL, SRCCOPY); if(hPaletteGlobal) { SelectPalette(hDC, hOldPal, TRUE); } SelectObject(hDC, hOldBrush); SelectObject(hDC, hOldPen); return; } HWND CreateButtonImage(HWND hWnd) { HWND hButton; HIMAGELIST hImage=0; DWORD dwStyle; DWORD dRet; RECT rcTree; POINT ptTopLeft; GetWindowRect(hTreeKey, &rcTree); ptTopLeft.x = rcTree.left; ptTopLeft.y = rcTree.top; ScreenToClient(hWnd, &ptTopLeft); dwStyle =BS_OWNERDRAW | WS_CHILD | BS_PUSHBUTTON; //Create owner drawn button for displaying Dicom images hButton = CreateWindowEx( WS_EX_CLIENTEDGE, // extended window style "Button", // pointer to registered class name "", // pointer to window name dwStyle, // window style ptTopLeft.x, // horizontal position of window ptTopLeft.y, // vertical position of window rcTree.right - rcTree.left, // window width rcTree.bottom- rcTree.top, // window height hWnd, // handle to parent or owner window (HMENU)IDC_BUTTON_IMAGE, // handle to menu, or child-window identifier hInst, // handle to application instance NULL // pointer to window-creation data ); if (hButton == NULL) dRet = GetLastError(); return hButton; }