Page 1 of 1

Is there a way to close a SimpleDialog

Posted: Tue May 02, 2023 10:09 pm
by mminsel
Hi,

Is there a way to close a SimpleDialog, which was started with DoModal?

I've tried to call OnOK(), OnCancel() and EndDialog(dlg) but they were all undefined (nil).

I would like to close the modal dialog, after another button than the OK/Cancel button was clicked.

Re: Is there a way to close a SimpleDialog

Posted: Wed May 03, 2023 8:15 am
by SimplSam
To my knowledge the answer is no, but I wish the answer was yes.I would even like the option to close them from code in the main application.

Re: Is there a way to close a SimpleDialog

Posted: Fri May 05, 2023 11:02 am
by mminsel
Hi Sam,

That was my suspicion. I've now created a c++ lua module that allows to close the modal dialog using a workaround:

Code: Select all

extern "C" __declspec(dllexport) int closeMenuWindow(lua_State * L)
{
	lua_lock(L);
	const char* windowName = luaL_checkstring(L, -1);
	lua_pushnil(L);
	lua_unlock(L);

#ifdef _WIN32
			std::thread([]() {
				std::this_thread::sleep_for(std::chrono::milliseconds(100));
				HWND hwnd = FindWindowA("LM_Wnd", windowName);
				if (!hwnd) {
					return 1;
				}
				bool status = PostMessageA(hwnd, WM_KEYDOWN, VK_RETURN, 0);
				if (!status) {
					DWORD lastError = GetLastError();
					int i = 0;
				}
				}).detach();
#endif
	return 1;
}
This needs to be done in a thread with a small delay, as the moho interface needs to have time to react, apparently.

Re: Is there a way to close a SimpleDialog

Posted: Sat May 06, 2023 4:51 am
by SimplSam
That's a neat work-around. I also have an Elgato Stream Deck keypad which I use to initiate script and/or key-press sequences which are used to control some features of Moho.

Re: Is there a way to close a SimpleDialog

Posted: Sun May 07, 2023 4:37 am
by bbrraayyaann
mminsel wrote: Tue May 02, 2023 10:09 pm Hi,

Is there a way to close a SimpleDialog, which was started with DoModal?

I've tried to call OnOK(), OnCancel() and EndDialog(dlg) but they were all undefined (nil).

I would like to close the modal dialog, after another button than the OK/Cancel button was clicked.
To close a Domodal from another button you simply create a button in the dialog like this:

Code: Select all

d.boton = LM.GUI.Button("Close dialog", LM.GUI.MSG_CANCEL)
l:AddChild(d.boton)

Re: Is there a way to close a SimpleDialog

Posted: Mon May 27, 2024 10:29 pm
by MehdiZangenehBar
mminsel wrote: Fri May 05, 2023 11:02 am Hi Sam,

That was my suspicion. I've now created a c++ lua module that allows to close the modal dialog using a workaround:

Code: Select all

extern "C" __declspec(dllexport) int closeMenuWindow(lua_State * L)
{
	lua_lock(L);
	const char* windowName = luaL_checkstring(L, -1);
	lua_pushnil(L);
	lua_unlock(L);

#ifdef _WIN32
			std::thread([]() {
				std::this_thread::sleep_for(std::chrono::milliseconds(100));
				HWND hwnd = FindWindowA("LM_Wnd", windowName);
				if (!hwnd) {
					return 1;
				}
				bool status = PostMessageA(hwnd, WM_KEYDOWN, VK_RETURN, 0);
				if (!status) {
					DWORD lastError = GetLastError();
					int i = 0;
				}
				}).detach();
#endif
	return 1;
}
This needs to be done in a thread with a small delay, as the moho interface needs to have time to react, apparently.
Any chance we can have access to that extension?