Thread: Messages from child windows with MFC

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    87

    Messages from child windows with MFC

    Hi.

    How can I catch a message from a child window in MFC environtment? I mean for example the LVN_KEYDOWN notify from a listview, which is not associated with an object of type CListView. I create this control in the CDailog::OnInitDialog() function of the dialog and I hold the handler in a member variable of the class. I couldn't find a way to do this with Class Wizard and Wizard Bar.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    You can add message handers for the control via the Properties window. The message map would look something like this:

    ON_NOTIFY(nMessage, nControlID, MessageHandler)

    Kuphryn

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    Thank you, Kurphyn, but it doesn't seem to work.

    I create the list view like this:
    Code:
    	hListView=::CreateWindowEx(NULL,WC_LISTVIEW,"#1006",
    		WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
    		0,0,500,250,this->m_hWnd,NULL,theApp.m_hInstance,NULL);
    And in the message map of the class of the dialog box I have this:
    Code:
    ON_NOTIFY(LVN_COLUMNCLICK, IDC_MAIN_LIST_VIEW, OnColumnClicked)
    where I have defined:
    Code:
    #define IDC_MAIN_LIST_VIEW 1006
    And I have the function:
    Code:
    void CKasaDBDlg::OnColumnClicked(NMHDR *pNotifyStruct, LRESULT *result )
    {
    	int i=1;
    	i++;//here it is a breakpoint
    }
    But this function doesn't seem to be called.

    P.S. This function is declared as follows:
    Code:
    afx_msg void OnColumnClicked(NMHDR *pNotifyStruct, LRESULT *result );
    Last edited by Gravedigga; 08-04-2004 at 07:44 AM.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    Any suggestions?

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Where did you define IDC_MAIN_LIST_VIEW?

    Kuphryn

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    In the resource file:
    Workspace->Resources->Right Click and from the pop up menu "ID=Resource Symbols"

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    In the createwindowex call

    "HMENU hMenu, // menu handle or child identifier"

    else the control has ID# == null
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User
    Join Date
    Sep 2003
    Posts
    87
    Thank you, novacain.

    It was my mistake. I thought that the child identifier is passed trought the lpWindowName parameter as "#num" like this:

    Code:
    hListView=::CreateWindowEx(NULL,WC_LISTVIEW,"#1006",...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  2. Sending windows messages
    By Ideswa in forum Windows Programming
    Replies: 2
    Last Post: 03-02-2006, 01:27 PM
  3. Resizing MDI child windows
    By bennyandthejets in forum Windows Programming
    Replies: 4
    Last Post: 05-18-2004, 12:33 AM
  4. Windows Messages Queuing Up Whilst Looping
    By mrpickle in forum Windows Programming
    Replies: 12
    Last Post: 12-16-2003, 03:23 PM
  5. Dialog Windows Hidden Problem :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 11-27-2002, 11:11 PM