filerequester?

Monkey Targets Forums/Desktop/filerequester?

Supertino(Posted 2013) [#1]
Hi - I might have missed it but is there a filerequester dialogue for GFLW? making an editor and need to load/save files etc. Thought it would be in the os mod but not it seems.


ImmutableOctet(SKNG)(Posted 2013) [#2]
No, to my knowledge there isn't. But, you could always implement it yourself. If you want it to be cross-platform, and you don't want to do it from scratch, you may want to look into something like wxWidgets or the Qt framework.

Or, you could always use MonkeyMax so you can use BlitzMax's "RequestFile" command. But if you don't have BlitzMax, and you don't know C++, you're pretty much out of luck.


therevills(Posted 2013) [#3]
It's pretty easy to add to Monkey for Windows at least, I just Googled C++ Windows file requester, grabbed the code from here: http://www.daniweb.com/software-development/cpp/threads/159753/opening-a-filedialog

And within 2 minutes I've got it working:

Monkey Code:
Import "native/extern.cpp"
Extern
   Function OpenFileName:String() = "diddy::openfilename"
Public


extern.cpp:
#include <windows.h>
#include <string.h>
#include <iostream>

class diddy
{
	public:
	// Returns an empty string if dialog is cancelled
	static String openfilename() {
		char *filter = "All Files (*.*)\0*.*\0";
		HWND owner = NULL;
		OPENFILENAME ofn;
		char fileName[MAX_PATH] = "";
		ZeroMemory(&ofn, sizeof(ofn));

		ofn.lStructSize = sizeof(OPENFILENAME);
		ofn.hwndOwner = owner;
		ofn.lpstrFilter = filter;
		ofn.lpstrFile = fileName;
		ofn.nMaxFile = MAX_PATH;
		ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
		ofn.lpstrDefExt = "";

		String fileNameStr;

		if ( GetOpenFileName(&ofn) )
			fileNameStr = fileName;

		return fileNameStr;
	}
}



ImmutableOctet(SKNG)(Posted 2013) [#4]
Therevills, isn't that outdated these days? It should work well enough for a while(BlitzMax uses it currently), but it's still worth looking into something 'higher level' that can be easily backed by more up to date code, like wxWidgets or Qt(Which is what 'Ted' uses). Or once again, writing it yourself in C++.

Also, you're working with C++, not C#, for something like this, classes and namespaces aren't necessary(Especially with how lazily Monkey imports C++ code). C++ will work just fine with procedural/procedurally formatted code. Unless of course you're actually adding it to Diddy, and if that's the case, thanks, now I can be lazy.


therevills(Posted 2013) [#5]
isn't that outdated these days?

No idea! LOL! I've quickly googled it and it was one of the first results... and it worked (at least on Win8).

And just reading that page: "Starting with Windows Vista...", so I guess it depends on how far back you want to support.

like wxWidgets or Qt

All for a simple File Requester? Seems overkill to me...

classes and namespaces aren't necessary

Yeah I know, its just I've got Diddy here and its really quick to add the code to it to test... ;)

Unless of course you're actually adding it to Diddy, and if that's the case, thanks, now I can be lazy.

I'm undecided... If Samah ever finishes his StoryBoard Editor it might be useful then.

And with the Vista onwards approach if we do it that way, I bet someone will come along and complain it doesn't work on WinXP! :P


ImmutableOctet(SKNG)(Posted 2013) [#6]
I completely forgot about this when I made my post, but here: http://monkeycoder.co.nz/Community/posts.php?topic=3610

AdamRedwoods made a Monkey wrapper for wxWidgets a while back. I have no idea how well it works, but it's worth looking into.


Samah(Posted 2013) [#7]
@Sonickidnextgen: ...but it's worth looking into.

Not if all you want is a file dialog. It'd mean including a bajillion libraries with your app, and introducing another failure point.
Native Windows API calls are the best solution in this case.

@therevills: If Samah ever finishes his StoryBoard Editor...

Storyboard Editor? XD


ImmutableOctet(SKNG)(Posted 2013) [#8]
Samah: Not if all you want is a file dialog. It'd mean including a bajillion libraries with your app, and introducing another failure point.
Native Windows API calls are the best solution in this case.

He's making an editor, wxWidgets could be good for a number of things. And when I said that I thought it was worth looking into, I wasn't specifically talking about his current project. It could easily be useful for future projects. Also, depending on how the wrapper was done, it could follow Monkey's "Inefficiency is efficiency" design philosophy, where only what you use is included. I'm pretty sure that isn't the case, but it's not like it's all that big anyway.

Plus, I somewhat doubt that Supertino knows very much C and/or C++, so that would be a working cross-platform alternative.

And to begin with, this is all subjective brainstorming, don't go around saying that one method is the best for a situation we barely know anything about. Let alone the fact that that's just your opinion, and like mine, it doesn't have much depth, this is of course due to the amount of knowledge we have about Supertino's editor. He may need more than just a file requester in the future, or he may not. And if he ever does, we gave him plenty of places to turn to.


Supertino(Posted 2013) [#9]
Thanks guys, revs method worked a treat, seems it sparked a little debate too. I always forget how relatively easy it is to plug external code in Monkey.


therevills(Posted 2013) [#10]
Glad it worked Supertino, I've just pushed a version of Diddy which includes it and the SaveAs version too (OpenFileName & SaveFileName).


blueFire(Posted 2014) [#11]


Monkey Code:

Import "native/extern.cpp"
Extern
   Function OpenFileName:String() = "diddy::openfilename"
Public

extern.cpp:
#include <windows.h>
#include <string.h>
#include <iostream>

class diddy
{
	public:
	// Returns an empty string if dialog is cancelled
	static String openfilename() {
		char *filter = "All Files (*.*)\0*.*\0";
		HWND owner = NULL;
		OPENFILENAME ofn;
		char fileName[MAX_PATH] = "";
		ZeroMemory(&ofn, sizeof(ofn));

		ofn.lStructSize = sizeof(OPENFILENAME);
		ofn.hwndOwner = owner;
		ofn.lpstrFilter = filter;
		ofn.lpstrFile = fileName;
		ofn.nMaxFile = MAX_PATH;
		ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
		ofn.lpstrDefExt = "";

		String fileNameStr;

		if ( GetOpenFileName(&ofn) )
			fileNameStr = fileName;

		return fileNameStr;
	}
}




Will this solution work on all platforms (including mobile) or on windows only?

Jason


AdamRedwoods(Posted 2014) [#12]
Will this solution work on all platforms (including mobile) or on windows only?

windows only. it'd be nice to get all 3 desktop platforms with this (no mobile!), maybe i'll work on that later today.


Emil_halim(Posted 2014) [#13]
Hi all,

just want to tell you that , with my monkey ext we can put the cpp code with the monkey code together

here it is
Import -lcomdlg32

inlineC
        
    //' Returns an empty String If dialog is cancelled
	static String openfilename() {
		const char *filter = "All Files (*.*)\0*.*\0";
		HWND owner = NULL;
		OPENFILENAME ofn;
		char fileName[MAX_PATH] = "";
		ZeroMemory(&ofn, sizeof(ofn));

		ofn.lStructSize = sizeof(OPENFILENAME);
		ofn.hwndOwner = owner;
		ofn.lpstrFilter = filter;
		ofn.lpstrFile = fileName;
		ofn.nMaxFile = MAX_PATH;
		ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
		ofn.lpstrDefExt = "";

		String fileNameStr;

		if ( GetOpenFileName(&ofn) )
			fileNameStr = fileName;

		return fileNameStr;
	}
 
endC

Extern
   Function OpenFileName:String() = "openfilename"
Public

Function Main:Int()
    Print OpenFileName()    
    Return 0
End



nikoniko(Posted 2014) [#14]
Emil_halim wrote:
just want to tell you that , with my monkey ext we can put the cpp code with the monkey code together


How make out it for different desktop platforms - Win, Lin and Mac?


Emil_halim(Posted 2014) [#15]
I posted the monkey trans EXT , it included the source code , so it is only need to compile in each platform.

BTW , in Win platform , Import -lcomdlg32 will work with gcc.
ues #LIBS+="comdlg32.lib" with MSVC2010.