GUI Tricks for the MFC Widgets

  A wiki would probably be handier...

The intent of this document is to provide notes by developers of discoveries they have made with the cost of blood, sweat, and tears -- or at least a day of thrashing. There is a plethora of forums on the internet but they rarely cover our exact situation. Anyway, nearly every widget we use is already subclassed in Atgmain so functionality and behavior may be proprietary. Plus, there is precious little public documentation (or comments) on RogueWave stuff. Hopefully, searches for things like "combobox" or "flyover" will yield a situation that is similar to what you are encountering.

Dynamic Update of BrowseGrid Column ComboBoxes [top]

Problem:  I want to provide a combobox list that will change with every selection. This can be done by processing GRID_COMBO_CLOSEUP or GRID_ROWCOL_CHANGE events but what I have encountered are cases where a selected combobox will not update. That is because it is a COLUMN combobox instead of an individual one. The column combobox gets updated but the list loaded into the GUI widget doesn't reflect the change. This mostly happens when the keyboard is used instead of the mouse.

Solution:  I notice that de-selecting the grid cell and coming back to it does update combobox. To simulate this, I just reselect the cell. The message pump appears to distribute the updated selection list to the opened combobox. You should add a recursion flag since it is probably in a GRID_ROWCOL_CHANGE handler:

	ROWCOL currrow, currcol;
	m_DstContentCnv.GetCurrentCell(&currrow, &currcol);
	if (currcol == COMBOBOX_COLUMN) {
	   m_DstContentCnv.SetCurrentCell(currrow,currcol);
	}
This appears to be meaningless activity, but it does solve an aggravating case of when a column combobox list won't propagate to the GUI combobox.

CListCtrl Flyover Completion of Truncated Text [top]

Problem:  If I want a Report style CListCtrl, the only scrolling is vertical. This will cause too-long text to cut off with the customary dot-dot-dot and not provide a way to scroll over.

Solution:  Create a flyover auto-completion similar to what tree views provide. I have looked for the capability in our Atg list controls and found none. One forum gave half an answer and I found the rest by examining LParams (I flat refuse to buy into Experts-Exchange). Here is an example of creating a flyover for a CListCtrlCheck control. I subclass the control and override the PresubclassWindow (only to set mode) and process LVN_GETINFOTIP message. The invaluable info that NMLVGETINFOTIP has in it is the item number. It works when scrolled also. Just grab the item text and move it to where NMLVGETINFOTIP.pszText points. The GetStringWidth() CListCtrl function is very handy to compare pixel widths:

	class CTTListCtrlCheck : public CListCtrlCheck
	{
	public:
	   virtual void PreSubclassWindow();
	protected:
	   afx_msg BOOL OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult);
	   DECLARE_MESSAGE_MAP()
	};
 
	BEGIN_MESSAGE_MAP(CTTListCtrlCheck, CListCtrl)
	   ON_NOTIFY_REFLECT_EX(LVN_GETINFOTIP, OnGetInfoTip)
	END_MESSAGE_MAP()
 
	void CTTListCtrlCheck::PreSubclassWindow()
	{
	   CListCtrl::PreSubclassWindow();
	   SetExtendedStyle(LVS_EX_INFOTIP | GetExtendedStyle());
	}
 
	BOOL CTTListCtrlCheck::OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult)
	{
	   NMLVGETINFOTIP* pInfoTip = (NMLVGETINFOTIP*)pNMHDR;
	   int itemnum = pInfoTip->iItem;
	   if (itemnum != -1) {
	      CString itemText = GetItemText(itemnum, 0);
	      if (GetStringWidth(itemText) > GetColumnWidth(0)) {
	         _tcsncpy(pInfoTip->pszText,
	                  itemText.GetString(),
	                  pInfoTip->cchTextMax);
	      }
	   }
	   return FALSE;    // Pass it on
	}
This works when scrolling also: