Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help finding sample code 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
I'm sure that somewhere on this forum I've found VB sample code showing you how to place a graphic within a textbox by using various APIs to paint onto the textbox (for example, drawing a magnifying glass in a textbox to signify that you should enter a search term).

Unfortunately I can't find this article and now I'm thinking that I imagined it! Can anyone help me find it, or does it sound impossible and therefore probably never existed in the first place?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
It's more basic to show your graphic on an image control placed inside a borderless frame.
Have an invisible Frame1(0) with your visible Image1(0) inside it on the form. Set the Image(0) to stretch.
To show the pic - create a copy of the frame and image
a=1
Load Frame1(a)
Load Image1(a)
set Image1(a).container=Frame1(a)
set Image1(a).picture=loadpicture("your picture file name")
Frame1(a).move L,T,W,H ' L & T are where you want the image to be which can be related to the left and top of your text box.
Image1(a). move 0,0,Frame1(a).width,Frame1(a).height
Frame1(a).visible=true

You can change different images with the loadpicture statement andnhave as many of these on the form as you like by giving them a different index when you vreate them

To destroy them -
Unload Image1(1)
Unload Frame1(1)

You might consider to show it beside the box as it could obscure the text you are entering.
 
Thanks, I know that's an easier way of doing it but I was hoping for a solution that didn't involve creating more controls on the form, since painting to the textbox would be a code-only solution. If it's not possible to do what I wanted then I'll do it the way you suggest.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Of course it is possible. And it doesn't really need the APi (except for a simple call to get the device context for the textbox that MS decided not to expose in VB). Wether it is Aedvisable is a different matter. Anyway, here's some complicated example code; you'll need a form with a textbox and a command button:
Code:
[blue]Option Explicit
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Private Sub Command1_Click()
    Dim myPic As IPicture
    Set myPic = LoadPicture("c:\test.bmp") [green]' obviously you load your own image here
    ' It isn't well documented, but Render method works with an inverted Y axis, so we have to invert back to the VB orientation[/green]
    myPic.Render GetDC(Text1.hwnd), 0, 0, ScaleX(myPic.Width, vbHimetric, vbPixels), ScaleY(myPic.Height, vbHimetric, vbPixels), 0, myPic.Height, myPic.Width, -myPic.Height, 0&
End Sub[/blue]
 
Interesting.
Is it possible to use this to superimpose any control over any other (like a label over a movie)?
 
Ted,

The entire desktop is really just a bitmap. You can use the API to easily blit from any part of it to any other part of it.

However, the technique illustrated above relies on the fact that the source of the image being painted is an object (IPicture) that knows how to render itself. Most controls do not have that capability, so this specific method could not be directly used to achieve what you ask.
 
Thanks.

Which reference needs adding to support the IPicture type?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top