Sending EM_GETZOOM to a Rich Edit control always returns a ratio of 0/0 even after programmatically changing it.

DaveF 21 Reputation points

I'm using Visual Studio 2022 on Windows 10.

I have a Rich Edit control that I've created using the following line of code:

editWrap = CreateWindowEx(ES_EX_ZOOMABLE, MSFTEDIT_CLASS, nullptr, ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_AUTOVSCROLL | ES_DISABLENOSCROLL, 0, 0, 0, 0, hwnd, nullptr, appInstance, nullptr);

In my WindowProc, I have the following code in a switch case that handles the EN_UPDATE notification from the Rich Edit control:

WPARAM numerator{};
LPARAM denominator{};
if (auto result = SendMessage(getCurrentEditor(), EM_GETZOOM, numerator, denominator); result == TRUE)
    std::wstringstream messageStream{};
    messageStream << result << ": " << LOWORD(numerator) << "/" << LOWORD(denominator) << "\n";

When that block of code executes, the SendMessage() call always returns FALSE since the debug string never shows up in the Output pane of Visual Studio. It doesn't matter whether I've zoomed the control using the mouse or using the menu items that I've wired up to programmatically change the zoom ratio.

Is there something I'm missing?

By the way, getCurrentEditor() returns the HWND for the currently active editor. My app has two editors that I switch between based on whether wrapping is enabled or not.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,512 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,629 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 43,051 Reputation points

    Pass the address of the numerator and the denominator --

    SendMessage(getCurrentEditor(), EM_GETZOOM, &numerator, &denominator);

    The posted code initializes the two variables to 0, which is the same as passing NULL for both parameters in the call to SendMessage. That is why the function always returns FALSE. The docs say, "The message returns TRUE if message is processed, which it will be if both wParam and lParam are not NULL."

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful