Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Few Questions dealing with pictures


Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2002, 04:33 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Question Few Questions dealing with pictures


Well, I have a few questions that i ran into on about the same place. I'll just number them, according to what i would like answered first, thank you.

1. Let's say that I opened a .bmp file. In this .bmp file there is a series of different pictures all put together in blocks. How would i make is so it just showed part of this one big picture, so that i would be able to view just one of those pictures?

2. Is there a way to show a animated .gif file in a picture box. I wasn't sure if this was done the same way as a regular picture or not, so yeah.

3. well, i can't remember what i was gonna ask here, but if i think of it, i'll just ask in a reply.

Thanks in advance for the help.
Reply With Quote
  #2  
Old 06-17-2002, 04:40 PM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

1. Load the picture into a hDC and then BitBlt the portions of it that you require.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #3  
Old 06-17-2002, 04:55 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

well, i don't think this is what my 3rd question was going to be, but i just thought of it, so i figured i would ask:

Is there a way to get a popup menu in VB(Learning Edition)
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
  #4  
Old 06-17-2002, 06:07 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

just, seeing that i had like 2 views on this post, besides mine, in the past hour... Again, I'm just gonna say what i need:

1. Is it possible (If so, how) to show animated .gif files, being fully animated.

2. How do you make pop-up menu's

3. I think i got this one already, but if there is a different way, than BitBlt i would like to know. How to show just one specific part of a picture.

thanks
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
  #5  
Old 06-17-2002, 06:13 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

You can show an animated GIF in a webbrowser control, but there are 3rd party controls out there as well. The Hand posted one here at one time, but I think the attachment got lost during the great forum change.

I forget about popup menus off the top of my head...but I seem to recall that they are regular menus that you can call separately. I'll look in MSDN.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #6  
Old 06-17-2002, 06:15 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

From MSDN:
Quote:
Visual Basic Concepts

Displaying Pop-up Menus


A pop-up menu is a floating menu that is displayed over a form, independent of the menu bar. The items displayed on the pop-up menu depend on where the pointer was located when the right mouse button was pressed; therefore, pop-up menus are also called context menus. In Microsoft Windows 95 or later systems, you activate context menus by clicking the right mouse button.

Any menu that has at least one menu item can be displayed at run time as a pop-up menu. To display a pop-up menu, use the PopupMenu method. This method uses the following syntax:

[object.]PopupMenu menuname [, flags [,x [, y [, boldcommand ]]]]

For example, the following code displays a menu named mnuFile when the user clicks a form with the right mouse button. You can use the MouseUp or MouseDown event to detect when the user clicks the right mouse button, although the standard is to use the MouseUp event:

Private Sub Form_MouseUp (Button As Integer, Shift As _
Integer, X As Single, Y As Single)
If Button = 2 Then ' Check if right mouse button
' was clicked.
PopupMenu mnuFile ' Display the File menu as a
' pop-up menu.
End If
End Sub

Any code following a call to the PopupMenu method is not run until the user selects an item in the menu or cancels the menu.

Note Only one pop-up menu can be displayed at a time. While a pop-up menu is displayed, calls to the PopupMenu method are ignored. Calls to the PopupMenu method are also ignored whenever a menu control is active.

Often you want a pop-up menu to access options that are not usually available on the menu bar. To create a menu that will not display on the menu bar, make the top-level menu item invisible at design time (make sure the Visible check box in the Menu Editor is not checked). When Visual Basic displays a pop-up menu, the Visible property of the specified top-level menu is ignored.

The Flags Argument
You use the flags argument in the PopupMenu method to further define the location and behavior of a pop-up menu. The following table lists the flags available to describe a pop-up menu's location.

Location constants Description
vbPopupMenuLeftAlign Default. The specified x location defines the left edge of the pop-up menu.
vbPopupMenuCenterAlign The pop-up menu is centered around the specified x location.
vbPopupMenuRightAlign The specified x location defines the right edge of the pop-up menu.


The following table lists the flags available to describe a pop-up menu's behavior.

Behavior constants Description
vbPopupMenuLeftButton Default. The pop-up menu is displayed when the user clicks a menu item with the left mouse button only.
vbPopupMenuRightButton The pop-up menu is displayed when the user clicks a menu item with either the right or left mouse button.


To specify a flag, you combine one constant from each group using the Or operator. The following code displays a pop-up menu with its top border centered on a form when the user clicks a command button. The pop-up menu triggers Click events for menu items that are clicked with either the right or left mouse button.

Private Sub Command1_Click ()
' Dimension X and Y variables.
Dim xloc, yloc

' Set X and Y variables to center of form.
xloc = ScaleWidth / 2
yloc = ScaleHeight / 2

' Display the pop-up menu.
PopupMenu mnuEdit, vbPopupMenuCenterAlign Or _
vbPopupMenuRightButton, xloc, yloc
End Sub

The Boldcommand Argument
You use the boldcommand argument to specify the name of a menu control in the displayed pop-up menu that you want to appear in bold. Only one menu control in the pop-up menu can be bold.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #7  
Old 06-17-2002, 06:19 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

thanks, i'll look at all of this. and make sure it works for me.
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
  #8  
Old 06-17-2002, 08:08 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

ok, well I tried them all, but the only thing i had the problem with was the BitBlt function. I'm not too good with API Calls, but i do understand them, once i see what is needed with what i am wanting. Anyway, here is what i have for the BitBlt code:
Code:
Declare Function BitBlt Lib "gdi32" ( _
           ByVal hDestDC As Long, _
           ByVal x As Long, _
           ByVal y As Long, _
           ByVal nWidth As Long, _
           ByVal nHeight As Long, _
           ByVal hSrcDC As Long, _
           ByVal xSrc As Long, _
           ByVal ySrc As Long, _
           ByVal dwRop As Long _
) As Long
that was in the General Declerations. However, i got the following Error once i tried to run it:


Compile Error:
Constants, Fixed-Length Strings, Arrays, User-Defined Types and Declare Statements not allowed as Public members of object modules.


I would appreciate it if someone could help me, and tell me what i need to do... Thanks
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
  #9  
Old 06-17-2002, 08:57 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

You didn't put the declaration inside the function did you? It should go outside, near the top of the form or module.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #10  
Old 06-17-2002, 10:21 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

it's at the very top, right underneath on line, that just tells me what i am wanting to do with it... which infront of the whole sentence is a '
Reply With Quote
  #11  
Old 06-17-2002, 10:25 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

also, since it is in the same project, how would you change what a certain thing in a ListBox says, like for example i might have, "boo" but i want to change it to "hi" how would i do that?
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
  #12  
Old 06-17-2002, 10:38 PM
Stoicus
Guest
 
Posts: n/a
Default

Well, if you have "boo" selected, you could do:

Code:
ListBox1.List(ListBox1.ListIndex) = "hi"
If its not selected, I suppose you'd have to search through your list to find the entry. Something like:

Code:
strSearch = "boo"
strReplace = "hi"
For x = 0 To ListBox1.ListCount - 1
  If ListBox1.List(x) = strSearch Then
    ListBox1.List(x) = strReplace
    Exit For
  End If
Next x
[I haven't run this code myself, so it may take a couple tweaks to be totally correct, but I know it's close.]
Reply With Quote
  #13  
Old 06-17-2002, 10:40 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

ok, thanks, that worked, great, i just need to know how to fix my problem, with the showing only a certain part of a picture
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
  #14  
Old 06-17-2002, 10:45 PM
Stoicus
Guest
 
Posts: n/a
Default

You have to use the Private keyword.

Code:
Private Declare Function BitBlt Lib "gdi32" ( _ 
  ByVal hDestDC As Long, ByVal X As Long, _ 
  ByVal Y As Long, ByVal nWidth As Long, _ 
  ByVal nHeight As Long, ByVal hSrcDC As Long, _
  ByVal xSrc As Long, ByVal ySrc As Long, _
   ByVal dwRop As Long) As Long
Reply With Quote
  #15  
Old 06-17-2002, 10:53 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

ok, on form load, here is what i put:
Code:
boooo = BitBlt(Picture6.Picture, 0, 0, 16, 16, Picture43.Picture, 0, 0)
boooo is identified as long, and is put there, because it says that it needed the = sign...
I get the error:

Argument Not Optional

on the line that i pasted...
Thanks for the help so far.
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
  #16  
Old 06-17-2002, 10:55 PM
Stoicus
Guest
 
Posts: n/a
Default

Use BitBlt without parentheses. Also, you need to send BitBlt the hDC of the pictures, not the Picture property. [edit: don't forget the raster-operation code. To copy exactly, use vbSrcCopy.]

Code:
BitBlt Picture6.hDC, 0, 0, 16, 16, Picture43.hDC, 0, 0, vbSrcCopy
Reply With Quote
  #17  
Old 06-17-2002, 10:56 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

ok, i did that exactly, and i am still getting the same error...

edit: nevermind, i see what was wrong
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
  #18  
Old 06-17-2002, 10:56 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

For BitBlt, you don't pass the picture property, you pass the hDC. Plus, you forgot the last Flags term.

add

, vbSrcCopy

or one of the other flags.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #19  
Old 06-17-2002, 10:58 PM
Stoicus
Guest
 
Posts: n/a
Default

I edited my post when I realized you left off the last argument. See the [edit] about the raster-op code

[edit2: argh, why can't we delete posts? :P hehe]
Reply With Quote
  #20  
Old 06-17-2002, 11:00 PM
crazycheetah's Avatar
crazycheetah crazycheetah is offline
Junior Contributor
 
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
Default

ok, well i got this to go, just fine w/o any errors, but the picture doesn't show up in the picturebox... i made sure i was looking at the correct picturebox, and i was, but i also was wondering if having the picturebox's property from the one that has the full picture in it was Visible - False
__________________
Code: PONG! | RPG! | Isometric RPG Map Editor!
Tutorial: IRC
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->