Thread: Another tree-view problem.

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005

    Question Another tree-view problem.

    Okay, this is my problem now:

    When I run this:
    	case DO_CREATE:
    		int a,b;
    		//add some items to the the tree view common control
    		tvi.pszText=TEXT(tempSrc);			 //item label
    		tvi.cchTextMax=lstrlen(tvi.pszText);	//length of item label
    		tvis.item.mask = TVIF_TEXT;
    		tvis.hParent=TVI_ROOT;				 //parent item of item about to be inserted 
    		return 0;
    bool FindFiles_(int nType, char cFile[MAX_PATH])
    if(nType == DIR)
    PostMessage(hwndOtherUse, DO_CREATE, MAKEWPARAM(1, 0), 0); 
    else if(nType == DOC)
    PostMessage(hwndOtherUse, DO_CREATE, MAKEWPARAM(1, 0), 0);
    It works fine.
    But... when I take the line MessageBox(hwndOtherUse,cFile,0,0); out, all of the titles are the same on all of the items.

    I have not the slightest idea why displaying some text in a message box makes it work fine, an without it, not work.

    Please help, thanks, August.

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    I don't think this is the problem but I don't think you need the "{" and "}" around your case DO_CREATE:. It's in a switch and it could just look like this:
    case DO_CREATE:
    //all your code here without those wrapping it up
    return 0;    //the return 0; is what tells it that case is done
    //break; works as well but I prefer return 0; for cases like that
    //and break; for "sub-cases" like in WM_COMMAND:
    Just a suggestion, doubt it's the problem though.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Nope, tried that. Didn't help at all.
    Any other suggestions. Anyone at all?

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    MessageBox runs an internal message loop. This means waiting messages will be dispatched while waiting for MessageBox to return. This fact is causing the behaviour you are seeing.

    Consider the case without the message box call. You call PostMessage to add each item. This adds these messages to the message queue but they will not be dispatched until you pump the message queue. You only do this after you have added all the files. Therefore, since you are using a global variable for the title, it will be the same for all items.

    When you call MessageBox and implicitly pump the messsage queue, the message is dispatched after each time and you get the correct titles.

    This is one of the reasons you should try to avoid global variables. In this case you should use SendMessage instead of PostMessage. SendMessage will call the target window procedure directly and will not return until it is complete.

  5. #5
    train spotter
    Join Date
    Aug 2001
    near a computer
    Or use the macros for this sort of thing


    TreeView_InsertItem() //in commctrl.h
    "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

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Okay, even so, is there a way I can do what a MessageBox() does without displaying a message box?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. binary tree token problem
    By OldSchool in forum C++ Programming
    Replies: 13
    Last Post: 05-28-2006, 10:42 PM
  2. searching and insertion in a binary search tree
    By galmca in forum C Programming
    Replies: 1
    Last Post: 03-26-2005, 04:15 PM
  3. problem in storing data in a binary search tree
    By alavardi in forum C Programming
    Replies: 5
    Last Post: 02-13-2005, 02:20 PM
  4. Binary tree problem
    By carrja99 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 08:36 PM
  5. problem on tree implementation
    By bjte2003 in forum C Programming
    Replies: 1
    Last Post: 02-24-2003, 10:04 PM
Website Security Test