Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » CExtGridWnd Collapse All
Subject Author Date
Roberto Manes Feb 1, 2008 - 9:07 AM

I wish to catch the mouse click onto a CExtGridWnd object from its parent window. I don’t want to create a new derived class just to monitor this event. Can you suggest how can I do it ? Thanks

Technical Support Feb 2, 2008 - 11:31 AM

We will assume your question is related to the CExtTreeGridWnd class. This is not difficult to code in your project or to improve the tree grid’ source code and provide you with the update. Similar task is already implemented in all the grids in Prof-UIS 2.82 and demonstrated in the new FilteredGrids sample application where you can type text in the text filter menu and the grid window becomes filtered on the fly. In any case the solution requires additional discussing. First of all, this feature will conflict with automatic editing feature which allows you to start typing on the focused grid cell without activating its inplace editor window. If the default keyboard input will be used for automatic searching, then the automatic editing feature implemented in the current version of all the Prof-UIS grid controls should be turned off. Second, we think this on-the-fly grid searching and navigation feature should use some popup window which displays characters you have already typed and it also should display at least two buttons near the editor: Find Next and Find Previous. Third, it’s possible to search grid cells by text in vertical direction to up/down, in horizontal direction to left/right and in both directions using some pre-defined way for walking through grid cells. Fourth, in some cases it’s may be required to define some ranges for searching or skip some grid cells using user-defined conditions. Fives, there are over 40 grid cell classes available and not all of them are displaying at least some text. The CExtGridCellInplaceSlider class implements grid cell which looks like slider or like scroll bar common control. But it’s possible to search this cell by text which is current position value in the slider cell re-presented in form of string. Some other cells will not be searchable at all: CExtGridCellPicture and CExtGridCellCheckBox for instance. Most of the grid cells can be reviewed in the Grids page of the ProfUIS_Controls sample application. In any case, we can assume your message as feature request but we need to discuss details of what you exactly need in your real project.

Technical Support Feb 2, 2008 - 11:28 AM

The CExtGridWnd class can be configured using four 32-bit styles which can be applied using SiwModifyStyle(), SiwModifyStyleEx(), BseModifyStyle() and BseModifyStyleEx() methods. Most of these flags are already defined and used. So we have 32x4=128 possible configuration options in the grid control. These style does not cover all the possible settings of the grid window and several behavior improvements can be done by overriding virtual methods or coding grid cell and data provider classes only. This is related to the plain grid control implemented in the CExtGridWnd class only. We do not discuss tree, report and property grids here.

The number of possible input, validation and of some action events of the CExtGridWnd class is much greater that the number of its options and styles. We think the virtual methods and replaceable parts coded as new C++ classes are best way to customize the CExtGridWnd control.

As the mouse click event: it’s typically connected to a click on a grid cell or its part, whichcauses focus and/or selection changing in the grid control, pressing some check box or button in some grid cell with further displaying of popup menu or some modal dialog. Generally, the "how to handle the mouse click in the grid window?" question is enough wide and requires details about particular task. In the easiest case, it’s possible to use the following template class:

template < class _BT > class CMouseEventRedirection : public _BT
{
public:
      CWnd * m_pWndTargetForMouseMessagePreTransaltion;
      CMouseEventRedirection( CWnd * pWndTargetForMouseMessagePreTransaltion = NULL )
            : m_pWndTargetForMouseMessagePreTransaltion( pWndTargetForMouseMessagePreTransaltion )
      {
      }
      virtual BOOL PreTranslateMessage( MSG * pMsg )
      {
            if(         m_pWndTargetForMouseMessagePreTransaltion != NULL
                  &&    pMsg->hwnd == m_hWnd
                  &&    WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST
                  &&    GetSafeHwnd() != NULL
                  &&    pWndTargetForMouseMessagePreTransaltion->PreTranslateMessage( pMsg );
                  )
                  return TRUE;
            return _BT::PreTranslateMessage( pMsg );
      } 
};
The CMouseEventRedirection template class allows you to pre-translate mouse messages of any window (including CExtGridWnd) in any other window which is specified as the m_pWndTargetForMouseMessagePreTransaltion property. So, you can use the CMouseEventRedirection < CExtGridWnd > template based class in your project instead of the CExtGridWnd class type as is:
class CSomeYourDialog : public . . .
{
      . . .
public:
      CMouseEventRedirection < CExtGridWnd > m_wndGrid;
      . . .
Then you should initialize it in the constructor of the CSomeYourDialog class:
CSomeYourDialog::CSomeYourDialog( . . . )
{
      m_wndGrid.m_pWndTargetForMouseMessagePreTransaltionq = this;
. . .
}
Then you should override the PreTranslateMessage() virtual method in a CSomeYourDialog class (can be done with Visual C++ wizards) and catch all the grid’s mouse messages in it:
BOOL CSomeYourDialog::PreTranslateMessage( MSG * pMsg )
{
      if(         pMsg->hwnd == m_wndGrid.m_hWnd
            &&    WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST
            &&    m_wndGrid.GetSafeHwnd() != NULL
            )
      {
            . . .
      }
      . . .
Visual C++ does not support adding user defined and registered window messages into message map of CWnd-derived class using some wizard. It support only standard window messages and messages of some common controls like combo box, list box, tree view, list view, etc. So, defining your own grid class or using template based solution described above is the easiest way.

Pedro Ferreira Feb 1, 2008 - 2:22 PM

Well I guess it is much simpler if you just make your own class derived from CExtGridWnd and then overload the OnKeyDown operation (or something like that, not sure about the name...). You already have everything in place to use that mechanism, no need to recode all that...