I cannot reproduce your problem.
#include <Windows.h>
LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_CREATE:
CreateWindowA("BUTTON", "Click here", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
10, 10, 200, 30, hWnd, (HMENU)1, NULL, NULL);
break;
case WM_NCCALCSIZE: {
if (wParam == TRUE) {
SetWindowLong(hWnd, DWLP_MSGRESULT, 0);
return TRUE;
}
return FALSE;
}
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
switch (wmId)
{
case 1:
{
PRINTDLGEX pdx{ .lStructSize{sizeof(pdx)} };
// Allocate an array of PRINTPAGERANGE structures.
LPPRINTPAGERANGE pPageRanges = (LPPRINTPAGERANGE)GlobalAlloc(GPTR, 10 * sizeof(PRINTPAGERANGE));
if (!pPageRanges)
return E_OUTOFMEMORY;
pPageRanges->nFromPage = 2;
pPageRanges->nToPage = 100;
pdx.hwndOwner = hWnd;
pdx.Flags = PD_PAGENUMS;
pdx.nPageRanges = 1;
pdx.nMaxPageRanges = 10;
pdx.lpPageRanges = pPageRanges;
pdx.nMinPage = 1;
pdx.nMaxPage = 100;
pdx.nCopies = 1;
pdx.nStartPage = START_PAGE_GENERAL;
auto hResult = PrintDlgEx(&pdx);
}
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}
case WM_PAINT:
return 0;
default:
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
hInstance = GetModuleHandle(NULL);
WNDCLASSEX wcx{ sizeof(WNDCLASSEX) };
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.hInstance = hInstance;
wcx.lpfnWndProc = WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.lpszClassName = L"MyWindow";
wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcx.hCursor = LoadCursor(hInstance, IDC_ARROW);
RegisterClassEx(&wcx);
HWND hwnd = CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW,
L"MyWindow",
L"MainWindow",
WS_MAXIMIZEBOX | WS_THICKFRAME,
100, 100, 500, 400,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}