Unable to change Tab's label Text of VC++ CMFCOutlookBar - c++

Its been a while i have stopped working on VC++ and now i have some project which i have again started my development on VC++.... I am having a strange issue right now the label of the control is not getting change at all here is my code for initialization of mfcoutlookbar
BOOL CMainFrame::CreateOutlookBar(CMFCOutlookBar& bar, UINT uiID, CMFCShellTreeCtrl& tree, CCalendarBar& calendar,CListCtrlBar &listctrl,int nInitialWidth)
{
bar.SetMode2003();
BOOL bNameValid;
CString strTemp;
bNameValid = strTemp.LoadString(IDS_SHORTCUTS);
ASSERT(bNameValid);
if (!bar.Create(strTemp, this, CRect(0, 0, nInitialWidth, 32000), uiID, WS_CHILD | WS_VISIBLE | CBRS_LEFT))
{
return FALSE; // fail to create
}
CMFCOutlookBarTabCtrl* pOutlookBar = (CMFCOutlookBarTabCtrl*)bar.GetUnderlyingWindow();
if (pOutlookBar == NULL)
{
ASSERT(FALSE);
return FALSE;
}
pOutlookBar->EnableInPlaceEdit(FALSE); //we dont want editing
static UINT uiPageID = 1;
// can float, can autohide, can resize, CAN NOT CLOSE
DWORD dwStyle = AFX_CBRS_FLOAT | AFX_CBRS_AUTOHIDE | AFX_CBRS_RESIZE;
CRect rectDummy(0, 0, 0, 0);
const DWORD dwTreeStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
//Create tree
tree.Create(dwTreeStyle, rectDummy, &bar, 1200);
//bNameValid = strTemp.LoadString(IDS_FOLDERS);
ASSERT(bNameValid);
pOutlookBar->AddControl(&tree, L"Folders", 2, TRUE, dwStyle);
//create calender
calendar.Create(rectDummy, &bar, 1201);
// bNameValid = strTemp.LoadString(IDS_CALENDAR);
// ASSERT(bNameValid);
pOutlookBar->AddControl(&calendar, L"CALLLLLL",1, TRUE, dwStyle);
//create list control bar
listctrl.Create(rectDummy,&bar,1202);
// bNameValid = strTemp.LoadString(IDS_DASHBOARD);//Dashboard to check the statistics and statical reports
// ASSERT(bNameValid);
pOutlookBar->AddControl(&listctrl, L"Some", 0, TRUE, dwStyle); //the digit represent icon
bar.SetPaneStyle(bar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
pOutlookBar->SetImageList(theApp.m_bHiColorIcons ? IDB_PAGES_HC : IDB_PAGES, 24);
pOutlookBar->SetToolbarImageList(theApp.m_bHiColorIcons ? IDB_PAGES_SMALL_HC : IDB_PAGES_SMALL, 16);
pOutlookBar->RecalcLayout();
BOOL bAnimation = theApp.GetInt(_T("OutlookAnimation"), TRUE);
CMFCOutlookBarTabCtrl::EnableAnimation(bAnimation);
bar.SetButtonsFont(&afxGlobalData.fontBold);
return TRUE;
}
if you see i am using two different controls by providing them the text label e,,g,
pOutlookBar->AddControl(&listctrl, L"Some", 0, TRUE, dwStyle);
and the other is
pOutlookBar->AddControl(&calendar, L"CALLLLLL",1, TRUE, dwStyle);
now the label "Some" and "CALLLLLL" is not being displayed i have tried everything but i dont know why its still displaying the default text of
"Calenders" and "Folders"
I have changed all the text inside String table as well ...this code is generated by Visual Studio C++ by wizard using Office 2000.
What is the mistake i am doing???

Okay finally figured out the problem is the cache , the outlookbased bar for any application save the caption and label in registry...so cleaning your solution rebuilding it again and again will not give you the right tabs captions unless you delete the registry entries for that application.
HKEY_USERS\S-1-5-21-3153867254-3211561466-2840709754-1000\Software\Local AppWizard-Generated Applications\test2
and then delete this test2 project key ....after that run your application it will display the correct label.

Related

How should I change the IMAGE(doesn't matter the type) of the button in the toolbar in MFC applications?

I know that this is stupid problem but I am stuck with it for the past 4 days. Why it is so complicated to just modify the toolbar in the MFC apps?
I create New Visual studio MFC application that is dialog based. I create new Toolbar resource. And then how should I set images(png, bitmap, jpeg...) or whatever type to be used in my toolbar?
I have set size to w50 and h50 and I can draw inside the buttons. But I cant find way to use image.
Instead this 2 buttons that I have just tried if its working, I want to use 8 images that are in bitmap format and in png. I read somewhere that PNG is not supported by MFC applications so I converted to Bitmap.
I load my toolbar in the dialog app like this in the OnInitDialog() method:
DWORD dwCtrlStyle = TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CBRS_SIZE_DYNAMIC;
DWORD dwStyle = AFX_DEFAULT_TOOLBAR_STYLE;
CMFCToolBar::m_dblLargeImageRatio = 1;
if (m_ToolBar.CreateEx(this, dwCtrlStyle, dwStyle, CRect(1, 1, 1, 1), IDR_TOOLBAR1))
{
dwStyle = CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC;
m_ToolBar.SetPaneStyle(m_ToolBar.GetPaneStyle() | dwStyle);
CMFCToolBarInfo info;
m_ToolBar.LoadToolBarEx(IDR_TOOLBAR1, info, FALSE);
CSize sizeToolBar = m_ToolBar.CalcFixedLayout(TRUE, TRUE);
m_ToolBar.SetWindowPos(NULL, 0, 0, sizeToolBar.cx, sizeToolBar.cy, SWP_NOACTIVATE |
SWP_NOZORDER);
CPoint ptOffset(0, sizeToolBar.cy);
}
Please if someone can help me I would be really grateful. The image format doesn't matter. I just want to put image in the toolbar.
This is my app currently:
UPDATE: I have tried this way. ID_BUTTON_1 if the first button in the toolbar and i tried to change its image. But with this there is no button in the toolbar at the place for the first button. What I am doing Wrong?
VERIFY(m_toolbar.LoadBitmap(IDB_BITMAP1));
CMFCToolBarButton mbutton;
mbutton.SetImage(m_toolbar.GetImages()->GetCount() - 1);
m_toolbar.ReplaceButton(ID_BUTTON_1, CMFCToolBarButton(ID_BUTTON_1, 0));
I answered this recently and can no longer find my answer. You can use PNG images for your toolbars. Under the hood you still use the BMP version for the resource editor to create your event handlers etc. But you can then add your PNG as a resource and then load it into your dialog.
For example, I call this in my OnInitDialog function:
void CMeetingScheduleAssistantDlg::CreateToolbar()
{
DWORD dwCtrlStyle = TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CBRS_SIZE_DYNAMIC;
DWORD dwStyle = AFX_DEFAULT_TOOLBAR_STYLE;
CMFCToolBar::m_dblLargeImageRatio = 1; // AJT v20.1.7 Bug fix
if (m_ToolBar.CreateEx(this, dwCtrlStyle,
dwStyle, CRect(1, 1, 1, 1), IDR_TOOLBAR))
{
dwStyle = CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC;
m_ToolBar.SetPaneStyle(m_ToolBar.GetPaneStyle() | dwStyle);
CMFCToolBarInfo info;
info.m_uiColdResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiHotResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiLargeColdResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiLargeHotResID = IDB_PNG_MAIN_TOOLBAR;
m_ToolBar.LoadToolBarEx(IDR_TOOLBAR, info, FALSE);
CSize sizeToolBar = m_ToolBar.CalcFixedLayout(TRUE, TRUE);
m_ToolBar.SetWindowPos(NULL, 0, 0, sizeToolBar.cx, sizeToolBar.cy,
SWP_NOACTIVATE | SWP_NOZORDER);
// Move all controls down
CPoint ptOffset(0, sizeToolBar.cy);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild)
{
if (pwndChild->GetSafeHwnd() != m_ToolBar.GetSafeHwnd())
{
pwndChild->GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
}
pwndChild = pwndChild->GetNextWindow();
}
// Resize the window
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.bottom += sizeToolBar.cy;
MoveWindow(rcWindow, FALSE);
}
}
I don't know where my previous answer has gone to, else I would have flagged this as duplicate. #confused.

Create derived control at runtime cause assertion

I am trying to create a control at run-time, but it causes assertion, and I don't know what's causing it. The control I am using is the Tree ComboBox Control from this link: https://www.codeproject.com/Articles/187762/Tree-ComboBox-Control
I added the code to register the class as follow:
CTreeComboBox::CTreeComboBox()
...
{
...
RegisterWindowClass();
}
CTreeComboBox::~CTreeComboBox()
{
m_BrushAlert.DeleteObject();
}
BOOL CTreeComboBox::RegisterWindowClass()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetInstanceHandle();
if (!(::GetClassInfo(hInst, _T("TreeComboBox"), &wndcls)))
{
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = NULL;
wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
wndcls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = _T("TreeComboBox");
if (!AfxRegisterClass(&wndcls))
{
AfxThrowResourceException();
return FALSE;
}
}
return TRUE;
}
I tried to create the control at run-time using the following code in the test program:
BOOL CTestComboBoxDlg::OnInitDialog()
{
...
m_ComboBox2.CreateEx(WS_EX_CLIENTEDGE, _T("TreeComboBox"), _T(""), WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP,
CRect(0, 0, 100, 50), this, 100000, NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
I also tried creating the control using a button click event thinking that I should let the GUI finish initializing, but the same error occur:
void CTestComboBoxDlg::OnBnClickedButton1()
{
m_ComboBox2.CreateEx(WS_EX_CLIENTEDGE, _T("TreeComboBox"), _T(""), WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP,
CRect(0, 0, 100, 50), this, 100000, NULL);
}
When I run the program, it stopped at the file dbgrptt.cpp at the following line:
__try
{
if (_CRT_ASSERT == nRptType && _InterlockedIncrement(&_crtAssertBusy) > 0)
{
/* use only 'safe' functions -- must not assert in here! */
_ERRCHECK(_itoa_s(nLine, szLineMessage, DBGRPT_MAX_MSG, 10));
OutputDebugStringA("Second Chance Assertion Failed: File ");
OutputDebugStringA(szFile ? szFile : "<file unknown>");
OutputDebugStringA(", Line ");
OutputDebugStringA(szLineMessage);
OutputDebugStringA("\n");
It stop here===> _CrtDbgBreak();
retval=-1;
__leave;
}
The program run fine if I create the control manually using the Visual Studio GUI editor, so I am not sure what's wrong. Can you help me figure out how to create this control at run-time?
Note: change the statement: TRACE1(_T("Item selected: %s\n"), GetItemText(hItem)); to TRACE(_T("Item selected: %s\n"), GetItemText(hItem)); in the file ComboTreeCtrlExt.cpp if you if you want to run the code and are using MFC
To answer my own question. Move the following code from the CTreeComboBox::PreSubclassWindow() to the CTreeComboBox::OnCreate()
CRect rect(0, 0, 0, 0);
DWORD dwStyle = WS_POPUP | WS_BORDER;
CWnd* pWnd = &m_Tree;
pWnd->CreateEx(0, WC_TREEVIEW, NULL, dwStyle, rect, GetParent(), 0, NULL);
m_Tree.Init(this);
GetClientRect(rect);
SetDroppedWidth(rect.Width());
SetDroppedHeight(m_nDroppedHeight);
dwStyle = CBS_DROPDOWNLIST & GetStyle();
ASSERT(CBS_DROPDOWNLIST == dwStyle);

How to adjust the size of a CDockablePane?

I am writing a SDI application on Visual Studio 2012. The MFC Wizard generated two CDockablePane-derived objects. The right-side CPropertiesWnd (CDockablePane-derived) object is named m_wndProperties. I embed in m_wndProperties a CPropertySheet object with a CPageNone (CPropertyPage-derived) object captioned "HELP" like this (I use the CPropertySheet class directly). However, the real size of the CPropertySheet object is bigger.
I have tried to adjust the size of the dialog related to the CPageNone object (named m_pageNone) in the Dialog Editor. This has no effect. In the MainFrm.cpp, the only lines relating to m_wndProperties I can find are:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
.....
m_wndProperties.EnableDocking(CBRS_ALIGN_RIGHT);
DockPane(&m_wndProperties);
.....
}
.....
BOOL CMainFrame::CreateDockingWindows()
{
.....
CString strPropertiesWnd;
bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
ASSERT(bNameValid);
if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
{
TRACE0("無法建立 [屬性] 視窗\n");
return FALSE; // 無法建立
}
.....
}
.....
void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)
{
.....
HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);
}
And here is the AdjustLayout() in my PropertiesWnd.cpp:
void CPropertiesWnd::AdjustLayout()
{
if (GetSafeHwnd () == NULL || (AfxGetMainWnd() != NULL && AfxGetMainWnd()->IsIconic()))
{
return;
}
CRect rectClient;
GetClientRect(rectClient);
m_PropertySheet.SetWindowPos (NULL, rectClient.left, rectClient.top, rectClient.Width (), rectClient.Height (), SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
}
And in my PageNone.cpp, I only have three functions: the default constructor, the default destructor and DoDataExchange.
My question is how can I adjust the size of m_wndProperties or m_pageNone to fit each other? Thank you very much.
I have got this working in a different way (the code is too large to give in this answer, but the main points are:
a) don't do anything in CMainFrame::OnCreate()
b) in CMainFrame::CreateDockingWindows(), after m_wndProperties.Create(), add the following code
m_PropertySheet.Create(...);
CRect rc;
m_PropertySheet.GetRect(&rc);
m_wndProperties.SetMinSize(rc.Width(), rc,Height());
m_wndProperties.EnableDocking(CBRS_ALIGN_RIGHT);
DockPane(&m_wndProperties);
ShowPane(&m_wndProperties, TRUE, FALSE, TRUE);
Your code in AdjustLayout() is plausible right, but I think during startup it will be called too early. Because the default size will be read from CWinAppEx::LoadState(), which always read the previous size from the Registry. It can probably disabled with CWinAppEx::EnableLoadWindowPlacement(FALSE). not tested.
Post a User-Defined Message at the end of InitInstance(). Or just try with a timer in CMainFrame::Create() .. SetTimer(123,2000,NULL);
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 123)
{
m_wndProperties.SetWindowPos(this, 0, 0, 400, 200, SWP_NOZORDER | SWP_FRAMECHANGED);
RecalcLayout();
KillTimer(123);
}
CFrameWndEx::OnTimer(nIDEvent);
}

