Recent Posts

Sunday, June 29, 2008

Minimise VB 6.0 Application to Task Bar

Open a new standard project in vb 6.0

Then add a module named modPublic.bas in the project and add the following code in the module which are the public declaration and API call code:

Option Explicit

Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As MinimiseIconData) As Boolean

'constants required by Shell_NotifyIcon API call:
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201 'Button down
Public Const WM_LBUTTONUP = &H202 'Button up
Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
Public Const WM_RBUTTONDOWN = &H204 'Button down
Public Const WM_RBUTTONUP = &H205 'Button up
Public Const WM_RBUTTONDBLCLK = &H206 'Double-click


Then add other module named modType for the public type declaration for the project. Add the following code in this module:

Public Type MinimiseIconData
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 64
End Type

Then on the Form1 properties select the icon which you want to display when your application is minimised to the task bar.
Note: icon has the extention .ico

Add one command button on the form

Then in the Form1 code page add the following code:

Option Explicit

Private minIco As MinimiseIconData

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Form_Load()
If App.PrevInstance Then

End
End If
With minIco

.cbSize = Len(minIco)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon ' <== You can change this to another icon
.szTip = "Double-click this icon to make the application visible" & vbNullChar ' <== You can change this also.

End With
Shell_NotifyIcon NIM_ADD, minIco
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lngButtonAction As Long

lngButtonAction = X / Screen.TwipsPerPixelX

Select Case lngButtonAction

Case WM_LBUTTONDBLCLK
' Left mouse button has been double clicked
' If app is currently minimized ….
Me.WindowState = vbNormal
Me.Show
'If Me.WindowState = vbMinimized Then ' … then restore it to normal size
' Me.WindowState = vbNormal
' Shell_NotifyIcon NIM_DELETE, nid ' and remove the icon
'ElseIf Not Me.Visible Then ' Else, if the app is hidden …
' Me.Show ' then show the form again
' Me.WindowState = vbNormal
' Shell_NotifyIcon NIM_DELETE, nid ' and remove the icon
'End If

Case WM_LBUTTONDOWN
' You could put code in here to make something happen when
' left mouse button is single clicked on the icon

Case WM_RBUTTONDOWN
' You could put code in here to make something happen when
' right mouse button is single clicked on the icon

End Select

End Sub

Private Sub Form_Resize()
On Error Resume Next

If Me.WindowState = vbMinimized Then
Me.Hide
Shell_NotifyIcon NIM_ADD, minIco
Else ' otherwise don't show it
Me.Show
Shell_NotifyIcon NIM_DELETE, minIco ' รง This removes the icon
End If
End Sub


Private Sub Form_Terminate()
Shell_NotifyIcon NIM_DELETE, minIco
End Sub



The code to minimise the application to the taskbar is at the following link. Please click the following link to download and use the code: http://prateek.regmi.googlepages.com/minimise_App_To_Taskbar.rar


Read more!

Win API Timer in VB 6.0

If you need to execute the particular piece of code in certain duration in your vb 6.0 application without using the vb Timer control then this code sample will help you a lot.

This API call doesn't uses the unwanted cpu processor but it only executes the Function or a sub at a given time and closes the timer when ordered.

Fist in the module put the following code:

Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, _
ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long



Public lngIden As Long

Public Function StartTimer()

lngIden = SetTimer(0, 0, 5000, AddressOf TimerCallback)

End Function

Public Function CloseTimer()

KillTimer 0, lngIden

End Function

Public Function TimerCallback(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent _
As Long, ByVal dwTime As Long) As Long

Dim lngRetVal As Long
lngRetVal = MsgBox("Hi its' me making a callback! Want me to prompt again?", _
vbExclamation + vbYesNo, "CallBack Functions")

If lngRetVal = vbNo Then
Call CloseTimer
End If

End Function

Now call the functions from the form

Private Sub Form_Load()
Call StartTimer
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call CloseTimer
End Sub



The Code sample can be downloaded and can be used from the following link below:

http://prateek.regmi.googlepages.com/WinApi_Timer.rar

If any comments or add ons on the code then please don't hesisate to comment on this blog.
Thanks


Read more!

Wednesday, June 25, 2008

Interface based programming in VB 6.0 ( Inheritance example)

Complete object oriented programming using interface in vb 6.0.

Full source code provided with the running application that shows how we can reuse our code in creating different instances and using the instances in different tasks to do. It completely explains how inheritance can be applied from vb 6.0 application. People might think full object orientation is not required in vb but if this concept can be taken in mind then we can use the full use of our code re use and can be helpful for those programmers who are targetting to go ahead in com or D- com programming.

The application also shows how to use API calls to play .wav sound from the vb Application. You can download and use the application from the following link provided.

http://prateek.regmi.googlepages.com/InterfacewithVB.rar


Read more!

Monday, June 23, 2008

Create chat program using WinSock in VB 6.0

How to use Winsock Component

How to create a chat program from vb


The you can Download the sample application from the link below :


http://prateek.regmi.googlepages.com/WinsockTest.rar


Read more!

Displaying all prime numbers below 100 in VB 6.0

Displaying all prime numbers below 100 in VB 6.0

