|
Hi,
I posted this in general questions and then realized I should have posted it here. I have a large vb6 app that I turned into a dll so I could run it from vb .net. When I run the vb6 & .net projects in debug everything works fine. If I open the forms non modally everything works fine all the time.
However when I compile the vb6 into a dll the vb6 forms are not being placed in the .Net container form when I open them modally (non modal is OK). The vb6 form just sits in the upper left of the screen.
I came up with this solution based on an article by Eduardo Campano on embedding vb6 forms in .Net applications from July 2007. Great article and a good idea if you have a million lines of code to convert to .net.
I have sample code but don't see how to upload it to the forum.
The code for loading the vb6 into the container is from the container load event in .net:
SetParent(mintFormHandle, Me.Handle.ToInt32)
SendMessage(Me.Handle.ToInt32, WM_NCACTIVATE, 1, 0)
SetForegroundWindow(Me.Handle.ToInt32)
LockWindowUpdate(0)
Such a Larry
modified 24-Oct-13 11:17am.
|
|
|
|
|
larry118 wrote: Great article and a good idea if you have a million lines of code to convert to .net. Calling VB6 code from VB.NET is not a conversion. It's merely building another layer on something that should have been retired a few years ago.
What does "sit there" mean? Does it still process messages? You can test if it is by dragging another application over it - if a white smear appears, then the paint handler is no longer being called. I suggest you turn your DLL back into an executable; that's the easiest way.
Outside of that, the recommended way to use legacy code would be by using the InterOp Form Toolkit[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes of course the best thing would be to convert the code but its not going to happen right away when there is so much code and so many customers and users (100's).
By stripping the vb6 forms borders and putting them in a .net wrapper we get a really nice look in Windows 7 & 8 and now we have more time to properly analyze and convert the remaining code and marketing can demo an upgraded look and feel to the application.
As far as sit there. The vb6 form is frozen but you can drag stuff over it without a paint problem.
I wish I could upload the code.
Larry
Such a Larry
|
|
|
|
|
larry118 wrote: I wish I could upload the code. VB6 has been dead to me for a few years.
larry118 wrote: and now we have more time to properly analyze and convert the remaining code and marketing can demo an upgraded look and feel to the application Microsoft extended support ended in 1998. Your excuse was valid until 2007.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Larry you have my sincere sympathies, imagine working for an organisation so forward thinking that they don't plan for an end of life on their development platform. Then wait 6 YEARS after the end of support to attempt to remedy the situation.
To top it off the development is now being driven by the marketing departments need to show of a new look and feel. You really should submit your situation to WTF it sounds like a classic to me!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
These are really good people. I like them and don't mind being responsible for converting the code. I have made some progress on this issue. The setparent now seems to be working. The vb6 form is now appearing in the .net container. The problem was passing the parent from vb6 and that is now handled.
So setparent works now but it's followed by a send message, setforegroundwindow and lockwindowupdate which appear not to be working. My declarations are as follows:
<system.runtime.interopservices.dllimport("user32.dll")> _
Private Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Int32
End Function
Public Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal s As String _
) As Int32
<system.runtime.interopservices.dllimport("user32.dll")> _
Private Shared Function SetForegroundWindow(ByVal hwnd As IntPtr) As IntPtr
End Function
<system.runtime.interopservices.dllimport("user32.dll")> _
Private Shared Function LockWindowUpdate(ByVal hwndLock As IntPtr) As Boolean
End Function
and the code is:
SetParent(mintFormHandle, Me.Handle.ToInt32)
SendMessage(mintFormHandle, WM_ACTIVATE, 1, IntPtr.Zero)
SetForegroundWindow(mintFormHandle)
LockWindowUpdate(0)
Me.Refresh()
Any suggestions?
Such a Larry
|
|
|
|
|
larry118 wrote: Any suggestions? Both the SetForgroundWindow and the LockWindowUpdate should be superfluous. The parent would already be the foreground-window and thus active. Painting the window should not have been locked in the first place. If it is, then you'll probably need to send a WM_SETREDRAW to reactivate.
larry118 wrote: These are really good people. Them being kind does not make VB6 any less dead. Companies that keep building on outdated blocks tend to become outdated themselves.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks but that did not help the vb6 form is still frozen. As soon as I get this working I can begin the conversion.
Such a Larry
|
|
|
|
|
larry118 wrote: Thanks but that did not help the vb6 form is still frozen. The difference between an executable and a dll is an executing thread. The easy way is to turn it into an executable, the correct way is to google for the Interop Toolkit.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Sadly there is very little documentation on the interop toolkit the way I am using it. Ironically the answer was in the order of doing things. If I execute the setparent function before I open the vb .net form it works perfectly. Lots of time lost for a stupid problem.
Such a Larry
|
|
|
|
|
I WANT TO KNOW HOW TO READ THE DATA FROM BCP BARCODE SCANNER .ALL THE DATA ARE STORE IN BARCODE
AND WANT TO FILL ALL DATA IN DATAGRID VIEW...
IN VB.NET CODE
|
|
|
|
|
First, writing your post in all-caps makes it look like you're shouting. That's kinda unkind.
Member 10355332 wrote: HOW TO READ THE DATA FROM BCP BARCODE SCANNER BC scanners come with a driver that usually makes the scanner act like a keyboard - scan an item, and the code comes out as if typed using a keyboard. Means that you can use a textbox; give it focus, wait for the number.
Member 10355332 wrote: ALL THE DATA ARE STORE IN BARCODE AND WANT TO FILL ALL DATA IN DATAGRID VIEW... How to display data using the DataGridView is explained here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi all,
I need to develop a small but rather advanced email app using vb.net
Up to now everything has been going smoothly until my lecturer asked me to include pictures in the email
I successfully managed to include the picture as attachment but he wanted the picture to be included in the email body itself and not as attachment
Now for 1 image I managed to do it by converting the email into html format and sending it
But now the real problem is when the user wishes to include several pictures in the email
How am i to detect the number of pictures and rewrite the equivalent email html??
I am using a richtextbox for the input of text and pictures
What I managed to do up till now is as follows
Imports System.Net.Mail
Imports System.Net.Mime
Public Class Form1
Dim picturePath As String
Dim pictureExt As String
Dim filePath As String = ""
Private Sub btnSend_Click(sender As System.Object, e As System.EventArgs) Handles btnSend.Click
Dim smtp As New SmtpClient
Dim avHtml As AlternateView
Dim mail As MailMessage = New MailMessage
Dim htmlBody As String
Dim pic1 As LinkedResource
Dim x() As String
x = txtBody.Text.Split(" ")
smtp.UseDefaultCredentials = False
smtp.Credentials = New Net.NetworkCredential("myEmail@yahoo.com", "myPassword")
smtp.Port = "25"
smtp.EnableSsl = True
smtp.Host = "smtp.live.com"
Try
htmlBody = "<html> "
htmlBody = htmlBody & "<body> "
If Not x(0) = Nothing Then htmlBody = htmlBody & x(0)
htmlBody = htmlBody & "<br /> "
htmlBody = htmlBody & "<img src='cid:Pic1'> "
htmlBody = htmlBody & "<br /> "
If Not x(1) = Nothing Then htmlBody = htmlBody & x(1)
htmlBody = htmlBody & "</body> "
htmlBody = htmlBody & "</html>"
avHtml = AlternateView.CreateAlternateViewFromString(htmlBody, Nothing, MediaTypeNames.Text.Html)
Select Case pictureExt
Case "jpg", "JPG", "jpeg", "JPEG"
pic1 = New LinkedResource(picturePath, MediaTypeNames.Image.Jpeg)
Case "gif", "GIF"
pic1 = New LinkedResource(picturePath, MediaTypeNames.Image.Gif)
Case "tiff", "tif", "TIFF", "TIF"
pic1 = New LinkedResource(picturePath, MediaTypeNames.Image.Tiff)
End Select
pic1.ContentId = "Pic1"
avHtml.LinkedResources.Add(pic1)
mail.From = New MailAddress("myEmail@yahoo.com")
mail.To.Add(txtTo.Text)
mail.Subject = txtSubject.Text
mail.IsBodyHtml = True
mail.Body = htmlBody
mail.AlternateViews.Add(avHtml)
If Not filePath = "" Then mail.Attachments.Add(New System.Net.Mail.Attachment(filePath))
smtp.Send(mail)
MsgBox("Email sent!")
txtBody.Text = ""
txtSubject.Text = ""
txtTo.Text = ""
picturePath = ""
pictureExt = ""
filePath = ""
Catch ex As Exception
MsgBox(ex.ToString)
Finally
End Try
End Sub
Private Sub btnAddImage_Click(sender As System.Object, e As System.EventArgs) Handles btnAddImage.Click
Dim openDlg As OpenFileDialog = New OpenFileDialog
Dim filter As String = openDlg.Filter
Dim tmp() As String
Dim img As Image
Dim orgData
openDlg.Filter = "Image File (*.tiff;*.jpg;*.gif)|*.tiff;*.jpg;*.gif"
openDlg.Title = "Open an image file"
If (openDlg.ShowDialog() = DialogResult.OK) Then
picturePath = openDlg.FileName
tmp = picturePath.Split(".")
pictureExt = tmp(1)
img = Image.FromFile(picturePath)
orgData = Clipboard.GetDataObject
Clipboard.SetImage(img)
txtBody.Paste()
End If
End Sub
Private Sub btnAddAttachement_Click(sender As System.Object, e As System.EventArgs) Handles btnAddAttachement.Click
Dim openDlg As OpenFileDialog = New OpenFileDialog
If (openDlg.ShowDialog() = DialogResult.OK) Then
filePath = openDlg.FileName
End If
End Sub
End Class
|
|
|
|
|
There's a content-id in your html, where you're referring to the image;
htmlBody = htmlBody & "<img src='cid:Pic1'>
How about adding more than one?
Dhanish Balloo wrote: How am i to detect the number of pictures and rewrite the equivalent email html?? Keep a List<> , and add each picture to the list when the user uses the opendialog. When generating the list, loop trough the list and add the content-id tag foreach picture.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
HI,
fanx 4 ur reply
must say i didnt fink abt the list
its a gud idea but 1 prb stil remains
wen i'll b creating the html, how to knw exactly where the user placed the picture?
|
|
|
|
|
Please don't use text speak - it makes you sound stupid and is rude in polite conversation.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Sorry about that
What i said is :
"Thanks for your reply. Must say I didn't think about the list. It's a good idea but one problem still remains. When I'll be creating the html, how to detect exactly where the user placed the picture??
|
|
|
|
|
Or like Ali G is in tha house. Good for comedy but not for anything else.
|
|
|
|
|
Dhanish Balloo wrote: wen i'll b creating the html, how to knw exactly where the user placed the picture? You don't know that now either, do you?
You could ask it's position by looking where the cursor is at that moment. There's a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.selectionstart.aspx">SelectionStart</a>[<a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.selectionstart.aspx" target="_blank" title="New Window">^</a>] property on the textbox that tells you where the cursor is located. I'd go for the easy way, and insert a "tag" at that location - some kind of word that's literally visible in the text and that hints that picture number X should go there. If you don't want such a visual marker you'd need to muck around with a RichTextBox, like shown here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hmmm.....that seems pretty interesting
I'll give it a try...thanks
|
|
|
|
|
You're welcome
|
|
|
|
|
I am a beginner in visual basic 6 and i need help in creating an application. I am trying to create an application in visual basic 6 which would display the meaning of a word(from the site Dictionary.com) entered in the text box on clicking on the "Search" button. It is actually a web browser which opens the page which contains the meaning of the desired word. Can anyone give me the code for the "Search" button such that after typing in the desired word in the text box and clicking on the "Search" button it would open the Dictionary.com page containing the meaning of that word. I have tried numerous methods but every time it is displaying some error or the other in loading the page.
The code which I used for the search button:
Private Sub Command1_Click()
WebBrowser1.Navigate ("http://dictionary.reference.com/browse" & Text1.Text)
End Sub
Or is there anything else that I can do to remove the error?
|
|
|
|
|
Don't you need a slash after "browse" in the url?
|
|
|
|
|
I had the "/" entered after the browse as well but still error is displayed.
|
|
|
|
|
Bitan Galactico Basak wrote: I am a beginner in visual basic 6
I'll stop you there.
VB6 is a dead technology. It was released in 1998, when the Internet was something that only nerds had access to. Support from Microsoft ended in 2008.
There will never be an update to VB6. None of the outstanding bugs will ever be fixed. New technologies will forever remain beyond its grasp.
Don't start by learning a dead technology. Get yourself a copy of Visual Studio 2013 Express[^], and start learning VB.NET[^] instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|