How to display the value of a variable in the WIN API

int i = 5; TCHAR text[256]; _stprintf(text, TEXT("%d"), i); TextOut(hdc, 700, 50, text,100); 

It does not print anything, the line in the debug works, everything converts, but there is no output (

    2 answers 2

    Hello, maybe the problem is that you set the number of characters to 100, and not to strlen(text)

     int i=5; char text[50]={'\0'};//можно ещё обнулить, для уверенности itoa(i,text,10);//переводим число в строку TextOutA(hdc,10,10,text,strlen(text)); 

    I recall that in WM_PAINT HDC we get the function BeginPaint(HWND,LPPAINTSTRUCT) , release EndPaint(HWND,LPPAINTSTRUCT) . In all other cases - GetDC(HWND) \ GetWindowDC(HWND) , release ReleaseDC(HWND,HDC)

      We need brackets ( BeginPath and EndPath ) and, perhaps, we need to set the color ( SetTextColor and SetBkMode ) in order not to write black on black.

       BeginPath(hdc); // SetTextColor(hdc, ...); // SetBkMode(hdc, ...); TextOut(hdc, 700, 50, text,100); EndPath(hdc); 
      • Unfortunately does not help - user207044
      • @ user207044 Did you try to change the color, as advised by the respondent? - StateItPrimitive
      • Yes, set black, did not help - user207044
      • @ user207044 and, for example, is it possible to draw a rectangle? And the suspicion is that you are hdc wrong hdc . Show more code around. - Ilya