File association with a program

Windows specific forum
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

File association with a program

Post by Large »

Sorry if the title to the thread is not correct, did not know what to call it, lol.

Anyway want I want to be able to achieve is this . . .

I have created a program that will print a fax header ready to be faxed on a fax machine, I have managed to get the program to save the faxes which is basically a text file containing things like the recipient, date, message, etc.

I have associated my program files (.fxm) with the program and when you click on one of these files it opens my program which is kinda right but when the program opens all the fields are blank, I want to click a file and my program to read in the values and put them in the appropriate boxes, similar to clicking on a Word document and it opening Word with the letter on your screen.

Can anyone give me an example, please remember I'm a newbie.

Kind regards

Andy ( aka Large )
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

You might want to checkout, in your program, what parameters is passed to it ;) Look in manual for the command 'ProgramParameter()''.
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Post by Large »

This could be useful Pupil . . .

But I'm clicking on a file to open my program I need a way for my program to know what the path and filename I have just clicked on then I can set the gadgets with values.

basically . . .

if user clicked file
get filename and path
read file and set gadget values
end if

Kind regards

Andy ( aka Large )
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

When someone d-clicks on your file the file name will be sent as a parameter to the recieving program, as if you are starting your program from the cmd line.

like this:

FaxHeaderPrinter.exe TestFax.fxm

so in your FaxHeaderPrinter.exe program check for the name of 'TestFax.fxm' file using ProgramParameter() then open this file read the contents and do with them what you will. simple :)
--Kale

Image
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Post by Large »

Thanks Kale and Pupil, you guys are cool !

I'm gonna try a few things with the programparameter() command, I'll let you know how I get on.

Kind regards

Andy ( aka Large )
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Post by Large »

Well I'm afraid I'm not getting on to well . . .

I'm using this line at the beginning of my program.

Code: Select all

parameter$ = ProgramParameter() 
and then to see what parameter$ holds I'm testing it with.

Code: Select all

SetGadgetText (1,parameter$)
that way I can see the filename but when I try this gadget 1 is empty.

You guys got any idea's how I can click on a file which will open the associated program and the program to know the path and filename that launched it.

Any help greatly appreciated.

Kind Regards

Andy ( aka Large )
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Andy, I think Kale's advice puts you on the right path. But, your file
association must tell the OS what to do with the file. So your "open"
command must pass the filename.

I don't have my notes with me, but as I recall it is something like this:

in action you need
\PureBasic\PBProgram.exe "%1"
or
\PureBasic\PBProgram.exe "%file"

Sorry I can't be more exact. I have simply forgotten how these
parameters are defined in the association. Hope this will get you a
starting place to figure it out.

Terry
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Post by Large »

Hi Terry,

I think I understand, I have alter the association on my pc so that it send the filename when I click on it.

I will look up file assocation setting to get the correct parameters.

Kind regards

Andy ( aka Large )
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Post by Large »

I have set up the file association so that clicking on the file and the program opens, the file assocation has by default added "%1" for the file path part.

I'm using :

Code: Select all

file$=programparameter()
setgadgettext(2,file$)
but the gadget is empty.

Any idea's anyone ???

Kind regards

Andy ( aka Large )
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Compile this code and associate a file to the .exe, then double click the file!

Code: Select all

parameter.s = ProgramParameter()
OpenWindow(1, 0, 0, 600, 40, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, parameter)
CreateGadgetList(WindowID(1))
StringGadget(1, 10, 10, 580, 20, "")
SetGadgetText(1, parameter)
Repeat
    EventID.l = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
--Kale

Image
HarryO
User
User
Posts: 42
Joined: Wed May 07, 2003 4:25 am
Location: Palatine,IL.,USA

Post by HarryO »

Large,

Look at this posting:

viewtopic.php?t=6365

it is just a snippet of code to help you get all of the
parameters passed to a program.

Hope this helps.

HarryO
Large
User
User
Posts: 56
Joined: Tue Apr 29, 2003 8:24 pm

Post by Large »

Thanks for all your help guys.

I managed to get the program parameters correctly and I have read the file back into my program with success.

Kind regards

Andy ( aka Large )
Post Reply