How do I get the Window Handle for a Win32 Desktop application running on Sierra Chart and Setup Message Loop?

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?

EDIT:

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:

1
2
HWND g_hwndBar = NULL;  // Window handle of dialog box 
MSG g_msg;


Dialog Procedure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
			}
		}
	}
}
Last edited on
Not sure what you mean with message loop. Dialogs use only on callback function for messages but no loops.
Can you show us the code?
@thomas1965:

I not using Modal Dialogs. You can't do that with Sierra Chart exactly due to the fact of it's use of callbacks.

I have edited my question to add further details and code.
Are you sure that you need this loop with GetMessage ?
What happens when you remove it ?
In a normal Windows program you have this kind of loop only in the WinMain function.
I'm not really sure, no. I tried removing it and nothing happened.
Does it still crash ?

What is SCSFExport ?

Your function promises to return it but it doesn't.
No it is not crashing anymore.

SCSFExport is required for Sierra Chart Studies.

I also found a forum specifically for Sierra Chart Programming help. Here is what I have so far: https://www.sierrachart.com/SupportBoard.php?ThreadID=39309#post_last

Also, as it turns out I do not need a message loop because Sierra Chart handles it. Sierra Chart also provides a variable to get the main window handle.
Topic archived. No new replies allowed.