Looking for some guidance

Pages: 12
HI All,
I want to write some desktop apps. Right now I have a couple of books on C++. One by Deitel & Deitel, and the other by Ivar Horton. These books cover C++ but no windows apps. These books cover console apps.

I have been doing some research on writing desktop apps and found Win App SDK. Is this where I want to go?

What about .NET 7?

If Win App SDK is the way to go should I continue to study C++ and then go to Win App?
Also can you recommend a good book for learning how to write desktop apps?

Any help is appreciated.
Mark
Last edited on
Personally I recommend either QT (portable UI library) or C# (windows mostly) for the UI, and C++ for any high performance sections called by the UI. The reason is that M$ mangled the language (its basically a new c++ derived language) when doing the UI in c++, unless you go back to their very old stuff with MFC (still works, still supported, but not advisable).
If you want to learn their managed C++, there should be online resources for it but I have avoided it and can't point to any one as 'better'
You are using the abbreviation UI does this mean Win UI3? By the way, I like C++ programming it is very powerful. The books I have are over 800 pages long.
Last edited on
If you want to learn about the Win Desktop API, what used to be called Win32, there is an old tutorial online:

theForger's Win32 API Tutorial
http://www.winprog.org/tutorial/

It is old, the Win Desktop API has seen some major changes over the years. If you are using a compiler newer than Visual Studio 6 or so the example code can have some warnings and problems compiling the examples as is.

I mucked around and updated as I saw fit the example code to be more modern. So Visual Studio 2019/2022 doesn't whinge as much. I put the original and revised code in a git repository.

https://github.com/GeorgePimpleton/theForger-winapi-tutorial
It means User Interface. This can be anything from a console program where the UI is reading text and typing on the keyboard with a simple 1) x 2) y menu like you do in your first few programs all the way to interaction via a VR headset and gloves.

For windows, specifically, I meant their heavily mouse driven rectangular window frames with menus/buttons/hotspots/text boxes /combo boxes/ etc. The standard windows desktop interface one thinks of when talking about windows programs. The version does not matter too much, most of the changes are cosmetic.

I like C++ as well; its my primary language. I hate that M$ has refused to provide a modern, pure C++ library for their desktop developers, but they are obsessed with the idea that C++ is flawed and they keep trying to 'fix' it.
Last edited on
I am not interested in doing any win 32 apps. As far as I am concerned those days are long gone. Windows 11 is 64 bit. I want to be in that arena. My current use for development is to use Visual Studio 2022. I am aware that there is lots of mouse movement. That is ok with me. What I am trying to achieve is to write some windows apps. using C++.
I remember years ago that Visual Studio used to have Visual C++. What ever happened to that.
If you want to be writing for 64-bit, I second the recommendation of QT. https://www.qt.io/

Visual C++ is still part of Visual Studio. You just have to select it when you install VS. It is not installed by default.

I am not interested in doing any win 32 apps

The Win32 API, as I said, has been updated to the Win Desktop API that includes what's needed for 32-bit and 64-bit apps.

The Win32 API is all about user interface constructs, and more, the same things you need to know when dealing with Win 10/11.

Standard C++ console mode code:
1
2
3
4
5
6
#include <iostream>

int main()
{
   std::cout << "Hello World!\n";
}


The absolute bare minimum to cruft a Windows capable app Unicode based (it doesn't do much, it's a message box):
1
2
3
4
5
6
7
8
#include <windows.h>

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR szCmdLine, int iCmdShow)
{
   MessageBoxW(NULL, L"Hello World!", L"Hello Message", MB_OK);

   return 0;
}

