Solved

Cannot Open BMP Files in VB

Posted on 2000-05-11
13
284 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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
 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 42
Microsoft Access combo box help 2 45
clicking a shape in a frame array vb6 3 45
Advice in Xamarin 21 78
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

776 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