IT Community - Software Programming, Web Development and Technical Support

Advanced Programming in Visual Basic 6.0

This is a discussion on Advanced Programming in Visual Basic 6.0 within the VB.NET Programming forums, part of the Software Development category; About Microsoft Windows Image Acquisition Automation Layer The Microsoft Windows - Image Acquisition (WIA) Automation Layer version 2.0 is a ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > VB.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 03-12-2007, 05:01 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Advanced Programming in Visual Basic 6.0

About Microsoft Windows Image Acquisition Automation Layer

The Microsoft Windows - Image Acquisition (WIA) Automation Layer version 2.0 is a high-quality, full-featured image manipulation component that provides end-to-end image processing capabilities for Microsoft Visual Basic® 6.0, Active Server Pages (ASP), and scripting languages.

The WIA Automation Layer exposes features in Windows XP Service Pack 1 or later to make it easy to acquire images on digital cameras, scanners, or web cameras, and to rotate, scale, and annotate your image files. Earlier versions of Windows are not supported.

Other new features include the ability to:
  • Access the properties of image files.
  • Read and write image files and their properties to databases.
  • Modify pixels including alpha values.
  • Write ASP pages that generate thumbnail images on the fly.
  • Take pictures with your web camera.
  • Automatically download pictures from cameras as soon as they are connected, even if a script is not already running.

Follow the steps to make use of WIA
  1. include "wiaaut.dll" dll file to the Project reference
  2. There is a class name "ImageFile". Declare a variable
  3. Use ImageFile.LoadFile to load a picture file of any formats (Note you can load any image file types. e.g "*.png" also)
  4. Following code example explain about the rotate flip functionality in WIA class object

Dim pic As ImageFile

While (prcs.Filters.Count > 0)
prcs.Filters.Remove 1
Wend

prcs.Filters.Add prcs.FilterInfos("RotateFlip").FilterID



thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-16-2007, 05:45 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Re: Advanced Programming in Visual Basic 6.0

Visual Basic 6.0 is very good development tool for windows applications. I am very much interested in doing system oriented programming in VB. For system operations, we should be aware of Windows API’s(Application Programming Interface).

The API is nothing but, we can use the system functions by simply calling the functions from the system dlls.


I have given the following API and the windows system dll

GetVersionEx - kernel32.dll

I have given the following example to make use of API functions in VB

How to get the Windows version

Example :
Place the following code in the form declaration part

Option Explicit

Private Type OSVERSIONINFO ' 148 bytes
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type


Private Declare Function GetVersionEx Lib "kernel32" Alias _
"GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long


Place the following code in the form command1 click event

Dim os_Version As OSVERSIONINFO
Dim nWinOsMajorVersion As Long, nWinOsMinorVersion As Long
Dim nWinOsBuild As Long, sWinOs As String
os_Version.dwOSVersionInfoSize = 148
Call GetVersionEx&(os_Version)
nWinOsMajorVersion = os_Version.dwMajorVersion
nWinOsMinorVersion = os_Version.dwMinorVersion
nWinOsBuild = os_Version.dwBuildNumber

Select Case nWinOsMajorVersion
Case 4:
'Could be Windows 95, 98, ME or NT 4


If nWinOsBuild = 1381 Then
sWinOs = "Windows NT 4"
Else

Select Case nWinOsMinorVersion
Case Is < 10:
sWinOs = "Windows 95"
Case Is < 90:
sWinOs = "Windows 98"
Case Else:
sWinOs = "Windows ME"
End Select
End If
Case 5:
'Could be Windows 2000, XP, 2003


Select Case nWinOsMinorVersion
Case Is < 1:
sWinOs = "Windows 2000"
Case Is < 2:
sWinOs = "Windows XP"
Case Else:
sWinOs = "Windows 2003 Server"
End Select
End Select
Print sWinOs



thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-20-2007, 06:56 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Re: Advanced Programming in Visual Basic 6.0

GDI+ in Visual Basic 6.0


About GDI+

Purpose

Microsoft Windows GDI+ is a class-based API for C/C++ programmers. It enables applications to use graphics and formatted text on both the video display and the printer. Applications based on the Microsoft Win32 API do not access graphics hardware directly. Instead, GDI+ interacts with device drivers on behalf of applications. GDI+ is also supported by Microsoft Win64.

Where Applicable

GDI+ can be used in all Windows-based applications. GDI+ is new technology that is included in Windows XP and the Windows Server 2003. It is required as a redistributable for applications that run on the Microsoft Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Millennium Edition (Windows Me) operating systems.

Developer Audience

The GDI+ C++ class-based interface is designed for use by C/C++ programmers. Familiarity with the Windows graphical user interface and message-driven architecture is required.
Here we can use the GDI+ API in Visual Basic also. I have given the sample program to load a picture through GDI+.

Run-time Requirements

Gdiplus.dll is included with Windows XP. For information about which operating systems are required to use a particular class or method, see the More Information section of the documentation for the class or method. GDI+ is available as a redistributable for Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Me.

Before start working on GDI+. We must do the following things properly
• Start the Gdiplus Session by calling GdiplusStartup API
• Donot forget to shutdown the GDI+ in application exit/close by simply calling the GdiplusShutdown


Declare the following APIs in your General declaration part in VB6.


Option Explicit

Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type

'This function is used to start the GDI+ session
Private Declare Function GdiplusStartup Lib "gdiplus" ( ByRef rToken As Long, ByRef rInput As GdiplusStartupInput, ByRef pvOutput As Any) As Long

'This function is used to close the GDI+ session
Private Declare Sub GdiplusShutdown Lib "gdiplus" ( ByVal Token As Long)

