 |
|

06-17-2002, 04:33 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
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.
|
|

06-17-2002, 04:40 PM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
1. Load the picture into a hDC and then BitBlt the portions of it that you require.
|
|

06-17-2002, 04:55 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
|
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)
|
|

06-17-2002, 06:07 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
|
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
|
|

06-17-2002, 06:13 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
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
|

06-17-2002, 06:15 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
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
|

06-17-2002, 06:19 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
|
thanks, i'll look at all of this. and make sure it works for me.
|
|

06-17-2002, 08:08 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
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
|
|

06-17-2002, 08:57 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
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
|

06-17-2002, 10:21 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
|
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 '
|
|

06-17-2002, 10:25 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
|
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?
|
|

06-17-2002, 10:38 PM
|
|
|
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.]
|
|

06-17-2002, 10:40 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
|
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
|
|

06-17-2002, 10:45 PM
|
|
|
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
|
|

06-17-2002, 10:53 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
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.
|
|

06-17-2002, 10:55 PM
|
|
|
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
|
|

06-17-2002, 10:56 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
|
ok, i did that exactly, and i am still getting the same error...
edit: nevermind, i see what was wrong
|
|

06-17-2002, 10:56 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
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
|

06-17-2002, 10:58 PM
|
|
|
|
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]
|
|

06-17-2002, 11:00 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Sunny Southern California
Posts: 347
|
|
|
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
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|