How do I go about making modeless dialog boxes? Code Provided. - futures io
futures io futures trading



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


Discussion in Sierra Chart

Updated by ludvig
    1. trending_up 717 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 8 replies
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

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

(login for full post details)
  #1 (permalink)
Atlanta, Georgia, USA
 
 
Posts: 19 since Dec 2018
Thanks: 2 given, 0 received

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 futures io?
IB Bracker Order
Platforms and Indicators
Monthly VWAP and SD Levels trading NQ
Emini and Emicro Index
Horizontal Line Indicator
Platforms and Indicators
Confusing strategy order handling in Ninja 8!?
NinjaTrader
ATR of only green candles
EasyLanguage Programming
 
 
(login for full post details)
  #3 (permalink)
Atlanta, Georgia, USA
 
 
Posts: 19 since Dec 2018
Thanks: 2 given, 0 received


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
 
(login for full post details)
  #4 (permalink)
Atlanta, Georgia, USA
 
 
Posts: 19 since Dec 2018
Thanks: 2 given, 0 received

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

Any help would be appreciated.

Reply With Quote
 
(login for full post details)
  #5 (permalink)
Atlanta, Georgia, USA
 
 
Posts: 19 since Dec 2018
Thanks: 2 given, 0 received

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

Reply With Quote
 
(login for full post details)
  #6 (permalink)
russia kaliningrad
 
 
Posts: 19 since Jan 2011
Thanks: 0 given, 21 received

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
The following 2 users say Thank You to ludvig for this post:
 
(login for full post details)
  #7 (permalink)
Atlanta, Georgia, USA
 
 
Posts: 19 since Dec 2018
Thanks: 2 given, 0 received


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
 
(login for full post details)
  #8 (permalink)
russia kaliningrad
 
 
Posts: 19 since Jan 2011
Thanks: 0 given, 21 received

OK, after holidays

Reply With Quote
 
(login for full post details)
  #9 (permalink)
russia kaliningrad
 
 
Posts: 19 since Jan 2011
Thanks: 0 given, 21 received


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
Register to download File Type: 7z SCDllDialogTest.7z (510.2 KB, 8 views)
Reply With Quote
The following user says Thank You to ludvig for this post:


futures io Trading Community Platforms and Indicators Sierra Chart > How do I go about making modeless dialog boxes? Code Provided.


January 2, 2019


Upcoming Webinars and Events
 

Dealing with burnout w/Linda Bradford Raschke

Elite only
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts