list control is not working on first click? - mfc

I have a two item in list control in mfc .On clicking on each item i am doing something.but fist time when i clicked nothing effecting.after second clicking everything working fine.what will be the reason.

Related

How to force LVN_HOTTRACK to always fire even when a CMenu is currently open

This is my scenario:
I have a CListCtrl which I show a CMenu upon right click, by using CMenu::TrackPopupMenu.
And then, I also have the event handler LVN_HOTTRACK in which I store the current item index of the list control, which updates it every mouse move.
Next, on the menu items of CMenu mentioned in #1, I have the UPDATE_COMMAND_UI event handler, where I check some conditions, then enable/disable the corresponding menu item.
Now, LVN_HOTTRACK works as expected, except when the CMenu is shown/open. I tested this by updating the title bar to "0" on UPDATE_COMMAND_UI, while I set it to "1" during LVN_HOTTRACK, and noticed that no matter how many times I move the mouse while the menu is open, it never updates to "1".
Additional info:
I tried calling SetForegroundWindow() first before calling TrackPopupMenu() and behavior is the same.
EDIT:
My question would be:
How would I let the LVN_HOTTRACK fire always, that it would not be blocked by the menu being open?
What I'm trying to do is enable/disable the menu item, which are "Move up", which switches the selected list item with the item above it, and "Move down" which switches with the list item below.
The customer requirement is that I should have a context/right-click menu, and not have buttons to switch items.
If the selected list item is the topmost item, "Move up" should be disabled, and if the selected list item is the bottom most item, "Move down" should be disabled. And enabling/disabling these menu items as far as I understand is done in UPDATE_COMMAND_UI.
As I understand it the menu window (an internal popup controlled by the system) performs a mouse capture, your list is not going to receive any mouse related events until that goes away.

how to add desired propertypages to propertysheet when next button is clicked

I Want to add propertypages to my propertysheet .I will let you know my intention i.e,Initially I created a propertysheet and added 4 propertypages . Now in wizard mode as we have Next,Back,Cancel which are used for switching between pages. I want to add different pages when I click on Next button.Moreover I had first propertypage which consists of three buttons where if click first button I must add a page and again if go for second page I must be able to add a page which is different from the previous one.Similarly,when I click on the third button I must add one more different page.I will show the sequence of pages,
FirstPage:
Button1:
Button2:
Button3:
Back Next Cancel
if "Button1" is clicked then Next will be enabled and then click Next then Page2 should be added and again rollback and click button2.
if "Button2" is clicked then Next will be enabled and then click Next then Page3 should be added and again rollback and click button3.
if "Button3" is clicked then Next will be enabled and then click Next then Page4 should be added.
I tried handling it in "virtual LRESULT OnWizardNext()" method ,which returns CPropertyPage::OnWizardNext(). But it is not working fine ,can anyone please let me know where to handle the event such that i must be able to add differnt pages when go for the three different buttons.
At any time you can call RemovePage in OnWizardNext and you can call AddPage in on Wizard next.
But you should never remove the page that is currently active (causing the OnWizadNext call).
This code will remove all pages following the current one and you are free to add others. returning 0 lets the wizard to continue to the next page:
// Delete all following pages
CMySheet *pSheet = static_cast<CMySheet*>(GetParent());
while (pSheet->GetActiveIndex()<pSheet->GetPageCount()-1)
pSheet->RemovePage(pSheet->GetPageCount()-1);
if (case1)
pSheet->AddPagesForCase1();
else if (case2)
pSheet->AddPagesForCase2();
...
// Do the default and advance to the next page
return 0;

How do I set focus to CEdit in child dialog that is inside TabCtrl?

I have a dialog box (CDialog) with owner-drawn CTabCtrl in it. Tabs content are child dialogs (one for each tab). There is an CEdit in each tab. When the user clicks a tab, I'm hiding all child dialogs using ShowWindow(SW_HIDE) and showing a selected one.
The problem is that when I have, for example, two tabs, click inside an edit box in the first tab and then switch to second, input focus stays on that (invisible) edit box in the first tab no matter what I do in my code (tried calling all methods that potentially can set focus, nothing changed).
Try this:
GetDlgItem(IDC_YOURCONTROL)->SetFocus();
Or the related variable linked with the control:
m_YOURCONTROLControl.SetFocus();

What triggers LBN_SELCANCEL?

I'm trying to understand the listbox notification LBN_SELCANCEL. MSDN says "Notifies the application that the user has canceled the selection in a list box." OK, but how exactly does a user "cancel the notification"? I've got LBS_NOTIFY set, and I've tried selecting another item, clicking outside the listbox, clicking another window, and none of these trigger LBN_SELCANCEL.
Anyone know what specifically triggers this notification?
I believe LBN_SELCANCEL only applies to ComboBox controls because they also use lists.
It should be called when you open the drop down hover over an element then press ESC.

Customize the buttons in a QWIzard?

QWizard have some options related to the buttons as follows:
NoDefaultButton
NoBackButtonOnStartPage
NoBackButtonOnLastPage
DisabledBackButtonOnLastPage
HaveNextButtonOnLastPage
HaveFinishButtonOnEarlyPages
NoCancelButton
CancelButtonOnLeft
HaveHelpButton
HelpButtonOnRight
Now these options are not enough to me, is there any way to do the customization??
For example, after setting a QWizardPage as a final page, the "next" button is still there since the page originally have next page.
What I want is to change "next" to "finish" instead of one more "finish" button.
Another example is that at the first page, I want the "back" button shows up but is disabled.
How can I control these buttons in a more flexible way?
I want make some buttons disappear and some be disabled.
If you call the follwing function:
QAbstractButton * QWizard::button ( WizardButton which ) const
with following argument:
QWizard::NextButton
then you should get a pointer to the "Next" button.
The only thing left to do is to call setVisible(bool) function of the button when you are one the last but one (pre-last) page?
I have never done this, just tried to help you.