Easy graphical editor for Dialog Box Styles (Windows) - c

I am working on a very Big and old C code. The windows for GUI are designed with Dialog Box Styles (Windows) in a resource file(*.rc). one simple window in this code is designed like this:
ID_DIALOGEX 0, 0, 264, 197
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_CLIPSIBLINGS
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_NAME_ORG,83,39,174,14,ES_AUTOHSCROLL
EDITTEXT IDC_NAME_REF,83,57,174,14,ES_AUTOHSCROLL
LTEXT "Name for field 1:",IDC_STATIC,7,41,73,8
LTEXT "Name for field 2:",IDC_STATIC,7,60,73,8
COMBOBOX IDC_SAVEBIG_FIELD,84,157,144,42,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Data field:",IDC_STATIC,35,158,34,8
EDITTEXT IDC_NAME_XMIN,83,76,174,14,ES_AUTOHSCROLL
EDITTEXT IDC_NAME_XMAX,83,95,174,14,ES_AUTOHSCROLL
LTEXT "Name for x-axis min:",IDC_STATIC,7,79,73,8
LTEXT "Name for x-axis max:",IDC_STATIC,7,98,73,8
EDITTEXT IDC_NAME_YMIN,83,113,174,14,ES_AUTOHSCROLL
EDITTEXT IDC_NAME_YMAX,83,131,174,14,ES_AUTOHSCROLL
LTEXT "Name for y-axis min:",IDC_STATIC,7,115,73,8
LTEXT "Name for y-axis max:",IDC_STATIC,7,135,73,8
CTEXT "don't save the info",IDC_STATIC,34,9,194,25
CONTROL "Use zlib compression",IDC_SAVE_CBX_ZIP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,177,81,10
END
the 4 numbers after each line are the x,y,width andh height. So it is pretty exhausting to edit a window like this. I wanted to know is there a easy graphical designer that can produce code like this?

Related

Tristate CheckBoxes as labels for GroupBox elements in MFC dialog

I am working on this popup dialog and I am at the design stage:
I have three tristate checkboxes at the top and three group boxes with 4 checkboxes in each. The concept is simple:
If all 4 check boxes are ticked then the master checkbox is ticked.
If none of them are ticked then the master one is untickd.
If only 1 to 3 of them are ticked then the master one is set to intermediatery.
The user will be able to tick the master check box to bulk switch on all off all the associated checkboxes.
My question relates to the 3 static group boxes. I want those three lables changed into the 3 tri-state checkboxes as it will look nicer. When I played with WPF i had full control over how the labels looked for groupboxes but whatabout here in a MFC project?
This is the resource in my test project:
IDD_MFCAPPLICATION4_DIALOG DIALOGEX 0, 0, 309, 184
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Assignment Slips"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,199,163,50,14
PUSHBUTTON "Cancel",IDCANCEL,252,163,50,14
CONTROL "Main hall",IDC_CHECK1,"Button",BS_AUTO3STATE | WS_TABSTOP,18,7,43,10
GROUPBOX "Main hall",IDC_STATIC,7,23,94,82
CONTROL "Bible Reading",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,38,59,10
CONTROL "Initial Call",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,53,47,10
CONTROL "First Return Visit",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,67,69,10
CONTROL "Bible Study",IDC_CHECK5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,82,51,10
GROUPBOX "Aux. Class 1",IDC_STATIC,107,23,94,82
CONTROL "Bible Reading",IDC_CHECK6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,117,38,59,10
CONTROL "Initial Call",IDC_CHECK7,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,117,53,47,10
CONTROL "First Return Visit",IDC_CHECK8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,117,67,69,10
CONTROL "Bible Study",IDC_CHECK9,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,117,82,51,10
GROUPBOX "Aux. Class 2",IDC_STATIC,207,23,94,82
CONTROL "Bible Reading",IDC_CHECK10,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,217,39,59,10
CONTROL "Initial Call",IDC_CHECK11,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,217,53,47,10
CONTROL "First Return Visit",IDC_CHECK12,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,217,68,69,10
CONTROL "Bible Study",IDC_CHECK13,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,217,82,51,10
GROUPBOX "Other",IDC_STATIC,7,108,94,69
CONTROL "Opening Prayer",IDC_CHECK14,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,126,66,10
CONTROL "Closing Prayer",IDC_CHECK15,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,141,62,10
CONTROL "Aux. Class 1",IDC_CHECK18,"Button",BS_AUTO3STATE | WS_TABSTOP,117,7,56,10
CONTROL "Aux. Class 2",IDC_CHECK19,"Button",BS_AUTO3STATE | WS_TABSTOP,217,7,56,10
CONTROL "Congregation Bible Study",IDC_CHECK16,"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | WS_TABSTOP,17,156,76,17
END
Update
One posibility is to adjust the design style like this:
That is quite clear and avoids the need for a checkbox as the label of the group box. But I would prefer the original approach if at all possible.
Update
Looking at this answer I cameup with a solution:

