Download Library
SavvyUI C++ Windows Component Library
Integrating SavvyUI with Existing C++ Windows App
Update the existing Project Settings
NOTE: The following instructions are specific to Visual Studio 2019, but they should be similar for other versions of Visual Studio. Follow these instructions to link the SavvyUI library and header files to your new project.
- Right-click the project node under Solution Explorer, select Properties from the context menu, we will create a 64-bit application, so we will configure the x64/Debug and x64/Release configurations.
- Under the Project Property Pages dialog, select "Debug" from the Configuration dropdown, and then select "x64" from the Platform dropdown
- Expand the "Configuration Properties" node
- Click the "VC++ Directories" node, and then click the "Include Directories" value inside the right-side panel, this will shown the dropdown arrow, click it, and then click the "<Edit...>" option under that dropdown.
- Add the path of the SavvyUI library folder inside the box at the top of the shown dialog, this will be the parent folder of the include directory of the SavvyUI library distribution, click OK once that folder is selected.
- Click the "Library Directories" node inside the left side panel, and then click the value field inside the right-side panel, this will shown the dropdown arrow, click it, and then click the "<Edit...>" option under that dropdown.
- Add the path of the SavvyUI library folder inside the box at the top of the shown dialog; i.e. SavvyUI/VC2019, and then click OK.
- Next, expand the "Linker" node under Configuration Properties inside the left-side panel.
- Click the "Input" node under the Linker node.
- Click the "Additional Dependencies" value inside the right-side panel, this will shown the dropdown arrow, click it, and then click the "<Edit...>" selection under that dropdown.
- Add the entry "SavvyUI_X64_Debug.lib" without the double-quotes to the box at the top of the shown dialog; i.e. SavvyUI_X64_Debug.lib, and then click OK.
- Expand the C/C++ node and click on Code Generation, change the value of the Runtime Library property to /MTd for the Debug configuration, and /MT for the Release configuration.
- Repeat these steps for the Release/x64 Configuration, but this time, specify the library name as SavvyUI_X64.lib instead of SavvyUI_Debug.lib. Click OK when done to save the changes you made to these configurations in the Project Property Pages dialog.
Edit Your Windows Application main .cpp file (The file that contains the main function and the message loop), and then make the following changes to that file.
- Add the following includes:
#include <include/Frame.h> #include <include/CardPanel.h> #include <include/EventListeners.h>
- Create a class that inherits the SavvyUI Frame class:
class MainFrame : public Frame, public ActionListener { CardPanel _mainView; public: MainFrame(const wstring& title) : Frame(title) { setLicense(L"Set Your SavvyUI License String Here!!!"); } void onConstructWindow() { setWindowCentered(); // Add the child components Bounds clientRect; GetClientRect(clientRect); // LAYOUT THE MAIN WINDOW COMPONENTS HERE!!! GridPanel* contentPane = getContentPane(); contentPane->setLayout({ 5, -1, 5 }, { 5, -1, 5 }); contentPane->addComponent(&_mainView, 1, 1); // SET THE MAIN WINDOW ICON IF NEEDED BY CALLING setIcon setIcon(IconSource(IconType::CALCULATOR)); // CREATE THE MAIN WINDOW MENUBAR IF NEEDED Menu* fileMenu = addMenu(L"File"); if (fileMenu) { fileMenu->addTextItem(10, L"New"); fileMenu->addTextItem(11, L"Open"); Menu* saveAsMenu = fileMenu->addPopupItem(L"Save As Image"); if (saveAsMenu) { saveAsMenu->addTextItem(10291, L"PNG"); saveAsMenu->addTextItem(10292, L"JPG"); saveAsMenu->addTextItem(10292, L"GIF"); } fileMenu->addTextItem(12, L"close"); fileMenu->addSeparatorItem(); fileMenu->addTextItem(13, L"Exit"); } Menu* editMenu = addMenu(L"Edit"); if (editMenu) { editMenu->addTextItem(21, L"Copy"); editMenu->addTextItem(22, L"Paste"); editMenu->addTextItem(23, L"Cut"); editMenu->addTextItem(24, L"Select All"); } // REGISTER THIS FRAME AS THE LISTENER TO RECEIVE THE MENU EVENTS, THE EVENTS WILL BE DISPATCHED THROUGH onAction setMenuBarListener(this); } // IMPLEMENT onAction TO RECEIVE ACTION EVENTS FROM THE MENUBAR, BUTTONS, ETC. void onAction(const ActionEvent& ev) { if (ev.actionId == 10) { DialogFactory::showInfo(this, L"File->New action"); } else if (ev.actionId == 10291) DialogFactory::showInfo(this, L"File->Save As PNG"); } }; - UPDATE THE MAIN FUNCTION TO INSTANTIATE THE Frame CLASS WE CREATED ABOVE
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); long screenWidth, screenHeight; UICommonUtils::getScreenSize(screenWidth, screenHeight); Bounds rect; rect.left = 0; rect.top = 0; rect.right = screenWidth > 1400 ? 1400 : screenWidth; rect.bottom = screenHeight > 800 ? 800 : screenHeight; MainFrame frame(L"YOUR APPLICATION TITLE"); return frame.show(rect.left, rect.top, rect.width(), rect.height()); }