Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all 1500 articles
Browse latest View live

monster packet vb6 codes , various type v1

$
0
0
monster packet source want to share that i found in pc

tried to upload , gone past size limits so cant add attachment

i uploaded to sendspace
http://www.sendspace.com/file/lij39l

em this is must se and have by me + had it very long time and want to share +

i will share mega pack 2 /3/4

also got paid planet source and i will share with u all its my licence so i can share

How To Set More Than 1 Minute To A Timer

$
0
0
Many people facing this problem can't set timer more than 1 minute interval here is one of solution to all you need a timer and text box add this code to timer

I am showing how to make timer interval 10 minute :wave:

Private Sub Timer1_Timer()
If text1.text="10" then
'here type what you need to do after interval 10 minutes
text1.text="0"
else
text1.text=val(text1)+1
end if
end sub

VB6 - MailCall: LAN App to App Alerts

$
0
0
Sometimes when a data client application can be in use by multiple people it may be useful to know when certain updates have been done so you can requery. This can be true whether you use a database or a set of random files... or some other shared resource. In theory you might even use it to monitor progress reports from a "batch" program running on another PC.

Example:

Perhaps you have a customer list table in a database and you use it to populate a Customer ListBox. When somebody adds a new customer you might want to reload your ListBox.

Now, you could beat on the database almost continuously using a Timer to reload every few seconds. This has performance implications though and they can be very serious when you use a shared file-based DBMS such as Jet.


MailCall

You can add a MailCall instance to a Form as an alternative.

MailCall has a Listen() method that you pass a Name to that is unique to your application. This causes MailCall to create the server end of a Mailslot and set up a broadcast name that it will use when you call its Send() method.

Send() accepts a String of up to to 100 Unicode characters and broadcasts it to all other computers on the LAN.

MailCall has its own Timer control that it uses to poll for inbound broadcasts every 1 to 65 seconds (set via the PollInterval property).

When this Timer's event handler reads an inbound message it will optionally skip any originating from itself depending on the value of the ReportLocal property. It also skips duplicate message payloads it finds during that poll since it is possible for Mailslot broadcasts to be delivered more than once depending n your network configuration).

If these criteria are met it raises its Receive() event, passing the data payload.

By passing different Name values to Listen() calls you can reuse MailCall in separate applications without collisions.


Data

Your 0 to 100 characters of Data can be whatever makes sense for your application. It might be empty, just a "ping" to everyone. Or it might be a database table name. Or it might be a signal from an "admin" program saying to close the database because maintenance is going to be performed.

You should be able to format the DATA as any Unicode characters, even NULs though that's usually not valuable. And you can parse incoming Data and act upon it in any way you see fit.

You can make up a protocol with a Msg ID code and comma-separated parameters. As long as it fits within 100 characters.

If desperate, you can also jam up to 200 ANSI characters into the String.


Requirements

Most of these are spelled out in the comments within MailCall. it should work on any machine that can run VB6 programs.

In case it isn't clear: Mailslots do not work over the Internet. Again, see the comments for more detail.

Your PCs' firewalls must permit MS Networking traffic ("File and Printer Sharing"), and all of the machines must be in the same Workgroup or Domain.

Win9x clients have limitations on the Mailslot names they can use. There can only be one Mailslot server for a given Mailslot name in one PC.


The Demo

So you can't really test the Demo thoroughly by running two copies on your computer.

But since there are no Demo dependencies aside from (a.) Windows and (b.) the VB6 runtime you could run A second Windows OS in a VM with networking support (and in the same Domain or Workgroup) and copy the compiled EXE there to test "pinging" back and forth between a copy on your PC and running in the VM.

And you can run the Demo standalone, talking to itself. Normally though an application instance doesn't want to see its own broadcasts (see the comments).
Attached Files

VB6 - Msms2Libs: Extract VS6/VB6 MSMs to Libraries

$
0
0
Purpose

Those who package and deploy VB6 Projects using Windows Installer tools that create MSI packages have the luxury of using Microsoft-built stable redistributable Merge Modules that contain the VB6-supplied OCXs and DLLs. But to get this stability when using a scripted setup maker such as the PDW it can be harder to come up with a source for them.

