?
Solved

Browseforfolder callback: global variable?

Posted on 2005-03-28
6
Medium Priority
?
443 Views
Last Modified: 2013-11-20
Hi experts,
I would like to have some customizable things in my programms.
I specifically would like to set a selected path in a BrowseForFolder dialog.
I found a callback function on EE that would take care of that:

int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lp, LPARAM pData)
{
   TCHAR szDir[MAX_PATH];
   switch(uMsg)
   {
   case BFFM_INITIALIZED:
      if (GetCurrentDirectory(sizeof(szDir)/sizeof(TCHAR), szDir))
      {
//Hardwirering the path in the sendmessage here.
//Want that to be a variable.
              SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)_T("c:\\"));
      }
      break;
   case BFFM_SELCHANGED:
      if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir))
      {
              SendMessage(hWnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
      }
      break;
   }
   return 0;
}

1.However, I need to specify the path in SendMessage(,,,LPARAM(PATH)).
   I would like to use a variable to do that.
2. The Callback function is global, right?
    Where in a project would I put it if I have multiple Dialogs that would call that function?
3. Where to put the global variable (if needed).
4. Is there a better way to do it?

BTW pidlRoot should stay NULL since I want the user to be able to change the selection
to whatever diretory he chooses on his computer.

Thanks alot,
Jens
0
Comment
Question by:allmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 13642441
LPARAM pData  is user data which is set in BROWSEINFO::lParam member. You can pass "this" pointer in lParam and access caller class using this pointer:

BROWSEINFO b;
...
b.lParam = this;
...
SHBrowseForFolder(&b);

int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lp, LPARAM pData)
{
    CMyClass* p = (CMyClass*)pData;   // get pointer to caller instance

    // access caller data through p pointer


}
0
 
LVL 5

Author Comment

by:allmer
ID: 13642512
I donot seem to be able to do the above :(
b.lParam = this;
Error msg:
error C2440: '=' : cannot convert from 'CSequestExtractionDlg *const ' to 'LPARAM'
Anyway,
how would I send a string or CString or anything similar to the callback function?
I would be fine with something like
b.lParam = "c:\\";
And getting the string in the callback function again.
Jens
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13642526
b.lParam = (LPARAM)this;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 48

Expert Comment

by:AlexFM
ID: 13642535
If only one Folders dialog may be shown at the same time, you can use global variable, in this case lParam is not necessary.

CString g_sPath;

void 'CSequestExtractionDlg::ShowFolderDialog()
{
    g_sPath = "C:\\";

    SHBrowseForFolder(...);
}    

int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lp, LPARAM pData)
{
    // use g_sPath directly
}
0
 
LVL 5

Author Comment

by:allmer
ID: 13642542
Forget the last comment Alex.
I got it:

    BROWSEINFO bi;      
...
   string p="c:\\";
   bi.lParam = (LPARAM)&p;
   bi.lpfn = &BrowseCallbackProc;
   pidl = ::SHBrowseForFolder(&bi);
...

int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lp, LPARAM pData)
{
      TCHAR szDir[MAX_PATH];
      string *path = (string*)pData;
      switch(uMsg)
      {
      case BFFM_INITIALIZED:
            SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)path->c_str());
            break;
...
}
Thanks alot,
Jens
0
 
LVL 5

Author Comment

by:allmer
ID: 13642543
Thanks alot for the quick answer!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question