Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Opening the Windows default "Open Dialog" in allegro?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Opening the Windows default "Open Dialog" in allegro?
MiliBytes
Member #3,130
January 2003
avatar

Hi All!
How do you run the Windows "Open" dialog in allegro?
I found this code but it doesn't work well:

1int loader() {
2 TCHAR buf[1024];
3 TCHAR filename[1024];
4 buf[0] = 0;
5 
6 OPENFILENAME file = {
7 sizeof(OPENFILENAME),
8 win_get_window(),
9 NULL,
10 "Block Ultra Map (*.map)",
11 NULL,
12 0,
13 1,
14 buf,
15 1024,
16 filename,
17 1024,
18 NULL,
19 NULL,
20 OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | 0x2000000 /* OFN_DONTADDTORECENT */,
21 /*
22 WORD nFileOffset,
23 WORD nFileExtension,
24 LPCTSTR lpstrDefExt,
25 LPARAM lCustData,
26 LPOFNHOOKPROC lpfnHook,
27 LPCTSTR lpTemplateName
28 */
29 0, 0, NULL, 0, NULL, NULL
30 };
31 
32 
33 BOOL ok = GetOpenFileName(&file);
34
35 return D_O_K;
36}

Please help me, and can you explain most of the things I'm new in C programming!:-/

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

I found this code but it doesn't work well:

Be specific. What are the error messages? Are you including winalleg.h?

I'm not even sure you can plop that into an Allegro program (especially if it's running fullscreen) and have it work, but if you could that would be pretty cool ...

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

MiliBytes
Member #3,130
January 2003
avatar

OK!
1- I didn't add "winalleg.h" to it
2- The Error:
- I can't see any files "*.map" (not even other file type (only folders and drives).

3- And finally how to add that it can see all the files too?

Oh and I got the code from: here

Korval
Member #1,538
September 2001
avatar

Quote:

I can't see any files "*.map" (not even other file type (only folders and drives).

I don't have MSDN up at the moment, but I'm pretty certain that your string, "Block Ultra Map (*.map)" is not sufficient to tell Windows what extension to use. You'll have to look it up in MSDN to find out the real answer.

Quote:

And finally how to add that it can see all the files too?

See above.

A J
Member #3,025
December 2002
avatar

your 4th arg, the string with "block ultra map"

here's what MSDN says:

