Another tree-view problem.

This is a discussion on Another tree-view problem. within the Windows Programming forums, part of the Platform Specific Boards category; Okay, this is my problem now: When I run this: Code: case DO_CREATE: { int a,b; a=1,b=2; //add some items ...

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

    Question Another tree-view problem.

    Okay, this is my problem now:

    When I run this:
    Code:
     
    	case DO_CREATE:
    		{
    		int a,b;
    		a=1,b=2;
    		//add some items to the the tree view common control
    		tvi.mask=TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_DI_SETITEM;
    		tvi.pszText=TEXT(tempSrc);			 //item label
    		tvi.cchTextMax=lstrlen(tvi.pszText);	//length of item label
    		tvi.iImage=a;						
    		tvi.iSelectedImage=b; 
    		tvis.item=tvi;
    		tvis.item.mask = TVIF_TEXT;
    		tvis.hInsertAfter=0;
    		tvis.hParent=TVI_ROOT;				 //parent item of item about to be inserted 
    		hPrev[CShPrev]=(HTREEITEM)SendMessage(g_hwndTreeView,TVM_INSERTITEM,0,(LPARAM)&tvis);
    		return 0;
    		}
    //...
    //...
    //...
    bool FindFiles_(int nType, char cFile[MAX_PATH])
    {
    MessageBox(hwndOtherUse,cFile,0,0);
     
    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
    Location
    MI
    Posts
    532
    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:
    Code:
    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."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    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
    Posts
    2,544
    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
    Location
    near a computer
    Posts
    3,859
    Or use the macros for this sort of thing

    ie

    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
    Posts
    1,342
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21