TextOut should work fine, if done in WM_PAINT, it needs to be drawn every time. (including minimization and recalibration)
LRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_PAINT: PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); TextOut(hdc, 10, 10, TEXT("Text Out String"),strlen("Text Out String")); EndPaint(hWnd, &ps); ReleaseDC(hWnd, hdc); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
You may also be interested in DrawText
LRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_PAINT: PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); RECT rec; // SetRect(rect, x ,y ,width, height) SetRect(&rec,10,10,100,100); // DrawText(HDC, text, text length, drawing area, parameters "DT_XXX") DrawText(hdc, TEXT("Text Out String"),strlen("Text Out String"), &rec, DT_TOP|DT_LEFT); EndPaint(hWnd, &ps); ReleaseDC(hWnd, hdc); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
What will draw the text in your window in the given rectangle,
The text will be drawn by Word Wrap inside this rectangle.
If you want your whole window as a drawing area, you can use GetClientRect(hWnd, &rec); instead of SetRect(&rec,10,10,100,100);