Decision. . As stated below, it is probably best to create your own method for the text, rather than trying to make the control behave abnormally. Thus, creating a user control for this would be better. I found a tutorial that explains all this: http://www.codeproject.com/Articles/559385/Custom-Controls-in-Win-API-The-Basics .
It was suggested, but no practical solutions.
I am trying to use static controls to display text, so updating is as simple as sending a message. I can also easily scratch the controls and just use a simple DrawText (), but this seems like a sloppier solution.
This is the method of drawing the owner.
else if (message == WM_DRAWITEM) {
LPDRAWITEMSTRUCT pDIS;
pDIS = (LPDRAWITEMSTRUCT)lParam;
RECT rc;
SetTextColor(pDIS->hDC, RGB(200,10,60));
SelectObject(pDIS->hDC, (HPEN)GetStockObject(NULL_PEN));
SelectObject(pDIS->hDC, (HBRUSH)GetStockObject(NULL_BRUSH));
SetBkMode(pDIS->hDC, TRANSPARENT);
Rectangle(pDIS->hDC, 0, 0, pDIS->rcItem.right+1, pDIS->rcItem.bottom+1);
DrawText(pDIS->hDC, "teststring", 10, &pDIS->rcItem, 0);
return 0;
}
and I get:

On the left is what I get, right is what I want.
CreateWindow("STATIC", "teststring", WS_CHILD | WS_VISIBLE | SS_OWNERDRAW, 20, 20, 120, 40, hwnd, (HMENU)(IDC_STATIC_TEST), GetModuleHandle(NULL), NULL);
This is what I use to create static.
I worked for more than 4 hours, trying to do this, I tried everything.
Any help is appreciated.
It would be better to just forget the static controls and return to use only with DrawText ().
Thank.
hwnd = CreateWindowEx (0, szClassName, "Test Transparent Static Main Window", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX , 100, 100, 300, 200, HWND_DESKTOP, NULL, hThisInstance, NULL);
ShowWindow (hwnd, nFunsterStil);
hWnd = hwnd;
hInstance = hThisInstance;
while (GetMessage (&messages, NULL, 0, 0)) {
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
switch (message) {
case WM_CREATE:
{
LRESULT lRes = DefWindowProc(hwnd, message, wParam, lParam);
HWND hWndStatic = CreateWindowEx(0, "Static", NULL, WS_CHILD | WS_VISIBLE, 10, 10, 200, 100, hwnd, NULL, hInstance, NULL);
StaticWndProc = (WNDPROC)SetWindowLong(hWndStatic, GWL_WNDPROC, (LPARAM)MyStaticWndProc);
return lRes;
}
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetBkMode(hdc, TRANSPARENT);
SetBkColor(hdc, RGB(110,110,110));
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK MyStaticWndProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam) {
if (Message == WM_PAINT) {
RECT rc;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0,100,200));
DrawText(hdc, "TESTTEXT", 8, &rc, DT_CENTER | DT_VCENTER | SS_LEFT);
EndPaint(hwnd, &ps);
return 0;
}
return StaticWndProc(hwnd, Message, wparam, lparam);
}
--------- EDIT ------------------------------------- --- -----------------
