Login Page - Create Account

Support Board


Date/Time: Fri, 19 Apr 2024 15:55:40 +0000



[Programming Help] - How to make modeless dialog boxes for a sierra chart study? Code provided.

View Count: 3575

[2018-12-20 17:46:17]
doetrader - Posts: 13
I'm writing an ACSIL/C++ program that runs in Sierra Chart. I'm trying to open a modeless dialog box from a Shortcut Menu item. The dialog box would accept text input that gets converted into floats, and then that is stored in a global variable so other Sierra Chart programs can use the values.

I'm using the windows API/visual c++. I understand the basics of message loops and dialog/window procedures. I also already have dialog resource templates design through the Dialog Editor.

What I'm stuck on now is to implement it. I'm especially confused on how to implement the message loop. When I tried putting the loop in the click event of the Short cut menu item inside the ACSIL Study Function, I made Sierra Chart crash.

I'm also confused on how to get the window handle. The owner should be the main Serra Chart window, but how do I get the handle? Should I use the windows get foreground handle function that is out there?

Could I get a general overview and steps on how to go about setting this up?

I'm following: https://docs.microsoft.com/en-us/windows/desktop/dlgbox/using-dialog-boxes#creating-a-modeless-dialog-box

and

http://www.winprog.org/tutorial/modeless_dialogs.html


Here is my code:

Global Variables:


HWND g_hwndBar = NULL; // Window handle of dialog box
MSG g_msg;

Dialog Procedure:


int foo;
BOOL CALLBACK FooBarProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
  UNREFERENCED_PARAMETER(lParam);
  switch (message)
  {
    case WM_INITDIALOG:
      return TRUE;
    case WM_COMMAND:
      switch (LOWORD(wParam))
      {
        case IDOK:
          foo = GetDlgItemInt(hwndDlg, IDINPUTBOX, NULL, FALSE);
          return TRUE;

        case IDCANCEL:
          DestroyWindow(hwndDlg);
          return TRUE;
      }
  }
  return FALSE;
}

My Study code:


SCSFExport scsf_FooBarStudy(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {

    sc.GraphName = "Foo bar study";

    sc.StudyDescription = "";

    sc.GraphRegion = 0;

    sc.AutoLoop = 0;

    sc.FreeDLL = 1;

    return;
  }

  int& r_MenuID = sc.GetPersistentInt(1);

  if (sc.LastCallToFunction)
    sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, r_MenuID);

  if (r_MenuID <= 0)
    r_MenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "bar");
  
  if (r_MenuID < 0)
    sc.AddMessageToLog("Add ACS Chart Shortcut Menu Item failed", 1);

  if (sc.MenuEventID != 0 && sc.MenuEventID == r_MenuID)
  {
    if (!IsWindow(g_hwndBar))
    {
      g_hwndBar = CreateDialogW(NULL, MAKEINTRESOURCE(IDD_SIMPLETARGETMENU), NULL, (DLGPROC)FooBarProc);
      ShowWindow(g_hwndBar, SW_SHOW);
    }

    BOOL bRet;

    while ((bRet = GetMessage(&g_msg, NULL, 0, 0)) != 0)
    {
      //if (bRet == -1){}
      if (!IsWindow(g_hwndBar) || !IsDialogMessage(g_hwndAddTarget, &g_msg))
      {
        TranslateMessage(&g_msg);
        DispatchMessage(&g_msg);
      }
    }
  }
}

[2018-12-20 18:11:18]
Sierra Chart Engineering - Posts: 104368
What I'm stuck on now is to implement it. I'm especially confused on how to implement the message loop.
You do not need the message loop. Sierra Chart has its own message loop and your dialog will get the messages. So that is automatically handled for you.

For the window handle it is perfectly fine to use the chart window handle instead of the main window and that is preferred anyway. Refer to:

ACSIL Interface Members - Variables and Arrays: sc.ChartWindowHandle
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:

Login

Login Page - Create Account