News:

Download Pelles C here: http://www.pellesc.se

Main Menu

Recent posts

#71
Work in progress / Controls notifications reflect...
Last post by Michele - September 19, 2026, 01:36:09 PM
Almost all windows UI programmers needed to create custom versions or behavior of standard controls to perform special function.
For simple hackings the control procedure subclassing is enough, but for some more sophisticated modifications we need to handle also the notifications messages.
The problem in this case is that the notification messages, in WM_COMMAND or WM_NOTIFY form, are sent only to the parent window. The solution is to insert the custom handling code inside the parent procedure, or subclass it adding another procedure function.
The result is always complex code difficult to read, debug and maintain, not mentioning the difficulties to route control private data structures and cleaning allocated resources: memory, properties, etc.
Another limitation is the portability, to reuse the customization for other controls requires many tweaking in the program sources.

It would be very nice to code all the custom functions inside the control subclass procedure, possibly with a transparent layer that reflects the window messages to the control subclass procedure and take care of infrastructure creation and cleanup.
To avoid reinventing the wheel, I thoroughly examined several well-established techniques that have been in use for years, observing how they are employed by frameworks such as MFC, ATL, and the like.
I built this simple framework for the code above. It isn't perfect, needs more tests and may get upgrades for added functionalities.
Up to now it works flawlessly for my code.

I share it in the hope that could be of any help to someone else.

P.S. It is freshly written code and I didn't put a lot of comments up to now, but I think it is easily understandable. The AI was of a lot of help to speed-up.
#72
Tips & tricks / Re: UTF-8 multilanguage consol...
Last post by TimoVJL - September 18, 2026, 12:14:50 PM
Windows 7 have Consolas font, but version 5.? and Windows 1x have version 7 font family.
Less interest to console, albeit file / folder names can have many kind of chars.
#73
Tips & tricks / Re: UTF-8 multilanguage consol...
Last post by Michele - September 18, 2026, 09:26:00 AM
Timovjl you successfully changed the codepage to UTF-8, in fact many characters are correctly displayed.
I agree that now the problem is the console font that doesn't contains the full set.
A known font known to render all charset is 'Consolas', try changing the face font with:
BOOL SetConsoleFontToConsolas(void)
{
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hConsole == INVALID_HANDLE_VALUE) return FALSE;

    CONSOLE_FONT_INFOEX cfi;
    cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);

    // Get the current font info first to preserve defaults
    if (!GetCurrentConsoleFontEx(hConsole, FALSE, &cfi))
    {
        return FALSE;
    }

    // Set font properties
    cfi.dwFontSize.X = 0;   // Width (0 lets Windows calculate based on height)
    cfi.dwFontSize.Y = 16;  // Height (Font size in points/pixels)
    cfi.FontFamily = FF_DONTCARE;
    cfi.FontWeight = FW_NORMAL;

    // Specify a TrueType font that supports UTF-8 Unicode characters
    // Common choices: L"Cascadia Code", L"Consolas", L"Lucida Console"
    wcscpy_s(cfi.FaceName, LF_FACESIZE, L"Consolas");

    // Apply the new font
    return SetCurrentConsoleFontEx(hConsole, FALSE, &cfi);
}

If still doesn't it confirms that the fonts in your OS version are limited.
You said that on a Win10/11 system it works?
#74
Tips & tricks / Re: UTF-8 multilanguage consol...
Last post by TimoVJL - September 18, 2026, 09:03:07 AM
Windows 7 x64 EN console.

Less fonts than Windows 1x versions.

#75
Tips & tricks / Re: UTF-8 multilanguage consol...
Last post by Michele - September 17, 2026, 10:06:40 PM
Hello Vortex, I imagine that the problem is the OS version.
I will not add mine, just report what Gemini says:
QuoteThe functions SetConsoleOutputCP and SetConsoleCP along with the CP_UTF8 code page constant (code page 65001) have been supported since Windows 2000.

However, the minimal OS version depends on what you are trying to achieve:

Basic Function Support (API availability): Windows 2000 or later. Calling SetConsoleOutputCP(65001) is supported on all Windows NT-based OS versions starting from 2000, as well as Windows XP, Vista, 7, 8, and 10.

Functional UTF-8 Console Rendering: Windows 10 Version 1903 (Build 18362) or later.

Why the distinction matters:
While the functions exist on older OS versions, UTF-8 support inside cmd.exe on legacy releases (Windows 7/8/early Win 10) was notoriously buggy:

Legacy Bugs: On older versions like Windows 7, setting the console to code page 65001 frequently broke C runtime output routines (printf), caused character truncation, or crashed batch scripts.

