Support Board
Date/Time: Tue, 21 Jan 2025 10:54:59 +0000
Adding Text with GDI Function to Study
View Count: 2743
[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? |
ProblemWithDrawText.png / V - Attached On 2018-08-08 18:55:24 UTC - Size: 83.22 KB - 523 views |
[2018-08-09 00:40:59] |
Sierra Chart Engineering - Posts: 104368 |
Understand we do not provide programming help. We are marking this as Programming Help.
Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2018-08-09 00:41:34
|
[2018-08-09 15:18:24] |
BlakJak - Posts: 108 |
OK. I have tried taking code from a standard windows program that draws text correctly on the screen at the position that I want and pasting that into my ACSIL GDI Function and it does not work (still draws it in the bottom right corner). So I suspect there is something extra that needs to be set in the DeviceContext for ACSIL programming that I am missing. If anyone out there in the community could share a GDI example using DrawText() I would really appreciate it. |
[2018-08-09 19:46:59] |
BlakJak - Posts: 108 |
I have been scratching my head with the way Sierra is handling GDI text drawing. In order to ensure my code was good, I wrote two programs, one in pure Win32 API and the other as a Sierra ACSIL study using the same drawing functions with the same parameters. Attachments: - Win32Example.cpp - Win32ExampleOutput.png - ExtendedGDIExample.cpp As you can see from the output of the Win32 example, the yellow rectangle and the text is properly showing on the window. You can see the code under the WM_PAINT case in the WndProc callback. It does not work properly with Sierra Charts in the extended GDI example I also attached. The yellow rectangle is drawn but the text does not appear. I cannot understand why my code works in a standard Windows API program but does not in my Sierra GDI function code. Please investigate further as I believe this proves that it is not a coding error but a potential bug in SC's GDI function handling. |
Win32Example.cpp - Attached On 2018-08-09 19:46:06 UTC - Size: 4.4 KB - 684 views Win32ExampleOutput.png / V - Attached On 2018-08-09 19:46:18 UTC - Size: 6.75 KB - 477 views ExtendedGDIExample.cpp - Attached On 2018-08-09 19:46:34 UTC - Size: 3.17 KB - 570 views |
[2018-08-10 04:28:58] |
Sierra Chart Engineering - Posts: 104368 |
the way Sierra is handling GDI text drawing. It does not. This is what you are doing. We give you the device context and then you are using that directly. Sierra Chart does not get into the middle of this at all. You are going straight to the Windows operating system. That should be clear.It is more likely it is just an issue possibly where the particular state of the device context is such that maybe the text does not appear due to certain attributes which may have been previously set. But this should not be a problem in the latest prerelease. Try the latest prerelease. Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
[2018-08-10 04:56:47] |
BlakJak - Posts: 108 |
It is more likely it is just an issue possibly where the particular state of the device context is such that maybe the text does not appear due to certain attributes which may have been previously set.
This is what I suspected was happening but I could not figure out what state the Device Context was in so I could correct it for my text drawing. I will try out the pre-release version. |
[2018-08-10 05:01:24] |
Sierra Chart Engineering - Posts: 104368 |
Just wait about an hour. We are putting out another release to ensure there is also no clipping region being set when the user provided GDI drawing function is called.
Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
[2018-08-10 09:22:57] |
BlakJak - Posts: 108 |
Is the latest pre-release 1788? I tried it out but the same problem exists as before.
|
[2018-08-10 12:40:30] |
Sierra Chart Engineering - Posts: 104368 |
Make sure you set the text align: void DrawToChart(HWND WindowHandle, HDC DeviceContext, SCStudyInterfaceRef sc ) { //Create a Yellow brush HBRUSH Brush = CreateSolidBrush(RGB(255,255,0)); //Select the brush into the device context HGDIOBJ PriorBrush = SelectObject(DeviceContext, Brush); //Draw a rectangle at the top left of the chart Rectangle(DeviceContext, 0,0 ,200, 200); //Remove the brush from the device context and put the prior brush back in. This is critical! SelectObject(DeviceContext,PriorBrush); //Delete the brush. This is critical! If you do not do this, you will end up with a GDI leak and crash Sierra Chart. DeleteObject(Brush); ::SetTextAlign(DeviceContext, TA_NOUPDATECP); ::TextOut(DeviceContext, 225, 225, "Hello.", 6); return; } Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
To post a message in this thread, you need to log in with your Sierra Chart account: