Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CFileDialog and tooltips

58 views
Skip to first unread message

Janiv Ratson

unread,
Sep 5, 2005, 10:58:47 AM9/5/05
to
I've added a toolbar button to my custom file dialog class using the
following code:
{
CWnd* wndParent = GetParent();
ASSERT(wndParent != NULL);

// Display File dialog in center
wndParent->CenterWindow();

// Implementation of Toolbar in file dialog is in class "ToolbarWindow32".
We get the toolbar by looping through all
// CFileDialog child controls and getting their class name.
TCHAR strClassName[255];
CWnd* wndChild = wndParent->GetWindow(GW_CHILD);
while( wndChild != NULL )
{
// Get the class name of child control
::GetClassName(wndChild->GetSafeHwnd(), strClassName, 255);

// if child control is toolbar then we add a button in it.
if( _tcscmp(_T("ToolbarWindow32"), strClassName) == 0 )
{
CToolBarCtrl* pToolbarCtrl = (CToolBarCtrl*)wndChild;
ASSERT(pToolbarCtrl != NULL);

// Get the number of buttons in existing toolbar control.
int nButCount = pToolbarCtrl->GetButtonCount();
// Add a new button in it. IDB_NEW_BUTTON is a bitmap resource
pToolbarCtrl->AddBitmap(1, IDI_ICON_NEW2);
// get the number of images in existing toolbar
int nImageCount = pToolbarCtrl->GetImageList()->GetImageCount();

// Define a new button
TBBUTTON tb;
// Index of new button image.
tb.iBitmap = nImageCount-1;
// Command associated with toolbar button
tb.idCommand = ID_ADD_BUTTON;
// Setting button state
tb.fsState = TBSTATE_ENABLED;
// Setting button style
tb.fsStyle = TBSTYLE_BUTTON;
tb.dwData = 0;
tb.iString = NULL;

// Insert it in existing toolbar control
pToolbarCtrl->InsertButton(nButCount, &tb);

break;
}
wndChild = wndChild->GetNextWindow();
}
// setup parent window procedure to capture the mouse click event of
Toolbar button//
m_wndProc
=(WNDPROC)SetWindowLong(wndParent->GetSafeHwnd(),GWL_WNDPROC,(LONG)CCustomFileDialog::WindowProcNew);
}

how do I set the tooltip for my new button ?
Thanks,
Janiv Ratson.


Christian ASTOR

unread,
Sep 5, 2005, 11:52:42 AM9/5/05
to
Janiv Ratson wrote:

> tb.iString = NULL;


> how do I set the tooltip for my new button ?

Fill tb.iString
(you don't need TBN_GETINFOTIP)

Janiv Ratson

unread,
Sep 5, 2005, 1:02:25 PM9/5/05
to
Thanks it did not work.
I've changed to:
tb.iString = IDS_STRING_DAY_1;

and still it does not work.

Is there something else ?

Thanks,

Janiv Ratson.

"Christian ASTOR" <cast...@club-internet.fr> wrote in message
news:uYDYaHjs...@tk2msftngp13.phx.gbl...

Frank Hickman [MVP]

unread,
Sep 5, 2005, 12:41:53 PM9/5/05
to
"Christian ASTOR" <cast...@club-internet.fr> wrote in message
news:uYDYaHjs...@tk2msftngp13.phx.gbl...

Actually, that won't work... iString is the zero based index in a the
control's string array for the button label of the button which must have
been previously entered using AddString. You should just be able to add a
string resource using the command value of your button (ID_ADD_BUTTON) to
have the tooltip text popup.

--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.


Christian ASTOR

unread,
Sep 5, 2005, 1:14:14 PM9/5/05
to
Frank Hickman [MVP] wrote:

>>Fill tb.iString
>>(you don't need TBN_GETINFOTIP)

> Actually, that won't work... iString is the zero based index in a the
> control's string array for the button label of the button which must have
> been previously entered using AddString.

I've tested in a single Win32 app before answering : it works.
(with tb.iString = "test"; and TB_ADDBUTTONS...)

Frank Hickman [MVP]

unread,
Sep 5, 2005, 3:42:43 PM9/5/05
to
"Christian ASTOR" <cast...@club-internet.fr> wrote in message
news:eG$H%230jsF...@TK2MSFTNGP14.phx.gbl...

Interesting, the only way I could get it to compile and work was to change
the code to this...

{
CWnd* wndParent= GetParent();
ASSERT( wndParent != NULL );

// Display File dialog in center
wndParent->CenterWindow();

// Implementation of Toolbar in file dialog is in class

// "ToolbarWindow32". We get the toolbar by looping
// through all CFileDialog child controls and getting
// their class name.


TCHAR strClassName[255];
CWnd* wndChild= wndParent->GetWindow( GW_CHILD );
while( wndChild != NULL )
{
// Get the class name of child control
::GetClassName( wndChild->GetSafeHwnd(), strClassName, 255 );

// if child control is toolbar then we add a button in it.

if ( _tcscmp( _T("ToolbarWindow32"), strClassName) == 0 )
{
CToolBarCtrl* pToolbarCtrl= static_cast< CToolBarCtrl* >(
wndChild );
// This is not needed since we would not be here if wndChild was
NULL...
// ASSERT( pToolbarCtrl != NULL );

// Get the number of buttons in existing toolbar control.
int nButCount = pToolbarCtrl->GetButtonCount();

// Add a new button in it. IDB_NEW_BUTTON is a bitmap resource

int nBmpID= pToolbarCtrl->AddBitmap(1, IDI_ICON_NEW2);

// Add the button string don't forget to terminate with 2
zeros...
// (the compiler adds one on string literals so just add one
more)
int nBtnStrID= pToolbarCtrl->AddStrings( _T("My Test
Button\0") );
// nBtnStrID == -1 is a failure...

// get the number of images in existing toolbar
int nImageCount = pToolbarCtrl->GetImageList()->GetImageCount();

// Define a new button
TBBUTTON tb;
// Index of new button image.

tb.iBitmap = nImageCount-1; // this is wrong, your setting
the id to a different button...


// Command associated with toolbar button
tb.idCommand = ID_ADD_BUTTON;
// Setting button state
tb.fsState = TBSTATE_ENABLED;
// Setting button style
tb.fsStyle = TBSTYLE_BUTTON;
tb.dwData = 0;

tb.iString= nBtnStrID;

// Insert it in existing toolbar control
pToolbarCtrl->InsertButton( nButCount, &tb );

// or
// tb.iBitmap = nBmpID;
// pToolbarCtrl->AddButtons( 1, &tb );

break;
}
wndChild = wndChild->GetNextWindow();
}

// setup parent window procedure to capture

// the mouse click event of Toolbar button
// m_wndProc= (WNDPROC)SetWindowLong(
// wndParent->GetSafeHwnd(), GWL_WNDPROC,
// (LONG)CCustomFileDialog::WindowProcNew );

Janiv Ratson

unread,
Sep 6, 2005, 5:24:50 AM9/6/05
to
Thanks you all.
Mr. Hickman's solution is working for me.

Please expect few more questions regarding CFileDialog.
Thanks again,
Janiv Ratson.

"Frank Hickman [MVP]" <fhickman3_NOSP@M_noblesoft.com> wrote in message
news:%23qGBxQl...@TK2MSFTNGP14.phx.gbl...

0 new messages