i'm trying build a method in my Sprite control for destroy it self, but until now without sucess:(
(in these case) the control is created in project-mode and deleted in run-mode...
any sugestions?
thanks
Printable View
i'm trying build a method in my Sprite control for destroy it self, but until now without sucess:(
(in these case) the control is created in project-mode and deleted in run-mode...
any sugestions?
thanks
Why not create it dynamically, when the app starts. Easier to destroy.
Well, without seeing any code, it seems that you want a magic answer, when the solution is to do some legwork now.
sorry, you have right.
heres my procedure
i have try using the destroywindow() api function and the and releaseDc() api function, ~but without sucess:(Quote:
Private Sub Destroyed()
On Error Resume Next
RaiseEvent Destroyed(lngOldPosX, lngOldPosY)
tmrNewEvents.Enabled = False
tmrAnimation.Enabled = False
tmrMouseStoped.Enabled = False
FileName = Empty
Set UserControl.MaskPicture = Nothing
Unhook2 UserControl.ParentControls(0).hWnd
HoverTime = 0
End Sub
i acept advices
i recive o(zero) in messagebox
information in these api function: http://www.ex-designz.net/apidetail.asp?api_id=330Code:MsgBox (ReleaseDC(Me.hWnd, UserControl.hdc))
(i'm portuguese)
On Error Resume Next is hiding your problem. Comment that line out, and try it again.
You still need to supply more code. How do you get the values? How do you create them?
Why don't you create a file of icons, and load them?
ok... i put here my group project, now you can see everything.
in UC you have the Destroyed procedure in Declaration section.
see and tell me what you think.... the FileName property is for you change the image(animateg cursors and gifs can be showed too).
thanks
I can't help with Vista/64, as I recall. I can try later.
Well, trying to exit with the Close 'X' crashes the IDE. Clicking on STOP in the IDE works correctly. I would use XML files to access the data in the property bag that is named.
yes i know about that error, but why?
for me it's strange:(
thanks for help me
did you want my msn(messenger) for more help(honestly i need more help in more things, in my sprite)?
(i found something interesting: http://books.google.pt/books?id=kVqB...um=8#PPA371,M1 )thanks
Because your app is sub-classing memory locations to fool the IDE into thinking something is different. The caution is that you can toast Windows, not only the IDE when you're writing memory that goes awry.
The exception in your program is generated when you try to set the UserControl.Height/Width in ShowImage after the window is destroyed. This will trigger UserControl_Resize which in turn calls ShowImage again, which will trigger the UserControl_Resize again and so on. It's a kind of stack overflow although the error says something else.
To prevent this error, you can add validation in your UserControl_Resize. If the UserControl.hWnd is valid (not 0), then perform the codes, otherwise, do nothing.
You can also check the hWnd even earlier than calling ShowImage if you want (e.g. even before calling Destroyed)Code:Private Sub UserControl_Resize()
If UserControl.hWnd = 0 Then
Debug.Print "UserControl_Resize ignored (HWND = 0)"
Else
On Error Resume Next
If blnAutoSize = False Then
picGraphicsEffects.Width = UserControl.ScaleWidth
picGraphicsEffects.Height = UserControl.ScaleHeight
End If
Call ShowImage
If (UserControl.Width <> lngOldWidth And UserControl.Height <> lngOldHeight) Then
ResizeTyp = ResizeVerticalHorizontal
ElseIf UserControl.Width <> lngOldWidth Then
ResizeTyp = ResizeHorizontal
ElseIf UserControl.Height <> lngOldHeight Then
ResizeTyp = ResizeVertical
End If
lngOldWidth = UserControl.Width
lngOldHeight = UserControl.Height
If strFileName = Empty Then Call SubTransparent
RaiseEvent Resize(UserControl.Width, UserControl.Height, ResizeTyp)
End If
End Sub
Hope it will help you :)
The memory location for UserControl.Height/Width might have been valid at one point, but not after the pointer was no longer pointing to a vaild width.
thanks my friend
i will see it in weekend. thanks
i know programming but sometimes(in these case in VB6), when i program, some strange things appens:(
like some code is working now, then(without change) isn't....
honestly i don't understand:(
because now i have some problems in my Sprite control:(
can you spend some time with me for resolve them?
(if you can use messenger/msn greate, if not that's ok)
thanks
You can always go back to your old code, when it was working right
yeah, thanks for the advice.
i need ask you something...
in UC, i need activate a API functions(like message windows(winproc()), but i don't know what event must use. because the initializate event is only for change the variables(i can't use it for more)... i could use the show event, but the show event is call it when it's created(with or without image/backcolor)?
i know i thing, the terminate event is called when the UC is created... why? can i ignore it(when is created)?
thanks
I don't understand the question
i'm sorry i will say in other words...
when the UC is created, why the Finalizate event is called? these event can be ignored when the UC is created?
anotherthing when the UC is created the Initializated event is called, but i only can change the variables values.... when the UC is created(Visible can or not be true, doesn't mine), the Show event is always called?
thanks
ok.. now i can continue with our conversation;)
i need build an Destroy method(i don't care if the object was created in Load function or in project-mode). can you advice me?
or give me informations?
thanks
Objects which are created at design-time cannot be destroyed at runtime. However, if you create an array, then additional elements can be loaded and unloaded at runtime. Still, the one you created at design-time must remain.
In the case of your sprites, one could be placed on the form at design-time, with an Index of zero. The other sprites would then be loaded/unloaded at runtime.
<EDIT>
Additionally, a UserControl cannot unload itself. The controls should be loaded and unloaded by the program in which they are used.
Simply place one object on the form, and set the Index property to zero. This will create an array.
Then at runtime:You can create the first element with an Index other than zero, if you want. Note also that elements can be unloaded in any order. So the UBound of the array will not be the same as the Count. In other words, if you have 5 elements (Indexes of 1 to 5), and you unload number 2, the UBound will still be 5, while the Count is 4. This means that you may encounter errors if you try to iterate through an array after unloading one or more elements where the Index is not the UBound.Code:Private Sub CreateSprite(X As Long, Y As Long, Color As Long)
Dim I As Long
I = MySpriteArray.UBound + 1
Load MySpriteArray(I)
MySpriteArray.Move X, Y
MySpriteArray.ForeColor = Color
MySpriteArray.Visible = True
End Sub
Private Sub KillSprite(Index As Long)
Unload MySpriteArray(Index)
End Sub
Objects can be created at runtime without being part of an array, but in that case you will not be able to catch the events without subclassing, which will very likely bring you many headaches.