lpstrFilter
Pointer to a buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.
The first string in each pair is a display string that describes the filter (for example, "Text Files"), and the second string specifies the filter pattern (for example, "*.TXT"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.TXT;*.DOC;*.BAK"). A pattern string can be a combination of valid filename characters and the asterisk (*) wildcard character. Do not include spaces in the pattern string.

The system does not change the order of the filters. It displays them in the File Types combo box in the order specified in lpstrFilter.

If lpstrFilter is NULL, the dialog box does not display any filters.

___________________________
The more you talk, the more AJ is right. - ML

miran
Member #2,407
June 2002

This should do the trick:

"Block Ultra Map (*.map)\0*.map\0\0",

Or am I wrong again?

--
sig used to be here

A J
Member #3,025
December 2002
avatar

wrong!

i think its \0\0\0 on the end
coz the first one is the terminator for the *.map
the next two are the terminators for the pairing, read the msdn text again.

___________________________
The more you talk, the more AJ is right. - ML

miran
Member #2,407
June 2002

MSDN said:

Pointer to a buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.

I thought that meant 2 NULL character at the end...

--
sig used to be here

A J
Member #3,025
December 2002
avatar

good point, depends how you read it...
lets presume im correct..
using 3 nulls will be OK.

now lets presume your correct..
using 2 nulls.. but in fact the correct way was my way.. then 2 nulls will fail.
3 nulls is safer, as it fits in both of our ways or reading the situation.

i would keep seeking clarification, but for the moment, presume 3 nulls, and it will work.. after all whats another null cost ?

___________________________
The more you talk, the more AJ is right. - ML

miran
Member #2,407
June 2002

Yeah I guess you're right. When reading Microsoft's documentation you have to be extremely carefull. Actually you better not even try it unless you have some sort of degree in law or something...

--
sig used to be here

A J
Member #3,025
December 2002
avatar

oh please, you think you need to be smart to do law....

law is robotic, you need to have a memory for everything that has gone before, thats it.

no thinking required.

___________________________
The more you talk, the more AJ is right. - ML

miran
Member #2,407
June 2002

I didn't say you need to be smart, what I meant was you need to know how to read lawyer talk to be able to understand MSDN and other Microsoft's documents...

--
sig used to be here

Bob
Free Market Evangelist
September 2000
avatar

There is a \0 automatically inserted at the end of litteral strings.

--
- Bob
[ -- All my signature links are 404 -- ]

miran
Member #2,407
June 2002

Didn't think of that. So that means you only need to add one \0 at the and the other is automatically inserted, right?

--
sig used to be here

A J
Member #3,025
December 2002
avatar

are you willing to rely on the compiler to do this ?

___________________________
The more you talk, the more AJ is right. - ML

spellcaster
Member #1,493
September 2001
avatar

Sure.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Evert
Member #794
November 2000
avatar

Please write complete words - I for one find it very hard and tiresome to read otherwise.

And if your compiler doesn't do this for you, well, it's broken and you really shouldn't use it.

A J
Member #3,025
December 2002
avatar

could say the same for all the other compiler bugs too.. should i stop using any compiler the moment i find it doesn't do what i thought it should.

btw, shouldn't you have written "should not".. as its very tiresome reading apostrophes. ;D

___________________________
The more you talk, the more AJ is right. - ML

MiliBytes
Member #3,130
January 2003
avatar

Hey guess what "Miran" was right!
It works!

But know how to add in the list (select file type)
"All Files (*.*)" and make it work?
If you told already told me about it I miss understand then!
:P

so the code end it up as:

1int loader() {
2 TCHAR buf[1024];
3 TCHAR filename[1024];
4 buf[0] = 0;
5 
6 OPENFILENAME file = {
7 sizeof(OPENFILENAME),
8 win_get_window(),
9 NULL,
10 "Block Ultra Map (*.map)\0*.map\0\0",
11 NULL,
12 0,
13 1,
14 buf,
15 1024,
16 filename,
17 1024,
18 NULL,
19 NULL,
20 OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | 0x2000000 /* OFN_DONTADDTORECENT */,
21 /*
22 WORD nFileOffset,
23 WORD nFileExtension,
24 LPCTSTR lpstrDefExt,
25 LPARAM lCustData,
26 LPOFNHOOKPROC lpfnHook,
27 LPCTSTR lpTemplateName
28 */
29 0, 0, NULL, 0, NULL, NULL
30 };
31 
32 
33 BOOL ok = GetOpenFileName(&file);
34
35 return D_O_K;
36}

miran
Member #2,407
June 2002

Replace "Block Ultra Map (*.map)\0*.map\0\0" with "Block Ultra Map (*.map)\0*.map\0All files (*.*)\0*.*\0\0" to add another entry in the file type selection listbox...

--
sig used to be here

Thomas Harte
Member #33
April 2000
avatar

Quote:

oh please, you think you need to be smart to do law....

law is robotic, you need to have a memory for everything that has gone before, thats it.

no thinking required.

Provided you live in a country that uses the precedential system of law and has no codified criminal code, you mean? I know very few such countries.

And what about the common-ish rule that you may commit a small crime to prevent a bigger one? Given that particularly in continental Europe there is only a very loose focus on the 'letter of the law' versus interpretation of what a particular statute is meant to prevent and allow, and also that the 'lawyer versus lawyer' model is rejected by a large number of such countries, there is no judgement or skill at all for such a decision?

Korval
Member #1,538
September 2001
avatar

Quote:

could say the same for all the other compiler bugs too.. should i stop using any compiler the moment i find it doesn't do what i thought it should.

If I can't rely on a compiler to put a '\0' at the end of a string literal, then that compiler is too buggy to be usable. If it can't do something as simple, basic, and common as that, there's no guarentee that the compiler won't choke on basic statements like while, for, if, and so forth.

Most real compiler bugs are advanced features like optimization or high-end C++ stuff (templates, namespaces, etc).

MiliBytes
Member #3,130
January 2003
avatar

Thank you all!

spellcaster
Member #1,493
September 2001
avatar

Does the filechooser work as expected?
What gfx mode are you in? Windowed? Fullscreen?

I remember trying to use the windows filechooser some time ago, and I think it opened nicely, but didn't respond to any events ...

What allegro version are you using?
Maybe I should try again with the most recent WIP :)

--
There are no stupid questions, but there are a lot of inquisitive idiots.

MiliBytes
Member #3,130
January 2003
avatar

Yes it seams to work...
I'm in a window mode
Using Allegro v:4.1.8 (works fine)
and I tried with the 4.0.3...
For the 4.0.3 There a lot of mouse problem
but the "Open Dialog Box" show and it works.

 1   2 


Go to: