File Picker

Marco Leise Marco.Leise at gmx.de
Sun Dec 8 02:17:20 PST 2013


Am Sun, 08 Dec 2013 05:49:34 +0100
schrieb "Malkierian" <rhydonj at gmail.com>:

> On Saturday, 7 December 2013 at 23:18:18 UTC, Adam D. Ruppe wrote:
> > On Saturday, 7 December 2013 at 23:00:00 UTC, Malkierian wrote:
> >> Is there anything in D that currently brings up a window to 
> >> find and choose a file, or am I going to have to make it 
> >> myself?  Isn't there a built-in something or other I can hook 
> >> into in Windows?
> >
> > Yeah, on Windows, you can just call the GetOpenFileName 
> > function (or GetSaveFileName if saving) and use the common 
> > dialog.
> > http://msdn.microsoft.com/en-us/library/windows/desktop/ms646927(v=vs.85).aspx
> >
> >
> > I wrote this quick example to show how you can use it in D:
> >
> > http://arsdnet.net/dcode/open.d
> >
> >
> > Since the windows headers distributed with dmd are woefully 
> > incomplete, the first thing I did was copy/paste the struct and 
> > file definition from MSDN.
> >
> > Then, below that, is the main() function which shows how to 
> > call it. There's a lot of customization you can do there, see 
> > the Microsoft docs for more info (or search the web for any C 
> > examples, the function works the same way in D.)
> 
> Man, that's great, thanks.  However, I have it set up in my 
> application, and when I first call it, I get this window:
> 
> http://gyazo.com/02bc18bdc23fdf3c24aa4ff70b46be1f
> 
> Then, if I cancel and open it again, I get the actual browser, 
> but then my program freezes up:
> 
> http://gyazo.com/4e5e873e57cd7a234d56c7a42198ab89
> 
> Any idea why it doesn't work the first time, but then does the 
> second and freezes?

Maybe it requires a working Windows® event loop in your
application, as is typical for GUI applications on any
platform. Windows typically generate all sorts of events, like
mouse clicks, key strokes, resize events etc. They add up in
the event queue and a white window like yours is typical of
Windows® to indicate that "this application is no longer
working off its event loop. (Or in your case never started to
do so.)
If that is indeed the problem, worry not, because most events
can be handled by the default handler, but you'll need to
write an simple event loop. I'm not sure, but it could be that
you'll need to create a dummy window as well since event loops
work with window handles. Maybe it is ok to pass 0 everywhere,
maybe you need a valid handle.

-- 
Marco



More information about the Digitalmars-d-learn mailing list