NexusFi: Find Your Edge


Home Menu

 





How do I go about making modeless dialog boxes? Code Provided.


Discussion in Sierra Chart

Updated
    1. trending_up 2,667 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 8 posts
    2. attach_file 2 attachments




 
Search this Thread
  #1 (permalink)
doetrader
Atlanta, Georgia, USA
 
Posts: 19 since Dec 2018
Thanks Given: 2
Thanks Received: 0

Following: https://www.sierrachart.com/SupportBoard.php?ThreadID=39298

I am unable to get a modeless dialog box to popup when a Shortcut Menu item is pressed. Here is what I have:


Quoting 
DlgResource.rc

 
Code
IDD_SIMPLEINPUTMENU DIALOGEX 0, 0, 215, 78
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Foobar"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    EDITTEXT        IDINPUTBOX,38,29,144,14,ES_AUTOHSCROLL | WS_GROUP
    GROUPBOX        "Bar",IDC_TARGETINROUP,25,7,169,44,BS_FLAT | WS_GROUP
    DEFPUSHBUTTON   "OK",IDOK,112,57,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,51,57,50,14
END



Quoting 
MainStudyFile.cpp

 
Code
#include "resource.h"
#include <windows.h>
#include "sierrachart.h"

SCDLLName("My Studies")

HWND g_hwndAddTarget = NULL;  // Window handle of dialog box 

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; 

} 


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) 

  { 

    g_hwndAddTarget = CreateDialogW(NULL,					 
                                    MAKEINTRESOURCE(IDD_SIMPLEINPUTMENU),										 
                                    (HWND)sc.ChartWindowHandle,									 
                                    (DLGPROC)FooBarProc);
    ShowWindow(g_hwndAddTarget, SW_SHOW);

  } 

}


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
Commodities
Iran Fired a Missile at Israel Last Night. The $8M June …
Prediction Markets & Event Contracts
$500M Riding on World Cup 2026: France/Spain Co-Favored …
Prediction Markets & Event Contracts
Hormuz Normalization Collapses to 19.5% -- Iran Regime F …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
205 thanks
Sober Journey With S&P
21 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
Thanks Mike. Godspeed.
7 thanks
  #3 (permalink)
doetrader
Atlanta, Georgia, USA
 
Posts: 19 since Dec 2018
Thanks Given: 2
Thanks Received: 0


By the way, that is all the code I have. Exactly how it is structured in my files. I'm not sure if that is the proper way to structure it or not. Any guidance will be helpful at this point.


Reply With Quote
  #4 (permalink)
doetrader
Atlanta, Georgia, USA
 
Posts: 19 since Dec 2018
Thanks Given: 2
Thanks Received: 0

https://www.sierrachart.com/SupportBoard.php?ThreadID=39309

Any help would be appreciated.


Reply With Quote
  #5 (permalink)
doetrader
Atlanta, Georgia, USA
 
Posts: 19 since Dec 2018
Thanks Given: 2
Thanks Received: 0

I still need help with all of this if anyone experienced would be willing to help in any way.


Reply With Quote
  #6 (permalink)
ludvig
russia kaliningrad
 
Posts: 19 since Jan 2011
Thanks Given: 0
Thanks Received: 21

Hi.
Try create a thread with MessageLoop() instead of creating dialog directly.
You can pass a pointer to s_sc structure to the dialog constructor then.
Maybe it's not a best way, but works fine for me. I'm using tnis set of classes for working with GUI windows coding - Win32++. Header only wrapper around winapi functoins, very nice to remove MFC.


Reply With Quote
Thanked by:
  #7 (permalink)
doetrader
Atlanta, Georgia, USA
 
Posts: 19 since Dec 2018
Thanks Given: 2
Thanks Received: 0


ludvig View Post
Hi.
Try create a thread with MessageLoop() instead of creating dialog directly.
You can pass a pointer to s_sc structure to the dialog constructor then.
Maybe it's not a best way, but works fine for me. I'm using tnis set of classes for working with GUI windows coding - Win32++. Header only wrapper around winapi functoins, very nice to remove MFC.

Could you provide a link to the documentation/reference on MessageLoop()? Also, could you provide a small code example of what you're talking about?


Reply With Quote
  #8 (permalink)