When you package applications you really don't want to use the "live" versions of these libraries, i.e. the versions installed and registered on your development system. The main reason is that you shouldn't try to install a version that is newer than the baseline version for the last Service Pack: now SP6 for VS6/VB6.

The PDW has a Redist folder, typically at:

C:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\Redist

When you install VS/VB this folder gets created and a basic set of files is placed there, but you the programmer are supposed to ensure that these files are updated appropriately and new files added over time. When files are placed here the PDW will use these versions for packaging your application instead of taking them from the "live" locations (System32, Program Files\Common Files, etc.).

There are several MS KB articles that cover this as well as related issues. Here are a few:

Best practices for deploying Visual Basic 6.0 applications

INFO: PDW [Do Not Redistribute] Section of VB6DEP.INI

INFO: Support for Third-Party Installers

INFO: How Setup Wizard and PDW Use Dependency Files


Msms2Libs

To get a set of the current baseline libraries I have written a VB6 program "Msms2Libs."

What it does is:
  • Run the merge modules package (msmenu.exe) to extract the MSMs to a subdirectory (Extracted) under the program's own directory (App.Path).
  • Create a "queue" of MSM files to process by scanning the directory.
  • Use the Windows Installer automation interface to extract the merge module CAB file from each merge module and into the same subdirectory.
  • Run an instance of the Microsoft utility Extract.exe against each CAB file to extract the files from the CAB into the same subdirectory.
  • Rename each extracted file from its name in the CAB file to its target name (the actual DLL or OCX name).
  • Delete all of the MSM and CAB files from the subdirectory.
