Click here to Skip to main content
15,891,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I display a directory tree (via SHBrowseForFolder and SHGetPathFromIDList) starting at a directory of my choosing, that directory is always at the bottom of the display panel. Is there a way to get it to start out somewhere else (like the middle of the panel)?

(Sorry about not including a picture but I can't seem to attach one.)
Posted
Comments
OriginalGriff 8-Apr-11 15:25pm    
You can't post images anywhere except as your Profile Picture and in Articles - the main reason being that the forums are not moderated, and with some of the idiots we get here, NSFW images would be posted very quickly! Since this could lead to the site becoming unavailable behind corporate firewalls, the rule is: "no pictures, no problem"

 
Share this answer
 
Comments
tom_delorenzo 8-Apr-11 17:37pm    
I am on Windows XP
You can adjust the scroll position inside your callback function:
case BFFM_SELCHANGED:
  if(This->_do_center_selection)
  {
    enum{ IDC_TREE = 0x3741, };
    This->_do_center_selection = This->_keep_center_selection;

    SCROLLINFO      si = {sizeof(SCROLLINFO),SIF_POS|SIF_RANGE|SIF_PAGE, };
    HWND            htree = GetDlgItem(hDlg,IDC_TREE);
    HTREEITEM        htir,htic,htis;
    int              count,pos;
    if(IsWindow(htree))
    {
      htir = TreeView_GetRoot(htree);
      htis = TreeView_GetSelection(htree);
      htic = TreeView_GetChild(htree,htir);
      for(count=pos=0;htic;htic=TreeView_GetNextVisible(htree,htic),count++){ if(htis==htic) pos=count; }
      GetScrollInfo(htree,SB_VERT,&si);
      si.nPage /= 2;
      if((pos>(int)(si.nMin+si.nPage)) && (pos<=(int)(si.nMax-si.nMin-si.nPage)))
      {
        si.nMax = si.nPos - si.nMin + si.nPage;
        for(;pos<si.nMax;pos++) PostMessage(htree,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0);
        for(;pos>si.nMax;pos--) PostMessage(htree,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0);
      }
    }
  }
break;

Good luck.
 
Share this answer
 
Comments
tom_delorenzo 12-Apr-11 13:11pm    
Thank you. Unfortunately, I cannot get this to compile no matter what I do. I'm not very proficient at C++ so a lot of what goes on behind the scenes is a complete mystery to me. I don't understand what "This->_do_center_selection" means nor do I understand why I can get the argument descriptions for all of the "TreeView_Getxxxx" macros but at the same time get an "error C2065: 'sndmsg' : undeclared identifier" error that points at "htir = TreeView_GetRoot(htree);". Another thing that I find confusing is that I get the error message "error C2660: 'CWnd::PostMessageA' : function does not take 4 parameters" but when I look up Post Message it shows that it takes 4 parameters. Why does it report an error for "PostMessageA" when I have used "PostMessage"?
mbue 13-Apr-11 8:45am    
Can you post the code how you have implemented the callback function.
The This variable is a pointer to my class i've casted to from the parameter in the callback function. Put the PostMessage into the global scope (like ::PostMessage). To use the Tree-control macros you have to include #include <commctrl.h>.
Regards.
tom_delorenzo 13-Apr-11 12:45pm    
Here's the code (minus the "This->" stuff (which I had no idea what to do with)) int CALLBACK CMergeTab::BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData) { SCROLLINFO si = {sizeof(SCROLLINFO),SIF_POS|SIF_RANGE|SIF_PAGE, }; HTREEITEM htir,htic,htis; int count,pos; switch(uMsg) { case BFFM_INITIALIZED: { if(strlen(NG2_tmpDir) == 0) GetCurrentDirectory(sizeof(NG2_tmpDir)/sizeof(TCHAR),NG2_tmpDir); // WParam is TRUE since you are passing a path. // It would be FALSE if you were passing a pidl. ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)NG2_tmpDir); break; } case BFFM_SELCHANGED: { if(strlen(NG2_tmpDir) == 0) { // Set the status window to the currently selected path. if (SHGetPathFromIDList((LPITEMIDLIST) lp ,NG2_tmpDir)) ::SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)NG2_tmpDir); } // try and get the pre-selected directory to be in the middle of the display panel htir = TreeView_GetRoot(hwnd); htis = TreeView_GetSelection(hwnd); htic = TreeView_GetChild(hwnd,htir); for(count=pos=0;htic;htic=TreeView_GetNextVisible(hwnd,htic),count++) { if(htis==htic) pos=count; } ::GetScrollInfo(hwnd,SB_VERT,&si); si.nPage /= 2; if((pos>(int)(si.nMin+si.nPage)) && (pos<=(int)(si.nMax-si.nMin-si.nPage))) { si.nMax = si.nPos - si.nMin + si.nPage; for(;pos<si.nmax;pos++)>si.nMax;pos--) ::PostMessage(hwnd,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0); } break; } default: break; } return 0; } The following are the error messages I get (at htir = TreeView_GetRoot(hwnd);) error C2065: 'sndmsg' : undeclared identifier error C2440: '=' : cannot convert from ''unknown-type'' to 'HTREEITEM' [all of the TreeView_Getxxxx statements get the C2440 error message]
tom_delorenzo 13-Apr-11 12:48pm    
OMG - I'm sorry about the code posting. It is completely unreadable. I've tried putting the code and/or inline code tags around it but it doesn't have much of an effect. Maybe you can cut and paste it where it will show up better. Thanks again. BTW - the #include for commctrl.h was added after the first compilation try. It doesn't seem to have any effect.
mbue 13-Apr-11 15:53pm    
substitute the TreeView-macros:

htir = (HTREEITEM)::SendMessage(htree,TVM_GETNEXTITEM,TVGN_ROOT,0);
htis = (HTREEITEM)::SendMessage(htree,TVM_GETNEXTITEM,TVGN_CARET,0);
htic = (HTREEITEM)::SendMessage(htree,TVM_GETNEXTITEM,TVGN_CHILD,(LPARAM)htir);
for(count=pos=0;htic;htic=(HTREEITEM)::SendMessage(htree,TVM_GETNEXTITEM,TVGN_NEXTVISIBLE,(LPARAM)htic),count++){ if(htis==htic) pos=count; }

Good luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900