L_DispContainerHandlePalette

#include "l_bitmap.h"

L_LTIVW_API L_BOOL EXT_FUNCTION L_DispContainerHandlePalette(hCon, uMessage, wParam, uFlags)

HDISPCONTAINER hCon;

/* handle to the container */

L_UINT uMessage;

/* message */

WPARAM wParam;

/* wParam value to be passed to the message */

L_UINT uFlags;

/* reserved for future use */

Provides an interface with the viewer to allow it to receive messages that inform the control that the palette has been changed.

Parameter

Description

hCon

Handle to the container.

uMessage

Value that indicate the message that will be sent to the viewer main window.

wParam

wParam value to be passed to the message.

uFlags

Reserved for future use. Pass 0.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function is used to display images correctly when working on 8-bit viewing systems.

The allowed messages to be recived through the parameter uMessage are:

In order to use this function, first set the uFlags parameter of the L_DispContainerCreate function to CONTAINER_HANDLEPALETTE.

Required DLLs and Libraries

LTIVW

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 2000 /XP/Vista.

See Also

Functions:

L_DispContainerCreate, L_DispContainerInsertCell, L_DispContainerSetCellBitmapList, L_DispContainerDestroy

Topics:

Using the Image Viewer

 

Image Viewer Functions: Using the Image Viewer

Example

This example creates a medical viewer control that works on 8-bit palette display monitors.

typedef struct tagDATA
{
   HBITMAPLIST      hBitmapList;
   L_BOOL           bWindowLevel;
   L_INT            nAction;
   HDISPCONTAINER   hCon;
   L_INT            nApplyToAllSubCells;
   HWND             hWndAnimationDialog;
}
DATA, * LPDATA;

HWND hWndParent;
#define SETDATA(hwnd, h) L_SETWINDOWLONGPTR(hwnd, GWLP_USERDATA, (HANDLE)(h))
#define LOCKDATA(hwnd) ((LPDATA) GlobalLock((HANDLE)L_GETWINDOWLONGPTR(hwnd, GWLP_USERDATA)))
#define UNLOCKDATA(hwnd) GlobalUnlock((HANDLE)L_GETWINDOWLONGPTR(hwnd, GWLP_USERDATA))

L_INT CreateNewCell(HWND hWnd, L_TCHAR * szText)
{
   L_INT nRet, nIndex;
   LPDATA pData = (LPDATA)LOCKDATA(hWnd);

   nRet = L_LoadBitmapList(szText, &pData->hBitmapList, 0, ORDER_BGRORGRAY, NULL, NULL);
   if (nRet != SUCCESS)
      return nRet;
   nIndex = L_DispContainerInsertCell(pData->hCon, -1, 0);

   nRet = L_DispContainerSetCellBitmapList(pData->hCon,
                                           nIndex,
                                           pData->hBitmapList,
                                           TRUE,
                                           0);

   return SUCCESS;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
   LPDATA pData = NULL;
   pData = (LPDATA)LOCKDATA(hWnd);

   switch(uMessage)
   {
   case WM_SYSCOLORCHANGE:
   case WM_QUERYNEWPALETTE:
      if (pData->hCon != NULL)
      {
         L_DispContainerHandlePalette(pData->hCon, uMessage, 0, 0);
         L_DispContainerRepaintCell(pData->hCon, hWnd, 0, 0);
      }
      break;

   case WM_PALETTEISCHANGING:
   case WM_PALETTECHANGED:
      if (pData->hCon != NULL)
      {
         L_DispContainerHandlePalette(pData->hCon, uMessage, wParam, 0);
         L_DispContainerRepaintCell(pData->hCon, hWnd, 0, 0);
      }
      break;
   }
   return DefWindowProc(hWnd, uMessage, wParam, lParam);
}

