MFC:set font for dialog childern - mfc

I am tring to create dynamic cntrl in dialog
like CStatic,CButton like below:
ProtocolName_ = new CStatic();
ProtocolName_->Create(protocolNameStr,WS_CHILD | WS_BORDER | WS_VISIBLE,rectTitle,parent,clac_id(index,1));
Start_ = new CButton();
Start_->Create(L"Start",WS_CHILD | WS_BORDER|WS_VISIBLE|BS_AUTOCHECKBOX,rectTitle,parent,clac_id(index,3));
but thay font is other from dialog
why ?
how I can repair the case or set the font?

When do you create your controls? Make sure you create them in CYourDlg::OnInitDialog(). Also, pay attention to the DS_SETFONT style of your dialog resource.
Read more here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632642(v=vs.85).aspx

Related

CRichEditCtrl 50W font issues

I'm dynamically (in runtime) creating a CRichEditCtrl control and when I set the text to it, the font is different from the other controls (e.g. CStatic - see the pictures) in the dialog (I didn't use any formatting for the rich edit control). The difference is best seen with the characters from alphabets like Chinese or Japanese. I tried using SetDefaultCharFormat method but it was not having the effect I wanted. Then I found out, that I first need to set the text to the rich edit control, and only then use the formatting function.
// 1. dynamically created rich edit ctrl
CRichEditCtrl* dynamic_rich = new CRichEditCtrl();
dynamic_rich->Create(WS_CHILD | WS_TABSTOP | ES_LEFT | ES_MULTILINE | WS_VSCROLL |
WS_HSCROLL | ES_WANTRETURN | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
CRect(10, 0, 184, 23), this, 1234);
dynamic_rich->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_DRAWFRAME);
dynamic_rich->SetWindowTextW(L"アラビア語"); // calling it here results in the 3rd picture
// which is the closest to the desired result, though it's still not the same as in CStatic
CHARFORMAT cf = { 0 };
dynamic_rich->GetDefaultCharFormat(cf);
_tcscpy_s(cf.szFaceName, L"MS Shell Dlg 2");
cf.dwMask = CFM_FACE;
dynamic_rich->SetDefaultCharFormat(cf);
// 2. statically created rich edit ctrl - defined in .rc file
CRichEditCtrl* static_rich = (CRichEditCtrl*)this->GetDlgItem(IDC_RICHEDIT);
static_rich->SetWindowTextW(L"アラビア語");
// 3. statically created cstatic - for the font comparison
CStatic* label = (CStatic*)this->GetDlgItem(IDC_STATIC);
label->SetWindowTextW(L"アラビア語");
When I leave the default font (without calling SetDefaultCharFormat) - seems blurry
When I call SetDefaultCharFormat, then set the text - the same result
When I set the text, then call SetDefaultCharFormat - not quite the same, but close
The font in the rich edit control still doesn't look the same as in CStatic (seems a bit different and also bigger), but that I can live with. Calling SetDefaultCharFormat every time I change a text is a problem though because I need to be constantly changing the text in the runtime and it could potentially cause an overhead. Does anybody have a better solution? Thanks.

Make icon above text for MFC Button

I wanted to create CMFCButton dynamically at runtime (Icon with Text on the button). The icon is created successfully but I wanted to display the icon above text.
I want to implement "Image on Top" property found in Resource Editor for the button.
My Code:
CMFCButton* appButton = new CMFCButton;
appButton->Create( _T("MfcButton1"), WS_CHILD | WS_VISIBLE, CRect(10, 10, 70, 50), this );
appButton->SetIcon( sfi.hIcon );
(according to the "NewControls" MFC sample).
To set an image in a CMFCButton use CMFCButton::SetImage.
To set the image above (or below) the text you can use the undocumented variable m_bTopImage
appButton->m_bTopImage = TRUE;
FYI: the complete samples can be downloaded from :
http://www.microsoft.com/en-us/download/details.aspx?id=5718

How to show caret in a disabled MFC CEdit control?

