Syslink in ListView - c++

If I have a listview control in report mode, how could I stick a syslink control into one of the columns?
I want to have a link the user can click in one of the columns.

The listview control doesn't support this itself.
You could create a real Syslink control that's a child of the listview. You would need to sub-class the listview and reposition the Syslink control whenever the list scrolls (watch for WM_HSCROLL / WM_VSCROLL messages) or when items are added or removed, or when it's sorted. You can use LVM_GETSUBITEMRECT to find out where to position it.
Alternatively, you could handle it yourself by using NM_CUSTOMDRAW to display the "link" in a different color, and handle NM_CLICK to catch when the user clicks on the link. This would be the simplest method in my opinion. Note that if you want a hand cursor to be displayed over the link you would still need to sub-class the list and handle WM_SETCURSOR yourself.

Related

CListCtrl (MFC) selection click passes through to control UNDERNEATH the list

My CListCtrl (Report View, single column) ignores item selection when there's another control behind the CListCtrl. It's as if the click passes through to the control BEHIND the CListCtrl.
Selection is fine if the list item isn't on top of another dialog-box item.
It's baffling because the CListCtrl's z order is ABOVE these other controls. Can anyone suggest something I could try to make the CListCtrl accept a click even when there's another overlapped control? Thanks!
User Spy++ to check the message flow. And to check if another control is above your control! Maybe there is something wrong with you´r z-order even if you think that the control is above. Also check if you overwrote WM_NCHITTEST

How to focus or select an item?

What is the correct way to select a button in WinAPI so that the button or item has input focus indicated by the dotted lines? If i just set focus it is not selected. An example: I select an item index in a combobox via CB_SETSEL, how to select the complete item (dotted line, blue background)?
Thank you very much!!
In a dialog, you should use the DM_SETDEFID message to make a push button the default. Simply calling SetFocus will give focus to a button (the "dotted lines") but won't make it the default button (the one that's actioned by pressing the Return key). For example,
SendMessage(hwndDlg, DM_SETDEFID, IDC_BUTTON, 0);
For other types of controls, SetFocus is all you need, e.g:
SetFocus(GetDlgItem(hwndDlg, IDC_COMBO));
The 'blue background' indicates the cell or list item is selected. The 'dotted line' indicates that the cell or list item has the focus. These are two different things that require two different method calls or messages. In the style you are using, you have to send the CB_SETCURSEL message also.
http://www.jasinskionline.com/windowsapi/ref/c/cb_setcursel.html

OnLButtonDown() is not fired if I click an item in my dialog (ListBox, CheckBox etc) but it fires ok if I click background or Static Text

If I click anywhere on the dialog window, like in the "background", or on a Static Text, the function OnLButtonDown() is fired. But if I click a ListBox/EditBox/Combo/Calendar/Checkbox etc is not fired.
I thought that because these have control variables atached to it, and the Static Text don't. But adding a new Listbox to my Dialog and testing, I see that it doesn't fire either, so now I am confused...
I added OnLButtonDown() with the Class Wizard, it appears in:
BEGIN_MESSAGE_MAP(CMFCTesting2Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
// other handlers, etc
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
My function:
void CMFCTesting2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
AfxMessageBox(CString("BUTTON DOWN"));
CDialogEx::OnLButtonDown(nFlags, point);
}
I tried calling CDialogEx:: ... before AfxMessageBox... but same result.
The CListBox item, has the Notify option set to True, as I seen some advices in other posts.
I suspect that the WM notification message is captured somehow by the ListBox, and not sent "forward" to my CMFCTesting2Dlg, but I understood that this should happen with the Notify option set to True, on the ListBox, no? (well, obviously, not...)
Sorry, I am new to dealing with WM in MFC.
BTW, I use Visual Studio 2010 Ultimate, and this is a Visual C++ - MFC- MFC Application - Dialog Based project.
How can I capture this mouse down event if clicked on a listbox / combo / etc?
On the LONG STORY, I am actually trying to accomplish this issue:
I have two listboxes (lets say), and I want to scroll them synchronously, when user scrolls one of them, others must scroll the same (or update in the next moment). And I thought of using on mouse down to track the position of every Listbox (with the GetTopIndex), and on mouse up, to GetTopIndex again and compare with the previous ones. If a change was made, then a listbox was scrolled and then update all listboxes with SetTopIndex. The unfriendly solution for the user, but simpler for me, would be clicking a button that does this verification / update, but its not elegant at all, and it can only set them at the same level, but can't determine which one was scrolled last time. This automatically scrolling of the listboxes should be made just for displaying, it is not important the selections in the listboxes. I tried using the Message Type in the Add Event Handler for the Listbox, but none that are displayed work for my problem, KillFocus and SetFocus, are not fired if the scroll-bar is dragged, only if an item in the listbox is clicked... and I didn't succeed on the others message type either, from the Add Event Handler.
Once a window handles a message, it stops being sent to the other windows beneath it. A static window doesn't handle a mouse down, so it goes to the dialog. The other controls all handle it in some fashion (setting focus at least) so it never gets to the dialog.
You can override the OnLButtonDown handler in each of the controls to do something else once they've finished their default handling in the base class. You might also get to see the message in the PreTranslateMessage method of the dialog.
As far as getting the List Controls to sync scrolling goes, your best bet would be to intercept WM_VSCROLL by subclassing CListCtrl or perhaps by PreTranslateMessage, and then calling SetScrollInfo on the other list. If the number of items in the lists are the same, it should be fairly simple.

Win32 API GetMessage()

I want to change the default behaviour of a combobox (c++, win32 api). I make the combobox drop down when something is entered in its edit control I want to avoid the default behaviour that the combobox searches for the first match in the list, selects it, and enters the selected string into the edit control. Can I suppress this behaviour by catching the respective (LB_SETCURSEL etc.) messages out of the message queue myself with GetMessage()?
Does anyone habe a different idea of how to do it?
Greets
Michbeck
You likely want to implement Window subclassing. This allows you to insert your own WndProc function into the combobox control that gets called before the control's own WndProc is called. You can filter out (and drop) window messages you don't want the control to get.
I'm not booted into my windows partition right now to run Spy++ on a combobox to see what messages it actually receives. My guess is that you want to filter out WM_CHAR from being received by the combobox.

Making a groupbox button win32 C++

i have a button that is a rectangle how would i put words in it i want to make so ican click the word and it starts the progrma i know ShellExecute the style is BS_GROUPBOX
If you have more than one program you want to start, you need a button per program you want to start.
To start you external progrma, in the button parent window, you need to process the WM_COMMAND message with the BN_CLICKED notification.
To set the text of the button, you need to send WM_SETTEXT message to the button with the text you want shown.
Btw, BS_GROUPBOX is used for creating the rectangle around radio buttons. This style is not going to work for your scenario.
If you want an alternative to using multiple Button controls, you can use a Toolbar. In fact, it seems to me that a toolbar would be a better control for you. You can read more about creating a toolbar.