Once complete the Extracted subdirectory should have a set of the VB6 SP6 files contained in those MSM files. There will also be some VC6 files there that you can delete and ignore or use for VC6 projects (but that's a different subject).

Some MSMs are skipped, see the comments in Msms2Libs' UIForm.frm module for details.


Using Msms2Libs

The full Project source is in the attached archive. Unzip these to a Project folder.

Next you will need to put a copy of the Microsoft Cabinet SDK utility Extract.exe into this folder. This used to be easy: just download and run CabSDK.exe from Microsoft, then after the self-extractor runs copy the utility from the CabSDK folder created.

Microsoft no longer offers this download though. If you do not already have the Cabinet SDK on your computer you might try some web searches, some 3rd party sites may still host this download. Just be sure to run a good virus scan on it before running it.

Once you have the Project folder set up and Extract.exe copied there, you need to download the VS6 SP6 Merge Modules package:

Merge Modules for Service Pack 6 for Visual Basic 6.0 and Visual C++ 6.0

Put this in a safe place, and copy it into the Project folder as well so Msms2Libs can run it for you to extract the MSMs.

Now you can run Msms2Libs from within the VB6 IDE or compile it and run the EXE. This should perform the steps listed above for you, create a log.txt file listing its actions, and leave you with a set of libraries in the Extracted subfolder.

So to run Msms2Libs, at a minimum you'd have some read/write directory that contains:
  • Compiled Msms2Libs.exe
  • The Extract.exe utility
  • The downloaded MSM distribution package MSMenu.exe

Notes

General

Be sure to read the comments at the head of UIForm.frm before running the program. There are some Consts you might want to alter and you might want to make additional changes too.

The entire process is non-destructive. If anything goes wrong just delete the Extracted subfolder or at least its contents, then you can re-run after making any changes that might be required.

DEP Files

These Merge Modules are meant for use by MSI packaging tools. This means they do not supply any .DEP files (since those are never deployed to target systems anyway). The equivalent of the .DEP file contents is embeeded in the MSMs themselves as "rules" for installing the libraries and registering them.

Ideally when you copy these extracted libraries into the PDW's Redist folder you will also either create new .DEP files for each one or else copy the existing .DEP from each library's "live" location and update it with new version and timestamp information.

It would be difficult to have Msms2Libs generate these for you since they normally contain information that Microsoft supplies in them regarding subdependencies and localization resource DLLs as wel as version numbers and dates.
Attached Files

Multi Server Multi Client Chat Application

VB6 - RTBCompose RTF Editor UserControl

$
0
0
Sometimes you want to provide a RichTextBox control wrapped with some buttons and logic to let the user interact with it as a somewht fuller-featured editor for RTF data. This is easy enough but a little tedious to do over and over again.

RTBCompose is a UserControl for this which you can add to your Projects and drop into your Forms. It helps keep the fiddly button handling logic out of your Forms and away from your business logic.

Uses

The attached demo is a small Project using RTBCompose to create a sort of stripped-down WordPad like program.

A more practical use might be programs that let a user compose and send RTF messages. This is why the SendButton option exists in RTBCompose.

You may also have a database that contains RTF-format Memo fields that you need users to be able to enter text into and/or edit existing text.

What it adds

RTBCompose provides a simple button bar supporting common rich editing operations such as cut, copy, paste, bold, etc.

It also adds a font/color "picker" based on the Font Common Dialog (ChooseFont API) wrapped in a way that makes it "work like" the VB6 CommonDialog control.

And it also has a button for "insert picture."

It adds Ctrl-B, Ctrl-I, and Ctrl-U keystrokes in addition to the Ctrl-C, Ctrl-V, and Ctrl-X natively supported by the RichTextBox control. Users get used to these in other programs and get to expect them.

There are other misc. features such as a left-right Margins property, a SendClicked event linked to the Send button you may not need, an IsDirty property and IsDirtyChanged event useful for adjusting things like menu item enabled status in the parent Form and detecting unsaved changes.

What it subtracts

RTBCompose only exposes a few things like the RichTextBox's base Font, Text, and RTFText properties and the LoadFile and SaveFile methods. It already takes care of most of the Selxxx properties with its own code, so you generally would not need them in the parent Form.

Since you have the full source you could expose more properties, add or remove buttons, implement drag/drop, etc. as required.

System Requirements

Should pretty much work on any system that VB6 programs run on.
Attached Images
 
Attached Files

new pause funchion

$
0
0
Code:

Private Sub TimeOut(HowLong)
    Dim TheBeginning
    Dim NoFreeze As Integer
    TheBeginning = Timer


    Do
        If Timer - TheBeginning >= HowLong Then Exit Sub
        NoFreeze% = DoEvents()
    Loop
End Sub


use
TimeOut 4

VB6 Unexpected Error on Windows 7

$
0
0
A forms-based VB6 application that runs on XP and Windows Server 2003 fails on Windows 7 with "Unexpected Error", even before the first form is launched.

(I will be answering myself as I've just solved it. I just wanted to pass on the knowledge)

[RESOLVED] VB6 Unexpected Error on Windows 7

$
0
0
A forms-based VB6 application that runs on XP and Windows Server 2003 fails on Windows 7 with "Unexpected Error", even before the first form is launched.

(I will be answering myself as I've just solved it. I just wanted to pass on the knowledge)

How to Check the internet connections adapters list?

$
0
0
Hello :wave:
I have 2 internet connection on my pc, where one is broad-band connection "Local Area Connection" and another is a dial-up connection "Idea Internet".

Now here I want to get the list of all the connection adapters. Along with that want to get which is the Active i mean which is being used.

I searched in google but din't found any proper solution instead of "InternetGetConnectedStateEx" API which only shows if the internet is Active or Disabled.

Is it possible in VB6.0 to get lists of all Internet Connections Adapters with ther Active status?

Thanks in advace,
with warm Regards,

Mozilla Control Error

$
0
0
Hello everyone,
I have downloaded and installed the latest version of "Mozilla Active X control 1.7.12" from
Code:

http://www.iol.ie/~locka/mozilla/control.htm
Added it's component "mozctl.dll" in my vb6.0 project. It's browser is working fine and showing webpage.
But I am getting error "Automation error Library not registered." on getting the html source of the loaded webpage.
I am using codes

MozillaBrowser1.Document.body.innerHtml

I've searched about this error, but not getting any working solution. Which Library is not registered and how to register that? Where i am doing wrong. Please correct me and tell how to get webpage html source code by using Mozilla Control in vb6.

Thanks
Regards,

Cpu Utilization in vb6

$
0
0
Attachment 99175


Code:

Private Wmi As Object, Locator As Object
Private PrevCpuTime As Long, SampleRate As Long


Private Sub Form_Load()
    SampleRate = 2 'in seconds
    Timer1.Interval = SampleRate * 1000
    Set Locator = CreateObject("WbemScripting.SWbemLocator")
    Set Wmi = Locator.ConnectServer
    Timer1_Timer
End Sub


Private Sub Timer1_Timer()
    Dim Procs As Object, Proc As Object
    Dim CpuTime, Utilization As Single
    Set Procs = Wmi.InstancesOf("Win32_Process")


    For Each Proc In Procs


        If Proc.ProcessID = 0 Then 'System Idle Process
            CpuTime = Proc.KernelModeTime / 10000000


            If PrevCpuTime <> 0 Then
                Utilization = 1 - (CpuTime - PrevCpuTime) / SampleRate
                Text1.Text = Format(Utilization, "0.0%")
            End If
            PrevCpuTime = CpuTime
        End If
    Next
End Sub

Attached Images
 

VB6 - Zipper & ZipWriter, Zipping from VB programs

$
0
0
Background

A lot of us find the need to create ZIP archives programmatically from time to time. There are a number of techniques we can use, from spawning external utility programs to 3rd party components to Shell automation.

Here is yet another way to accomplish this: using the free, open source zlibwapi.dll


Minizip

In addition to providing a STDCALL version of ZLib that we can call easily from VB6 programs zlibwapi.dll includes the Minizip project code as well.

Like a lot of open source hacked out by C coders this can be rough in many places, but it is widely used and well proven. It should have few if any bugs in the most recent version.

I'm using version 1.25 here. You can get this from:

Minizip: Zip and UnZip additionnal library

See the typo there? This is just one symptom of some of the issues, but fortunately the code at least seems to work fine even if its source is wonky with lots of flaws in comments and general documentation issues.

This DLL is not included in the attachment. You must download it yourself.

Quote:

In zlib125dll.zip there is the Win32 Windows DLL of my Windows DLL named Zlibwapi.dll that contains both zLib and Minilib.
The file you want from this ZIP archive is:

zlib125dll.zip\dll32\zlibwapi.dll


ZipWriter

ZipWriter is a VB6 Class that wraps zlibwapi.dll to provide you with a way to create a ZIP archive and actually write data into it as archived files with no intermediate disk I/O steps.

You can use this as-is in many cases without the other code offered here.


Zipper

Zipper is a VB6 UserControl that wraps ZipWriter and a small helper ZipFile Class to give you the ability to create a ZIP archive (or add to an existing one) and add a list of disk files to it.

Zipper.Zip is an async operation and reports back progress, errors, and completion through several events. There is a Zipper.Cancel method if you need that.


ZipDemo

ZipDemo is a VB6 project that demonstrates use of the items described above.

You must download zlibwapi.dll and copy it into this project folder to run the program.

Much of the bulk of this attachment consists of the sample files in the "samples2" folder included.


There is a "ZipWriter" button that does a simple test of ZipWriter, creating a new ZIP archive "test.zip" with two files written to it. When that step completes the "Zipper" button is enabled.

The "Zipper" button tests Zipper, adding the files it finds in the "samples2" folder to the "test.zip" created in the first stage of the demo. While running a progressbar is updated and a "Cancel" button is enabled.

The "samples2" folder as supplied has just a few small files. Be sure to copy some larger files into it and rerun the program to see how things go with large files. The performance is fairly good.


Remarks

While you need to deploy zlibwapi.dll with your programs this is a standard DLL that you can feel free to place next to your EXE. No registration is required.

The results are better than those achieved using most other common techniques. Progress/Cancel/Complete can be really nice to have. There is no need for the shaky, convoluted, hackish window spelunking people often resort to when automating Shell objects.

There is a lot more you can do with zlibwapi.dll too. You can read from ZIP archives, unzip them, compress separate files outside of ZIP archives, compress/expand data in memory, etc. Even the huge-file Zip64 format is supported.

All you need is to write additional wrappers or just make the calls directly.
Attached Files

[VB6] HotKeyW - Unicode Hot Key UserControl

$
0
0
A simple and lightweight Hot Key UserControl that "enables the user to enter a combination of keystrokes to be used as a hot key". This is a drop-in ready UserControl module that wraps the Hot Key control from Windows' Common Controls Library.


Name:  Screenshot.png
Views: 15
Size:  18.3 KB
Attached Images
 
Attached Files

Very Cheap Text/Voice Chat Application


VB6 Crypto API

$
0
0
I cannot take credit for the cCrypt.cls used here, but I ran across it while searching for information on implementing TLS using the MS Crypto API. Unfortunately it did not help me with TLS, and I could not find who to give credit, but I was impressed with the quality of the code in the way that it encompassed most of the supported algorithms in the API. I am more interested in limited cryptography targeted to the TLS handshake, and I am having a great deal of difficulty finding relative information.

J.A. Coutts
Attached Files

create ocx tutorial

VB - LED simulator Simulating a LED light emitting diode

$
0
0
Interesting way to present a process monitor, servers, control aplications ON/OFF, electronic kits etc.
Simulating a LED light emitting diode, add sound may be an improvement ...

I hear comments
Greetings from Mexico
Attached Files

monster list codes 2

$
0
0
Capturing audio Events

Code:

Dim WithEvents Encoder As WMEncoder

Private Sub Encoder_OnStateChange(ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE)
    ' Wait until the encoding process stops before
    ' exiting the application.
    If enumState = WMENC_ENCODER_RUNNING Then
        ' TODO: Handle running state.
    ElseIf enumState = WMENC_ENCODER_PAUSED Then
        ' TODO: Handle paused state.
    ElseIf enumState = WMENC_ENCODER_STOPPED Then
        ' End the application.
        End
    Else
        ' TODO: Handle other encoder states.
    End If
End Sub

Private Sub Form_Load()
    ' Create a WMEncoder object.
    Set Encoder = New WMEncoder
 
    ' Retrieve the source group collection and add a source group.
    Dim SrcGrpColl As IWMEncSourceGroupCollection
    Set SrcGrpColl = Encoder.SourceGroupCollection
    Dim SrcGrp As IWMEncSourceGroup2
    Set SrcGrp = SrcGrpColl.Add("SG_1")
   
    ' Add a video and audio source to the source group.
    Dim SrcVid As IWMEncVideoSource2
    Dim SrcAud As IWMEncAudioSource
    Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
    Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)
   
    ' Identify the source files to encode.
    SrcVid.SetInput "C:\\InputFile.mpg"
    SrcAud.SetInput "C:\\InputFile.mpg"
   
    ' Choose a profile from the collection.
    Dim ProColl As IWMEncProfileCollection
    Dim Pro As IWMEncProfile
    Dim i As Integer
    Dim lLength As Long
   
    Set ProColl = Encoder.ProfileCollection
    lLength = ProColl.Count
   
    For i = 0 To lLength - 1
        Set Pro = ProColl.Item(i)
        If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then
            SrcGrp.Profile = Pro
            Exit For
        End If
    Next
   
    ' Fill in the description object members.
    Dim Descr As IWMEncDisplayInfo
    Set Descr = Encoder.DisplayInfo
    Descr.Author = "Author name"
    Descr.Copyright = "Copyright information"
    Descr.Description = "Text description of encoded content"
    Descr.Rating = "Rating information"
    Descr.Title = "Title of encoded content"
     
    ' Specify a file object in which to save encoded content.
    Dim File As IWMEncFile
    Set File = Encoder.File
    File.LocalFileName = "C:\\OutputFile.wmv"
     
    ' Start the encoding process.
    Encoder.Start
End Sub


Broadcasting a Live Stream Using the Predefined UI
Code:

The following example shows how to create the predefined user interface and broadcast live multimedia content from the local computer. The audio and video sources are configured to use the default sound card and capture card. Use a blank form for this example.

' Create WMEncoderApp and WMEncoder objects.
  Dim Encoder As WMEncoder
  Dim EncoderApp As WMEncoderApp

Private Sub Form_Load()
  Set EncoderApp = New WMEncoderApp
  Set Encoder = EncoderApp.Encoder

' Display the predefined Encoder UI.
  EncoderApp.Visible = True

' Specify the source for the input stream.
  Dim SrcGrpColl As IWMEncSourceGroupCollection
  Dim SrcGrp As IWMEncSourceGroup
  Dim SrcVid As IWMEncSource
  Dim SrcAud As IWMEncSource

  Set SrcGrpColl = Encoder.SourceGroupCollection
  Set SrcGrp = SrcGrpColl.Add("SG_1")
  Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
  Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)

  SrcVid.SetInput "DEVICE://Default_Video_Device"
  SrcAud.SetInput "DEVICE://Default_Audio_Device"

' Specify a profile.
  Dim ProColl As IWMEncProfileCollection
  Dim Pro As IWMEncProfile
  Dim i As Integer

  Set ProColl = Encoder.ProfileCollection

  For i = 0 To ProColl.Count - 1
    Set Pro = ProColl.Item(i)
    If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then
        SrcGrp.Profile = Pro
        Exit For
    End If
  Next

' Create a broadcast.
  Dim BrdCst As IWMEncBroadcast
  Set BrdCst = Encoder.Broadcast
  BrdCst.PortNumber(WMENC_PROTOCOL_HTTP) = 8080

' Start the encoding process.
  Encoder.Start

End Sub


Configuring Multiple Source Groups
Code:

The following example shows how you can set up two source groups with audio and video content. The first source group uses a file (C:\InputFile.mpg), and the second source group uses the default sound card and capture card. The result is broadcasted from the local computer (http://computer_name:8080).

For information about enumerating the audio and video devices on your system, see the Listing All Devices (Visual Basic) example.

Sub Main()
' Create a Windows Media Encoder object.
  Dim Encoder As WMEncoder
  Set Encoder = New WMEncoder
 
' Create a source group collection object from the WMEncoder object.
  Dim SrcGrpColl As IWMEncSourceGroupCollection
  Set SrcGrpColl = Encoder.SourceGroupCollection
 
' Create a profile collection object from the WMEncoder object.
  Dim ProColl As IWMEncProfileCollection
  Set ProColl = Encoder.ProfileCollection
 
' Add a source group named SG1 to the collection.
' Create a source object for each type of multimedia content
' in the source group.
  Dim SrcGrp1 As IWMEncSourceGroup2
  Dim SrcAud1 As IWMEncAudioSource
  Dim SrcVid1 As IWMEncVideoSource2
  Set SrcGrp1 = SrcGrpColl.Add("SG1")
  Set SrcAud1 = SrcGrp1.AddSource(WMENC_AUDIO)
  Set SrcVid1 = SrcGrp1.AddSource(WMENC_VIDEO)
 
' Create a second source group named SG2, and two source objects.
  Dim SrcGrp2 As IWMEncSourceGroup2
  Dim SrcAud2 As IWMEncAudioSource
  Dim SrcVid2 As IWMEncVideoSource2
  Set SrcGrp2 = SrcGrpColl.Add("SG2")
  Set SrcAud2 = SrcGrp2.AddSource(WMENC_AUDIO)
  Set SrcVid2 = SrcGrp2.AddSource(WMENC_VIDEO)
 
' Create an IWMEncBroadcast object and specify a port and a protocol.
  Dim Brdcst As IWMEncBroadcast
  Set Brdcst = Encoder.Broadcast
  Brdcst.PortNumber(WMENC_PROTOCOL_HTTP) = 8080
 
' Specify the input for the sources in the first source group.
' For this example, source group 1 uses file sources.
  SrcAud1.SetInput "C:\InputFile.mpg"
  SrcVid1.SetInput "C:\InputFile.mpg"
 
' Create a profile object. For brevity, this example uses the first
' profile in the collection. Then specify this profile object as
' the profile to use in source group 1.
  Dim Pro As IWMEncProfile
  Set Pro = ProColl.Item(0)
  SrcGrp1.Profile = Pro
 
' Specify the input sources for source group 2. In this example,
' the sources are the default audio and video devices.
' Set the profile for source group 2 to the same profile object.
  SrcAud2.SetInput "DEVICE://Default_Audio_Device"
  SrcVid2.SetInput "DEVICE://Default_Video_Device"
  SrcGrp2.Profile = Pro
 
' Set source group 1 to roll over automatically to source group 2.
' -1 indicates that the rollover happens when source group 1
' has been encoded.
  SrcGrp1.SetAutoRollover -1, "SG2"
 
' Start encoding.
  Encoder.Start

' For this example, use a message box to stop the application when you
' have finished encoding.
  MsgBox "Click OK to stop encoding."

End Sub


Controlling a Digital Device (Visual Basic)

Code:

Controlling a Digital Device (Visual Basic)
This example shows how to:

Use a digital device as a source.
Use VCR-style buttons to forward, rewind, play, and stop the tape.
View the device output as you cue the tape before encoding.
Use events to monitor changes in state.
This example uses a pre-preview to display the stream before encoding begins, and a preview of the stream during encoding.

To use this example, you need:

A form (Form1).
A frame (PreviewFrame).
Four VCR-style buttons (btnREW, btnPLAY, btnFF, and btnSTOP).
A button to start the encoding process (btnEncode).
A label (Label1) for displaying the state of the device.
In addition to the Windows Media Encoder reference, you must also add the Windows Media Encoder Device Control and the Windows Media Encoder Preview Control references to your project.

It is also assumed that you have a digital device connected to the computer. The Windows Media Encoder SDK supports digital video (DV) devices connected to an IEEE 1394 digital video port, and video tape recorder (VTR) devices connected through a COM port using the Sony RS422 protocol.

Option Explicit

'Declare variables.
Dim WithEvents Encoder As WMEncoder
Dim SrcGrpColl As IWMEncSourceGroupCollection
Dim SrcGrp As IWMEncSourceGroup2
Dim SrcAud As IWMEncSource
Dim SrcVid As IWMEncVideoSource
Dim ProColl As IWMEncProfileCollection
Dim Pro As IWMEncProfile
Dim File As IWMEncFile
Dim DCPlugMgr As IWMEncDeviceControlPluginInfoManager
Dim PlugInfo As IWMEncPluginInfo
Dim DCColl As IWMEncDeviceControlCollection
Dim DControl As IWMEncDeviceControl
Dim DCPlugin As IWMEncDeviceControlPlugin
Dim DVColl_Preview As IWMEncDataViewCollection
Dim Preview As WMEncDataView
Dim PrePreview As WMEncPrepreview
Dim lPreviewStream As Integer
Dim sDeviceString As String
Dim i As Integer, j As Integer

Private Sub Form_Load()
' Create a WMEncoder object.
  Set Encoder = New WMEncoder

' Retrieve a device control plug-in info manager object from WMEncoder.
  Set DCPlugMgr = Encoder.DeviceControlPluginInfoManager

' Loop through the connected digital devices on the system such as DV cameras and VTRs.
  For i = 0 To DCPlugMgr.Count - 1

  ' Set the IWMEncPluginInfo object to the current plug-in.
    Set PlugInfo = DCPlugMgr.Item(i)
   
  ' Find the first device plug-in that supports resources.
    If PlugInfo.SchemeType = "DeviceControl" And PlugInfo.Resources = True Then
        sDeviceString = PlugInfo.Item(0)
        Exit For
    End If

  Next i
 
' Add the device as the audio source and video source.
  Set SrcGrpColl = Encoder.SourceGroupCollection
  Set SrcGrp = SrcGrpColl.Add("SG_1")
  Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)
  Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
  SrcAud.SetInput ("Device://" & sDeviceString)
  SrcVid.SetInput ("Device://" & sDeviceString)

' Encode to a file.
  Set File = Encoder.File
  File.LocalFileName = "C:\DeviceOutput.wmv"
   
' Select a profile from the collection and set it into the source group.
  Set ProColl = Encoder.ProfileCollection
  For i = 0 To ProColl.Count - 1
    Set Pro = ProColl.Item(i)
    If (Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)") Then
        SrcGrp.Profile = Pro
    End If
  Next i
   
' Retrieve the device control collection, then add a device to it.
  Set DCColl = SrcGrp.DeviceControlCollection
  Set DControl = DCColl.Add
  DControl.SetInput ("DeviceControl://" & sDeviceString)

  ' Initialize the encoding session.
  Encoder.PrepareToEncode True

  ' Get the plug-in from the device.
  Set DCPlugin = DControl.GetDeviceControlPlugin

  ' Get the source plug-in for the pre-preview and then display it in the frame.
  Set PrePreview = SrcVid.GetSourcePlugin
  PrePreview.SetCaptureParent PreviewFrame.hWnd

  ' Retrieve the preview collection and create a preview object.
  Set DVColl_Preview = SrcVid.PreviewCollection
  Set Preview = New WMEncDataView

End Sub
Private Sub btnEncode_Click()
  ' Specify the stream to preview.
  lPreviewStream = DVColl_Preview.Add(Preview)
 
  ' Disable the VCR buttons.
  btnREW.Enabled = False
  btnPLAY.Enabled = False
  btnFF.Enabled = False
  btnSTOP.Enabled = False
   
  ' Start encoding.
  Encoder.Start

  ' Display the preview in PreviewFrame.
  Preview.SetViewProperties lPreviewStream, PreviewFrame.hWnd
  Preview.StartView (lPreviewStream)
   
End Sub
Private Sub btnREW_Click()
  ' Rewind.
  DCPlugin.SetOperation (WMENC_DEVICE_REW)
End Sub
Private Sub btnPLAY_Click()
  ' Play.
  DCPlugin.SetOperation (WMENC_DEVICE_PLAY)
End Sub
Private Sub btnFF_Click()
  ' Forward.
  DCPlugin.SetOperation (WMENC_DEVICE_FF)
End Sub
Private Sub btnSTOP_Click()
  ' Stop.
  DCPlugin.SetOperation (WMENC_DEVICE_STOP)
End Sub

Private Sub Encoder_OnDeviceControlStateChange(ByVal EnumState As WMEncoderLib.WMENC_DEVICECONTROL_STATE, ByVal sName As String, ByVal sScheme As String)
' When the device state changes, display the state in Label1.
  Select Case EnumState:
        Case WMENC_DEVICECONTROL_PLAYING
        Label1.Caption = "Playing"
       
        Case WMENC_DEVICECONTROL_STOPPED
        Label1.Caption = "Stopped"
       
        Case WMENC_DEVICECONTROL_FASTFORWARDING
        Label1.Caption = "Forwarding"
       
        Case WMENC_DEVICECONTROL_REWINDING
        Label1.Caption = "Rewinding"
       
        Case WMENC_DEVICECONTROL_UNSTABLE
        Label1.Caption = "Unstable"
       
        Case WMENC_DEVICECONTROL_EJECT
        Label1.Caption = "Eject"
       
        Case WMENC_DEVICECONTROL_ENDOFTAPE
        Label1.Caption = "End of tape"
        bDone = True
       
    End Select
   
 End Sub

How to read last two records in .txt file in VB?

$
0
0
Hi ,

I am very new to VB. Actually i am Mainframe resouce and i got an oppertunity to write hummingbird programming scrip which is equal to VB.

As i have tight deadlines, i am not able to spend much time on learning VB. Hence i am looking for quick help.

I got a situation to read the last two records in .TXT file for some comparision logic. So,

Can you please help on how to read the last two records in .TXT file?
How to read specific record in .TXT file?
how to write the record in beginning of the .txt file every time that we write (Append at first line)

Thanks a lot in advance for your in-time help. Look fwd for your valuable response. Thanks!

Regards
Agasthya
Viewing all 1500 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>