how to create or dock dockable pane on full client screen MFC?

i want to create a dockable pane full size on client screen i want it load full size on client screen by default when application load at start point.i have tried with many ways like override setwindowpos() method and setminsize() method but it didn't work window not called this method on cdockable pane here is my code on oncreate() method in parent window
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
BOOL bNameValid;
// Create output window
CString strOutputWnd;
bNameValid = strOutputWnd.LoadString(IDS_OUTPUT_WND);
ASSERT(bNameValid);
if (!m_wndOutput.Create(strOutputWnd, this, CRect(0, 0, 0, 0), TRUE, ID_VIEW_OUTPUTWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Output window\n");
return FALSE; // failed to create
}
m_wndOutput.EnableDocking(CBRS_ALIGN_ANY );
int screen_height=GetSystemMetrics(SM_CYSCREEN);
int screen_width =GetSystemMetrics(SM_CXSCREEN);
m_wndOutput.SetMinSize(CSize(screen_height,screen_width)
m_wndOutput.CalcFixedLayout(FALSE,TRUE);
DockPane(&m_wndOutput);
}

MFC docking windows and where they dock

I have created (generated) a MDI project with tabbed documents with
VS2008 Pro.
Visual Studio generates an application with the File/Class view
window, properties window, output window and the first MDI document/
view.
I want to control the sides on which the windows dock. I thought this
was done in BOOL CMainFrame::CreateDockingWindows() , i changed the
CBRS_TOP to CBRS_BOTTOM and CBRS_RIGHT to CBRS_LEFT , but the windows
still come out the same in the client area. It makes no difference
what is use for a window style attribute of CBRS_xxxx. Where and how
can i control where in the client area these windows dock ?
I changed then in :
BOOL CMainFrame::CreateDockingWindows()
{
BOOL bNameValid;
// Create class view
CString strClassView;
bNameValid = strClassView.LoadString(IDS_CLASS_VIEW);
ASSERT(bNameValid);
if (!m_wndClassView.Create(strClassView, this, CRect(0, 0, 200, 200), TRUE,ID_VIEW_CLASSVIEW, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Class View window\n");
return FALSE; // failed to create
}
// Create file view
CString strFileView;
bNameValid = strFileView.LoadString(IDS_FILE_VIEW);
ASSERT(bNameValid);
if (!m_wndFileView.Create(strFileView, this, CRect(0, 0, 200, 200),TRUE, ID_VIEW_FILEVIEW, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT| CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create File View window\n");
return FALSE; // failed to create
}
// Create output window
CString strOutputWnd;
bNameValid = strOutputWnd.LoadString(IDS_OUTPUT_WND);
ASSERT(bNameValid);
if (!m_wndOutput.Create(strOutputWnd, this, CRect(0, 0, 100, 100),
TRUE, ID_VIEW_OUTPUTWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Output window\n");
return FALSE; // failed to create
}
// Create properties window
CString strPropertiesWnd;
bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
ASSERT(bNameValid);
if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |CBRS_RIGHT | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Properties window\n");
return FALSE; // failed to create
}
SetDockingWindowIcons(theApp.m_bHiColorIcons);
return TRUE;
}
Could someone please help explain to me how to control the sides where
these windows dock?
Thanks.
IIRC, CBRS_TOP etc. are for where they can dock, not for where they are docked when you start the application. That is saved in the registry, basically it will show up where it was when the application was shut down the last time.
In the past (this was not with the Feature Pack docking framework) if you wanted to dock on startup to a specific side you had to set the side where you wanted the toolbar to be docked as the only one allowed (e.g. on the right), create the toolbar, dock it (there was a SetDocked() or something like that) and then modify the allowed dock sides to the directions you wanted to allow. I'm not sure if that behavior persists in the current version but I think it does, as that was something build on low level docking toolbar functionality which the feature pack stuff just builds on.
Not a real answer but hopefully it'll set you on your way...