What's needed to create the bare minimum WinAPI Desktop app (with a bit extra):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI wWinMain(_In_      HINSTANCE hInstance,
                    _In_opt_  HINSTANCE hPrevInstance,
                    _In_      PWSTR szCmdLine,
                    _In_      int nWinMode)
{
   static const WCHAR szAppName[] = L"MinWinAPIApp";

   WNDCLASSEXW wc;

   wc.cbSize        = sizeof(WNDCLASSEX);
   wc.style         = CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc   = WndProc;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = hInstance;
   wc.hIcon         = (HICON)   LoadImageW(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
   wc.hIconSm       = (HICON)   LoadImageW(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
   wc.hCursor       = (HCURSOR) LoadImageW(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
   wc.hbrBackground = (HBRUSH)  (COLOR_WINDOW + 1);
   wc.lpszMenuName  = NULL;
   wc.lpszClassName = szAppName;

   if ( 0 == RegisterClassExW(&wc) )
   {
      MessageBoxW(NULL, L"Can't Register the Window Class!", szAppName, MB_OK | MB_ICONERROR);
      return E_FAIL;
   }

   static const WCHAR szAppTitle[] = L"WinAPI Desktop Skeletal Application";

   HWND hwnd = CreateWindowW(szAppName, szAppTitle,
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT, CW_USEDEFAULT,
                             CW_USEDEFAULT, CW_USEDEFAULT,
                             NULL, NULL, hInstance, NULL);

   if ( NULL == hwnd )
   {
      MessageBoxW(NULL, L"Unable to Create the Main Window!", szAppName, MB_OK | MB_ICONERROR);
      return E_FAIL;
   }

   ShowWindow(hwnd, nWinMode);
   UpdateWindow(hwnd);

   // enter the main message loop
   MSG msg;

   while ( GetMessageW(&msg, NULL, 0, 0) )
   {
      TranslateMessage(&msg);
      DispatchMessageW(&msg);
   }

   return (int) msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch ( message )
   {
   case WM_PAINT:
      HDC         hdc;
      PAINTSTRUCT ps;
      hdc = BeginPaint(hwnd, &ps);

      RECT rect;
      GetClientRect(hwnd, &rect);
      DrawTextW(hdc, L"Hello, Modern Windows!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

      EndPaint(hwnd, &ps);
      return S_OK;

   case WM_DESTROY:
      PostQuitMessage(0);
      return S_OK;
   }

   return DefWindowProcW(hwnd, message, wParam, lParam);
}

That a lot of code! But then the app is fully integrated into the Windows system.

The original Win API was C based. MFC was designed after C++ had been created and designed to hide all the pesky details needed to create a Win API app that "plays nice with Windows."

MFC_APP.hpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once

// compile for Windows 7 or higher
// #define WINVER       0x0601
// #define _WIN32_WINNT 0x0601

// compiling for Windows 10 (recommended)
// if you want to compile for Win 11 use the Win 11 versions
// I have no need for those, I am Win 10
#define WINVER       0x0A00
#define _WIN32_WINNT 0x0A00

#include <afxwin.h>

// application class
class CTheApp : public CWinApp
{
public:
   BOOL InitInstance();
};

// main window class
class CMainWnd : public CFrameWnd
{
public:
   CMainWnd();

protected:
   afx_msg void OnPaint();

   DECLARE_MESSAGE_MAP()
};

MFC_APP.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "MFC_APP.hpp"

// construct a window
CMainWnd::CMainWnd()
{
   Create(NULL, L"An MFC Application Skeleton");
}

// initalize the application
BOOL CTheApp::InitInstance()
{
   m_pMainWnd = new CMainWnd;

   m_pMainWnd->ShowWindow(m_nCmdShow);
   m_pMainWnd->UpdateWindow();

   return TRUE;
}

// application's message map
BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd)
   ON_WM_PAINT()
END_MESSAGE_MAP()

// draw some text centered in the client area
void CMainWnd::OnPaint()
{
   CRect    rect;

   GetClientRect(&rect);

   CPaintDC dc(this);

   dc.DrawTextW(L"Hello, MFC!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}

// instantiate the application
CTheApp  theApp;

All this code is compileable as x86/64 as-is. Works with VS2019/2022.

I remember years ago that Visual Studio used to have Visual C++. What ever happened to that.

MSVC++ is now an optional package available for Visual Studio 2019/2022. Nothing has happened to it other than being moved around a bit.

Windows is no longer a purely Desktop interface model, keyboard and mouse. It is now available on tablets and other devices. So MS created more uniform ways to change how the UI is drawn and interacted with using the same code base. C# and XAML is one way.

QT is a 3rd party framework, allegedly to make creating WinAPI apps easier.
OK not going to do Qt. They want too much money for me. I am looking for a C++ piece of software that I can use and make an executable file to sell. I installed VC++ files in my VS Community. I don't know if I have everything I need.

George, I can read the code you put here but don't recognize some of the language.

If anyone has any knowledge about Windows App SDK and Win UI3, I would like to know more about that. Maybe I will use C#. But isn't C# like Java?
Last edited on
You can use modern Microsoft platforms like WPF (uses XAML + C#), and then interface with C++ if you still want the core logic to be in C++.

So you'd have one VS solution, and your user interface is a WPF/C# project, and the core logic is a C++ project.
you lost me Ganado. Not really interested in C#. More interested in C++. What you have here would seem to me to be more complicated.
OK not going to do Qt. They want too much money for me.

QT has a free license unless you're using it commercially.
I did not know that. So where can I download it? I think I am going to settle with Windows App SDK and Win UI 3. In the past it was easy to find books on just about everything software and hardware. There is a book written, that is recently written for Win App and Win UI3. I have seen a book by APress for Qt. Perhaps tomorrow and look for it on Amazon.
There is also a few books on C#. Too tired to go on.

Thanks for your help guys.
Last edited on
These books cover console apps.


Stroustrop's book 'Programming: Principles and Practice Using C++' uses FLTK (x-platform) to introduce gui programming.
https://www.amazon.co.uk/Programming-Principles-Practice-Using-C/dp/0321992784/ref=sr_1_11
https://www.fltk.org/
Last edited on
AbstractionAnon wrote:
QT has a free license unless you're using it commercially.
mathman54 wrote:
I am looking for a C++ piece of software that I can use and make an executable file to sell.

(Bolding mine.)
Last edited on
You can use it commercially even without a "commercial license" as long as you follow the terms of the free license.

Wikipedia wrote:
Qt is available under the following free software licenses: GPL 2.0, GPL 3.0, LGPL 3.0 and LGPL 2.1 (with Qt special exception). Note that some modules are available only under a GPL license, which means that applications which link to these modules need to comply with that license.

There is nothing preventing you from selling a program licensed under the GPL but it basically means you have to license your whole program under the terms of the GPL (or a compatible license) which gives the users the same rights to use, modify and distribute as was given to you.

LGPL is more permissive. You can use a library that is licensed under the LGPL regardless of what license you use in the rest of the program, but you essentially have to dynamically link to it (there might be other ways to fulfil the requirements but as far as I have understood it the user needs some way to swap out the LGPL part of the program if he or she wants to).
Last edited on
LGPL is more permissive. You can use a library that is licensed under the LGPL regardless of what license you use in the rest of the program, but you essentially have to dynamically link to it (there might be other ways to fulfil the requirements but as far as I have understood it the user needs some way to swap out the LGPL part of the program if he or she wants to).

Exactly that. Qt can be used under GPL, LGPL or commercial license – at your choice.

The GPL requires that any software which includes/links GPL'ed code (even small portions) must be distributed under GPL too, as a whole – provided that you actually distribute your software. As long as the software containing GPL'ed code only runs on your own servers, the GPL doesn't require you to publish any of your own code or the (modified) GPL'ed code at all. That's why the AGPL came to be.

The LGPL allows linking proprietary code with LGPL'ed code and distributing the combined work without the requirement to put the whole work under the LGPL – provided that the LGPL'ed portion and the proprietary portion remain strictly separate, and that the LGPL'ed portion has not been modified. If you want to modify the LGPL'ed portion, then those modifications have to be distributed under the LGPL.

It is usually understood that linking a proprietary executable to a LGPL'ed library as a "shared" library (DLL) is fine 🙂

So, even if you want to build a commercial application that will be distributed under a proprietary license, using Qt for "free" under the LGPL will be alright. The commercial license would only be required, if you need to link Qt into your proprietary executable as a "static" library, or if you want to make your own modifications to the Qt library code which your are not willing to share.

Also, the commercial license gives you access to "extended" support, i.e. you get security patches for old Qt versions that have run out of "standard" support. Without a commercial license, you'll effectively be forced to upgrade to the latest Qt version regularly.
Last edited on
Sorry I haven’t been paying enough attention, but I noticed “Deitel & Deitel” in the questions list and had to stop.

Throw that crap out. Those two have been ruining future programmers for years.

Here’s a list of garbage to avoid, and why:
https://www.cs.technion.ac.il/users/yechiel/CS/BadBooksC+C++.html

If you really want to get going with C++, check out:
https://www.learncpp.com/
That list is old! I'm not a fan of Deitel but their later books are popular and IMO have improved over the last few years. Their latest re C++20 isn't that bad but I'm still not a fan (I prefer Horton's Beginning C++20 as an intro book). Schildt hasn't written a C++ book since 2008 (he was popular when Turbo C ruled) - so yes, definitely don't get any of his C++ books (even cheap second hand). I have no knowledge of the others. IMO as of the date of this posting, anyone wanting to learn C++ shouldn't get a book that was published before 2020.
Pages: 12