scroll bar in mfc - mfc

how to add Scroll bar to a static text in MFC dialog box

A static can't have a scroll bar. If you mean a read-only edit box, just turn it on in the resource editor.

Yes it is possible to create a scroll bar with static text control.
First you should add dialog box one scorll bar and one static text control.
step1: Set scroll positon or set scroll range of scroll bar
step2:create a member variable of static text
step3:static text member variable assigend getscrollrange of scroll bar
using cstring to int ie.means cstring to convert int format.viceversa

Related

Unable to hide MFC controls in a CDialog derived class

I have a dialog that is derived from our specific base class that is inturn derived from CDialog class
This dialog contains a combobox with combobox items in it (string)
There is a group box, labels, checkbox and a text box as well (I will call them grouped controls for this discussion)
If I select an item in index 0 from combo box, the Grouped controls are shown and if I select an item in index 1 from combo box, the group controls should be hidden
I have used the code to show or hide the controls as
void MyDerivedClass::HideMyControls(bool hide)
{
int param = (false == hide)? SW_SHOW : SW_HIDE;
GetDlgItem(IDC_ENABLE_TP_DIRECTORY)->ShowWindow(param);//This is Checkbox control
GetDlgItem(IDC_STATIC_NOTE)->ShowWindow(param);//This is label control
GetDlgItem(IDC_STATIC_DIR_NAME)->ShowWindow(param);//This is label control
GetDlgItem(IDC_EDIT_TP_DIRECTORY)->ShowWindow(param);//This is text control
GetDlgItem(IDC_STATIC_TP_GRPBOX)->ShowWindow(param);//This is label control
InvalidateRect(NULL); //NULL for testing
UpdateWindow();
}
The issue is the controls are still seen on the screen even after the above method is called with true parameter. If I move some other window on top of the (supposed to be) hidden controls, then it is actually disappears. So this seems to be a refresh issue. My assumption is that the InvalidateRect and UpdateWindow should have taken care of repainitng this. but is not happening.
Tried with InvalidateRect(NULL) to paint the whole screen, but still no use.
Could you please suggest how I can hide the controls? any clean way of doing this?
Note: when the controls are (supposed to be) hidden but are still seen on the screen, I will not be able to perform any action on those controls (like setting checkbox or typing in the text box).
So I believe that the controls are marked as hidden but not painted.

MFC - Change font in a CMFCToolTipCtrl used in CDialogEx control

I'm trying to display a ToolTip for a CStatic derived control in my dialog.
What I've already done:
Added a CMFCToolTipCtrl item to my CDialogEx member.
In the init dialog member I've specified CMFCToolTipInfo structure and passed it as argument in CMFCToolTipCtrl item constructor.
Call the EnableToolTips(); member for my CStaticExts and for my CDialogEx.
Overrided the PreTranslateMessage of my CDialogEx adding the "RelayEvent".
Set "Notify: TRUE" in the resource editor.
Doing so I managed to display the tooltip in a partially customized way (baloon and background color) but now I would like to enlarge the font, make it bold and, eventually, display an icon, similarly to the tool tips I can see on my toolbar.
I already tried calling "SetFont" and "SetIcon" methods for the CMFCToolTipCtrl item but it didn't work.
Is that possible?
The normal Font that is used in CMFCToolTipCtrl ist retrieved from a global data store inside the MFC (see GetGlobalData()->fontTooltip). This data structure AFX_GLOBAL_DATA is filled when the MFC is started. SetFont has no effect here.
If you want to change the behaviour you have to create your own CMFCToolTipCtrl class and overwrite OnDrawLabel. You have the source of the MFC so it is easy to provide your own implementation.

How do I set focus to CEdit in child dialog that is inside TabCtrl?

I have a dialog box (CDialog) with owner-drawn CTabCtrl in it. Tabs content are child dialogs (one for each tab). There is an CEdit in each tab. When the user clicks a tab, I'm hiding all child dialogs using ShowWindow(SW_HIDE) and showing a selected one.
The problem is that when I have, for example, two tabs, click inside an edit box in the first tab and then switch to second, input focus stays on that (invisible) edit box in the first tab no matter what I do in my code (tried calling all methods that potentially can set focus, nothing changed).
Try this:
GetDlgItem(IDC_YOURCONTROL)->SetFocus();
Or the related variable linked with the control:
m_YOURCONTROLControl.SetFocus();

CToolBar with checkbox only - not showing properly

I have an MFC CToolBar (dockable to a CFrameWnd) containing a checkbox and a button.
This works fine now, but I need to remove the button, and then the CToolBar does not show properly any more. As it seems because it gets "zero" height. The checkbox style is "turned into" a TBBS_SEPARATOR using a call to CToolBar::SetButtonInfo before it is "created".
How can I make the toolbar visible also without that dummy button?
I solved this by overriding the CToolBar::CalcDynamicLayout method and provided the size of the toolbar there. Then the button was not needed any more. This assumes the toolbar is created with CBRS_SIZE_DYNAMIC.

How to get a CView based Windows that do not contain title bar and status bar

I am writing MFC application, I choose CView based application other then Dialog based application. I don't know how to remove title bar and status bar, is there any method to do this? And made a CView based application just like dialog based application ?
Many thanks!
Status bar can be removed by deleting all references to the CStatusBar member in your MainFrm class.
Title bar, what do you mean - the menu, the toolbar or the caption bar? First two you remove by commenting out the relevant parts in OnCreate() of CMainFrm, the last one I'm not 100% but I think you can do it by modifying cs.style in PreCreateWindow of your CMainFrm. Set the style to WS_DLGFRAME, that should work I think.