Font Rendering: Legacy consoles couldn't render multi-byte UTF-8 sequences properly unless using specific TrueType fonts.

Full ConPTY Overhaul: Microsoft fully overhauled the Windows Console infrastructure in Windows 10 version 1903 (Build 18362)—the exact same release that introduced manifest-based UTF-8 ACP support—making UTF-8 output reliable and stable in the terminal.
#76
Tips & tricks / Re: UTF-8 multilanguage consol...
Last post by Vortex - September 17, 2026, 10:01:22 PM
Hi Michele,

Thanks for your code. Testing your executable on my Windows 7 Sp1 64-bit, I get a lot of garbled characters, probably a limitation of Windows 7.
#77
Tips & tricks / UTF-8 with windows mixed ANSI/...
Last post by Michele - September 17, 2026, 09:52:41 PM
This other example shows how to use the manifest to change the process codepage for a window program.
When we change the process codepage to UTF-8 the ANSI version of many (warning not all!) windows messages automatically translates from process codepage to internal UTF-16 (unicode) format.
Winapi explicitly allows the mixed use of ANSI and WIDE messages providing behind the scenes the translation from between the process codepage and unicode. This means that you can create an ANSI window/control and send to it wide messages or the reverse, and also means that you are free to create a unicode or ansi application as you like and use which encoding you prefer.
But if your codepage doesn't cover the whole range of alphabets, i.e. if you use a typical latin western 1252 encoding, supplying an utf8 string will produce garbage output.
The trick is to set the process codepage to UTF-8 using the specific manifest command, but this feature has benn introduced starting from Windows 10 Version 1903 (Build 18362), and will be silently ignored in previous versions. The manifest code is:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
  <windowsSettings>
    <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
  </windowsSettings>
</application>
The attached sample demonstrate how it works. You can test it in both versions ANSI and WIDECHAR, just change the '#if 1' to '#if 0' to compile in ANSI mode.

The idea was born creating a program based on sqlite3 that is UTF-8 based.

If your system does'nt supports the process codepage change you can use the standar conversion functions:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

// 1. UTF-8 (multibyte char*) -> UTF-16 (wchar_t*)
wchar_t* Utf8ToUtf16(const char* utf8_str) {
    if (!utf8_str) return NULL;

    // Get required buffer size in wchar_t elements (including null-terminator)
    int size_needed = MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, NULL, 0);
    if (size_needed == 0) return NULL;

    wchar_t* wstr = (wchar_t*)malloc(size_needed * sizeof(wchar_t));
    if (!wstr) return NULL;

    // Perform conversion
    MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, wstr, size_needed);
    return wstr; // Caller must free()
}

// 2. UTF-16 (wchar_t*) -> UTF-8 (multibyte char*)
char* Utf16ToUtf8(const wchar_t* wstr) {
    if (!wstr) return NULL;

    // Get required buffer size in bytes (including null-terminator)
    int size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
    if (size_needed == 0) return NULL;

    char* utf8_str = (char*)malloc(size_needed);
    if (!utf8_str) return NULL;

    // Perform conversion
    WideCharToMultiByte(CP_UTF8, 0, wstr, -1, utf8_str, size_needed, NULL, NULL);
    return utf8_str; // Caller must free()
}
#78
Tips & tricks / UTF-8 multilanguage console pr...
Last post by Michele - September 17, 2026, 08:38:58 PM
Somewhere on this forum there was a discussion about how to print multilanguage strings on console output.
The small attached sample shows the code that use the console codepage set functions using the UTF-8 encoding that is, at least for me, a very powerful option because while allows the multilanguage text let you use the simple and efficient ansi text functions (strcpy, ctrcat, strcmp, ...).
#79
Add-ins / Re: Add-Ins
Last post by TimoVJL - September 17, 2026, 04:45:37 PM
When someone want to see compiled C-code in assembler, easist way is to use Add-In, that show podump.exe output from object file in poide Output window in easy way.

The poide have over 50 Add-Ins with source code, so lot of code for everyone to study.

https://forum.pellesc.de/index.php?msg=29747
#80
Add-ins / Re: Add-Ins
Last post by John Z - September 14, 2026, 09:55:47 PM
Definitely agree with you Timo !  The ability to do Add-In's is exceptional.  User feature requests are where I started to develop Add-In's from requests for simple button on the toolbar to Linecounter+ to Copy Mode  and Hint.  You are the king of the Add-In's in my book.

Many might not know that a few revision back Pelle significantly enhanced the Add-In's capability for the Debug mode.  Seems like a lot of potential there.

John Z