Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
Roberto Manes
|
Nov 7, 2005 - 3:53 AM
|
How can I attach to a CExtCmdItem a custom control in a toolbar ? My custom control is Cedit derived class. Thanks in advance
|
|
Technical Support
|
Nov 7, 2005 - 6:42 AM
|
|
|
Roberto Manes
|
Nov 7, 2005 - 11:45 AM
|
I wrote the following code but I’m still seeing the the toolbar button
CMyEdit *pEdit = new CMyEdit; pEdit->Create(WS_CHILD|WS_VISIBLE, CRect(0,0,60,20), &m_wndMyToolBar, ID_MY_EDIT); if( !m_wndMyToolBar.SetButtonControl( m_wndMyToolBar.CommandToIndex(ID_MY_EDIT, pEdit, true) ) { TRACE("error\n"); return -1; } g_CmdManager->CmdGetPrt( my_app->m_pszProfileName, pEditGetDlgItem() )->m_szmenuText = _T("xxx"); If I add the following code I can see the edit g_CmdManager->CmdGetPrt( my_app->m_pszProfileName, pEditGetDlgItem() )->StateSetTextField() Now I would have a question. If I add a CExtButton as a child into my edit control and I try to create it into its PresubClass() method I get a system crash in the button create function. Can you suggest any idea ? Thanks in advance
|
|
Roberto Manes
|
Nov 7, 2005 - 11:37 AM
|
I wrote the following code but I’m still seeing the the toolbar button CMyEdit *pEdit = new CMyEdit; pEdit->Create(WS_CHILD|WS_VISIBLE, CRect(0,0,60,20), &m_wndMyToolBar, ID_MY_EDIT); if( !m_wndMyToolBar.SetButtonControl( m_wndMyToolBar.CommandToIndex(ID_MY_EDIT, pEdit, true) ) { TRACE("error\n");
|
|
Technical Support
|
Nov 7, 2005 - 12:13 PM
|
Your code may look like as follows: pEdit->Create(
WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL|ES_LEFT,
CRect( 0, 0, 60, 20 ),
&m_wndMyToolBar,
ID_MY_EDIT
);
m_wndMyToolBar.InsertButton( -1, ID_MY_EDIT );
m_wndMyToolBar.SetButtonCtrl(
m_wndMyToolBar.CommandToIndex( ID_MY_EDIT ),
pEdit
);
pEdit->SetFont(
CFont::FromHandle( (HFONT)::GetStockObject(DEFAULT_GUI_FONT) )
);
pEdit->SetWindowText( _T("Edit in toolbar") ); With the code above, you can insert a standard edit control, but we advise you to use built-in text/combo fields. Of course you can use standard edit and combo-boxes in the toolbars instead of built-in text/combo fields, but you would lose some important features: - only built-in text/combo fields can be drag-and-dropped in the customize mode - only built-in text/combo fields can be used in popup menus (for example, popup items in the menu bar and popup menu invoked with the toolbar’s chevron button ( or the Toolbar Options button )) - the CExtCustomizeSite class provides automatic synchronization of multiple copies of a text/combo field anywhere - having chosen the combo box control, you will have to keep all list box string values in the control’s memory You can find how to use standard edit and combo box in the ProfUIS_Controls and ProfStudio samples. How to use built-in edit and combo fields you can find in the StyleEditor sample. As for the question about CExtButton it is not completely clear when exactly the application crashes. To help you, we need to take a look at the source code.
|
|
Roberto Manes
|
Nov 8, 2005 - 1:30 AM
|
I forgot to give you two more information. CMyEdit class is derived from CExtEdit and I do not have to insert the button into the tollbar because I’m replacing the one I already inserted from the Visual Studio resourse manager. So we have a CExtEdit with a child control of type CExtButton. I get the crash in the PreSubclass() method of the CMyEdit class when I try to create the child button as follows void CMyEdit::PreSubclassWindow() {
CRect rc, re;
GetClientRect(&rc);
rc.left = rc.right - 60; m_button.Create("Inches", WS_CHILD|WS_VISIBLE|WS_TABSTOP, rc, this, ID_BUTTON_UNMIS); CFont pFont; pFont.CreateStockObject(DEFAULT_GUI_FONT); m_button.SetFont(&pFont);
m_button.GetWindowRect(&re);
SetMargins(0, rc.Width() - re.Width());
CExtEdit::PreSubclassWindow(); } I do not have such a problem all the times I use the same CMyEdit control into any CExtResizable dialog.
|
|
Technical Support
|
Nov 8, 2005 - 7:09 AM
|
You need to handle the WM_CREATE message and use this handler instead of PreSubclassWindow() .
|
|
Roberto Manes
|
Nov 8, 2005 - 7:59 AM
|
I overrided the OnCreate() method for my CExtEdit derived class, I moved the code from the Presubclass() method into the OnCreate() method for the creation of the child CextButton, but I only can see the edit control without its child button. Please have a look at the project I already sent you by adding the OnCreate() method in the CExtEdit derived class and copying the content of the PreSubClass() method inside it. Thanks Note: anyway if I want to see the original tollbar button replaced by my edit control I have to use the StateSetTextField() method
|
|
Technical Support
|
Nov 8, 2005 - 10:29 AM
|
You need to cut the code for creating the edit (in the CMainFrame::OnCreate() method) and paste it after the CExtCustomizeSite::CustomizeStateLoad() method call. Don’t forget to remove the customization data from the registry.
Additionally we would advise you to do the following.
First. Add the #include #lt;Prof-UIS.h#gt; line to the StdAfx.h header and remove the same includes in the other places. After that, Prof-UIS will be linked with your application only once (not in each module).
Second. We noticed a memory leak because you doesn’t delete the pEdit pointer: CUICtrlEditUnMis * pEdit = new CUICtrlEditUnMis Just override the PostNcDestroy() virtual method and delete the CUICtrlEditUnMis object: void CUICtrlEditUnMis::PostNcDestroy()
{
delete this;
}
|
|
Roberto Manes
|
Nov 8, 2005 - 11:15 AM
|
Thanks a lot now it works
|
|
Roberto Manes
|
Nov 10, 2005 - 4:12 AM
|
I would have another question now. As you suggested I moved the code I wrote from the PreSubClass() method in the OnCreate() method of my CextEdit derived class. But if I want to use such a control in CextResizableDIalog by using the DoDataExchange() mechanism I will never get the WM_CREATE message. That is I can see the edit control but without it child button. Can you suggest anything ? Thanks in advance
|
|
Technical Support
|
Nov 10, 2005 - 5:41 AM
|
Just add some variable to the edit class. It will allow you to determine where you need to create the button. void CreateButton()
{
....
}
void PreSubclassWindow()
{
...
if( m_bEditInDialog )
{
CreateButton();
}
...
}
int OnCreate(...)
{
...
if( ! m_bEditInDialog )
{
CreateButton();
}
...
}
|
|
Roberto Manes
|
Nov 10, 2005 - 6:01 AM
|
Thanks I’ve already done it like that.
|
|