Click here to Skip to main content
15,896,063 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCustom tree control Pin
Marissa1821-Aug-03 21:03
Marissa1821-Aug-03 21:03 
GeneralRe: Custom tree control Pin
HPSI2-Aug-03 1:37
HPSI2-Aug-03 1:37 
GeneralRe: Custom tree control Pin
Michael Dunn2-Aug-03 5:39
sitebuilderMichael Dunn2-Aug-03 5:39 
GeneralWeird popup menu display on XP Pin
liop1-Aug-03 19:06
liop1-Aug-03 19:06 
GeneralRe: Weird popup menu display on XP Pin
MAAK1-Aug-03 22:52
MAAK1-Aug-03 22:52 
QuestionMFC application in NT services giving problem on LOG OFF???? Pin
Rohit Dhamija1-Aug-03 18:41
Rohit Dhamija1-Aug-03 18:41 
GeneralPopup Menus Pin
Marissa1821-Aug-03 17:52
Marissa1821-Aug-03 17:52 
GeneralRe: Popup Menus Pin
HPSI1-Aug-03 18:22
HPSI1-Aug-03 18:22 
It would be better to use WM_CONTEXTMENU instead of the right-click. The reason for this is that OnContextMenu() also catches Shift+F10, which is the Windows standard shortcut key for context menus (try it in the Explorer). But to catch right-clicks with OnContextMenu(), you also have to have a handler for ON_WM_RBUTTONDOWN - otherwise, the tree control will think you are starting a drag operation. One final thing: if OnContextMenu gets called because of Shift+F10, the point will always be -1, -1. Therefore, always use GetCursorPos() to get the actual point.

Here is an example (it assumes you have derived a minimal CMyTreeCtrl from CTreeCtrl):
void CMyTreeCtrl::OnRButtonDown(UINT nFlags, CPoint point) 
{
    // disable this message to allow OnContextMenu to work
    
    //CTreeCtrl::OnRButtonDown(nFlags, point);
}

void CMyTreeCtrl::OnContextMenu(CWnd* pWnd, CPoint point) 
{
    CPoint pos;
    GetCursorPos(&pos);
    ScreenToClient(&pos);

    UINT flags = 0;
    HTREEITEM hItem = HitTest(pos, &flags);

    SetFocus();
    if (hItem != NULL)
    {
        SelectItem(hItem);

        CMenu menu;
        menu.CreatePopupMenu();

        VERIFY(menu.AppendMenu(MF_STRING, ID_MYID, "My Selection"));

        // display the menu
        GetCursorPos(&pos);        // need screen coordinates
        VERIFY(menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pos.x, pos.y, this));
    }
    else
    {
        TRACE("not on item\n");
    }
}



HPS HwndSpy
- GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
GeneralRe: Popup Menus Pin
Snillet2k7-Mar-04 9:01
Snillet2k7-Mar-04 9:01 
GeneralRe: Popup Menus Pin
Anonymous2-Aug-03 0:22
Anonymous2-Aug-03 0:22 
QuestionHow to use ofstream to output muliple files, please help! Pin
tomsspc1-Aug-03 17:37
tomsspc1-Aug-03 17:37 
AnswerRe: How to use ofstream to output muliple files, please help! Pin
Michael Dunn1-Aug-03 18:25
sitebuilderMichael Dunn1-Aug-03 18:25 
GeneralRe: How to use ofstream to output muliple files, please help! Pin
Anonymous2-Aug-03 12:33
Anonymous2-Aug-03 12:33 
GeneralSendMessage and buffer question Pin
alex.barylski1-Aug-03 15:12
alex.barylski1-Aug-03 15:12 
GeneralRe: SendMessage and buffer question Pin
Chris Richardson1-Aug-03 15:49
Chris Richardson1-Aug-03 15:49 
GeneralRe: SendMessage and buffer question Pin
alex.barylski2-Aug-03 16:22
alex.barylski2-Aug-03 16:22 
GeneralRe: SendMessage and buffer question Pin
Michael Dunn1-Aug-03 17:03
sitebuilderMichael Dunn1-Aug-03 17:03 
GeneralCFileFind Pin
Dor1-Aug-03 15:04
Dor1-Aug-03 15:04 
GeneralRe: CFileFind Pin
HPSI1-Aug-03 18:03
HPSI1-Aug-03 18:03 
GeneralSQL server OLEDB connection with vc++ Pin
haritadala1-Aug-03 14:27
haritadala1-Aug-03 14:27 
GeneralAppWizard. Pin
WREY1-Aug-03 13:05
WREY1-Aug-03 13:05 
GeneralRe: AppWizard. Pin
Chris Richardson1-Aug-03 14:14
Chris Richardson1-Aug-03 14:14 
GeneralRe: AppWizard. Pin
Chris Richardson1-Aug-03 15:41
Chris Richardson1-Aug-03 15:41 
GeneralRe: AppWizard. Pin
WREY1-Aug-03 21:26
WREY1-Aug-03 21:26 
GeneralRe: AppWizard. Pin
WREY2-Aug-03 0:05
WREY2-Aug-03 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.