Is there a way to get messages from a button inside a groupbox?

So I have a groupbox-style button. I can put a button inside it by creating a button with the groupbox as the parent. However, if I do that, the groupbox gets the button-click message instead of the window. Is there any way I can intercept these messages or have them forwarded on?
There is an example on PasteBin, where instead of putting the button in the groupbox they hover it over the top, however this means that I can't simply make the groupbox and its contents invisible in one command (and it's cheating, so is likely to go wrong at some point). So, is there a way to do it where the button is actually in the groupbox?
Example code to create the controls:
HWND hSoFGrp = CreateWindowEx(WS_EX_LEFT, "BUTTON", _T("Group Text"), WS_CHILD | WS_TABSTOP | WS_VISIBLE |
BS_GROUPBOX | BS_TEXT | BS_LEFT | BS_TOP,
0, 250, 150, 100, hwnd, (HMENU) 40,
GetModuleHandle(NULL), NULL);
HWND hSoFBtn = CreateWindowEx(WS_EX_STATICEDGE, "BUTTON", _T("Button"), WS_CHILD | WS_TABSTOP | WS_VISIBLE |
BS_PUSHBUTTON | BS_CENTER | BS_TEXT | BS_VCENTER | BS_MULTILINE,
100, 15, 48, 30, hSoFGrp, (HMENU) 41,
GetModuleHandle(NULL), NULL);
Example code to handle the messages:
switch (msg)
{
case WM_COMMAND:
if (LOWORD(wParam) == 40)
{
//This would be messages from the groupbox
}
else if (LOWORD(wParam) == 41)
{
//This would be messages from the button if the groupbox wasn't intercepting them!
}
break;
}
So, is it possible?
Group boxes are typically not used as parent windows to the controls visibly contained within them. The hierarchical structure of HWNDs does not necessarily match the visible organization of controls. Instead you should make the group box a sibling of its grouped controls.
Note that the group box should be positioned immediately before (above) its grouped controls in z-order; that way activating the mnemonic from the group box label will move focus to the first control in the group. Even though the group box control will be above its grouped controls, a group box explicitly allows other controls to draw themselves over it.

Can I have win32 C checkboxes in a listbox control?

