Click here to Skip to main content
15,914,070 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: pass data to vbcodeprovider Pin
cstrader23226-Sep-07 15:24
cstrader23226-Sep-07 15:24 
QuestionHelp on code translated from c# Pin
MikeMarq26-Sep-07 14:17
MikeMarq26-Sep-07 14:17 
AnswerThe code for the form Pin
MikeMarq26-Sep-07 14:18
MikeMarq26-Sep-07 14:18 
AnswerRe: Help on code translated from c# Pin
Dave Doknjas26-Sep-07 14:38
Dave Doknjas26-Sep-07 14:38 
GeneralRe: Help on code translated from c# Pin
MikeMarq26-Sep-07 14:52
MikeMarq26-Sep-07 14:52 
Generalc# Main Pin
MikeMarq26-Sep-07 14:52
MikeMarq26-Sep-07 14:52 
GeneralRe: c# Main Pin
Dave Doknjas26-Sep-07 15:21
Dave Doknjas26-Sep-07 15:21 
Generalc# Formats Pin
MikeMarq26-Sep-07 14:53
MikeMarq26-Sep-07 14:53 
//----------------------------------------------------------------------------
// File: Formats.cs
//
// Copyright (c) Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;

public class FormatsForm : Form
{
private struct FormatInfo
{
public WaveFormat format;
public override string ToString()
{
return ConvertWaveFormatToString(format);
}
};
private Button buttonOk;
private Button buttonCancel;
private ListBox lbFormatsInputListbox;
private Label labelStatic;

private MainForm mf = null;
private ArrayList formats = new ArrayList();
private bool[] InputFormatSupported = new bool[20];
public FormatsForm(MainForm mf)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.mf = mf;

ScanAvailableInputFormats();
FillFormatListBox();
}
#region InitializeComponent code
private void InitializeComponent()
{
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.lbFormatsInputListbox = new System.Windows.Forms.ListBox();
this.labelStatic = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonOk
//
this.buttonOk.Enabled = false;
this.buttonOk.Location = new System.Drawing.Point(10, 128);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(75, 23);
this.buttonOk.TabIndex = 0;
this.buttonOk.Text = "OK";
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(97, 128);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// lbFormatsInputListbox
//
this.lbFormatsInputListbox.Location = new System.Drawing.Point(10, 24);
this.lbFormatsInputListbox.Name = "lbFormatsInputListbox";
this.lbFormatsInputListbox.Size = new System.Drawing.Size(162, 95);
this.lbFormatsInputListbox.TabIndex = 2;
this.lbFormatsInputListbox.SelectedIndexChanged += new System.EventHandler(this.lbFormatsInputListbox_SelectedIndexChanged);
//
// labelStatic
//
this.labelStatic.Location = new System.Drawing.Point(10, 11);
this.labelStatic.Name = "labelStatic";
this.labelStatic.Size = new System.Drawing.Size(75, 13);
this.labelStatic.TabIndex = 3;
this.labelStatic.Text = "Input Format:";
this.labelStatic.Click += new System.EventHandler(this.labelStatic_Click);
//
// FormatsForm
//
this.AcceptButton = this.buttonOk;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(183, 170);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.lbFormatsInputListbox);
this.Controls.Add(this.labelStatic);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "FormatsForm";
this.Text = "Select Capture Format";
this.ResumeLayout(false);

}
#endregion
private void ScanAvailableInputFormats()
{
//-----------------------------------------------------------------------------
// Name: ScanAvailableInputFormats()
// Desc: Tests to see if 20 different standard wave formats are supported by
// the capture device
//-----------------------------------------------------------------------------
WaveFormat format = new WaveFormat();
CaptureBufferDescription dscheckboxd = new CaptureBufferDescription();
CaptureBuffer pDSCaptureBuffer = null;

// This might take a second or two, so throw up the hourglass
Cursor = Cursors.WaitCursor;

format.FormatTag = WaveFormatTag.Pcm;

// Try 20 different standard formats to see if they are supported
for (int iIndex = 0; iIndex < 20; iIndex++)
{
GetWaveFormatFromIndex(iIndex, ref format);

// To test if a capture format is supported, try to create a
// new capture buffer using a specific format. If it works
// then the format is supported, otherwise not.
dscheckboxd.BufferBytes = format.AverageBytesPerSecond;
dscheckboxd.Format = format;

try
{
pDSCaptureBuffer = new CaptureBuffer(dscheckboxd, mf.applicationDevice);
InputFormatSupported[ iIndex ] = true;
}
catch
{
InputFormatSupported[ iIndex ] = false;
}
if (pDSCaptureBuffer != null)
pDSCaptureBuffer.Dispose();
}
Cursor = Cursors.Default;
}
private void GetWaveFormatFromIndex(int Index, ref WaveFormat format)
{
//-----------------------------------------------------------------------------
// Name: GetWaveFormatFromIndex()
// Desc: Returns 20 different wave formats based on Index
//-----------------------------------------------------------------------------
int SampleRate = Index / 4;
int iType = Index % 4;

switch (SampleRate)
{
case 0: format.SamplesPerSecond = 48000; break;
case 1: format.SamplesPerSecond = 44100; break;
case 2: format.SamplesPerSecond = 22050; break;
case 3: format.SamplesPerSecond = 11025; break;
case 4: format.SamplesPerSecond = 8000; break;
}

switch (iType)
{
case 0: format.BitsPerSample = 8; format.Channels = 1; break;
case 1: format.BitsPerSample = 16; format.Channels = 1; break;
case 2: format.BitsPerSample = 8; format.Channels = 2; break;
case 3: format.BitsPerSample = 16; format.Channels = 2; break;
}

format.BlockAlign = (short)(format.Channels * (format.BitsPerSample / 8));
format.AverageBytesPerSecond = format.BlockAlign * format.SamplesPerSecond;
}
void FillFormatListBox()
{
//-----------------------------------------------------------------------------
// Name: FillFormatListBox()
// Desc: Fills the format list box based on the availible formats
//-----------------------------------------------------------------------------
FormatInfo info = new FormatInfo();
string strFormatName = string.Empty;
WaveFormat format = new WaveFormat();

for (int iIndex = 0; iIndex < InputFormatSupported.Length; iIndex++)
{
if (true == InputFormatSupported[iIndex])
{
// Turn the index into a WaveFormat then turn that into a
// string and put the string in the listbox
GetWaveFormatFromIndex(iIndex, ref format);
info.format = format;
formats.Add(info);
}
}
lbFormatsInputListbox.DataSource = formats;
}
private static string ConvertWaveFormatToString(WaveFormat format)
{
//-----------------------------------------------------------------------------
// Name: ConvertWaveFormatToString()
// Desc: Converts a wave format to a text string
//-----------------------------------------------------------------------------
return format.SamplesPerSecond + " Hz, " +
format.BitsPerSample + "-bit " +
((format.Channels == 1) ? "Mono" : "Stereo");
}
private void FormatsOK()
{
//-----------------------------------------------------------------------------
// Name: FormatsOK()
// Desc: Stores the capture buffer format based on what was selected
//-----------------------------------------------------------------------------

mf.InputFormat = ((FormatInfo)formats[lbFormatsInputListbox.SelectedIndex]).format;
this.DialogResult = DialogResult.OK;
Close();
}
private void buttonOk_Click(object sender, System.EventArgs e)
{
FormatsOK();
}

