Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Commondlg for freeBASIC-progs... how?
#1
Hi Community!

(Before I really start: I'm just a German pupil, so I think my english isn't very well... And I'm new to this Community. But the German one didn't answer my question. So I thought - try the big Brother 8) )

I'm writing a Font Editor, an application to change a font file in a own format. Well, the sense of such an program is to save the changed file, isn't it?
For this, I have to write an Load/Save-Dlg....exept someone could explain me, how to use the Windows-pre-programmed Version...?

So, short and easy:
How do I use the CommonDLG of Windows?

Thanks for your answers!

Have a nice day
Ciao
ometimes, i think it is not logical to say
x = x + 1


This post is fully recycleable
Reply
#2
I'm afraid you must call the windows API to do that:
The function is GetSaveFilename
It's use is explained here
http://msdn.microsoft.com/library/defaul...leName.asp
and you must include win\commctrl32.bi to have it working.
Antoni
Reply
#3
Hallo Dusky-Joe!

[quote="Dusky_Joe"]
How do I use the CommonDLG of Windows?

PowerBasic is almost semilar to freeBASIC, so download this one here:

http://www.reonis.com/POFFS/poffsbas.zip

That is the "PowerBasis-Offline-Forum", there you'll find TONS of examples (about 2,500), just search for a keyword like "GetSaveFileName", translate the example to freeBASIC (is really easy) and then you have it.

The original homepage is here:
http://www.reonis.com/POFFS/

There are also extra-examples to download.


Here is the original-text from the homepage
============================

PowerBASIC OFF-line forum Search (download size 7.7 MB - updated to February 28, 2005)
PowerBASIC OFF-line forum Search in postings made to Power Basic's Online Forums. Extremely informative, with many thousands of questions, answers and source code samples available for fast and easy off-line search. All in all, the unpacked databases totally carries more than 180 MB of useful information about everything regarding the Power Basic product line, plus lots and lots of excellent tips for programming in both DOS and Windows.

The file above contains the main program plus databases from following discussion forums: Product Announcements, Frequently Asked Questions and Source Code forum (with ~2,500 source code samples!). Simply download and unzip to a suitable folder, then create a shortcut to the program the usual way.
erman freeBASIC-mailinglist: de.groups.yahoo.com/group/free-basic.
For subscribing send an empty e-mail to free-basic-subscribe@yahoogroups.de.
Reply
#4
I see that a couple of people have posted "how to do it"'s, but has anyone actually gotten it to work? If so, please post a sample because I haven't gotten it yet.

The bloody null characters (chr$(0)) are giving me fits!
Reply
#5
Quote:For this, I have to write an Load/Save-Dlg....exept someone could explain me, how to use the Windows-pre-programmed Version...?

Guten Tag Dusky_Joe,
if I understand correctly you need the OpenFileDialog and SaveFileDialog of Windows?

here are code snippets I used awhile ago, hope they still work:
Code:
option explicit
option private

#INCLUDE "kernel32.bi"
#INCLUDE "user32.bi"
#INCLUDE "gdi32.bi"
#INCLUDE "commdlg32.bi"
''
''
''
''
declare FUNCTION  OpenFileDialog (hWndOwner As Long, default As String, filter As String, initDir As String, title As String) as String
'
'
'
FUNCTION  OpenFileDialog (hWndOwner As Long, myfileName As String, filter As String, initDir As String, title As String ) as String
    

    dim ofn As OPENFILENAME
   ' dim SHARED hInst
    dim buffer2 as string

    ofn.lStructSize = LEN(ofn)              'set length of struct
    ofn.hwndOwner   = hWndOwner             'set parent window handle
    ofn.hInstance   = GetModuleHandle(0)    'set the application's instance

'select a filter
'pstrFilter points to a buffer containing pairs of null-terminated
'filter strings. The first string in each pair describes a filter
'(for example, "Text Files"), and the second specifies the
'filter pattern (for example, "*.TXT"). Multiple filters can be
'specified for a single item by separating the filter pattern strings
'with a semicolon (for example, "*.TXT;*.DOC;*.BAK"). The last string
'in the buffer must be terminated by two NULL characters. If this member
'is NULL, the dialog box will not display any filters.
'The filter strings are assumed to be in the proper order - the
'operating system does not change the order.

'   filter = "XB Files (*.x, *.dec)" + CHR$(0) + "*.x;*.dec" + CHR$(0) + "Text Files (*.txt)" + CHR$(0) + "*.txt" + CHR$(0) + "All Files (*.*)" + CHR$(0) + "*.*" + CHR$(0) + CHR$(0)
    ofn.lpstrFilter = sadd(filter)

    'create a buffer for the returned file
    IF myfileName = "" THEN
        myfileName = SPACE(254)
    ELSE
        myfileName = myfileName + SPACE(254 - LEN(myfileName))
    END IF

    ofn.lpstrFile = Sadd(myfileName)
    ofn.nMaxFile  = 255                     'set the maximum length of a returned file


    buffer2 = SPACE(254)
    ofn.lpstrFileTitle  = sadd(buffer2)     'Create a buffer for the file title
    ofn.nMaxFileTitle   = 255               'Set the maximum length of a returned file title

    ofn.lpstrInitialDir = sadd(initDir)     'Set the initial directory

    ofn.lpstrTitle = sadd(title)            'Set the title

    ofn.flags = OFN_FILEMUSTEXIST OR OFN_PATHMUSTEXIST OR OFN_EXPLORER  'flags

    IF GetOpenFileName ( ofn) = 0 THEN
        myfileName = ""
        OpenFileDialog = ""
    ELSE
        OpenFileDialog = RTrim(myfilename) 'TRUE
    END IF


END FUNCTION

Code:
option explicit
option private

#INCLUDE "kernel32.bi"
#INCLUDE "user32.bi"
#INCLUDE "gdi32.bi"
#INCLUDE "commdlg32.bi"
''
''
''
''
declare FUNCTION  SaveFileDialog (hWndOwner As Long, default As String, filter As String, initDir As String, title As String) as String
'
'
'
FUNCTION  SaveFileDialog (hWndOwner As Long, myfileName As String, filter As String, initDir As String, title As String ) as string
    

    dim ofn As OPENFILENAME
    dim buffer2 as string

    ofn.lStructSize = LEN(ofn)              'set length of struct
    ofn.hwndOwner   = hWndOwner             'set parent window handle
    ofn.hInstance   = GetModuleHandle(0)    'set the application's instance

    'select a filter
    'pstrFilter points to a buffer containing pairs of null-terminated
    'filter strings. The first string in each pair describes a filter
    '(for example, "Text Files"), and the second specifies the
    'filter pattern (for example, "*.TXT"). Multiple filters can be
    'specified for a single item by separating the filter pattern strings
    'with a semicolon (for example, "*.TXT;*.DOC;*.BAK"). The last string
    'in the buffer must be terminated by two NULL characters. If this member
    'is NULL, the dialog box will not display any filters.
    'The filter strings are assumed to be in the proper order - the
    'operating system does not change the order.

    'example: filter = "XB Files (*.x, *.dec)" + CHR$(0) + "*.x;*.dec" + CHR$(0) + "Text Files (*.txt)" + CHR$(0) + "*.txt" + CHR$(0) + "All Files (*.*)" + CHR$(0) + "*.*" + CHR$(0) + CHR$(0)

   ' filter = filter + CHR$(0)
    ofn.lpstrFilter = sadd ( filter )

    'create a buffer for the returned file
    IF myfileName = "" THEN
        myfileName = SPACE(254)
    ELSE
        myfileName = myfileName + SPACE(254 - LEN(myfileName))
    END IF

    ofn.lpstrFile = Sadd(myfileName)
    ofn.nMaxFile  = 255                            'set the maximum length of a returned file


    buffer2 = SPACE(254)
    ofn.lpstrFileTitle  = sadd(buffer2)            'Create a buffer for the file title
    ofn.nMaxFileTitle   = 255                      'Set the maximum length of a returned file title

    ofn.lpstrInitialDir = sadd(initDir)            'Set the initial directory

    ofn.lpstrTitle = sadd(title)                   'Set the title

    ofn.flags = OFN_PATHMUSTEXIST OR OFN_EXPLORER  'flags

    IF GetSaveFileName ( ofn) = 0 THEN
        myfileName = ""
        SaveFileDialog = ""
    ELSE
        SaveFileDialog = RTrim(myfilename)         'TRUE
    END IF


END FUNCTION
I really hope it still works... Big Grin
Reply
#6
why not set up a repository with working Win-API snippets?

No need to reinvent the wheel...

In 2 years from now it's all obsolete anyhow.
Win32-API will still work on AVALON, the new 3d gui of Microsoft Windows, but emulated and probably slower...
Hope the new gui-api will be reachable without .net :barf:
Reply
#7
Quote:In 2 years from now it's all obsolete anyhow.
Win32-API will still work on AVALON, the new 3d gui of Microsoft Windows, but emulated and probably slower...
Hope the new gui-api will be reachable without .net :barf:

I wouldn't put much stock in Avalon (or Longhorn). MS is going to have a hard sell on both, and from the current buzz, most people are not going to bother. This will end up being another Windows ME (and .Net) fiasco. The current api's will be around for some time to come.
Reply
#8
Thanks you all!

@ Antoni Gual:
Yes, I already knew, that I have to uste the WinAPI, or is there any other way to use Win-Functions Wink ?
Well, thanks for the URL, I'll have some looks on it Wink

@ PeterHarder:
I startet the Download, but I won't start learning PB in near future...
Well, maybe anytime, I will. It's a good language for Game-Programmers, isn't it?

@ fsw:
Yes, you're right!
And those example-programms are perfekt!
May I use them in my progs?
They're non-commercial, of course, but it's your accomplishment...
Otherwise I would try to understand your code (lot's of comments => shouldn't be difficult *g*). Well, I'd try to understand it even if you allowed me to use *g*



Have a nice day!
Ciao
ometimes, i think it is not logical to say
x = x + 1


This post is fully recycleable
Reply
#9
Quote:@ fsw:
Yes, you're right!
And those example-programms are perfekt!
May I use them in my progs?
Use it as you wish, actually, as far as I remember, I converted the code (specially the comments) from xBlite. :wink:
Reply
#10
Quote:@ Antoni Gual:
Yes, I already knew, that I have to uste the WinAPI, or is there any other way to use Win-Functions Wink ?
Well, thanks for the URL, I'll have some looks on it Wink

Well, the Win API could be used thru built-in language functions, as it was possible in RapidQ. FB is not been developed this way so that's not possible.

You could use too an external wrapper library.Some people is doing things with wx-widgets. The main advantage is that library has a linux version so anything you program with wx-widgets will work in linux.
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)