get the text of edit box from other program - vb6

I'm not sure how to get text of edit box from other application using visual basic. In C++ I just find the handle of edit box with FindWindow and FindWindowEx, ... using WIN API. How to do this in visual basic ?

For VB6 just use FindWindow and FindWindowEx... using WIN API.
you'll need the proper declares at the top:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Look at the PInvoke site for the correct syntax for whatever flavor of VB you are using
The real trick is that the V6B controls use to different class names than you might be used to.

Related

I'm loading a .DLL in runtime, but always i stop the solution in debug mode and start again the program will crash

I'm using a device in my vb6 program and i loaded the .dll of this device during runtime in a module.
I need to declare all the methods of the .dll
Example:
Declare Function FTRGetParam Lib "FtrAPI.DLL" _
(ByVal Param As Long, ByRef value As Any) As Integer
But when i enter in this module again in the next execution, the program will crash and i must to close the Visual Studio IDE.
Any Idea?

New exe icon not reflecting in windows 7 task bar for vb6

I changed the resource file for a new icon for my exe and generated the exe for vb6 project. However, the exe icon has changed but the windows 7 task bar is still showing the old icon.
If I generate the exe in some other location other than my project directory its working fine. Could someone please help on this issue?
You need to tell Windows you updated the icon so it can update its cache.
If you're using VB6, make yourself a little utility:
Create a new EXE project (name it "ForceIconsRefresh" or something like that)
In the project properties, change the Startup Object to "Sub Main"
Add a new module, remove the default Form object
In the module add the following:
Option Explicit
Private Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Long, ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long) As Long
Private Const SHCNE_ASSOCCHANGED As Long = &H8000000
Private Const SHCNF_FLUSHNOWAIT As Long = &H2000
Sub Main()
Call SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, 0, 0)
End Sub
Compile
Execute after building an EXE with an updated icon
VoilĂ !

VB6 Compile Outlook add-in - Compile Error: Automation Type Not supported in Visual basic

