As I am in a forgiving mood, here is a simple sample that you can modify to your own needs.
This simple program creates a main Window with an EDIT control inside it. On clicking the
Open
selector of the
File
menu item some text will be posted to the control.
As you can see this has nothing to do with C++11, or any other version.
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h> // general windows definitions
#define ID_FILE_OPEN 201 //
#define ID_APP_EXIT 203 //
static HWND hWndEdit;
BOOL OnCreate(HWND hWnd,
LPCREATESTRUCT pCreateStruct
)
{
hWndEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
TEXT("EDIT"),
NULL,
WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
0,
0,
0,
0,
hWnd,
0,
pCreateStruct->hInstance,
0
);
return TRUE; }
void OnSize(HWND hWnd, UINT uState, int nWidth, int nHeight)
{
if (nWidth == 0)
return;
MoveWindow(hWndEdit, 0, 0, nWidth, nHeight, TRUE);
}
static
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMessage,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMessage)
{
case WM_CREATE:
return OnCreate(hWnd, reinterpret_cast<LPCREATESTRUCT>(lParam));
case WM_COMMAND:
{
if (LOWORD(wParam) == ID_FILE_OPEN)
{
SetWindowText(hWndEdit, L"\r\n\r\n\tThe rain in Spain falls mainly on the ground ...");
return 0;
}
return 1; }
case WM_SIZE:
OnSize(hWnd, wParam, LOWORD(lParam), HIWORD(lParam));
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
return 0;
}
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PWSTR pszCmdLine,
int nCmdShow
)
{
WNDCLASSEX wndClassEx; HWND hWnd;
MSG msg;
wndClassEx.cbSize = sizeof wndClassEx;
wndClassEx.style = CS_HREDRAW | CS_VREDRAW;
wndClassEx.lpfnWndProc = WndProc;
wndClassEx.cbClsExtra = 0;
wndClassEx.cbWndExtra = 0;
wndClassEx.hInstance = hInstance;
wndClassEx.hIcon = nullptr;
wndClassEx.hCursor = LoadCursor(NULL, IDC_SIZEWE);
wndClassEx.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1);
wndClassEx.lpszMenuName = TEXT("IDR_MAINFRAME");
wndClassEx.lpszClassName = TEXT("SimpleEdit");
wndClassEx.hIconSm = NULL;
if (!RegisterClassEx(&wndClassEx))
{
return FALSE;
}
hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE, wndClassEx.lpszClassName, TEXT("SimpleEdit"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 600, 350, NULL, NULL, hInstance, NULL );
if (!hWnd)
{
return FALSE; }
ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Include the following resource script to add the menu to the main Window.
#include <winresrc.h>
IDR_MAINFRAME MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open", 201 MENUITEM SEPARATOR
MENUITEM "E&xit", 203 END
END
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1, 0, 0, 0
PRODUCTVERSION 1, 0, 0, 0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#if defined(_DEBUG)
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "FileDescription", "SimpleEdit Application"
VALUE "FileVersion", "1, 0, 0, 0"
VALUE "ProductName", "SimpleEdit"
VALUE "ProductVersion", "1, 0, 0, 0"
VALUE "InternalName", "SimpleEdit"
VALUE "OriginalFilename", "SimpleEdit.exe"
VALUE "CompanyName", "CodeProject"
VALUE "LegalCopyright", "Copyright© 2020"
VALUE "LegalTrademarks", ""
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 0x4b0
END
END