ludvig
russia kaliningrad
 
Posts: 19 since Jan 2011
Thanks Given: 0
Thanks Received: 21

OK, after holidays


Reply With Quote
  #9 (permalink)
ludvig
russia kaliningrad
 
Posts: 19 since Jan 2011
Thanks Given: 0
Thanks Received: 21


Main dll *cpp:

 
Code
#include "stdafx.h"
#include "TestDialog.h"

SCDLLName("Dialog Test")

HANDLE m_hThread = nullptr;
CMyDialog* TestDlg = nullptr;
CWinApp TheApp;

static UINT32 __stdcall TestDlgThreadProc(void * pParam)
{
	s_sc* p_sc = reinterpret_cast<s_sc*>(pParam);
	if (p_sc == nullptr)
		return 1L;

	if (TestDlg == nullptr)
	{
		TestDlg = new CMyDialog(IDD_DIALOG, p_sc);
		TestDlg->Create();
		TestDlg->ShowWindow();
		TestDlg->UpdateWindow();
		TheApp.Run();
	}

	_endthreadex(0);
	return 0;
}

void StartDialog(SCStudyInterfaceRef sc)
{
	UINT ThreadId = 0;

	if (m_hThread == nullptr)
	{
		m_hThread = (HANDLE)::_beginthreadex(NULL,
			NULL,
			TestDlgThreadProc,
			&sc,
			CREATE_SUSPENDED,
			&ThreadId);

		if (NULL == m_hThread)
		{
			return;
		}
		else
		{
			::ResumeThread(m_hThread);
			sc.IsFullRecalculation = 1;
		}
	}
}


SCSFExport scsf_DialogTest(SCStudyInterfaceRef sc)
{
	SCSubgraphRef Average = sc.Subgraph[0];
	 
	if (sc.SetDefaults)
	{
		
		sc.GraphRegion = 0;

		Average.Name = "Average";

		Average.PrimaryColor = RGB(0, 255, 0);
		Average.DrawStyle = DRAWSTYLE_LINE;
		Average.LineWidth = 2;

		sc.AutoLoop = 1;

		sc.AlertOnlyOncePerBar = true;
		sc.UpdateAlways = 1;
		
		sc.FreeDLL = 1;
		sc.AutoLoop = 1;

		return;
	}

	StartDialog(sc);
	
	int len = 30;
	sc.DataStartIndex = len - 1;

	
	sc.SimpleMovAvg(sc.Close, Average, len);

	
	if (sc.LastCallToFunction)
	{
		TestDlg->SendMessage(WM_CLOSE, 0, 0);

		DWORD result = WaitForSingleObject(m_hThread, INFINITE);

		if (result == WAIT_OBJECT_0)
		{
			CloseHandle(m_hThread);
			m_hThread = NULL;
			delete TestDlg;
			TestDlg = nullptr;
		}
	}
}
VS2017 project attached to this post.

As for MessageLoop(),
it is windows messaging prosedure, TheApp.Run() returns this one:

 
Code
MessageLoop()
	{
		// This gets any messages queued for the application, and dispatches them.
		MSG Msg;
		ZeroMemory(&Msg, sizeof(MSG));
		int status = 1;
		LONG lCount = 0;

		while (status != 0)
		{
			// While idle, perform idle processing until OnIdle returns FALSE
			// Exclude some messages to avoid calling OnIdle excessively
			while (!::PeekMessage(&Msg, 0, 0, 0, PM_NOREMOVE) &&
								(Msg.message != WM_TIMER) &&
								(Msg.message != WM_MOUSEMOVE) &&
								(Msg.message != WM_SETCURSOR) &&
								OnIdle(lCount) != FALSE  )
			{
				++lCount;
			}


			lCount = 0;

			// Now wait until we get a message
			if ((status = ::GetMessage(&Msg, NULL, 0, 0)) == -1)
				return -1;

			if (!PreTranslateMessage(Msg))
			{
				::TranslateMessage(&Msg);
				::DispatchMessage(&Msg);
			}

		}

		return LOWORD(Msg.wParam);
	}
Happy coding!


Attached Files
Elite Membership required to download: SCDllDialogTest.7z
Reply With Quote
Thanked by:




Last Updated on January 2, 2019


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts