Opening the Windows default "Open Dialog" in allegro?
MiliBytes

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
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 ...

MiliBytes

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
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

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.

miran

This should do the trick:

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

Or am I wrong again?

A J

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.

miran
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...

A J

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 ?

miran

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...

A J

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.

miran

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...

Bob

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

miran

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

A J

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

spellcaster

Sure.

Evert

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

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

MiliBytes

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

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...

Thomas Harte
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
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

Thank you all!

spellcaster

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 :)

MiliBytes

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.

Evert
AJ said:

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

No - shouldn't is perfectly valid english, while u for you and r for are is not ;)

Seriously though - I do find it hard to read.

A J

you are right, it makes it difficult for non-native english readers to read this text, i should have known better. thank you.

Thread #234551. Printed from Allegro.cc