Go Back   AnandTech Forums > Software > Programming

Forums
· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Home and Garden
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2014
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions
   

Reply
 
Thread Tools
Old 06-27-2007, 11:49 PM   #1
Schadenfroh
Elite Member
 
Schadenfroh's Avatar
 
Join Date: Mar 2003
Location: Boston
Posts: 38,418
Default File Association in VB .NET

I have been playing around with the code here, it was mainly written for startup only , but the one I am currently working on only needs one instance open at a time and I wish it to be able to read-in text files of a current extension.

I have already conquered associating a file type with my program and getting it to read in it's text content on startup, but how would I go about getting it to read in if the program is already open? I theorized using a background worker with similar code to the one that I linked and the results were.... not pretty.

Anyone know of a better way?

Thanks

Update: I gave up and I am porting it all to C#
__________________
"how we live is so far removed from how we ought to live, that he who abandons what is done for what ought to be done, will rather bring about his own ruin than his preservation"
- Niccolò Machiavelli
Schadenfroh is offline   Reply With Quote
Old 06-28-2007, 01:18 AM   #2
Markbnj
Moderator
Programming
 
Markbnj's Avatar
 
Join Date: Sep 2005
Posts: 13,398
Default File Association in VB 2005

Hmm, well, it's Explorer.exe that launches the associated application and passes in the target file description. In the advanced section of the file associations dialog you can tell explorer to use DDE to notify a running application of a file launch. The application would have to be written to handle the DDE events, and I don't know how that is done in .Net, never having messed with it. It's probably handled similarly to file drop events.

Otherwise, explorer will attempt to launch a new instance of the associated application. What you could do is have that application check for a previously running instance on startup (you can use FindWindow, or one of the process APIs), before it draws its own window. Of course, you would still need to communicate between the processes, so you're into DDE or pipes or message insertion or something anyway, but at least the behavior wouldn't depend on having set up the file association correctly.
__________________
Everytime I try to tell you, the words just come out wrong

**
Some meaningless scribbling of no account

The 4th Realm

Arts and Letters Daily - Get some culture
Markbnj is offline   Reply With Quote
Old 06-28-2007, 04:50 PM   #3
Schadenfroh
Elite Member
 
Schadenfroh's Avatar
 
Join Date: Mar 2003
Location: Boston
Posts: 38,418
Default File Association in VB .NET

Interesting idea, Mark. I have thought about launching a 2nd application and figuring out a way to transfer the data if I cannot find a less complex way. I have done much searching and cannot find an easier way to do it

Any VB .NET gurus able to offer any ideas?
__________________
"how we live is so far removed from how we ought to live, that he who abandons what is done for what ought to be done, will rather bring about his own ruin than his preservation"
- Niccolò Machiavelli
Schadenfroh is offline   Reply With Quote
Old 06-30-2007, 01:53 AM   #4
Noobsa44
Member
 
Join Date: Jun 2005
Posts: 65
Default File Association in VB .NET

You don't say if you're using .net 1.1 or 2.0, which does make a difference.

In .net 2.0 (using visual studios) there is a check box (under "Application") to sent your program to Single Instance. This isn't a perfect solution, as if you try to open multiple instances before the first instance is up, it will cause the program to crash. Also, this requires you to do some fancy work to pass the arguements after the program has started.

In .net 1.x you have to use a mutex and (if I recall right) use the windows API to send data back and forth. For more on that, check this page out: http://www.codeproject.com/vb/net/singleinstance.asp

I happen to have examples of both methods, as I have used both for my open source media player, called GAmp. For the .net 2.0 method, look at my GAmp 2.0 release, and for the .net 1.x method, look at my 1.0 release.
Noobsa44 is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 06:51 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.