If an edit control is disabled, the caret disappears. that case, if the edit is displaying a long text, then it is not possible to see the rest of the words.With the caret i, we can do that.
I think you must use an enabled readonly edit control instead of a disabled one.
Check 'readonly' in the edit box property window or use ES_READONLY when calling Create.
Also, don't forget to check Auto HScroll (ES_AUTOHSCROLL) ( and AutoVScroll if multiline).
CEdit* pEdit = new CEdit;
pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER
| ES_AUTOHSCROLL | ES_READONLY, (10, 10, 100, 100), this, 1);

MFC MDI tabbed application - want to add non-document windows to the tab group

I have an MFC MDI application I've developed in Visual Studio with a tabbed interface. I would like to open views in the tab group that are non-document views – i.e. they have no associated document, no need to save them, etc. In a way they would behave like a non-modal dialog, but tabbed. [These windows are simply to display information and take commands]
The internal machinery of the MDI apps seems very geared toward working with the DocTemplate – Document – Frame – View object structures along with their associated windows.
Q1) Anybody got any ideas on how to create such windows and add them into the already-established MDI tab group? I’ve tried to create a RichEdit window and added it in, with:
// m_wndListingView will be a non-editable CRichEditCtrl
m_wndListingView->Create(WS_CHILD | WS_VISIBLE | ES_WANTRETURN | WS_VSCROLL |
WS_HSCROLL | ES_MULTILINE | ES_LEFT | ES_AUTOHSCROLL | ES_SAVESEL |ES_READONLY,
CRect(0, 0, 20, 20), pMainFrame, 1234);
// get Tab control and add a new tab
CMFCTabCtrl *mm_wndTabCtrl = &pMainFrame->GetMDITabs();
mm_wndTabCtrl->AddTab (m_wndListingView, _T("LISTING"));
This created and displayed the window .. but it was not added to the tab group.
Q2) If I managed to get a window (perhaps it needs to be a frame window) displayed properly in the tab group, how do I tell the ‘system’ that when the user closes it, I do not want the app to prompt the user to Save the document ? Perhaps I can overload an 'OnClose' method ... but it can't be document::OnClose(), because there is no document.
Thanks for any ideas,
CAS
You need to create a frame and view on which to host your rich edit. This can be done without a document. The view will be the parent of the richedit (rather than pMainFrame).
Something along these lines (warning, untested):
CFrame* pFrame = (Crame*)RUNTIME_CLASS( CFrame )->CreateObject();
CCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS( CView );
context.m_pCurrentDoc = NULL;
context.m_pCurrentFrame = NULL;
context.m_pLastView = NULL;
context.m_pNewDocTemplate = NULL;
// NOTE: create IDR_SOMERESOURCE string (for tab title), menu, etc as needed
BOOL frameLoaded = pFrame->LoadFrame( IDR_SOMERESOURCE, WS_OVERLAPPEDWINDOW, pMainFrame, &context );
if (frameLoaded)
Frame->InitialUpdateFrame( NULL, TRUE );
// now create your rich edit with the view as its parent

WS_CLIPCHILDREN does not work when in fullscreen

I have a main window created with :
if (!fullscreen)
{
wStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN;
wExStyle = WS_EX_TOPMOST;
}
else
{
wStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN;
wExStyle = WS_EX_TOPMOST;
}
I have also a child window created runtime with :
wStyle = WS_VISIBLE | WS_POPUP | WS_CHILD;
wExStyle = WS_EX_TOPMOST;
Everything is going well when I am not in fullscreen. (i.e. The child window is well displayed on top of the parent window.)
But, when I am on fullscreen mode, the parent window is painted over the child window which cause an awful flickering.
How to set properties to the main and the child window in order to display well the child window, even in fullscreen mode ?
Thanks in advance for all your answers.
WS_POPUP cannot be used with WS_CHILD. Not positive that's the cause though.
Those style flag combinations are invalid. A child window cannot be a popup nor can it be top-most. No idea what kind of side effects that might have, never tried to get this wrong intentionally.
Getting stuck on this might be educational but not very practical. Have you considered using a class library to take care of the gooey stuff?