L_INT DispContainerHandlePaletteExample(HINSTANCE hInstance)
{
   MSG                     uMessage;
   WNDCLASS                wndclass;
   HANDLE                  hMem;
   LPDATA                  pData;
   HACCEL                  hAccel;
   RECT                    rcRect;
   DISPCONTAINERPROPERTIES DispContainerProp;
   DISPCELLPROPERTIES      DispCellProp;
   L_TCHAR                 szText[L_MAXPATH];
   L_INT                   nRet;

   //register the Image child window class
   wndclass.style         = CS_HREDRAW | CS_VREDRAW;
   wndclass.lpfnWndProc   = WndProc;
   wndclass.cbClsExtra    = 0;
   wndclass.cbWndExtra    = sizeof(HANDLE);
   wndclass.hInstance     = hInstance;
   wndclass.hIcon         = NULL;
   wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground = GetStockBrush(GRAY_BRUSH);
   wndclass.lpszMenuName  = NULL;
   wndclass.lpszClassName = TEXT("HandlePaletteExample");

   if (!RegisterClass(&wndclass))
      return 0;

   hWndParent = CreateWindowEx(WS_EX_CLIENTEDGE,
                               TEXT("HandlePaletteExample"),
                               TEXT("Image Viewer Demo"),
                               WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
                               CW_USEDEFAULT,
                               CW_USEDEFAULT,
                               CW_USEDEFAULT,
                               CW_USEDEFAULT,
                               NULL,
                               NULL,
                               hInstance,
                               NULL);

   hMem = GlobalAlloc (GHND, sizeof (DATA));
   SETDATA (hWndParent, hMem); 
   if(!hMem)
      return(FALSE);

   pData = (LPDATA)LOCKDATA(hWndParent);
   memset(pData, 0, sizeof(LPDATA));
   pData->hCon = NULL;

   // you must unlock the medical suite in order to be able to use the medical viewer.
   //UNLOCKSUPPORT();

   // Initialize the container by making it the same size as its parent.
   GetClientRect(hWndParent, &rcRect);
   pData->hCon = L_DispContainerCreate(hWndParent, &rcRect, CONTAINER_HANDLEPALETTE);

   // If there is a problem occur while 
   if (pData->hCon == NULL)
   {
      L_INT nError = GetLastError();
      wsprintf(szText, TEXT("Error %d"), nError);
      MessageBox(hWndParent, szText, TEXT("Aborting"), MB_OK);

      L_DispContainerDestroy(pData->hCon, TRUE, 0);
      GlobalFree(hMem);
      return FALSE;
   }

   // Add some action and activate them 
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_WINDOWLEVEL, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_ALPHA, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_OFFSET , 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_MAG, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_SCALE , 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_STACK , 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_ANNOTATION_RULER, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_ANNOTATION_ELLIPSE, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_ANNOTATION_RECTANGLE, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_ANNOTATION_TEXT, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_ANNOTATION_ARROW, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_ANNOTATION_ANGLE, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_ANNOTATION_HILITE, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_RECTANGLE, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_NUDGETOOL, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_SHRINKTOOL, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_ELLIPSE, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_POLYGON, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_FREEHAND, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_MAGICWAND, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_COLORRANGE, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_CIRCLE, 0);
   L_DispContainerAddAction(pData->hCon, CONTAINER_ACTION_REGION_SQUARE, 0);

   // assign the action to a mouse button.
   L_DispContainerSetAction(pData->hCon, CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSE_BUTTON_LEFT, 0);
   L_DispContainerSetAction(pData->hCon, CONTAINER_ACTION_OFFSET, CONTAINER_MOUSE_BUTTON_RIGHT, 0);
   L_DispContainerSetAction(pData->hCon, CONTAINER_ACTION_SCALE, CONTAINER_MOUSE_BUTTON_MIDDLE, 0);
   L_DispContainerSetAction(pData->hCon, CONTAINER_ACTION_STACK, CONTAINER_MOUSE_WHEEL, 0);

   SetCursor(LoadCursor(NULL, IDC_WAIT));

   // set the image viewer interface to show two cells, that are arranged horizontaly
   DispContainerProp.uStructSize = sizeof(DISPCONTAINERPROPERTIES);
   DispContainerProp.uNumCols = 2;
   DispContainerProp.uNumRows = 1;
   DispContainerProp.uMask = DCPF_NUMROWS | DCPF_NUMCOLS;

   nRet = L_DispContainerSetProperties(pData->hCon, &DispContainerProp, 0);

   CreateNewCell(hWndParent, TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\xa.dcm"));

   // Set some tags.
   L_DispContainerSetCellTag(pData->hCon, 0, 2, DISPWIN_ALIGN_TOPLEFT,    DISPWIN_TYPE_USERDATA,      TEXT("EX. ID 230-36-5448"), 0);
   L_DispContainerSetCellTag(pData->hCon, 0, 4, DISPWIN_ALIGN_TOPLEFT,    DISPWIN_TYPE_FRAME,         NULL,0);
   L_DispContainerSetCellTag(pData->hCon, 0, 6, DISPWIN_ALIGN_TOPLEFT,    DISPWIN_TYPE_SCALE,         NULL,0);
   L_DispContainerSetCellTag(pData->hCon, 0, 2, DISPWIN_ALIGN_BOTTOMLEFT, DISPWIN_TYPE_WLCENTERWIDTH, NULL,0);
   L_DispContainerSetCellTag(pData->hCon, 0, 1, DISPWIN_ALIGN_BOTTOMLEFT, DISPWIN_TYPE_FIELDOFVIEW,   NULL,0);
   L_DispContainerSetCellTag(pData->hCon, 0, 1, DISPWIN_ALIGN_TOPRIGHT,   DISPWIN_TYPE_USERDATA,      TEXT("Good, Guy"), 0);
   L_DispContainerSetCellTag(pData->hCon, 0, 2, DISPWIN_ALIGN_TOPRIGHT,   DISPWIN_TYPE_USERDATA,      TEXT("PID 125-98-445"), 0);
   L_DispContainerSetCellTag(pData->hCon, 0, 3, DISPWIN_ALIGN_TOPRIGHT,   DISPWIN_TYPE_USERDATA,      TEXT("DOB 08/02/1929"), 0);
   L_DispContainerSetCellTag(pData->hCon, 0, 5, DISPWIN_ALIGN_TOPRIGHT,   DISPWIN_TYPE_USERDATA,      TEXT("03/16/1999"), 0);
   L_DispContainerSetCellTag(pData->hCon, 0, 0, DISPWIN_ALIGN_BOTTOMLEFT, DISPWIN_TYPE_RULERUNIT,      NULL,  0);

   DispCellProp.uStructSize = sizeof(DISPCELLPROPERTIES);
   DispCellProp.bIsFit = TRUE;
   DispCellProp.uMask = DCCELLPF_IMAGE_FIT;

   nRet = L_DispContainerSetCellProperties(pData->hCon, 0, &DispCellProp, 0);

   CreateNewCell(hWndParent, TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\mr.dcm"));

   // set some tags
   L_DispContainerSetCellTag(pData->hCon, 1, 1, DISPWIN_ALIGN_TOPLEFT,       DISPWIN_TYPE_USERDATA,      TEXT("MRI"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 2, DISPWIN_ALIGN_TOPLEFT,       DISPWIN_TYPE_USERDATA,      TEXT("EX. ID G-1194-24"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 4, DISPWIN_ALIGN_TOPLEFT,       DISPWIN_TYPE_FRAME,         NULL,0);
   L_DispContainerSetCellTag(pData->hCon, 1, 6, DISPWIN_ALIGN_TOPLEFT,       DISPWIN_TYPE_SCALE,         NULL,0);
   L_DispContainerSetCellTag(pData->hCon, 1, 2, DISPWIN_ALIGN_BOTTOMLEFT,    DISPWIN_TYPE_WLCENTERWIDTH, NULL,0);
   L_DispContainerSetCellTag(pData->hCon, 1, 1, DISPWIN_ALIGN_BOTTOMLEFT,    DISPWIN_TYPE_FIELDOFVIEW,   NULL,0);
   L_DispContainerSetCellTag(pData->hCon, 1, 0, DISPWIN_ALIGN_BOTTOMLEFT,    DISPWIN_TYPE_USERDATA,      TEXT("THK 10 mm"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 3, DISPWIN_ALIGN_BOTTOMLEFT,    DISPWIN_TYPE_USERDATA,      TEXT("TR 1333.33"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 4, DISPWIN_ALIGN_BOTTOMLEFT,    DISPWIN_TYPE_USERDATA,      TEXT("TE 11.98"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 6, DISPWIN_ALIGN_BOTTOMLEFT,    DISPWIN_TYPE_USERDATA,      TEXT("Comm longaxis - Normal"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 0, DISPWIN_ALIGN_TOPRIGHT,      DISPWIN_TYPE_USERDATA,      TEXT("Community Hospital"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 1, DISPWIN_ALIGN_TOPRIGHT,      DISPWIN_TYPE_USERDATA,      TEXT("Nice, Fellow"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 2, DISPWIN_ALIGN_TOPRIGHT,      DISPWIN_TYPE_USERDATA,      TEXT("PID 123-45-6789"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 3, DISPWIN_ALIGN_TOPRIGHT,      DISPWIN_TYPE_USERDATA,      TEXT("DOB 05/13/1936"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 4, DISPWIN_ALIGN_TOPRIGHT,      DISPWIN_TYPE_USERDATA,      TEXT("Sex M"), 0);
   L_DispContainerSetCellTag(pData->hCon, 1, 5, DISPWIN_ALIGN_TOPRIGHT,      DISPWIN_TYPE_USERDATA,      TEXT("06/26/1995"), 0);

   // set the cell interface so it shows 4 frames at once.
   DispCellProp.uNumCols = 2;
   DispCellProp.uNumRows = 2;
   DispCellProp.bIsFit = TRUE;
   DispCellProp.bOnMove = TRUE;
   DispCellProp.uMask = DCCELLPF_COLS | DCCELLPF_ROWS | DCCELLPF_IMAGE_FIT | DCCELLPF_APPLYONMOVE;

   nRet = L_DispContainerSetCellProperties(pData->hCon, 1, &DispCellProp, 0);


   SetCursor(LoadCursor(NULL, IDC_ARROW));

   ShowWindow(hWndParent, SW_MAXIMIZE);
   UpdateWindow(hWndParent);

   hAccel = LoadAccelerators(hInstance, TEXT("HandlePaletteExample"));

   while (GetMessage (&uMessage, NULL, 0, 0))
   {
      if(!TranslateMDISysAccel (hWndParent, &uMessage) &&
         !TranslateAccelerator (hWndParent, hAccel, &uMessage))
      {
         TranslateMessage (&uMessage);
         DispatchMessage (&uMessage);
      }
   }

   GlobalFree(hMem);
   return (L_INT)uMessage.wParam;
}