Dialoges builder from JSON for Windows (C++)
Add two files from include to the project. At the beginning, insert this code:
#include "<root project>\jDialogs\include\jdialogs.h"
namespace jDialogs = perchik71::jDialogs;
Set define JDIALOG_NO_MANIFEST_LINKER_COMMCTRL
if you don't need to link the manifest file for visual themes.
To load the dialog in ANSI, you need to select the class with the prefix A:
jDialogs::jDialogA* lpDialogs = new jDialogs::jDialogA();
And for Wide with the W prefix:
jDialogs::jDialogW* lpDialogs = new jDialogs::jDialogW();
Warning: Wide creates a dialog by calling the WinAPI Wide function. Your JSON file must be in UTF-8 encoding, all names will be decoded in Wide encoding. For ANSI, the your file must be in ANSI encoding. Also, Wide allows you to load files not only in the English-language file path.
Load a file:
(ANSI)
lpDialogs->LoadFromFile("test.json");
(WIDE)
lpDialogs->LoadFromFile(L"test.json");
Display the dialog in normal mode:
lpDialogs->Show(hWnd, DlgProc, 0);
Display the dialog in modal mode:
lpDialogs->ShowModal(hWnd, DlgProc, 0);
By default, the dialog has the following styles:
WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | DS_SETFONT | DS_SETFOREGROUND | DS_3DLOOK
LISTVIEW
, TREEVIEW
They have a preset double buffering flag. Do not use the WS_EX_COMPOSITED
style for the dialog, to organize double buffering of the dialog by having these classes in the dialog.
If there is a certain need for double buffering, then disable the style for them by defining NOT LVS_EX_DOUBLEBUFFER
or NOT TVS_EX_DOUBLEBUFFER
.
Sample file json:
{"ExStyle": 0,
"Style": ["WS_SYSMENU", "WS_THICKFRAME", "WS_MINIMIZEBOX"],
"Title": "Dialog for testing",
"ClassName": "",
"x": 0,
"y": 0,
"Width": 520,
"Height": 365,
"FontName": "Microsoft Sans Serif",
"FontSize": 12,
"FontWeight": 400,
"FontItalic": 0,
"Controls": [
{"Type": "GROUPBOX", "Title": "Hello World", "x": 10, "y": 10, "Width": 400, "Height": 300},
{"Type": "LTEXT", "Title": "Hello World", "x": 20, "y": 28, "Width": 230, "Height": 12},
{"Type": "CTEXT", "Title": "Hello World", "x": 20, "y": 40, "Width": 230, "Height": 12},
{"Type": "RTEXT", "Title": "Hello World", "x": 20, "y": 52, "Width": 230, "Height": 12},
{"Type": "EDITTEXT", "Title": "Hello World", "Style": ["ES_AUTOHSCROLL"], "x": 20, "y": 64, "Width": 230, "Height": 14},
{"Type": "DEFPUSHBUTTON", "Title": "Hello World", "x": 20, "y": 80, "Width": 120, "Height": 12},
{"Type": "LISTBOX", "x": 60, "y": 100, "Width": 120, "Height": 80},
{"Type": "COMBOBOX", "x": 200, "y": 100, "Width": 120, "Height": 80},
{"Type": "AUTORADIOBUTTON", "Title": "Hello World", "x": 200, "y": 200, "Width": 120, "Height": 14},
{"Type": "AUTOCHECKBUTTON", "Title": "Hello World", "x": 200, "y": 220, "Width": 120, "Height": 14},
{"Type": "PROGRESSBAR", "x": 60, "y": 240, "Width": 120, "Height": 20}
]
}
Warning: By default, Windows uses the so-called Dialog Unit for the location and size of dialogs and their controls. I also implemented a mechanism for accessing these magic values, so specify all x
, y
, Width
, Height
only in pixels
. In msdn, it is written that half of the size in height and width of the specified font is taken.
Styles must be typed either in []
, or 0
, or not specified at all. Some styles are already embedded and can be specified as a string, while others can be typed in hex, where 0x
must be specified at the beginning (hex should be string in ""
).
To create a control of an undefined class, use the following option (The class name must be specified and registered by the application in the system):
{"ClassName": "SysListView32", "Title": "List1", "Style": ["LVS_SINGLESEL", "LVS_REPORT"], "ExStyle": ["LVS_EX_GRIDLINES"], "x": 10, "y": 10, "Width": 400, "Height": 300},
The project depends on https://github.com/nlohmann/json used for working with JSON data.
Класс | Описание |
---|---|
TEXT | String element |
LTEXT | Left-aligned string control |
CTEXT | Center-aligned string control |
RTEXT | Right-aligned string control |
EDITTEXT | Entry control |
DEFPUSHBUTTON | Button control with tabstop |
PUSHBUTTON | Button control |
LISTBOX | ListBox control |
COMBOBOX | ComboBox control (read only) |
COMBOBOXEX | ComboBox control (with edit) |
RADIOBUTTON | RadioButton control |
CHECKBUTTON | CheckButton control |
AUTORADIOBUTTON | RadioButton control (auto changing state) |
AUTOCHECKBUTTON | CheckButton control (auto changing state) |
GROUPBOX | GroupBox control |
LISTVIEW | ListView uses CommCtrl 6.0 |
TREEVIEW | TreeView uses CommCtrl 6.0 |
TABVIEW | TabControl uses CommCtrl 6.0 |
BITMAP | Static control for Bitmap (Title = indetificator resource bitmap) |
ICON | Static control for Icon (Title = indetificator resource icon) |
BITMAPEX | Center-aligned Static control for Bitmap (Title = indetificator resource bitmap) |
ICONEX | Center-aligned Static control for Icon (Title = indetificator resource icon) |
SCROLLBAR | ScrollBar control |
REBAR | ReBarControl uses CommCtrl 6.0 |
HOTKEY | HotKey uses CommCtrl 6.0 |
IPADDRESS | IpAddress control uses CommCtrl 6.0 |
MONTHCAL | MonthCalendar control uses CommCtrl 6.0 |
STATUSBAR | StatusBar control |
PROGRESSBAR | ProgressBar control uses CommCtrl 6.0 |
ANIMATE | SysAnimate control uses CommCtrl 6.0 |
HEADER | SysHeader control uses CommCtrl 6.0 |
RICHEDIT | RichEdit20 control (Ansi = RichEdit20A or Wide = RichEdit20W) |
DATETIMEPICKER | DateTimePick control uses CommCtrl 6.0 |
The classes is licensed under the MIT License:
Copyright © 2021 Alex (Perchik71)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The class contains the JSON Parser from Niels Lohmann which is licensed under the MIT License (see above). Copyright © 2013-2021 Niels Lohmann