I have the following dialog:
IDD_REMINDERS DIALOGEX 20, 20, 102, 166
STYLE DS_SETFONT | WS_POPUP | WS_SYSMENU | WS_THICKFRAME
FONT 7, "Small Fonts", 0, 0, 0x0
BEGIN
LISTBOX IDC_REMINDERS_LIST, 1,12,100,152, LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | LBS_USETABSTOPS | LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "×",IDC_CLOSE,90,-1,12,11,WS_GROUP | NOT WS_TABSTOP
LTEXT "...", IDC_REMINDERS_CAP, 1,1,75,8
PUSHBUTTON "+", IDC_REMINDERS_NEW, 78,-1,12,11, WS_GROUP | NOT WS_TABSTOP
END
In this dialog I'd like to display checkboxes on the right side.
I was under the impression that calling the following code should add checkboxes to the listbox:
ListView_SetExtendedListViewStyleEx(hWndListView, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
Though, I now suspect I may be mixing up listboxes and listviews. Either way, I tried the same ListView_SetExtended call on a listview with the following code in the RC:
CONTROL "",IDC_KEYS,"SysListView32", LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_OWNERDRAWFIXED | LVS_OWNERDATA | LVS_NOCOLUMNHEADER | WS_TABSTOP,4,64,250,136
Sadly, this listview refused to show checkboxes as well.
Is it possible to have checkboxes in a listbox? (Without going ahead and drawing them yourself. Which will work fine short term, but seems more of a hassle in terms of longer term OS compatibility.)
Can this work if the listbox is set to "owner draw"? (I'm using that due to custom text coloring.)

Win API, How to write text inside a dialog box?

I'm creating a small program of my own on WinAPI, (to practice the WIN API programing)
and I wanted to create an "about us" box, like where it is told who built the program, which version is it and such...
I was able to create the window sucsessfully, though I could only created an empty window..
I was wondering how can I write text in the box?
This is my function that creates the dialog box, where ghInstance is the instance of the window :
void CreateDialogBox(HWND hwnd)
{
CreateWindowEx(WS_EX_DLGMODALFRAME | WS_EX_TOPMOST, TEXT("DialogClass"), TEXT("About Us"), WS_VISIBLE | WS_SYSMENU | WS_CAPTION , 100, 100, 200, 150, NULL, NULL, ghInstance, NULL);
}
So how can I write inside that empty window some stuff?
Thanks!
This tutorial, provided by Microsoft (MSDN) themselves should come in handy:
http://msdn.microsoft.com/en-us/library/vstudio/bb384843.aspx
Take note of the WM_PAINT section. That's for drawing simple text.
You can also create controls on the window, for example:
C++ Win32 Multiline static label
If you are using MS VC++, you can try editing the pre-made About us in the resource script. Or you hand craft it in a resource script.
DialogboxName DIALOGEX 0, 0, 170, 62
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Us"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
ICON 128,IDC_STATIC,14,14,21,20
LTEXT "Program by you, Version 1.0",IDC_STATIC,42,14,114,8,SS_NOPREFIX
LTEXT "Copyright (C) 2016",IDC_STATIC,42,26,114,8
DEFPUSHBUTTON "OK",IDOK,113,41,50,14,WS_GROUP
END
You can reference Charles Petzold Windows programming book, version 5 of it.

Creating a window using CreateWindowEx without an icon

With C#, I was easily able to get the effect I wanted:
However, I'm having trouble doing the same thing using the Win32 API in C. I don't know how to create a window that has no icon (at all), but still has a caption, a minimize button, and a close button.
I registered my class properly, but I can't figure out what to put for the window styles/extended window styles.
static const TCHAR lpctszTitle[] = TEXT("Stuff"), lpctszClass[] =
TEXT("StuffClass");
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST, lpctszClass,
lpctszTitle, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, 0, 250, 55, NULL, NULL, hThisInstance, NULL);
The code above produced:
which still has an icon in the title bar and is not what I wanted.
A standard window requires an icon because it needs some form of representation in the taskbar at the bottom of the screen. What should be displayed when you press Alt+Tab in the window switcher if one of the main windows doesn't have an icon?
You need to specify the WS_EX_DLGMODALFRAME extended style. This is the same effect that WinForms sets when you turn off the icon in the title bar.
You also need to make sure that you do not specify an icon when you register the window class. You need to set the hIcon and hIconSm fields of the WNDCLASSEX structure to 0.
Change your code to the following:
static const TCHAR lpctszTitle[] = TEXT("Stuff"), lpctszClass[] =
TEXT("StuffClass");
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST, lpctszClass,
lpctszTitle, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, 0, 250, 55, NULL, NULL, hThisInstance, NULL);
On a side note, use Spy++ or other similar tool to see the styles that any given HWND actually uses. Point it at your C# window, then duplicate the reported styles in your C code.

Resources