I have got an infuriating problem trying to compile a VB6 Outlook Add-in component following an upgrade of Office on the same PC to Office 2013 Pro Plus.
The error
Compile Error: Automation type not supported in Visual Basic
is being thrown on the line:
Implements IDExtensibility2
I will paste the full code from that file below.
On another PC, I managed to get everything set up, and upgrade Office to 2012 and it compiled no problem, but on that same PC now - I get the same error. I have messed around a lot with the Office install in the interim so I couldn't accurately tell you what I did in between it working and not working, but the bottom line is it seems it shouldn't be beyond possibility to do what I am trying to do (as I have done it!), I just need some guidance on what I may need to do to get back to a working setup. Any ideas??
Implements IDTExtensibility2
Private gBaseClass As New clsOlkAddIn
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
'To Be Declared for IDTExtensibility2
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
'To Be Declared for IDTExtensibility2
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
gBaseClass.InitHandler Application, AddInInst.ProgId
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Dim objCB As Office.CommandBar
On Error Resume Next
'If RemoveMode = ext_dm_UserClosed Then
Set objCB = golApp.ActiveExplorer.CommandBars("Addin")
objCB.FindControl(Type:=msoControlPopup, Tag:="Menu").Delete
objCB.FindControl(Type:=msoControlButton, Tag:="AddEmailsButton").Delete
objCB.FindControl(Type:=msoControlButton, Tag:="SyncContactsButton").Delete
objCB.FindControl(Type:=msoControlButton, Tag:="SyncTasksButton").Delete
objCB.FindControl(Type:=msoControlButton, Tag:="SyncCalendarButton").Delete
objCB.Delete
'End If
gBaseClass.UnInitHandler
Set gBaseClass = Nothing
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
'To Be Declared for IDTExtensibility2
End Sub
Another cause of this error, as I found today is having an optional parameter on a function and giving it a default, e.g.
Public Function Foo(MyString as String, Optional MyVariant as variant = null)
Changing this to:
Public Function Foo(MyString as String, Optional MyVariant as variant)
Solved it, I didn't get there as simply as it looks above though (hence, why I'm hanging around here), I did change the optional parameter to a string first, which worked, in fact, even with a variant parameter, having a default of anything other than Null worked. It was the default of Null that was causing the error.
As you've confirmed in your answer (in comments), ensuring you've upgraded to the latest service pack is always the best option unless you know you're relying upon features that were dropped or changed in later service packs.
Installing the "Cumulative update rollup for the Visual Basic 6.0 Service Pack 6 Runtime Extended Files" (https://support.microsoft.com/en-us/help/957924/description-of-the-cumulative-update-rollup-for-the-visual-basic-6-0-s) resolved this error in my instance.

Visual Studio 2008 BuildEvent Macros not Firing

I added this well documented macro to MyMacros, Environment Events in VS 2008 Macros in order to cancel failed builds:
Private Sub BuildEvents_OnBuildProjConfigDone(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String, ByVal Success As Boolean) Handles BuildEvents.OnBuildProjConfigDone
If Success = False Then
'The build failed...cancel any further builds.
DTE.ExecuteCommand("Build.Cancel")
End If
But it's not canceling my builds. I also set breakpoints to hopefully catch it firing but they are not hit either.
I also added this test macro but its not being fired either:
Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
Beep()
Beep()
End Sub
The "Allow macros to run" option is set.
Why is it not being fired? Why are my breakponts not being hit?
Thanks for your help
Apparently you have to run Debug (green play button) in the Macros IDE for breakpoints to be hit.
Now I know.

XP Look-and-feel for VB6 Outlook Property Page?

I am writing a PropertyPage for Outlook using VB6. This is implemented as a VB6 OCX.
When running in a newer version of Outlook (like 2007) on XP (or newer), my dialog looks weird because it doesn't have XP look and feel. Is there a way to do this?
Preferably without adding a manifest file for Outlook.exe.
I think you're right to avoid using a manifest. Unfortunately the standard well-known hacks to support XP themes from VB6 rely on manifests. This MSDN article on developer solutions for Outlook 2007 warns that providing your own manifest for Outlook 2007 might cause it to hang.
I don't think you can do it in VB6 ... those controls are going to look like what they look like. You can, however, create your property pages with Visual Studio .NET and Visual Basic .NET and get the XP, 2007 and Vista look and feel. It's a bit of a change from what you're doing, but you're really behind the times developing with VB6 anyway. More details on how to do that are here and the office developer center.
Not that I know of using VB6
If you can use .NET instead - one way is WPF. I saw earlier an example on code-project.
Here's the link
Edit: And another tool to assist here
This is what I do in all of my VB6 Apps, only ever tested in a standalone EXE so not sure if it will work as an OCX.
Private Type tagInitCommonControlsEx
lngSize As Long
lngICC As Long
End Type
Private Declare Function InitCommonControlsEx Lib "comctl32.dll" _
(iccex As tagInitCommonControlsEx) As Boolean
Private Const ICC_USEREX_CLASSES = &H200
Public Function InitCommonControlsVB() As Boolean
On Error Resume Next
Dim iccex As tagInitCommonControlsEx
' Ensure CC available:
With iccex
.lngSize = LenB(iccex)
.lngICC = ICC_USEREX_CLASSES
End With
InitCommonControlsEx iccex
InitCommonControlsVB = (Err.Number = 0)
On Error Goto 0
End Function
Public Sub Main()
InitCommonControlsVB
'
' Start your application here:
'
End Sub
Create a file similar to this: http://pastebin.com/f689388b2
Then you add the manifest file to your resource file as type RT_MANIFEST (24)
I can't quite remember if that's all you need to do as I always just use the same pre-made .res file now.
Source: http://www.vbaccelerator.com/home/vb/code/libraries/XP_Visual_Styles/Using_XP_Visual_Styles_in_VB/article.asp

Resources