ImageGear for C and C++ on Windows v19.4 - Updated
IG_GUI_select_track_mouse
API Reference Guide > Core Component API Reference > Core Component Functions Reference > GUI Functions > GUI Mouse Selection Functions > IG_GUI_select_track_mouse

This function is called when you want to use the mouse to delineate a rectangle within an image window.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_GUI_select_track_mouse ( 
        HIGEAR hIGear, 
        DWORD dwGrpID, 
        HWND hWndImage, 
        INT nX, 
        INT nY, 
        LPFNIG_GUISELECT lpfnSelect, 
        LPVOID lpPrivate 
);

Arguments:

Name Type Description
hIGear HIGEAR HIGEAR handle of image.
dwGrpID DWORD Display group identifier, used for drawing image in the image window.
hWndImage HWND Handle of the Image window.
nX INT The X position of the left mouse button click.
nY INT The Y position of the left mouse button click.
lpfnSelect LPFNIG_GUISELECT Far pointer to the GUI Select callback function. This is called when a rectangle is created.
lpPrivate LPVOID Far pointer to private data (passed to the callback function).

Return Value:

Returns the number of ImageGear errors that occurred during this function call.

Supported Raster Image Formats:

All pixel formats supported by ImageGear for C and C++.

Sample:

Display, Clipboard

Example:

 
Copy Code
PFNIG_GUISELECT   MyGUISelectCB;/* Called when rect delineated  */
HIGEAR  hIGear;/* HIGEAR handle of image     */
struct  tagMyPriv  {
   BOOL     bRectWasSelected; /* TRUE=User delineated a rect  */
   AT_RECT  rcUserRect:      /* This is the rectangle      */
   }         PrivateStruct;  /* Name of private data area    */
/* Window-message handling routine:    */
LPARAM CALLBACK  MsgHandler
        ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
 ...
switch ( msg )
  {
  CASE WM__LBUTTONDOWN:
         ...
        IG_GUI_select_track_mouse ( hIGear, IG_GRP_DEFAULT, hWnd, 
        LOWORD(lParam), HIWORD(lParam), MyGUISelectCB, 
        (LPVOID) &PrivateStruct );
         ...
  }
 ...
}
VOID ACCUAPI  MyGUISelectCB ( LPVOID lpPrivate, 
        LPAT_RECT lprcRectSelected )
/* This function will record the rectangle selected, in PrivateStruct, pointed to by
lpPrivate. */
{
struct tagMyPriv *   structPtr; /* Will point to PrivateStruct */
structPtr =  lpPrivate;      /* Copy the pointer */
structPtr -> bRectWasSelected  =  TRUE; /* Indicate a rect here */
structPtr -> rcUserRect        =  *lprcRectSelected;  /* Copy rect */
return;      /* Done */
}

Remarks:

Call this function in response to the windows message WM_LBUTTONDOWN. The mouse position is followed while the left mouse button is down. When the left mouse button is released, your lpfnSelect callback function is called with the coordinates of the rectangle that was described. The callback function may use the rectangle data in any way.

If aspect ratio preservation is in effect for the image (that is, if the aspect ratio setting is anything other than IG_DSPL_NOT_FIXED), then the dragged rectangle will automatically be aspect ratio corrected.

You can obtain the starting mouse coordinates (nX, nY) from the parameters passed by Windows with the WM_... message.

You cannot use IG_GUI_..._track_mouse() functions with a WM_RBUTTONDOWN message. ImageGear responds only to left mouse button clicks.