private void lbFormatsInputListbox_SelectedIndexChanged(object sender, System.EventArgs e)
{
buttonOk.Enabled = true;
}

private void buttonCancel_Click(object sender, EventArgs e)
{

}

private void labelStatic_Click(object sender, EventArgs e)
{

}
}
GeneralRe: c# Formats Pin
Dave Doknjas26-Sep-07 15:22
Dave Doknjas26-Sep-07 15:22 
Generalc# Devices Pin
MikeMarq26-Sep-07 14:53
MikeMarq26-Sep-07 14:53 
Generalc# assembly info Pin
MikeMarq26-Sep-07 15:08
MikeMarq26-Sep-07 15:08 
GeneralRe: c# assembly info Pin
Dave Doknjas26-Sep-07 15:25
Dave Doknjas26-Sep-07 15:25 
GeneralRe: c# Devices Pin
Dave Doknjas26-Sep-07 15:25
Dave Doknjas26-Sep-07 15:25 
GeneralRe: Help on code translated from c# Pin
MikeMarq26-Sep-07 18:18
MikeMarq26-Sep-07 18:18 
GeneralRe: Help on code translated from c# Pin
Dave Doknjas27-Sep-07 5:16
Dave Doknjas27-Sep-07 5:16 
Questionwhat this code means? Pin
ArielR26-Sep-07 8:07
ArielR26-Sep-07 8:07 
AnswerRe: what this code means? Pin
ESTAN26-Sep-07 9:04
ESTAN26-Sep-07 9:04 
AnswerRe: what this code means? Pin
Luc Pattyn26-Sep-07 9:10
sitebuilderLuc Pattyn26-Sep-07 9:10 
GeneralRe: what this code means? Pin
ESTAN26-Sep-07 9:13
ESTAN26-Sep-07 9:13 
GeneralRe: what this code means? Pin
ArielR26-Sep-07 10:20
ArielR26-Sep-07 10:20 
AnswerRe: what this code means? Pin
Guffa26-Sep-07 9:11
Guffa26-Sep-07 9:11 
AnswerRe: what this code means? Pin
Christian Graus26-Sep-07 12:50
protectorChristian Graus26-Sep-07 12:50 
QuestionHow to filter data on Crystal Reports? Pin
shyne726-Sep-07 5:02
shyne726-Sep-07 5:02 
QuestionHow to know which control is selected at runtime for runtime generated controls Pin
VB 8.026-Sep-07 1:56
VB 8.026-Sep-07 1:56 
AnswerRe: How to know which control is selected at runtime for runtime generated controls Pin
ESTAN26-Sep-07 12:54
ESTAN26-Sep-07 12:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.