Is there a way to close a SimpleDialog

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
mminsel
Posts: 9
Joined: Fri Oct 25, 2019 10:38 am

Is there a way to close a SimpleDialog

Post 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.
User avatar
SimplSam
Posts: 1093
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Is there a way to close a SimpleDialog

Post 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.
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
mminsel
Posts: 9
Joined: Fri Oct 25, 2019 10:38 am

Re: Is there a way to close a SimpleDialog

Post 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.
User avatar
SimplSam
Posts: 1093
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Is there a way to close a SimpleDialog

Post 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.
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
bbrraayyaann
Posts: 68
Joined: Thu Jan 24, 2019 3:52 am

Re: Is there a way to close a SimpleDialog

Post 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)
User avatar
MehdiZangenehBar
Posts: 66
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Is there a way to close a SimpleDialog

Post 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?
Post Reply