Custom captions are done with DWM : Custom Window Frame Using DWM
For example, a test with a gradient :
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This is what i have written so far, my doubt is how to set the caption color of my new window to black.
// Step 4: the Window Procedure.
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
TerminateProcess(GetCurrentProcess(), 0);
break;
case WM_DESTROY:
case WM_QUIT:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
// Step 1-3 Creating a window procedure.
int Main()
{
WNDCLASSEX wc{};
MSG Msg;
LPCWSTR title = L"MyWindow";
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = 0;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = title;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wc))
{
DWORD err = GetLastError();
std::wstring error = L"Window Registration Failed.\nError: " + std::to_wstring(int(err));
MessageBox(NULL, error.c_str(), L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hWnd = CreateWindowW(
title,
title,
//WS_OVERLAPPEDWINDOW,
WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, 600, 300, // X,Y,W,H
nullptr, nullptr, nullptr, nullptr);
DWORD err = GetLastError();
if (hWnd == NULL)
{
std::wstring error = L"Window creation failed.\nError: " + std::to_wstring(int(err));
MessageBox(NULL, error.c_str(), L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
// Step 3: The Message Loop
while (GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0; // Msg.wParam;
}
Custom captions are done with DWM : Custom Window Frame Using DWM
For example, a test with a gradient :
Then just change the caption color like in the MSDN sample...
You can refer to the thread asnwered by Castorix31 :Draw a custom text on title bar using DWM