Login Page - Create Account

Support Board


Date/Time: Sun, 19 May 2024 00:28:41 +0000



[Programming Help] - How to get modeless dialog box working? Code Provided.

View Count: 5939

[2018-12-21 08:00:57]
doetrader - Posts: 13
Following: How to make modeless dialog boxes for a sierra chart study? Code provided.

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

DlgResource.rc


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



MainStudyFile.cpp


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

SCDLLName("My Studies")

HWND g_hwndFooBar = 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_hwndFooBar = CreateDialogW(NULL,          
MAKEINTRESOURCE(IDD_SIMPLEINPUTMENU),                    
(HWND)sc.ChartWindowHandle,                  
(DLGPROC)FooBarProc);
ShowWindow(g_hwndFooBar, SW_SHOW);

}

}

Date Time Of Last Edit: 2018-12-24 07:13:48
[2018-12-22 23:52:32]
doetrader - Posts: 13
What am I doing wrong?
[2018-12-23 11:58:49]
doetrader - Posts: 13
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.
[2018-12-23 17:27:10]
Sierra Chart Engineering - Posts: 104368
Use this function instead: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-createdialogparama

Do not use the Unicode functions.

If there is an error use GetLastError to find out what it is.
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
[2018-12-23 18:42:12]
doetrader - Posts: 13
Should I set the first argument, hInstance, to NULL?
[2018-12-23 20:35:23]
Sierra Chart Engineering - Posts: 104368
Yes according to the documentation that is correct but if the error relates to the instance handle we will provide the actual instance handle in the next version for you to use.
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
[2018-12-24 07:16:10]
doetrader - Posts: 13
I'm not sure if the error relates to an instance handle, however, please do provide the instance handle in the next version. Also, would sc.ProcID help somewhere here in any way?

I'm also currently getting an error that says that the study has just caused a "CPU exception".

This is the part of the code that I have changed:



if (sc.MenuEventID != 0 && sc.MenuEventID == r_MenuID)

{

g_hwndFooBar =CreateDialogParamA((HINSTANCE)GetWindowLong((HWND)sc.ChartWindowHandle, GWL_HINSTANCE),
           "IDD_SIMPLEINPUTMENU",
           (HWND)sc.ChartWindowHandle,
           (DLGPROC)FooBarProc,
           1);
ShowWindow(g_hwndFooBar, SW_SHOW);

    SCString log;
    log.Format("%s", GetLastError());
    sc.AddMessageToLog(log, 1);
}

}

Date Time Of Last Edit: 2018-12-24 07:21:14
[2018-12-24 11:19:24]
doetrader - Posts: 13
I'm sorry. I think I misunderstood your answer. I'll go back to to set it back to NULL again.
[2018-12-24 20:20:31]
Sierra Chart Engineering - Posts: 104368
The exception was caused by this code. We have corrected it as follows:
SCString LogMessage;
LogMessage.Format("CreateWindow error: %d", GetLastError());

Once you get the error code, let us know what it is.
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
Date Time Of Last Edit: 2018-12-24 20:20:59
[2018-12-25 04:41:06]
doetrader - Posts: 13
I know have this source code but no error returning nor is the dialog box popping up:




if (sc.MenuEventID != 0 && sc.MenuEventID == r_MenuID)

{

g_hwndFooBar = CreateDialogParamA(NULL,
       "IDD_SIMPLEINPUTMENU",
         (HWND)sc.ChartWindowHandle,
         (DLGPROC)FooBarProc,
         1);
ShowWindow(g_hwndFooBar, SW_SHOW);

    SCString LogMessage;
LogMessage.Format("CreateWindow error: %d", GetLastError());
}

}

[2018-12-29 12:55:30]
doetrader - Posts: 13
I still need help with all of this if anyone experienced would be willing to help in any way.
[2019-01-03 17:10:33]
norvik_ - Posts: 106
Here is working example.
imageСнимок экрана (5).png / V - Attached On 2019-01-03 17:09:42 UTC - Size: 83.42 KB - 539 views
attachmentSCDllDialogTest.7z - Attached On 2019-01-03 17:10:12 UTC - Size: 510.2 KB - 494 views
[2019-01-03 17:59:21]
Sierra Chart Engineering - Posts: 104368
Thank you for the example. We intended to try to get to an example but just did not yet have time.

doetrader, when you get it working, let us know where in your code you had a problem.
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
[2019-01-03 18:23:20]
User701453 - Posts: 176
Here is working example.
norvik,
Thanks for the example, but do you have a full English version of the source code?

Thanks.
Date Time Of Last Edit: 2019-01-03 18:34:34
[2019-01-03 23:32:19]
norvik_ - Posts: 106
Sorry, what do you mean as "full English version"? Is it locale of Visual Studio project ? I will try change, but not sure, I have English lang also installed in my VS.
[2019-01-04 00:06:51]
norvik_ - Posts: 106
May be, this attachment helps. If not, you can create new project from sources in your VS.
attachmentSCDllDialogTest_English.7z - Attached On 2019-01-04 00:06:34 UTC - Size: 510.11 KB - 495 views
[2019-01-04 01:13:53]
User701453 - Posts: 176
Screen shot attached on the non-english.
imagenorvik.PNG / V - Attached On 2019-01-04 01:13:15 UTC - Size: 15.16 KB - 532 views
[2019-01-06 23:35:43]
User701453 - Posts: 176
SC support.
Please provide your users a working .cpp example of how to display a fully functional and usable form.

Form should include buttons, input boxes, etc that actually perform an action when used.
A working form would/could look like screen shot of a form attached.
Date Time Of Last Edit: 2019-01-06 23:38:43
imageform.PNG / V - Attached On 2019-01-06 23:37:59 UTC - Size: 18.41 KB - 533 views
[2019-01-30 13:53:44]
doughtrader - Posts: 16
Nice example Norvik. How would you go about doing it for an input dialog box like what doetrader is seemingly trying to do? I see where you define the Timer, but what if a timer is not needed?

I also agree with User701453. Please, dear support, add examples for this area of development to the documentation. The more detailed the example the better.

Also, to add another question to mine above, how do you handle closing the dialog box via OK button without needing to remove the whole study?

How would you go about taking input from the edit box and button it into a container (list, vector, etc..) when a button is clicked?

Also does the wxx files/Win32++ Framework work with windows 10?

Also, when building, I seem to be getting this error:

MyDialog.obj : error LNK2019: unresolved external symbol __imp__InitCommonControls@0 referenced in function "void __cdecl Win32xx::LoadCommonControls(void)" (?LoadCommonControls@Win32xx@@YAXXZ)

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account