FeoggouFebruary 18th, 2008, AMHi! I have some questions .. How can I change the text of a control of a CFileDialog common dialog (after I have derived it )? I have tried in OnInitDialog () of my CMyFileDlg to use SetWindowText () and SetControlText () but does nothing.
Why here it does not work and in a CMyFontDlg derived from CFontDlg common dlg works? And what can I do in order to work?
Please help ..
ZerverFebruary 18th, 2008, AMIt has a rather strange design, so you have to call GetParent ().
CWnd * pParent = GetParent ();
PParent-> SetDlgItemText (edt1, "hello"); // this is the "file name" edit box
CWnd * pWnd = pParent-> GetDlgItem (lst2); // file list is in a child window
CListCtrl * wndLst1 = (CListCtrl *) (pWnd-> GetDlgItem (1); // here it is...
Copyright nfebruary 18th, 2008, AMThe text of what control do you want to change?
SetWindowText works good for the controls on your "customized" template.
GetParent-> SetWindowText (as well as SetControlText, of course !) Works for the controls on the original CFileDialog template.
Cocould you show your code? Feoggoufebruary 21st, 2008, amthanks, that was it! I work on the default template, I did not create another one and getparent ()-> setwindowtext () changes the text of the dialog's titlebar and getparent ()-> setdlgitemtext () changes the text of a Child Window's text.
Anyway, I have another question: if there is SetWindowText () (and GetDlgItem () and SetDlgItemText (), then why does SetControlText () exist?
And I have some problems with handling the toolbars, if you 'd like to help:
As it is seen, the CFileDialog dialog has 2 toolbars: a vertical one and a horizontal one. the main reason why I work with the CFileDialog is that I want to translate the text in my language. well, it seems that I can't get any button of the toolbar, I don't
Even know how they are built and what exactly they are: CToolBar ?? I have tried to use methods of CToolBar (like SetButtonInfo) but assertion errors occur (for example, here VERIFY (pBar-> DefWindowProc (TB_GETBUTTON, nIndex, (LPARAM) pButton )); for which I do
Not know the cause). Mabey it is not a CToolBar. But then what is it?
And how can I handle the elements of the toolbar from the top of the dialog? How can I handle that toolbar?
Please Help!
Export nfebruary 21st, 2008, amanyway, I have another question: if there is setwindowtext () (and getdlgitem () and setdlgitemtext (), then why does setcontroltext () exist? Just to make your life easier! Read the documentation and never mind cfiledialog child/parent problems!
... I have tried to use methods of ctoolbar (like setbuttoninfo) But assertion errors occur...
And how can I handle the elements of the toolbar from the top of the dialog? How can I handle that toolbar?
Please Help! How did you access the toolbar? Can you show your code?
Feoggoufebruary 21st, 2008, 09:38 amwell, in DLGS. H there is //
// Controls
//
# Define ctl1 0x04A0 I have used CToolBar * pCtl = (CToolBar *) GetParent ()-> GetDlgItem (ctl1); to access it and if I used pCtl-> ShowWindow (FALSE ); and the area which had the buttons "Desktop", "My Computers ets ",... has become clear: so that must be the toolbar. Extends nfebruary 21st, 2008, AMHave you tried Spy ++ to get this "toolbar" class? Perhaps, it is not a toolbat at all? FeoggouFebruary 21st, 2008, AMI have found 2 toolbars (ToolbarWindow32) which have the parent the window with "Save as" caption. Theese 2 must be.
One of them has the id 0x04A0 and the other 0x0440. The curios thing is that in dlgs. h file the item 0x0440 is presented as being static text (stc1)
Starting nfebruary 21st, 2008, AMstc1 is the "Label for the lst1 list box". It is used in the old-style dialog only!
Well, what code did you use with the pCtl to get the assertion errors and where did you use it?
FeoggouFebruary 21st, 2008, PMthe following funwing call _ GetButton and thus go to VERIFY (pBar-> DefWindowProc (TB_GETBUTTON, nIndex, (LPARAM) pButton);-Here is the error:
GetItemID, GetButtonInfo, GetButtonText, GetButtonStyle. May be others as well, I haven't tried all of them.
I have also tried RECT rect = pCtl-> GetBorders (); but rect's members become 0 xCDCDCDCD
I don't know if there is a thing from CControlBar/CToolBar that works here :(
Except nfebruary 21st, 2008, PMHere is the error:
GetItemID, GetButtonInfo, GetButtonText, GetButtonStyle. Where "here "? : Confused:
If you don't want to show your code that does fail then there is nothing to ask/discuss!
I don't know if there is a thing from CControlBar/CToolBar that works here :( What "works here "? How does it work here? Can you show the code to compare what does work and what does not?
Feoggoufebruary 21st, 2008, pmbool cmyfiledlg: oninitdialog ()
{
Cfiledialog: oninitdialog ();
// TODO: Add extra initialization here
HWND hWnd = GetParent ()-> m_hWnd;
OldWndProc = (WNDPROC) SetWindowLong (hWnd, GWL_WNDPROC, (LONG) NewWndProc );
GetParent ()-> SetWindowTextW (L "New Text here ");
// From here I modified things to other controls, that work
........................................ ...........................................
CToolBar * pCtl = (CToolBar *) GetParent ()-> GetDlgItem (ctl1 );
UINT u = pCtl-> GetItemID (0 );
Return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages shold return FALSE
}
All I have tried to do with pCtl ended in error.
For example, UINT u = pCtl-> GetItemID (0 );
In bartool. cppUINT CToolBar: GetItemID (int nIndex) const
{
ASSERT_VALID (this );
Assert (: iswindow (m_hwnd ));
Tbbutton button;
_ Getbutton (nindex, & button );
Return button. idcommand;
}
Here, _ getbutton (nindex, & button); goes in
Void ctoolbar: _ getbutton (INT nindex, tbbutton * pbutton) const
{
Ctoolbar * pbar = (ctoolbar *) This;
Verify (pbar-> defwindowproc (tb_getbutton, nindex, (lparam) pbutton ));
// Tbstate_enabled = tbbs_disabled so invert it
Pbutton-> fsstate ^ = tbstate_enabled;
} And defwindowproc (tb_getbutton, nindex, (lparam) pbutton) returns 0 which means, Error!
Export nfebruary 22nd, 2008, am1. does the same happen if you access the "Main" toolbar (at the top of the dialog )?
2. Did you try to step in the defwindowproc to see where it fails? Feoggoufebruary 22nd, 2008, am1. does the same happen if you access the "Main" toolbar (at the top of the dialog )? Yes, the same happens with the horizonal toolbar which is at the top of the dialog. Some interesting things about this toolbar are that:
1. I cocould not paint on it (I have tried to draw a rectangle with white brush, but nothing happened (I have also used MessageBox () after to ensure it does not repaint after );
2. I cocould not hide it (I used showwindow (false) but nothing happened );
3. I used getclassname () function on it (It's ID is 0x0440) and the string returned was "static" while with spy ++ it is "toolbarwindow32"
2. Did you try to step in the defwindowproc to see where it fails? It goes in lresult cwnd: defwindowproc (uint nmsg, wparam, lparam)
{
If (m_pfnsuper! = NULL)
Return: CallWindowProc (m_pfnSuper, m_hWnd, nMsg, wParam, lParam );
WNDPROC pfnWndProc;
If (pfnWndProc = * GetSuperWndProcAddr () = NULL)
//////////// The condition is true and returns the following
Return: DefWindowProc (m_hWnd, nMsg, wParam, lParam );
Else
Return: CallWindowProc (pfnWndProc, m_hWnd, nMsg, wParam, lParam );
} And about return: DefWindowProc (m_hWnd, nMsg, wParam, lParam);, I cannot step into this function, it only returns 0.
California nfebruary 22nd, 2008, amhave A Look At This thread (http://groups.google.com/group/microsoft.public.vc.mfc/browse_frm/thread/eef1eec5b1a696ca/1159baf18990947a? Hl = en & lnk = sT & Q = cfiledialog + toolbar + buttons # 1159baf18990947a) Feoggoufebruary 23rd, 2008, amyes, I have seen that the top toolbar can be handled in this method (using getwindow, then in a loop getnextwindow ). but I don't understand: How that I cannot handle it well with getdlgitem, but in the method above I can?
And second, I have put that code in my OnInitDialog, and it added an image (I have created one for the toolbar) on the toolbar that is on the top of the window. I have commented the break; command to see what happens for the second toolbar (the vertical one,
From the left of the dialog). But nothing happens; GetButtonCount returns 0, GetButton () does not modify it's parameter (LPTBBUTTON). But I get no assertion error.
Please tell me how that it works with the method u have shown and does not work with the simple GetDlgItem (I have also tried CToolBarCtrl * pCtl = (CToolBarCtrl *) GetParent () -> GetDlgItem (ctl1); instead of CToolBar * pCtl = (CToolBar *) GetParent ()-> GetDlgItem (ctl1 );
But it seems that for none of them I can get the number of buttons (GetButtonCount returns 0) in this way. And please tell me how I can handle the vertical toolbar items.
Extends nfebruary 25th, 2008, amonly a guess: Have you tried to get the ID of the "standard" toolbar in the SDI application?
Have you tried to get the toolbar pointer/hwnd using getdlgitem () for the "standard" toolbar in the SDI application and compare it with the correct toolbar handle? FeoggouFebruary 26th, 2008, AMOnly a guess: have you tried to get the id of the "standard" toolbar in the SDI application?
Have you tried to get the toolbar pointer/HWND using GetDlgItem () for the "standard" toolbar in the SDI application and compare it with the correct toolbar handle?
Now I have tried them, and it seems that I cannot get in a SDI application the toolbar in any way, if I do not have the m_wndToolBar. not using GetDlgItem (it has the ID 59392 and it seems it returns NULL if I try GetDlgItem) and with GetWindow and GetNextWindow
I have found 4 things which sounded like toolbars, but none of them had this ID. Their class name was AfxControlBar80ud.
And, by the way, I have found how to get the buttons in the vertical toolbar: I subclassed it, and handled it's messages, and in it's methods I cocould get some of its functionality (like GetButton, GetButtonCount, SetButtonInfo ). I do not understand why,
It worked that. I will ask about theese problems in the future, if I will need them, but now I have had enough of getting the toolbar!
Thanks for your help.
Listen nfebruary 26th, 2008, AMYou are welcome and I'm gglad you have solved your problem!
Cocould you share your solution (including obtaining the toolbar handle/pointer, subclassing and getting button info )? FeoggouFebruary 26th, 2008, AMhere? FeoggouFebruary 26th, 2008, AMyou mean, here, in the forum? Listen nfebruary 26th, 2008, AMYes, some code snippets wocould be interesting and useful for other people in the future. FeoggouFebruary 28th, 2008, 05:25 AMSo, here it is what I did in order to be able to get a button from the vertical toolbar, of my file dialog CMyFileDialog:
1. I derived a control from CToolBarCtrl, named CMyToolBarCtrl.
2. I added a member to CMyFileDialog, CMyToolBarCtrl m_Toolbar;
3. In the OnInitDialog of the CMyFileDialog I added the following code: CWnd * Child = GetParent ()-> GetWindow (GW_CHILD );
While (Child)
{
TCHAR clsName [16];
GetClassName (Child-> m_hWnd, clsName, 16 );
If (lstrcmp (clsName, L "ToolbarWindow32") = 0 & Child-> GetDlgCtrlID () = 0x04A0)
{
M_ToolBar.SubclassWindow (Child-> m_hWnd );
Break; // do not loop any more, after the job is done
}
Child = Child-> GetNextWindow ();
} So, what I did up here is:
-I sought for the vertical toolbar handle (the vertical one has the ID 0x04A0, which I found with Spy ++, the horizontal one has the ID 0x0440 ), through all the child windows of the dialog.
-When I found the right toolbar, I subclassed the m_ToolBar control so that it will handle that toolbar and handle messages in CMyToolBarCtrl class.
4. now I added the code which cocould not be handled in OnInitDialog of CMyFileDialog for the toolbar, in a member of CMyToolBarCtrl. in my case, it had to be a function called early, when the dialog is shown. I chose OnNcPaint.
5. I added the following code in the OnNcPaint function, and here is how it looks: void CMyToolBar: OnNcPaint ()
{
TBBUTTON tbbutton;
TBBUTTONINFO;
This-> GetButton (0, & tbbutton); // here we modify the first button
Traumatic brain injury. dwMask = TBIF_TEXT; // we change only the text
Traumatic brain injury. pszText = L "My New Text Here ";
Traumatic brain injury. cbSize = sizeof (traumatic brain injury );
This-> SetButtonInfo (tbbutton. idCommand, & trauma); // add the info
}
And now the first button, who first had the text "My Recent users", now has the text "My New Text Here"
Codeguru.com