Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
How do I go about making modeless dialog boxes? Code Provided.
Updated January 2, 2019
trending_up
1,679 views
thumb_up
3 thanks given
group
2 followers
forum
8 posts
attach_file
2 attachments
How do I go about making modeless dialog boxes? Code Provided.
December 23rd, 2018, 04:37 AM
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:
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
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);
}
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
December 23rd, 2018, 06:57 AM
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.
December 24th, 2018, 11:42 PM
Atlanta, Georgia, USA
Posts: 19 since Dec 2018
Thanks Given: 2
Thanks Received: 0
December 29th, 2018, 08:01 AM
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.
December 30th, 2018, 05:17 AM
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.
December 30th, 2018, 10:16 AM
Atlanta, Georgia, USA
Posts: 19 since Dec 2018
Thanks Given: 2
Thanks Received: 0
ludvig
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?
December 30th, 2018, 12:29 PM
russia kaliningrad
Posts: 19 since Jan 2011
Thanks Given: 0
Thanks Received: 21
OK, after holidays
January 2nd, 2019, 06:00 PM
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
Last Updated on January 2, 2019