Thanks, I already like and use WinMerge.
Also thank for the macro, I will study...
Still, I was thinking of an "editor text macro",
aka I type {Ctrl-Shift-T] in the editor part of VS with the [T] macro will write "SetWindowTextW(hwnd, L"Caption text"); at caret position.
Here is one of the things I've done so far...
Do not hesitate to tell if you see big No! No!
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include <ntsecAPI.h>
#include <shellapi.h>
#include <wininet.h>
#include "main.h"
static LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
HFONT MakeFontEx(LPCWSTR, int, int, DWORD, DWORD);
// ****************************************************************************
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, WCHAR* pszCmdLine, int nCmdShow)
{
HMODULE hRichEditLib = LoadLibraryW(L"MsftEdit.dll"); /* Load RichEdit "RichEdit50W" v4.1 */
// Register the main window class
WNDCLASSEX WinClass;
WinClass.cbSize = sizeof(WNDCLASSEX);
WinClass.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
WinClass.lpfnWndProc = MainWndProc;
WinClass.cbClsExtra = 0;
WinClass.cbWndExtra = 0;
WinClass.hInstance = hInstance;
WinClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
WinClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WinClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WinClass.lpszMenuName = 0;
WinClass.lpszClassName = L"SimpleClass";
WinClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
if (RegisterClassEx(&WinClass))
{
HWND hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,
L"SimpleClass",
L"RichEdit",
WS_OVERLAPPEDWINDOW,
(GetSystemMetrics(SM_CXSCREEN) - 500) / 2, //Center window on desktop
(GetSystemMetrics(SM_CYSCREEN) - 300) / 2, //Center window on desktop
500,
300,
NULL,
NULL,
hInstance,
0);
// Show and paint the main window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Pump messages until we are done
MSG msg = {0,0,0,0,0,0,0};
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Return msg.wParam;
}
FreeLibrary(hRichEditLib);
return(0);
}
//****************************************************************************
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
wchar_t pURL[INTERNET_MAX_URL_LENGTH];
CREATESTRUCT* pCreateStructure;
ENLINK* param = (ENLINK*)lParam;
switch (msg)
{
case WM_CREATE:
pCreateStructure = (LPCREATESTRUCT)lParam; //Get instance from wWinMain
static HINSTANCE hInstance;
hInstance = pCreateStructure->hInstance;
#ifdef _WIN64
SetWindowText(hwnd, L"Simple app - 64bit");
#else
SetWindowText(hwnd, L"Simple app - 32bit");
#endif
RECT rc;
GetClientRect(hwnd, &rc); //Get client rectangle
//Create a richedit control
static HWND hEdit;
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_RIGHTSCROLLBAR, L"RichEdit50W", L"",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL |
ES_WANTRETURN | ES_SAVESEL | ES_NOHIDESEL | WS_VSCROLL | WS_TABSTOP,
2, 2, rc.right - 4, rc.bottom - 4,
hwnd, NULL, hInstance, NULL);
//URL detection
SendMessage(hEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hEdit, EM_SETEVENTMASK, 0, ENM_LINK | ENM_PROTECTED);
//Create a font
static HFONT hFont;
hFont = (HFONT)MakeFontEx(L"Segoe UI", 12, FW_NORMAL, FALSE, FALSE); //Create desired font
SendMessage(hEdit, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)
TEXT("\n C++ RichEdit - Visual Studio 2019 !\n\n"
" http://www.objreader.com/index.php?topic=319.0\n"
" {Double click to go using default browser...}")); //Set text
//Set control background color
SendMessage(hEdit, EM_SETEDITSTYLE, SES_EXTENDBACKCOLOR, 0); //Extend background color
SendMessage(hEdit, EM_SETBKGNDCOLOR, 0, RGB(200, 200, 200)); //Set background color
//Set selection fore and back color
CHARFORMAT2 ChrFormat;
ChrFormat.cbSize = sizeof(CHARFORMAT2);
ChrFormat.dwEffects = 0;
ChrFormat.dwMask = CFM_COLOR | CFM_BACKCOLOR; //Flag for fore and back color
ChrFormat.crTextColor = RGB(200, 0, 255); //Fore color
ChrFormat.crBackColor = RGB(255, 255, 0); //Back color
SendMessage(hEdit, EM_SETSEL, 17, 36); // Select some text
SendMessage(hEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&ChrFormat); //Set selection fore and back color
SendMessage(hEdit, EM_SETSEL, -1, -1); //Remove selection by moving caret to the end
SetFocus(hEdit); //Set focus
break;
case WM_NOTIFY:
if ((param)->nmhdr.hwndFrom == hEdit) //Only hEdit
{
if ((param)->nmhdr.code == EN_LINK) //If we got EN_LINK code
{
if ((param)->msg == WM_LBUTTONDBLCLK) //If it is a double click
{
DWORD UrlLen = ((param)->chrg.cpMax - (param)->chrg.cpMin + 2); //Get lenght of URL
TEXTRANGE TxtRange;
TxtRange.chrg = (param)->chrg; //Copy text range
TxtRange.lpstrText = pURL; //Point to URL
SendMessage(hEdit, EM_GETTEXTRANGE, 0, (LPARAM)&TxtRange); //Get the URL text
HINSTANCE result;
result = ShellExecuteW(HWND_DESKTOP, L"open", pURL, L"", L"", SW_SHOW); //Open the URL using default browser.
PostMessage(hEdit, EM_SETSEL, (param)->chrg.cpMin, (param)->chrg.cpMin); //Remove selection
}
}
return FALSE;
}
break;
case WM_SIZE:
if (wParam != SIZE_MINIMIZED)
{
MoveWindow(hEdit, 2, 2, LOWORD(lParam) - 4, HIWORD(lParam) - 4, TRUE); //Resize the richedit control
}
break;
case WM_DESTROY:
PostQuitMessage(0); //Say bye!
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
break;
}
}
//****************************************************************************
bool CALLBACK MakeFontExEnumCharSet(LPLOGFONT elf, LPNEWTEXTMETRIC ntm, DWORD FontType, BYTE *CharSet)
{
//Get type of character set - ansi, symbol. A must for some fonts.
*CharSet = elf->lfCharSet;
//UNREFERENCED_PARAMETER( lplf );
return FALSE;
}
//****************************************************************************
HFONT MakeFontEx(LPCWSTR wFontName, int PointSize, int fBold, DWORD fItalic, DWORD fUnderline)
{
HDC hDC = GetDC(HWND_DESKTOP);
DWORD CyPixels = GetDeviceCaps(hDC, LOGPIXELSY);
//EnumFontFamilies(hDC, wFontName, &MakeFontExEnumCharSet, CharSet);
BYTE CharSet = 0;
EnumFontFamilies(hDC, wFontName, (FONTENUMPROC) &MakeFontExEnumCharSet, (LPARAM) &CharSet);
//EnumFontFamilies(hDC, wFontName, (FONTENUMPROC) 0, (LPARAM) CharSet);
ReleaseDC(HWND_DESKTOP, hDC);
PointSize = 0 - (PointSize * CyPixels) / 72;
HFONT font;
font = CreateFont(PointSize, 0, //Height, width(default=0)
0, 0, //Escapement(angle), orientation
fBold, //Weight (%FW_DONTCARE = 0, %FW_NORMAL = 400, %FW_BOLD = 700)
fItalic, //Italic
fUnderline, //Underline
FALSE, //StrikeThru
CharSet, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
FF_DONTCARE, wFontName);
return font;
}
//****************************************************************************