CreateBitmap() is failing on me... any ideas? 
Author Message
 CreateBitmap() is failing on me... any ideas?

I'm using VB4, and I'm rewriting a routine I did long ago with VB3 for
Win3.1... here's the general idea:

I've got a bitmap in a picturebox (which was on disk) that I need to
stretch (add some height) and add text to.  It's a black and white bitmap,
and remember... this all worked once with Win31 <grin>

The problem I'm having now is with the CreateBitmap function.  I can never
get it to return a valid file handle to a bitmap.  Ponder the following
(this code formatted to be cut into VB directly):

'The following is the declaration as it appears in my declarations module:
'   Declare Function CreateBitmap Lib "gdi32"
'       (ByVal nWidth As Long, ByVal nHeight As Long,
'       ByVal nPlanes As Long, ByVal nBitCount As Long,
'       lpBits As Any) As Long

'All variables are declared as Long...

'This, the ideal line, fails; the handle returned is 0
    DBmpHandle = CreateBitmap(DWide, DHigh, 1, 1, Null)

'This fails; the handle returned is 0
    DBmpHandle = CreateBitmap(DWide, DHigh, 1, 1, 0)

'This fails; the handle returned is 0
    DBmpHandle = CreateBitmap(CInt(DWide), CInt(DHigh), 1, 1, 0)

'This fails; the handle returned is 0
    DBmpHandle = CreateBitmap(384, 232, 1, 1, 0)

'This succeeds; the handle returned is valid.
'According to the MSDN API documentation,
'I now have the handle to a single white pixel.  WHEE...
    DBmpHandle = CreateBitmap(0, 0, 1, 1, 0)



Mon, 19 Mar 2001 03:00:00 GMT  
 CreateBitmap() is failing on me... any ideas?

Quote:

>'This fails; the handle returned is 0
>    DBmpHandle = CreateBitmap(DWide, DHigh, 1, 1, 0)

Just a guess. Try replacing the last zero with "Byval 0&". Otherwise,
you're passing a pointer to the value 0, not a Null pointer.

HTH,
Bart.



Tue, 20 Mar 2001 03:00:00 GMT  
 CreateBitmap() is failing on me... any ideas?


Quote:
> 'The following is the declaration as it appears in my declarations
module:
> '   Declare Function CreateBitmap Lib "gdi32"
> '       (ByVal nWidth As Long, ByVal nHeight As Long,
> '       ByVal nPlanes As Long, ByVal nBitCount As Long,
> '       lpBits As Any) As Long

> 'All variables are declared as Long...

> 'This, the ideal line, fails; the handle returned is 0
>     DBmpHandle = CreateBitmap(DWide, DHigh, 1, 1, Null)

Make that

 DBmpHandle = CreateBitmap(DWide, DHigh, 1, 1, ByVal 0)

and you should be in with a grin :-)

(The way you pass a "Null" to an API from VB is "ByVal 0&")

Or...you can do

Dim BitmapBits(0 to <somevalue>) As Byte
 DBmpHandle = CreateBitmap(DWide, DHigh, 1, 1, BitmapBits(0))

Jim Deutch
MS Dev MVP



Tue, 20 Mar 2001 03:00:00 GMT  
 CreateBitmap() is failing on me... any ideas?


Quote:
> > 'This, the ideal line, fails; the handle returned is 0
> >     DBmpHandle = CreateBitmap(DWide, DHigh, 1, 1, Null)

> Make that

>  DBmpHandle = CreateBitmap(DWide, DHigh, 1, 1, ByVal 0)

> and you should be in with a grin :-)

I'm grinning... thank you very much!

Quote:
> (The way you pass a "Null" to an API from VB is "ByVal 0&")

I.. I'm...
I'm speachless.  OK, howe come nobody told me?  :)

Thank you very much for your prompt & accurate reply.  Normally, when I go
to a newsgroup ask a question, I try and answer a few at the same time, to
keep up the balance.  Unfortunately, I don't now much about the graphics
API outside of what I've done (which you saw above), so I'll simply lavish
you with praise and thanks.

Colin Ritchie



Tue, 20 Mar 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. I am working on cool project, looking for creative idea to help

2. CreateBitmap()

3. Bad DLL Calling Convention during CreateBitmap()

4. How to use CreateBitmap

5. How to use CreateBitmap?

6. Help! CreateBitMap Failure

7. CreateBitmap API

8. Help! CreateBitMap Failure

9. Help! WinAPI function CreateBitMap Failure

10. CreateBitmap API

11. CreateBitmap and VB 5.0 - ???

12. Problem with CreateBitmap API

 

 
Powered by phpBB® Forum Software