Login Page - Create Account

Support Board


Date/Time: Tue, 21 Jan 2025 10:50:51 +0000



Post From: Adding Text with GDI Function to Study

[2018-08-08 18:55:42]
BlakJak - Posts: 108
I am unable to add text to a study with GDI functions, however, adding Rectangles, Chords, etc. is working fine.

Here is a sample GDIFunction which is failing along with a screen capture of what it produces.


void DrawBubbles(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc)
{
  HFONT hFont, hOldFont;
  HBRUSH hBrush;
  hFont = CreateFont(20, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 2, 0, L"SYSTEM_FIXED_FONT");
  hBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);

  // Select the variable stock font into the specified device context.
  if (hOldFont = (HFONT)SelectObject(DeviceContext, hFont))
  {
    SetTextColor(DeviceContext, RGB(0, 0, 0));

    TextOut(DeviceContext, 100, 100, L"Sample ANSI_VAR_FONT text", 25);

    std::stringstream bidAskTxt;
    RECT rc;
    SetRect(&rc, 200, 200, 500, 500);
    int retval = DrawTextA(DeviceContext, "X", -1, &rc, 0);

    SelectObject(DeviceContext, hOldFont);
    DeleteObject(hFont);
  }

  SelectObject(DeviceContext, hBrush);
  Chord(DeviceContext, 200, 200, 250, 250, 200, 225, 250, 225);
}

In this example there are three functions tested.

1) The call to TextOut displays text at the bottom right of the screen. Can be seen pointed out by the arrow in attached. No matter how the X,Y coords of the function are changed, the text always remains there.

2) The call to DrawTextA displays nothing no matter what is entered into the RECT.

3) A call to Chord which draws a black semi-circle correctly at the proper coordinates I specify. (I am adding this to show that my code is working.


Why do the first and second functions fail?
imageProblemWithDrawText.png / V - Attached On 2018-08-08 18:55:24 UTC - Size: 83.22 KB - 523 views