Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 15:07:02 +0000



Post From: How to make modeless dialog boxes for a sierra chart study? Code provided.

[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);
      }
    }
  }
}