Private Sub DisplayPrimeNumbers()

Dim Num As Long
Dim NN As Long
Dim IsPrime As Boolean

For Num = 2 To 100
IsPrime = True
For NN = 2 To Int(Num / 2)
If Num Mod NN = 0 Then
IsPrime = False
Exit For
End If
Next
If IsPrime Then
MsgBox CStr(Num) + " is a prime number!"
End If
Next

End Sub


Read more!

Microsoft Visual Basic version 9.0

Get
The Microsoft Visual Basic
Language Specification

Version 9.0

BY
Paul Vick
Microsoft Corporation

clicking on the following link :

http://prateek.regmi.googlepages.com/VisualBasicLanguageSpecification9.0.doc


Read more!

Sunday, June 22, 2008

VB 6.0 Putting the form to center of the screen/ Maximising the form

Public Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long


Public Sub MaximiseForm(frm As Form)
On Error GoTo SubError

Const SubName = "Maximise"

Dim ScreenWidth As Long
Dim ScreenHeight As Long
Dim ScreenLeft As Long
Dim ScreenTop As Long
Dim DesktopArea As RECT

Call SystemParametersInfo(SPI_GETWORKAREA, 0, DesktopArea, 0)

ScreenHeight = (DesktopArea.Bottom - DesktopArea.Top) * Screen.TwipsPerPixelY
ScreenWidth = (DesktopArea.Right - DesktopArea.Left) * Screen.TwipsPerPixelX
ScreenLeft = DesktopArea.Left * Screen.TwipsPerPixelX
ScreenTop = DesktopArea.Top * Screen.TwipsPerPixelY

With frm
.Top = ScreenTop
.Left = ScreenLeft
.Height = ScreenHeight
.Width = ScreenWidth
End With

SubExit:
Exit Sub

SubError:

ShowErr App.Title + " " + SubName
Resume SubExit

End Sub

'Puts the Form in the center of the Screen

Public Sub CentreForm32(frm As Form)
On Error GoTo SubError

Const SubName = "CentreForm"

Dim ScreenWidth As Long
Dim ScreenHeight As Long
Dim ScreenLeft As Long
Dim ScreenTop As Long
Dim DesktopArea As RECT

Call SystemParametersInfo(SPI_GETWORKAREA, 0, DesktopArea, 0)

ScreenHeight = (DesktopArea.Bottom - DesktopArea.Top) * Screen.TwipsPerPixelY
ScreenWidth = (DesktopArea.Right - DesktopArea.Left) * Screen.TwipsPerPixelX
ScreenLeft = DesktopArea.Left * Screen.TwipsPerPixelX
ScreenTop = DesktopArea.Top * Screen.TwipsPerPixelY

frm.Move (Screen.Width - frm.Width) / 2 + ScreenLeft, (ScreenHeight - frm.Height) / 2 + ScreenTop

SubExit:
Exit Sub

SubError:

ShowErr App.Title + " " + SubName
Resume SubExit

End Sub


Read more!

Sunday, June 15, 2008

.Net common Language Runtime Debugging services Error

Hi ,

I have an application written in .Net 2003 that runs every 5 mins from the task scheduler to send mail, but recently i am getting the error message shown below that i could not debug at all.

Right now I am just killing the process as it shows the error and then restarting the application again. This is just the temporary solution for me. The error message is as follows:

Application has generated and exception that could not be handled

process id=0x1760(5984), Thread id=0x16fc(5884)

click ok to terminate the application
click cancel to debug the application

I appreciate any comments on this thank you


Picture of the actual error is:


Read more!

Thursday, June 12, 2008

Sheridan 3D Control (THREED32.OCX) asking for License in VB 6.0 (get solution here)

This is a third party control and is called (Sheridan 3D Control).

This control was mainly developed in VB 4 .

So if we try to use it in vB6.0 then it asks for the license and won’t work

Therefore installing it in VB 6.0 we have to apply some trick as follows:

a. On the Visual Basic 6.0 installation CD go to
Common
Tools
VB
Controls

b. Then there are two files namely
i. THREED32.OCX and
ii. VBCTRLS.REG

c. Copy these files to your system32 folder and overwrite the old files.

d. Then on your system32 folder double click just installed VBCTRLS.REG file to register it to your computer.

e. Now your Sheridan 3D Control should work.


Read more!

Wednesday, June 11, 2008

Print output in in file from Vb 6.0 Application

Private Sub PrintOutput(ByVal strData As String)
Dim strPath As String
Dim strExcel As String

Dim strFileName As String

' saving the xml file

strExcel = Trim(lblFileName.Caption)
strExcel = Mid(strExcel, 1, InStr(1, strExcel, ".") - 1)
strFileName = "MerchantNo" & Trim(MDIMain.lblMerchantID.Caption) & strExcel & ".xml"
strPath = App.Path & "\XML\" & strFileName



Dim OutFile As Integer
On Error GoTo SErr:
Dim strTest As String

OutFile = FreeFile
Open strPath For Output As #OutFile
Print #OutFile, strData

Close #OutFile
MsgBox "XML Saved", vbOKOnly
'#############################################################
Exit Sub
SErr:
MsgBox Err.Description

End Sub


Read more!