Article View: borland.public.cppbuilder.nativeapi
Article #4209Re: Positioning the SHBrowseForFolder window
From: Remy Lebeau (TeamB)
Date: Tue, 07 Mar 2006 00:54
Date: Tue, 07 Mar 2006 00:54
79 lines
3377 bytes
3377 bytes
"Dennis Jones" <nospam@nospam.com> wrote in message
news:440cc788$1@newsgroups.borland.com...
> I would like to center the SHBrowseForFolder window
> over the window that it was called from.
You need to provide a callback function in the BROWSEINFO structure.
> The problem is that to correctly position the window, I must know
> its size first. Unfortunately, the browse window always opens to its
> minimum size, and then updates its size only after all of the
initialization
> has occured.
The callback function receives the BFFM_INITIALIZED notification when the
dialog has been fully initialized. You can then query the dialog's current
size and then re-position it as needed.
> Thus, if I try to execute my centering code from anywhere within the
> BrowseCallbackProc function, it is always too early because the
> window's size has not been updated yet.
Works fine when I use it.
> I was hoping I could post a custom message that would be received
> by BrowseCallbackProc, but I don't see an obvious way to do that.
You cannot post custom messages to that dialog.
> Does anyone know how I can execute some custom code after
> the browse window has been displayed and initialized?
Use the BFFM_INITIALIZED notification. For example:
int __stdcall BrowseCallbackProc(HWND hDlg, UINT uMsg, LPARAM lParam,
LPARAM lpData)
{
if( uMsg == BFFM_INITIALIZED )
{
TForm1 *pForm = reinterpret_cast<TForm1*>(lpData);
RECT r = {0};
::GetWindowRect(hDlg, &r);
::SetWindowPos(
hDlg,
NULL,
pForm->Left + (pForm->Width/2) - ((r.right-r.left)/2),
pForm->Top + (pForm->Height/2) - ((r.bottom-r.top)/2),
0,
0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
}
return 0;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TCHAR buffer[MAX_PATH+1];
BROWSEINFO bi = {0};
bi.hwndOwner = Handle;
bi.pszDisplayName = buffer;
bi.lpszTitle = "";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = BrowseCallbackProc;
bi.lParam = reinterpret_cast<int>(this);
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
if( pidl )
{
//...
CoTaskMemFree(pidl);
}
}
Gambit
Technical Details
Message-ID:
<440cd987$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<440cc788$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,722adf2ba600e8df X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <440cc788$1@newsgroups.borland.com> Subject: Re: Positioning the SHBrowseForFolder window Date: Mon, 6 Mar 2006 16:54:28 -0800 Lines: 81 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <440cd987$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1141692807 68.69.17.41 (6 Mar 2006 16:53:27 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail