Login Page - Create Account

Support Board


Date/Time: Sun, 22 Dec 2024 22:28:24 +0000



Post From: Problem with drawing using sc.p_GDIFunction

[2014-04-23 14:01:09]
norvik - Posts: 22
Dear SC Support,
I have a problem with drawing using sc.p_GDIFunction. Study is calculated only when it is applied on the chart or when I
press "Recalculate" at the chart menu. After I do some interactive action with chart, moving or scrolling, I see a wrong drawing result.

Code:
// GDI.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include <windows.h>
#include "C:\SierraChart\ACS_Source\sierrachart.h"

SCDLLName ("GDI Example")

// This file demonstrates the functionality to use the Windows graphics device interface with ACSIL to freely draw inside of the chart window

// Windows GDI documentation can be found here: http://msdn.microsoft.com/en-nz/library/windows/desktop/dd145203%28v=vs.85%29.aspx

/*==========================================================================*/
void DrawToChart(HWND hWnd, HDC hDC); //Drawing function declaration

int firstY;
int secondY;
int firstX;
int secondX ;
/*==========================================================================*/
SCSFExport scsf_DrawToChartExample(SCStudyInterfaceRef sc)
{

  if (sc.SetDefaults)
  {

    // Set the configuration and defaults

    sc.GraphName = "Draw To Chart Example";

    sc.AutoLoop = 0;

    // When specifying a GDI function below, this must be false. Otherwise, the GDI function will not be called.
    sc.FreeDLL = 0;

    sc.GraphRegion = 0;

    // This is how we specify the drawing function.
    sc.p_GDIFunction = DrawToChart;

    return;
  }


  // Do data processing
firstY = sc.RegionValueToYPixelCoordinate(sc.Close[sc.ArraySize - 1],0);
secondY = sc.RegionValueToYPixelCoordinate(sc.Close[sc.ArraySize - 100],0);
firstX = sc.BarIndexToXPixelCoordinate(sc.ArraySize - 1);
secondX = sc.BarIndexToXPixelCoordinate(sc.ArraySize - 100);


}
/*==========================================================================*/

//This is the actual drawing function. This function is specified by the "sc.p_GDIFunction" member in the main study function. This drawing function is called when Sierra Chart draws the study on the chart. This will only occur after there has been a call to the main "scsf_" study function which is defined above.

//Currently this drawing function does not have access to the ACSIL "sc." structure. We are considering how this might be possible to add in the future. Any study data that you need to access in this drawing function, should be placed into global variables by the main "scsf_" study function which can then be accessed by this function when it is called.

void DrawToChart(HWND hWnd, HDC hDC)
{
  // Создаем Pen
HPEN hPen = CreatePen (PS_SOLID, 2, RGB(255, 0, 0));

// Выбираем свой Pen в DC, запоминаем старый Pen
HPEN hOldPen = (HPEN)SelectObject (hDC, hPen);

// Перемещаем точку рисования в левый верхний угол окна
MoveToEx(hDC, firstX, firstY, NULL);
// Рисуем линию в правый нижний угол
LineTo(hDC, secondX, secondY);

// Выбираем старый Pen в DC (освобождаем свой Pen из DC)
SelectObject(hDC, hOldPen);

// Удаляем Pen
DeleteObject (hPen);

  return;
}

/*==========================================================================*/

imageAfterApplyingStudy.jpg / V - Attached On 2014-04-23 14:00:37 UTC - Size: 169.98 KB - 693 views
imageAfterResizingBarSpacing.jpg / V - Attached On 2014-04-23 14:00:46 UTC - Size: 181.66 KB - 617 views