|
Hi
I have a ActiveX control in V.Basic and need to load a bitmap and obtain the handle to use with API functions eg: SelectObject,GetObject,TransparentBlt,etc.
It´s work fine if the image is loaded from a file eg:
hImageGray = LoadImage(App.hInstance, "c:\gray.bmp", IMAGE_BITMAP, 0, 0, LR_COLOR Or LR_LOADFROMFILE)
The problem is when I try to load the bitmap from a resource file added in the ActiveX control project.
I try from different methods:
"ID_GRAY = 102
hImageGray = LoadImage(App.hInstance, CLng(ID_GRAY), IMAGE_BITMAP, 0, 0, LR_COLOR )"
" LoadBitmap(App.hInstance, ID_GRAY)"
"LoadBitmap(App.hInstance, "102") "
Ever with the same result. No work".
Also try to use the v.Basic method to load the image with LoadResPicture, returning a IPictureDisp with the image loaded.
This solution have a problem: the handle property of IPictureDisp isn't a bitmap handle to use with the GDI API´s.
Any ideas to solve this problem???
Thank´s (and sorry by my bad english!
MrSparc.
|
|
|
|
|
Yes, thanks for you help.
Now you are right, the variable does not get set to null at once, but if I try to create a new DC and select an old hBitmap in it, it return error...meaning a bitmap has been deleted successfully. Thanks again.
.
|
|
|
|
|
Haha...sorry man, I clicked it by accident, I actually wanted to reply to your answer to me just two lines before yours in this table.
Anyways, with respect to your question, I had the same problem and never succeeded in loading a bitmap from the resource. I perused all the books I had, Web sites, posted the same question at a several developer, sites...but nope, no answer. I guess it is not possible to explain to an API functions to use a bitmap from a VB resource. They made those wrapper functions to retreive an object from the resource, like LoadResPicture and alike, but it was never meant to be used by API functions. I also find it strange, for it is only logical if you use LR_LOADFROMFILE that you can use another constant to retreive a bitmap from the resource for example...but I don't think it is possible.
Anyways, thanks for your answer to my inquiry, you were absolutelly right.
|
|
|
|
|
This is THE solution:
The solution to load the resource of bitmap in a StdPicture object is really effective!.
I tried to use handle property of the IPictureDisp that returned the LoadResPicture but it failed because he is not handle of bitmap.
Nevertheless, if we assigned the IPictureDisp returned by LoadResPicture in a StdPicture object, the StdPicture.handle is perfect bitmap handle!!
This is the solution that I implemented :
Dim tBitmap As BITMAP
Dim iRes As Integer
Dim picTemp As New StdPicture
' 102 is the ID of a Bitmap in the .res file.
Set picTemp = LoadResPicture(102, vbResBitmap)
hImageGray = picTemp.handle
If hImageGray <> 0 Then
GetObjectAPI hImageGray, Len(tBitmap), tBitmap
' bla bla bla bla.....
........
DeleteObject hImageGray
' I think that this DeleteObject could be cleared since bitmap
' would have to be destroyed when Set picTemp = Nothing,
' but by the doubts that Bill has forgotten to him....
End If
Set picTemp = Nothing
This works excellent.
Mike_spice, when I discovered the solution jumped in a leg. I hope that it serves so much to you as it served my, since in my case, it had a ActiveX and it was already thinking the revolting thing that it would be to distribute bitmap along with the OCX .
MrSparc.
|
|
|
|
|
Folowing are the queries related to VB.NET
1.How to insert & update data into the table from the datagrid?
2.How to put validation in the datagrid while inserting data?
3.how to know the number of rows in the datagrid?
|
|
|
|
|
Hi guys. This one is really driving me crazy.
I create a memory DC, and load a bitmap in it:
MemDC = CreateCompatibleDC(0)
hBitmap = LoadImageA(App.hInstance, szPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
SelectObject MemDC, hBitmap
and it works fine, I can use it in processing with BitBlt function, now here comes the problem:
lRes = DeleteDC(MemDC)
If lRes = 0 Then
'We have an error deleting a DC, do something...
End If
lRes = DeleteObject(hBitmap)
If lRes = 0 then
'We have an error deleting an object, do something...
End If
but even tho it shows that it has deleted the hBitmap object, it actually didn't, cause I can get its handle from Immediate Pane by typing ?hBitmap. It is impossible to delete hBitmap from memory, and I effectively have a memory leak. Every time I create that object, it never gets deleted from the memory. Trying to delete it before I delete DC doesn't work either, cause DC flags it as being used and thus not deletable.
In C++ it is easy, you create an pOldBitmap at the beginning of the function and then you select it back into DC at the end of the function, so you can delete the bitmap you created, or you use CDC::SaveDC which is fine for MFC but does not have a related function in API. But how to do it here in VB with API functions?
I spent some serious time trying to figure this out, but couldn't. When I check a MemDC in the ImmediatePane of my IDE, like ?MemDC it shows NULL, so it really gets deleted, but if I do ?hBitmap then it shows something like 16110, and even 10 minutes after it will show the same, so the memory never got reclaimed.
Any help would be appreciated. Thanks.
.
|
|
|
|
|
You code this written good, safe with some small corrections.
MemDC = CreateCompatibleDC(hdc)
hBitmap = LoadImageA(App.hInstance, szPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
hOldBitmap = SelectObject( MemDC, hBitmap )
' bla bla bla
SelectObject MemDC, hOldBitmap
lRes = DeleteDC(MemDC)
If lRes = 0 Then
'We have an error deleting a DC, do something...
End If
lRes = DeleteObject(hBitmap)
If lRes = 0 then
'We have an error deleting an object, do something...
End If
Now the explication:
When call to the function DeleteDCo or DeleteObject, this delete the object from the memory, but not set to zero the variable param.
It is why you sees in the immediate window the same value of handle when typing "?hBitmap ".
The unquestionable test that bitmap was destroyed is to try to use his handle after to have called to DeleteObject(hBitmap).
Good Luck!!
MrSparc.
|
|
|
|
|
Please, does anyone know how the virtual functions are called in VB.NET? I'm very surprised the language uses it's own words, despite of common naming conventions. Now I have a serious problem: how should I mark the function to make it virtual.
Thanks
Vasek
VB6, C#, MS DNA, MS .NET software developer
|
|
|
|
|
e.g.,
Public Overridable Sub MyMethod()
End Sub
Then use
Public Overrides Sub MyMethod()
End Sub
in the Derived class
Kevin
|
|
|
|
|
Helo
One problem whit the TreeView in VB.NET, is that right-clicking
don´t select the node.
Im trying to add Context-menu´s to my Node´s.
But I cant figure out a way to catch the node that was right-clicked.

|
|
|
|
|
:-DHelo
If any one is intressted - I solved the problem.....
What I did:
A event handler tied to the MouseUp
Private Sub OnTreeViewMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles TreeViewA.MouseUp
Dim pt As Point
pt = New Point(e.X, e.Y)
recursNodeSearch(pt, TreeViewA.Nodes)
End Sub
And the Sub that do the trapping:
Private Sub recursNodeSearch(ByVal pt As Point, ByVal nodes As TreeNodeCollection)
Dim nNode As TreeNode
For Each nNode In nodes
Try
If nNode.Bounds.Top <= pt.Y And nNode.Bounds.Bottom >= pt.Y Then
'This check the row, is you want to check the exact location.
' If nNode.Bounds.Contains(pt) Then
'===================================
TreeViewA.SelectedNode = nNode
Exit Sub
ElseIf nNode.IsExpanded Then
recursNodeSearch(pt, nNode.Nodes)
End If
Catch
End Try
Next
End Sub
|
|
|
|
|
Im trying to insert a Return in my textBox
but all I´m end upp whit i a ugly "13"
--------------------
for i = 0 to ubound(aryInfoText)
txtInfo.AppendText(aryInfoText(i) & " " & System.Windows.Forms.Keys.Return)
next
--------------------
Baaaa
|
|
|
|
|
Thats because you are inserting 13 into the textbox. Try Chr(13).
|
|
|
|
|
Helo
Im new to VB-programming but im a good on ASP (VB-script).
In ASP I inserted a chr(13) if i wanted a [enter] in my HTML-kod.
But concating a chr(13) in a String ends up whit a square.
HELP !!!
|
|
|
|
|
You could try Chr(10) , this may work. Are you using VB6 or VB.NET
Nick Parker
|
|
|
|
|
I solved it, by using a RichTextBox.
Then concating chr(13) into a String, ended upp showing return´s.
(simple TextBox´s dont do the trick)
|
|
|
|
|
Hi Friend,
Try this for better.
Text1.Text = "Anbu" & VbNewLine & "Selvan"
Have a nice coding.
P.Anbuselvan
|
|
|
|
|
Isn't this what vbCrlf is for?
|
|
|
|
|
Yes in VB6 but in VB.NET it´s System.Windows.Forms.Key.Return
----
The I moved on to RichTextBox and found this nice sample -
using XHTML to RTF-format a RichTextBox
http://www.gotdotnet.com/userarea/keywordsrch.aspx?keyword=xhtml
(XHTML is well-formated HTML => XML)
no unclosed tags (ex: is in XHTML )
|
|
|
|
|
how come in VBScript there are no defined constants for keys like vbKeyDelete (VK_DELETE) and such? i instead have to use the real value of vbKeyDelete... 0x2E (&H2E in VBS)
- Roman -
|
|
|
|
|
Hi all,
I received 'ActiveX component can't create object' while creating Winsock control dynamically. How will I overcome this problem.
Thanks,
P.Anbuselvan
|
|
|
|
|
Do you have the Microsoft Winsock Control 6.0 control added to your application from Components section, this would cause it?
Nick Parker
|
|
|
|
|
Hi All,
I solved my problem.
Follows the informations from the given link
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q200271
for the solution.
Regards
P.Anbuselvan
|
|
|
|
|
Does anyone know how to access the Summary Tab fields in the File properties? When you right click on a file in w2k you can type an author, title, summary, etc. Is there a way you can use VB to extract this information?
John
|
|
|
|
|
Hello All
I'd like to be able to copycat the process of resetting
security permission on subfolder\subregistrykey to match that of the
parent folder\registrykey.
Using VB or anything else.
Does any one have a clue on how to do that ?
I know how to set permissions but how can i reset it for the child objects?
--Yoav
|
|
|
|
|