Solved

Cannot Open BMP Files in VB

Posted on 2000-05-11
13
262 Views
Last Modified: 2012-08-13
I have the following function defined in VB
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

When I call it with

Call ShellExecute(Me.hwnd, "open", DataGrid1.Columns(1), vbNullString, "C:\", sw_shownormal)

if works fine and will open word documents etc. no problem HOWEVER it will not open up .bmp files (which are associated with paintbrush),  any ideas why?
0
Comment
Question by:MrTimewalk
  • 6
  • 4
  • 2
  • +1
13 Comments
 

Expert Comment

by:keerthivasan
ID: 2799435
Mrtimewalk,

it is not that difficult opening bmps' in VB , bmps' being the proprietry image formats of microsoft products.

 There are 3 ways to open a bmp file in VB.

 the ways being
 
  1. open paintbrush calling shell function (not the function you have defined) and loading the bmp from  paintbrush or directly calling the bmp using shell function.
  2. drag & drop a image control, connect it to a image and at runtime display the image control.
  3. you can use the ole link /embed option to to display images. when you create a ole object it will automatically navigate you through the channel of creating a bmp to be viewed at runtime.

thanks
0
 

Expert Comment

by:keerthivasan
ID: 2799440

Dear mrtimewalk,

i have given you the solutions, it should be solving your problem.
0
 

Author Comment

by:MrTimewalk
ID: 2799462
I agree Keethivasan, your solution was excellent however for some reason on a PC which has Paintbrush associated with bitmaps it cannot open up the bitmap using this function call.  If I have a different graphics application associated with .bmps no problem but on a new PC I'm stuck
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2799465
Are you sure the association is there?? what happens when you double-click on a BMP from explorer?

Also check the variable you're passing to ShellExecute to make sure the pathname is correct.

Do you have this definition in your program:

   Const sw_shownormal = 1

After you run the ShellExecute, do a CTRL-ALT-DELETE and see if MSPAINT is a running task.  If it is running, then the instance of MSPAINT has been started hidden.  This happens if sw_shownormal equals zero.


Cheers!®©

0
 

Author Comment

by:MrTimewalk
ID: 2799473
I agree Keethivasan, your solution was excellent however for some reason on a PC which has Paintbrush associated with bitmaps it cannot open up the bitmap using this function call.  If I have a different graphics application associated with .bmps no problem but on a new PC I'm stuck
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2799475
By the way, if MSPAINT is running, you will have to terminate the running instances of it and set sw_shownormal to 1 before it will work...


Cheers!®©
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:MrTimewalk
ID: 2799479
I agree Keethivasan, your solution was excellent however for some reason on a PC which has Paintbrush associated with bitmaps it cannot open up the bitmap using this function call.  If I have a different graphics application associated with .bmps no problem but on a new PC I'm stuck
0
 

Author Comment

by:MrTimewalk
ID: 2799508
If I double click on a BMP in explorer it launches Windows PaintBrush.

The path IS correct for the bitmap

There isn't an instance of Paintbrush running in the background

The function call works perfectly for other programs like Word etc. however it doesn't do anything with Paintbrush.  

0
 
LVL 27

Expert Comment

by:Ark
ID: 2799534
Hi
Try res = ShellExecute....
and post here res value
Cheers
0
 

Author Comment

by:MrTimewalk
ID: 2799548
Folks I AM AN IDIOT

I apologise

It was running the .bmp invisibly. sw_shownormal was not defined

Thanks to everyone for the help
0
 
LVL 14

Accepted Solution

by:
mcrider earned 50 total points
ID: 2799586
You are not an idiot... It was just a bug... I'm glad I could help you. Please grade this.


Cheers!®©
0
 

Author Comment

by:MrTimewalk
ID: 2799591
Thanks very much
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2799598
Thanks for the points! Again, glad I could help you.  You know where we are if you need any more help ;-)


Cheers!®©
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now