Error in changing of direction of listcntrl in MFC - c++

I have a problem that I have a form which includes three pages (or forms), two pages are Persian in RTL direction and one of them is LTR. I set my parent form in RTL mode like this:
if (Create( CWnd::FromHandle(hWndParent),
WS_SYSMENU | WS_POPUP | WS_CAPTION | DS_MODALFRAME | WS_VISIBLE | DS_CONTEXTHELP ,
WS_EX_LAYOUTRTL | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME ) == 0 )
return IDCANCEL;
And all of my pages turn into the RTL mode. In that English page I have a listcntrl that have to be in LTR mode, so I write this code in the English page class:
LONG lStyle = ::GetWindowLong(GetDlgItem(IDC_LST_ITEMS)->m_hWnd,GWL_EXSTYLE);
lStyle &= ~WS_EX_LAYOUTRTL;
::SetWindowLong(GetDlgItem(IDC_LST_ITEMS)->m_hWnd, GWL_EXSTYLE, lStyle);
Actually all the items included in my list control change to LTR, but my header and column are RTL.
How can I fix this problem?

You can change the flag in dialog editor's "Properties Window". In dialog editor, open the target dialog, click the ListView control, hit F4 key, set "Right Align Text" to false for ListView control.
If you change it through code, you probably also need the handle to ListView's header control:
HWND hHeader = ListView_GetHeader(hListView);
LONG lStyle = ::GetWindowLong(hHeader, GWL_EXSTYLE);
lStyle &= ~WS_EX_LAYOUTRTL;
::SetWindowLong(hHeader, GWL_EXSTYLE, lStyle);

Related

How to multiline radio controls on dialog using MFC

I have three radio options on my dialog:
Is it possible to turn these radio options in to multiline?
Ignore the other controls that seem to overlap because they are only visible correctly at run time.
It is just the three radio options I would like to word wrap if possible.
This is on MFC Dialog.
Is it possible to turn these radio options in to multiline?
Yes! If you are using the resource editor, then select the radio-button in question and, in the "Properties" pane, set the "Multiline" condition (in the "Appearance" group) to True.
If you are editing the resource script manually, then add the BS_MULTILINE style to the control.
The following screenshot is from Visual Studio 2010, but the UI is very similar in VS 2019, IIRC:
And here is the resource script, for the above dialog box, showing the use of the BS_MULTILINE style:
IDD_ABOUTBOX DIALOGEX 0, 0, 258, 132
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About AppWizDog"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
ICON IDR_MAINFRAME, IDC_STATIC, 14,14,20,20
LTEXT "AppWizDog, Version 1.0",IDC_STATIC, 42,14,114,8, SS_NOPREFIX
LTEXT "Copyright (C) 2014", IDC_STATIC, 42,26,114,8
DEFPUSHBUTTON "OK", IDOK, 201,111,50,14, WS_GROUP
CONTROL "This is a long caption text", IDC_RADIO1, "Button",
BS_AUTORADIOBUTTON | BS_MULTILINE, 7,52,62,22
END

Remove Caption Bar - Windows 10 Dialog Window

I am trying to create a small modal dialog without caption(title) bar while retaining it resizable.
But I can't remove it by any means.
https://prnt.sc/jj4hrl
Here's the dialog part of the .RC file.
IDD_ABOUTBOX DIALOGEX 100, 100, 600,300
STYLE WS_THICKFRAME // | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX
//CAPTION "About WindowsProject2"
//FONT 8, "MS Shell Dlg"
BEGIN
DEFPUSHBUTTON "OK",IDOK,300,100,50,14,WS_GROUP
END
Can anyone tell me how to remove the caption bar from the dialog window?
Thanks.

Multiline controller to grow the height down

I have a multiline MFC checkbox created like this
checkBox = new CButton();
checkBox ->CreateEx(WS_EX_LEFT, _T("BUTTON"), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX | BS_MULTILINE, m_clRect, pclPanel, controlid))
Which result in this
But I want the text to start from the middle of the checkbox and grow down like this
Anybody knows how to achieve this?
You can use BS_TOP which "Places text at the top of the button rectangle."

Change Tab order by code in a MFC Dialog

I created a control by code in the OnInitDialog, but i cannot find any way to change the tab order of the dialog by code.
Anyone have any idea on how to do this?
First Option
use ctrl+d on resource view in visual studio. and change tab order
Other option
An easier solution is change the sequence of controls in .rc file...that will change your tab order and z order both.
For Eg.
this dialog will have Tab Order IDOK first, then IDCANCEL
IDD_ABOUT DIALOG DISCARDABLE 0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "&OK",IDOK,174,18,50,14
PUSHBUTTON "&Cancel",IDCANCEL,174,35,50,14
END
now if you change it to
IDD_ABOUT DIALOG DISCARDABLE 0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
PUSHBUTTON "&Cancel",IDCANCEL,174,35,50,14
DEFPUSHBUTTON "&OK",IDOK,174,18,50,14
END
This will have Tab Order IDCANCEL first then IDOK
The tab order of controls on a dialog is governed by the Z-Order of those controls. So, to change the tab order, change the z-order positioning of the relevant controls.
You can change the z-order by using SetWindowPos.

Calling a second dialog from a dialog window fails to make either one active

Sorry for stupid questions, I'm doing everything as described in this tutorial:
http://www.functionx.com/visualc/howto/calldlgfromdlg.htm
I create the dialog window and try to call another dialog in response to a button press using the following code:
CSecondDlg Dlg;
Dlg.DoModal();
Modal window appears but isn't active, and main window isn't active too and everything lags.
Here is a screenshot:
Two dialogs interfering with each other http://img713.imageshack.us/img713/3919/63418833w.gif
And here are the definitions for my dialogs:
IDD_DIARY_TEST_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "diary_test"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "Second",IDC_SECOND_BTN,209,179,50,14
PUSHBUTTON "Cancel",IDCANCEL,263,179,50,14
CTEXT "TODO: Place dialog controls here.",IDC_STATIC,10,96,300,8
END
IDD_SECOND_DLG DIALOGEX 0, 0, 195, 127
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_DISABLED | WS_CAPTION
CAPTION "Second"
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
LTEXT "TODO: layout property page",IDC_STATIC,53,59,90,8
PUSHBUTTON "Button1",IDC_BUTTON1,61,93,50,14
END
Let's just compare the styles of the two dialogs:
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_DISABLED | WS_CAPTION
I've indicated the differences in bold, and the reason for your problems should now be obvious: your second dialog is disabled (WS_DISABLED), thus preventing it from being activated! Another difference, the missing DS_MODALFRAME style, will cause it to appear slightly abnormal (but shouldn't greatly affect the behavior); the final difference (WS_SYSMENU) merely prevents a system menu (and left icon, right close button) from being displayed.
The other oddity illustrated in your screenshot, the second dialog displayed mixed into the controls on the first, is probably due to your initial use of WS_CHILD as patriiice surmised...
Given this and the other code you posted, I suspect you originally created this as a property page. Property pages, while similar to normal dialog templates, are intended to be displayed as child windows; normal modal dialogs are not.
You dont show your source code but it's probable that your second dialog box is defined as a child window instead of popup. Just verify in the resource editor.