'To load the Image to the picture1
Private Declare Function GdipLoadImageFromStream Lib "gdiplus" ( ByVal pStream As IUnknown, ByRef rImage As Long) As Long

'To Clear the image from the memory

Private Declare Function GdipDisposeImage Lib "gdiplus" ( ByVal pImage As Long) As Long

'Create the hdc for the picture1
Private Declare Function GdipCreateFromHDC Lib "gdiplus" ( ByVal hDC As Long, ByRef rGraphics As Long) As Long

'Delete the picture hdc from the memory
Private Declare Function GdipDeleteGraphics Lib "gdiplus" ( ByVal pGraphics As Long) As Long

'Load the image to picture1
Private Declare Function GdipDrawImage Lib "gdiplus" ( ByVal pGraphics As Long, ByVal pImage As Long, ByVal X As Single, ByVal Y As Single) As Long

'Create the image from the image data
Private Declare Function CreateStreamOnHGlobal Lib "ole32" ( ByRef hGlobal As Any, ByVal fDeleteOnRelease As Long, ByRef ppStream As IUnknown) As Long

'To Store the image file data as binary for creating the GDI+ image handle
Private m_ImageData() As Byte

Private m_GdipSession As Long
Private m_GdipImage As Long


'Loading the sample image to the picture box using GDI+
Private Sub Command1_Click()
Dim sFilename As String
Dim hFile As Integer
Dim iImageStream As IUnknown

sFilename = "samplefile.JPG"

hFile = FreeFile
Open sFilename For Binary Access Read Shared As #hFile
ReDim m_ImageData(0 To LOF(hFile) - 1)
Get #hFile, , m_ImageData
Close #hFile


If (CreateStreamOnHGlobal(m_ImageData(0), 0, iImageStream) = 0) Then
If (GdipLoadImageFromStream(iImageStream, m_GdipImage) <> 0) Then
Debug.Print "Couldn't Load Image"
End If

Set iImageStream = Nothing
End If

LoadPic Picture1
End Sub

'Start GDI+ session
Private Sub Form_Initialize()
Dim tGdiplusStartupInput As GdiplusStartupInput

With tGdiplusStartupInput
.GdiplusVersion = 1
.DebugEventCallback = 0
.SuppressBackgroundThread = 0
.SuppressExternalCodecs = 1
End With

If (GdiplusStartup(m_GdipSession, tGdiplusStartupInput, ByVal 0&) <> 0) Then
Debug.Print "GDI+ Initialization Failed"
End If
End Sub


'Load picture function for loading image by GDI+ API
Private Sub LoadPic(picCtrl As PictureBox)
Dim pGraphics As Long
If (GdipCreateFromHDC(picCtrl.hDC, pGraphics) = 0) Then
GdipDrawImage pGraphics, m_GdipImage, 20, 20
GdipDeleteGraphics pGraphics
End If
End Sub


'Unload the image from memory
Private Sub Form_Unload(Cancel As Integer)
If (m_GdipImage) Then
GdipDisposeImage m_GdipImage
End If
End Sub

'Shutdown the GDI+ session
Private Sub Form_Terminate()
If (m_GdipSession) Then
GdiplusShutdown m_GdipSession
End If
End Sub


thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-02-2007, 09:06 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Re: Advanced Programming in Visual Basic 6.0

Multithreadded Programming In VB6

Hi
Here I am going to give technics about how to implement the multi threadding in VB6. It is not easy to implement the multi threadding in Visual Basic. You can implement the multi threadding by using Timer controls. But for that you have to maintain flags to separate the process and also it will be a tedious work.
Using Windows API we can easily implement the multithreadded programming in Visual Basic 6.0. For that you need to declare the following API in your VB module.

'This API for maintaining the Window's functions.NOTE if you are not maintaining that, Your Application will raise illegal error closing


Public dThreadStartedFlag as Boolean
Public Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long

Public lngPrevWndProc As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long


Declare your Threaded function in the same VB module file

Public Function ThreadProc1(ByVal lngID As Long) As Long
Debug.Print "out side"
'Thread terminates when it exits this function.
End Function


Call the threadding function in the following manner using the Windows API functions

Dim lngRetVal As Long
Dim lngThread1 As Long
Dim lngFrmHandle As Long

If dThreadStartedFlag =false Then
lngFrmHandle = Me.hWnd
dThreadStartedFlag = True
lngPrevWndProc = SetWindowLong(lngFrmHandle, GWL_WNDPROC, AddressOf WndProc)

lngThread1 = 0
lngRetVal = CreateThread(0&, 0&, AddressOf ThreadProc1, Me.hWnd, 0&, lngThread1)
Else 'this is to terminate the thread
SetWindowLong lngFrmHandle, GWL_WNDPROC, lngPrevWndProc
End If


by using the above methodology you can implement the multithreadded programming.
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/vb-net-programming/528-advanced-programming-visual-basic-6-0-a.html
Posted By For Type Date
Digg / Programming / Upcoming This thread Refback 07-20-2007 06:58 AM
Digg / Programming / Upcoming This thread Refback 07-20-2007 04:20 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference of Visual Basic over a VB.net chocoguy VB.NET Programming 1 08-06-2008 03:56 AM
Visual Basic chocoguy Other Web Programming Languages 2 01-10-2008 05:16 PM
What is the difference between Windows programming and database programming? Arun VB.NET Programming 0 07-18-2007 08:58 AM
HTML Basic Programming spid4r HTML, CSS and Javascript Coding Techniques 2 04-23-2007 08:19 AM
Visual Basic At The Movies Gopisoft VB.NET Programming 1 03-05-2007 10:58 AM


All times are GMT -7. The time now is 06:45 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0