Thursday, December 2, 2010

Passing and Accessing a parameter for SWF



/***********************************************************************
Description:Here is one of the implementation of passing and accessing a parameter to SWF file.
Following code is compiled in Adobe Flash Professional CS5.
***********************************************************************/




Passing the parameter with in your html while embedding the SWF file:


<embed src=MyPlayer.swf" menu="false" quality="high" width="226" height="200" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="my_parameter=my_parameter_value" ></embed>


Accesing the parameter with in your SWF implementation code:

// implement loadParams() as event function for creationComplete event
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="loadParams()" preloaderChromeColor="#E51F1F" xmlns:s="library://ns.adobe.com/flex/spark" width="290">

// access your parameter inside the loadParams() function
string strMyParameterValue = this.parameters["my_parameter"];




Monday, October 25, 2010

Barcode Printing With VC++ - MFC



/***********************************************************************
Description:Printing Barcode Labels is as easy as printing normal text. Look at the following code.
"Free 3 of 9" font is used to print the bar code of a given text. This font can be downloaded as free from internet.

Importantly, a "*" character has to be added at the begining and end of the text for which you want to print the barcode (see the corresponding line of code). This is required for bar code scanner to identify start and end characters of the text while scanning.
Following code is compiled in VC++ - MFC environment. This can also be done similarly in other environments like C#, VB, etc. using print fucntions.
***********************************************************************/



void PrintLabel(int nX, int nY, CString strLable)
{
    CPrintDialog dlg(FALSE);
    dlg.GetDefaults();
    CDC dc;
    CDC* pDC = dc.FromHandle(dlg.m_pd.hDC);

    pDC->StartDocW(L"LABEL");
    pDC->StartPage();
    CFont fntBarCode,fntText;

    // create font for barcode, use the size as you require
    fntBarCode.CreatePointFont(800,_T("Free 3 of 9"));

    // create font for text, use the size as you require
    fntText.CreatePointFont(500,_T("Arial"));

    CFont* oldFont = pDC->SelectObject(&fntBarCode);
    pDC->TextOutW(nX,nY,_T("*") + strLable + _T("*"));
    TEXTMETRIC tm;
    pDC->GetTextMetrics(&tm);

    pDC->SelectObject(&fntText);
    pDC->TextOutW(nX,nY + tm.tmExternalLeading + tm.tmHeight + 10,strLable);

    pDC->EndPage();
    pDC->EndDoc();

    pDC->SelectObject(oldFont);
}

// usage:
PrintLabel(100,100,L"CODEFOUND");


// output of the above call:












Tuesday, October 19, 2010

IP Adress Conversion between String & Integer



/***********************************************************************
Description:Following code converts IP address from string type to unsigned long int
and vice-versa.
This code is compiled in Win32 - C++.
***********************************************************************/




_bstr_t FromIntToIPString( unsigned long ipAddress)
{
    _bstr_t ip = L"";
    TCHAR temp[32];

    _stprintf(temp,_T("%lu"),(ipAddress >> 24) & 0xff);        
    ip += temp;
    ip += L".";

    _stprintf(temp,_T("%lu"),(ipAddress >> 16) & 0xff);        
    ip += temp;
    ip += L".";

    _stprintf(temp,_T("%lu"),(ipAddress >> 8) & 0xff);        
    ip += temp;
    ip += L".";

    _stprintf(temp,_T("%lu"),(ipAddress) & 0xff);        
    ip += temp;

    return ip;
}


unsigned long FromIPStringToInt(const TCHAR * szIPString )
{
    if (_tcslen(szIPString) == 0)
    {
        return 0;
    }

    const TCHAR * szStart = szIPString;
    TCHAR * szEnd = NULL;

    unsigned long b1 = _tcstol(szStart, &szEnd, 10);
    if (b1 > 255) ASSERT(FALSE);
    szEnd++;
    szStart = szEnd;
    unsigned long b2 = _tcstol(szStart, &szEnd, 10);
    if (b2 > 255) ASSERT(FALSE);
    szEnd++;
    szStart = szEnd;
    unsigned long b3 = _tcstol(szStart, &szEnd, 10);
    if (b3 > 255) ASSERT(FALSE);
    szEnd++;
    szStart = szEnd;
    unsigned long b4 = _tcstol(szStart, &szEnd, 10);
    if (b4 > 255) ASSERT(FALSE);
    
    if (*szEnd != L'\0')
    {
        ASSERT(FALSE);    // Invalid address
    }

    unsigned long ip = ((b1 << 24) + (b2 << 16) + (b3 << 8) + (b4));

    return ip;
}

// usage
unsigned long int ulIP = FromIPStringToInt(L"250.255.1.10");
_bstr_t strIP = FromIntToIPString(ulIP);



Thursday, October 14, 2010

RS232 - Serial Port


/**********************************************************************
Description:CSerPort class compiled in Win32 - C++ environments.
Used for writing and reading the data with RS232 COMM port.
Derive further if you want add your specific features.
**********************************************************************/

class CSerPort
{
private:
    HANDLE m_hPort;
    DWORD m_dwBaud;
    BYTE m_iByteSize;
    BYTE m_iStopBits;
    BOOL m_bParity;
    CString m_strPort;
    BOOL m_bClose;
    BOOL m_bTimeOut;
    int m_nReqTime;

public:
    inline HANDLE GetHandle() { return m_hPort; }

    CSerPort()
    {
        // default values
        m_dwBaud = CBR_9600;
        m_iByteSize = 8;
        m_iStopBits = ONESTOPBIT;
        m_bParity = FALSE;
        m_strPort = "COM1";

        m_hPort = INVALID_HANDLE_VALUE;
        m_bClose = FALSE;

        m_nReqTime = 0;
        m_bTimeOut = FALSE;
    }

    CSerPort(CString strPort,DWORD dwBaud,BYTE iByteSize,BOOL bParity, BYTE iStopBits)
    {
        m_dwBaud = dwBaud;
        m_iByteSize = iByteSize;
        m_iStopBits = iStopBits;
        m_bParity = bParity;
        m_strPort = strPort;
        m_hPort = INVALID_HANDLE_VALUE;
        m_bClose = FALSE;

        m_nReqTime = 0;
        m_bTimeOut = FALSE;

    }
    virtual ~CSerPort()
    {
        if(m_hPort != INVALID_HANDLE_VALUE)
        {
            ::CloseHandle(m_hPort);
        }
    }

    void SetPort(CString strPort) { m_strPort = strPort; }
    CString GetPort() { return m_strPort; }
    void SetBaud(DWORD dwBaud) { m_dwBaud = dwBaud; }
    DWORD GetBaud() { return m_dwBaud; }
    void SetByteSize(BYTE iByteSize) { m_iByteSize = iByteSize; }
    BYTE GetByteSize() { return m_iByteSize; }
    void SetStopBits(BYTE iStopBits) { m_iStopBits = iStopBits; }
    BYTE GetStopBits() { return m_iStopBits; }
    void SetParity(BOOL bParity) { m_bParity = bParity; }
    BOOL GetParity() { return m_bParity; }
    int GetReqTime() { return m_nReqTime; }
    BOOL GetTimeOut() { return m_bTimeOut; }

    virtual void Close() { ::CloseHandle(m_hPort); m_bClose = TRUE; }
    inline BOOL IsClosed() { return m_bClose; }

    virtual BOOL Open()
    {
        DCB devBlock;

        m_hPort = ::CreateFile(m_strPort,GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);

        DWORD dw = ::GetLastError();

        if(m_hPort == INVALID_HANDLE_VALUE){
            ASSERT(FALSE);    // Unable to open port...
            return FALSE;
        }

        GetCommState(m_hPort,&devBlock);

        devBlock.ByteSize = m_iByteSize;
        devBlock.fBinary = TRUE;    
        devBlock.fParity = m_bParity;
        devBlock.StopBits = m_iStopBits;
        devBlock.BaudRate = m_dwBaud;

        ::SetCommState(m_hPort,&devBlock);

        COMMTIMEOUTS CommTimeouts;

        ::GetCommTimeouts(m_hPort, &CommTimeouts);

        // use your own timeout values all are in milliseconds
        CommTimeouts.ReadIntervalTimeout = 50;
        CommTimeouts.ReadTotalTimeoutMultiplier = 50;
        CommTimeouts.ReadTotalTimeoutConstant = 50;
        CommTimeouts.WriteTotalTimeoutMultiplier = 500;
        CommTimeouts.WriteTotalTimeoutConstant = 500;

        ::SetCommTimeouts(m_hPort, &CommTimeouts);

        ::SetCommMask(m_hPort,EV_RXCHAR);

        EscapeCommFunction(m_hPort,SETDTR);

        m_bClose = FALSE;

        return TRUE;
    }

    BOOL WriteData(BYTE* pBytes,int nBytes)
    {
        DWORD wr;
        if(m_hPort == INVALID_HANDLE_VALUE){
            ASSERT(FALSE); //Port not opened...
            return FALSE;
        }
        ::WriteFile(m_hPort,pBytes,nBytes,&wr,NULL);
        DWORD dw = ::GetLastError();


        ASSERT(wr == nBytes); // should write requested no of bytes

        return (wr == nBytes);
    }

    BOOL ReadData(BYTE* pBytes,int nBytesToRead,int nTries)
    {
        DWORD dwBytesRead = 0;
        int nTry = 0;

        BYTE* pBuff = new BYTE[nBytesToRead];
        int nBytesCopied = 0;
        while (nBytesCopied != nBytesToRead)
        {
            ::ReadFile(m_hPort,pBuff, nBytesToRead - dwBytesRead, &dwBytesRead,NULL);
            if(dwBytesRead > 0){
                ::CopyMemory(pBytes + nBytesCopied,pBuff,dwBytesRead);
                nBytesCopied += dwBytesRead;
            }

            // don't stay in the infinite loop when no data is received
            // for long time and come out with FALSE return
            if (nTry++ > nTries) {delete [] pBuff; return FALSE;}

            // this is required to allow processing of UI requests
            // when waiting for data to receive.
            MSG msg;
            if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }

        delete [] pBuff;
        return TRUE;
    }
};


Tuesday, October 12, 2010

Swap Bytes in a Buffer


/**********************************************************************
Description:Swaping of bytes may require while formatting the communication data in some of the systems due to big-endian / little-endian limitations.

This funstion does the swaping of bytes in the supplied buffer and its length.
This code is compiled in C & C++ environments.
***********************************************************************/

void SwapBytes(unsigned char* pBuff, unsigned int uiLength)
{
    if (uiLength == 0 || uiLength == 1)
    {
        return;
    }

    unsigned char* pTemp = pBuff + uiLength - 1;
    unsigned char byteTemp = 0;

    while(pBuff < pTemp)
    {
         byteTemp = *pBuff;
         *pBuff = *pTemp;
         *pTemp = byteTemp;
         pBuff++;
         pTemp--;
    }
}

// usage:
{
unsigned char pBuff[3] = {0x01,0x02,0x03};
SwapBytes(pBuff,3); // becomes {0x03,0x02,0x01};
}


Friday, October 8, 2010

Polymorphism with C++


/**********************************************************************
Polymorphism in C++ is implemented through virtual functions and inheritance mechanisms.
Polymorphism can be implemented/applied in various styles
**********************************************************************/




class Base
{
protected:
 int m_nValue;
public:
 Base()
 {
  m_nValue = 0;
 }
 virtual void Increment()
 {
  m_nValue++; // incremented by 1
 }
};

class Derived1 : public Base
{
public:    
 /* virtual */ void Increment()
 {
  m_nValue += 2; // incremented by 2
 }
};

class Derived2 : public Base
{
public:
 virtual void Increment()
 {
  Base::Increment();
  m_nValue += 2; // incremented by 2
 }
};

class Derived3_1 : public Derived1
{
public:
 void Increment()
 {
  m_nValue += 3;// incremented by 3
  // do something specific to Derived3_1 class
 }
};

class Derived4_2 : public Derived2
{
public:
 void Increment()
 {
  m_nValue += 3;// incremented by 3
  // do something specific to Derived4_2 class
 }
};
/****************************************************************
Let's see polymorphism and how functions are called by monitoring
the value of m_nValue at each line
****************************************************************/

void Polymorhism()
{
// CASE 1 :
// pPoly as Base class pointer and create object of
// any class derived at any level.
// Polymorphism is achieved by following code.
// Virtual functions are maintained in a table
// called VFT (virtual function table) for storing the
// function pointers of all derived objects of derived classes

 Base* pPoly = new Derived1();
//m_nValue = 0(Initialized in Base())
 pPoly->Increment();
// m_nValue = 2 (Only Derived1::Increment() is called)

 delete pPoly;
 pPoly = new Derived2();
//m_nValue = 0 (Initialized in Base())
 pPoly->Increment();
// m_nValue = 3 (Base::Increment() and Derived2::Increment()
// are called). Observe the difference between this call
// and above call (Dervied1::Increment())

 delete pPoly;
 pPoly = new Derived3_1();
// m_nValue = 0(Initialized in Base())
 pPoly->Increment();
// m_nValue = 3 (Only Derived3_1::Increment() is called)
// Derived3_1::Increment() is called though
// it is not virtual in its immediate parent class Derived1

 delete pPoly;
 pPoly = new Derived4_2();
// m_nValue = 0 (Initialized in Base())
 pPoly->Increment();
// m_nValue = 3 (Only Derived4_2::Increment() is called)
 delete pPoly;

// CASE 2 :
// This is also a polymorphism, but with Derived1 class pointer
 Derived1* pPoly1 = new Derived3_1();
// m_nValue = 0 (Initialized in Base())
 pPoly1->Increment();
// m_nValue = 3 (Only Derived3_1::Increment() is called)
// Observe that it is called though it's not declared as vitual
// in its immediate parent. It happens //because, VFT is maintained
// in super most class object and Derived3_1::Increment()
// function pointer is stoed.

 delete pPoly1;

// CASE 3 :
// This is also a polymorphism, but with Derived3 class pointer
 Derived2* pPoly2 = new Derived4_2();
// m_nValue = 0 (Initialized in Base())
 pPoly2->Increment();
// m_nValue = 3 (Only Derived4_2::Increment() is called)

 delete pPoly2;
}


Thursday, October 7, 2010

EEPROM Read Write with PIC24F & 24LC512



/*********************************************************************
Description : This article explains how to integrate EEPROM with a micro controller. It should be smooth when PLL is disabled.
But PLL has to be enabled some of the applications such as USB to meet the specified clock frequecy (48 MHz) in this case.
So, the system clock would be 32MHz(Please refer microchip's PIC24F datasheet for more details). Handling EEPROM Read & Write
functions when PLL enabled is not as straight as when disabled. Configuring the baud rate (clock cycle for EEPROM R/W) will be
bit confusing in this case. PIC24F datasheet says baud rate value can not be less than 2(Again, please refer the PIC24F datasheet
for the equation). But it works for the value 1 when PLL enabled. Though it works for the value 1, EEPROM communication breaks rarely.

This rare communication problem can be fixed by decreasing the system clock frequency somewhere to 16MHz (CPDIV=0x0004, 32MHz/2 = 16MHz).
Baud rate value calculated for this speed is equal to 4 (for 100KHz). Following circuit and code combination works perfect.

This EEPROM works for clock frequencies from 100KHz and up to 400KHz.


Hardware : Micro Controller - PIC24F series, EEPROM - 24LC512, 8MHz Crystal, Communication : I2C bus (recommended if both controller & EEPROM
on same PCB, SPI is good for longer tracks/cables)
Software : MPLAB C30 Compiler
*********************************************************************/


Schematic



 





 



 



void InitI2C2(void)
{
unsigned int config1 = 0;
unsigned int config2 = 0;

CloseI2C2();
Delay10ms(10);
ConfigIntI2C2(MI2C_INT_OFF); //Disable I2C interrupt
Delay10ms(10);

config1 = (I2C_ON | I2C_7BIT_ADD );
config2 = 4; // baud rate 100KHz
OpenI2C2(config1,config2); //configure I2C2
Delay10ms(10);
}
void EEPROMWriteByte(unsigned long int address, BYTE data)
{
// START
IdleI2C2();
StartI2C2();
while(I2C2CONbits.SEN ); //Wait till Start sequence is completed
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag

// Control Byte
MasterWriteI2C2(0xA0); //Write Slave address and set master for transmission
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);

// Address MSB
MasterWriteI2C2((address >> 8) & 0x00ff);
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);

// Address LSB
MasterWriteI2C2(address & 0x00ff);
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);

// data byte
MasterWriteI2C2(data);
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);

// STOP
StopI2C2();

// make sure write cycle is complete by polling acknowledgement from slave
do
{
// start
IdleI2C2();
StartI2C2();
while(I2C2CONbits.SEN ); //Wait till Start sequence is completed
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag

// Control Byte
MasterWriteI2C2(0xA0); //Write Slave address and set master for transmission
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
}while(I2C2STATbits.ACKSTAT);
}

void EEPROMRead(unsigned long int address,int length,BYTE* pData)
{
int i;

// START
IdleI2C2();
StartI2C2();
while(I2C2CONbits.SEN ); //Wait till Start sequence is completed
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag

// Control Byte
MasterWriteI2C2(0xA0); //Write Slave address and set master for transmission
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);

// Address MSB
MasterWriteI2C2((address >> 8) & 0x00ff);
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);

// Address LSB
MasterWriteI2C2(address & 0x00ff);
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);

// START for reading
IdleI2C2();
RestartI2C2();
while(I2C2CONbits.SEN ); //Wait till Start sequence is completed
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag

// Control Byte
MasterWriteI2C2(0xA1); //Write Slave address and set master for transmission
while(I2C2STATbits.TBF); //Wait till address is transmitted
while(!IFS3bits.MI2C2IF); //Wait for ninth clock cycle
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);

*(pData + 0) = MasterReadI2C2(); // read first byte
for(i = 1;i < length;i++) // read further bytes if requested
{
AckI2C2();
MI2C2_Clear_Intr_Status_Bit; //Clear interrupt flag
while(I2C2STATbits.ACKSTAT);
*(pData + i) = MasterReadI2C2();
}
NotAckI2C2();
StopI2C2();
}

Friday, August 6, 2010

WPF - Print - Print Preview with report viewer


/*********************************************************************
Description: Printing / Print Preview functionalities can be achieved with report viewer in C#-WPF. Just place following code snippet with your values, should be done in the class derived from Window(WPF base class).
*********************************************************************/




/* You may need to add the reference for following assemblies through Microsoft.ReportViewer.Common.dll, Microsoft.ReportViewer.WinForms.dll, WindowsFormsIntegration.dll */

using System.Windows.Forms.Integration;
using Microsoft.ReportingServices.Common;
using Microsoft.Reporting.WinForms;

    WindowsFormsHost host = new WindowsFormsHost();

    ReportViewer repViewer = new ReportViewer();
    repViewer.ProcessingMode = ProcessingMode.Local;
    repViewer.LocalReport.ReportPath = ReportPath + xx.rdlc"; // ReportPath is the folder path where xx.rdlc(your report designer file) resides

    repViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", _eventsTable.DefaultView)); // replace "DataSet1" with your dataset name embedded into the above report file (xx.rdlc)
    host.Child = repViewer;
    ReportArea.Children.Add(host);
    repViewer.RefreshReport();



Graphics - Circle Drawing


Call the Arc drawing function as bellow to make it a Circle.



TrigArc(int xOrg, int yOrg, int radius,0,360);


C# - Graphics - Distance Between 2 Points


/*********************************************************************
Description: C# implementation for calculating distance between 2 points (x1,y1) and (x2,y2).
*********************************************************************/



public int DistanceBetween2Points(int x1, int y1, int x2, int y2)
{
    return (int)Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}


Thursday, August 5, 2010

Windows Mobile - C# - Get Device ID


/*********************************************************************
Description: C# implementation of Windows Mobile to get DEVICE ID of the Smart Phone.
*********************************************************************/



using System.Runtime.InteropServices;

[DllImport("coredll.dll")]
private extern static int GetDeviceUniqueID(
    [In, Out] byte[] applicationdata,
    UInt32 cbApplictionData,
    UInt32 dwDeviceIDVersion,
    [In, Out] byte[] deviceIDOuput,
    [In, Out] uint pcbDeviceIDOutput);

// refer http://msdn.microsoft.com/en-us/library/aa908781.aspx for more details

private string GetDeviceID(string applicationName)
{
    byte[] applicationData = new byte[applicationName.Length];

    for (int i = 0; i < applicationName.Length; i++)
        applicationData[i] = (byte)applicationName[i];

    byte[] deviceIDOut = new byte[20]; // should be minimum of 20
    uint sizeID = 20; // should be minimum of 20

        GetDeviceUniqueID(applicationData, (UInt32)applicationData.Length, 1, deviceIDOut, sizeID);

        return BitConverter.ToString(deviceIDOut); // use this to return in the form of xx-xx-xx....
        // return BitConverter.ToString(deviceIDOut).Replace("-", ""); // use this to return in the form of xxxxxx....
}

// usage
string strDevID = GetDeviceID("Your Application Name");



C# - Stack


/*********************************************************************
Description: Stack class here is C# implementation.
*********************************************************************/



public class Stack
{
    private Node first = null;
    public bool Empty {
        get {
            return (first == null);
        }
    }
    public object Pop() {
        if (first == null)
            throw new Exception("Stack is empty.");
        else {
            object temp = first.Value;
            first = first.Next;
            return temp;
        }
    }
    public void Push(object o) {
            first = new Node(o, first);
        }
    class Node
    {
        public Node Next;
        public object Value;
        public Node(object value): this(value, null) {}
        public Node(object value, Node next) {
            Next = next;
            Value = value;
        }
    }
}

class Test
{
    static void Main() {
        Stack s = new Stack();
        for (int i = 0; i < 10; i++)
            s.Push(i);
        s = null;
    }
}


Tuesday, August 3, 2010

Graphics - Arc Drawing


/*********************************************************************
Description: This function draws an Arc pixel by pixel.
Parameters:
- int xOrg : x-cordinate of the origin
- int yOrg : y-cordinate of the origin
- int radius : Radius of the arc to draw
- int angleStart : Start angle of the arc (Anti Clock wise)
- int angleWidth : Width of the arc (Angle)

Language Specifics for DrawPixel(x, y,BLACK);
    Turbo/Ansi C - putpixel(x,y);
    C++_Win32 - ::SetPixel(hDC /*HDC*/, x, y, RGB(0,0,0)); // HDC hDC can be made as a parameter to the function
    VC++_MFC - pDC->SetPixel(x,y,RGB(0,0,0)); // CDC* pDC can be made as a parameter to the function

*********************************************************************/



#include "math.h" // for trignometric functions
#define PI (22.0 / 7.0)
void TrigArc(int xOrg, int yOrg, int radius,int angleStart,int angleWidth)
{
    for(int i = 0;i < angleWidth;i++)
    {
        int x = xOrg + radius * cos(((i + angleStart) * PI) / 180.0);
        int y = yOrg - radius * sin(((i + angleStart) * PI) / 180.0);
        DrawPixel(x, y,BLACK);
    }
}


Saturday, June 26, 2010

test



Extracting column details from the excel book is as good as reading the details from MS-Access MDB file. Following code demonstrates the procedure. Same procedure can be followed for MDB file also just by changing the connection string.
This code is compiled in VS2010, C#.
:












int main()
{
OleDbConnection conn = new OleDbConnection("Provider= Microsoft.Jet. OLEDB.4.0;Data Source=" + txtFileName.Text + ";Extended Properties=Excel 8.0");
string strSheetName = GetExcelSheetNames(txtFileName.Text)[0];
conn.Open();
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
new object[] { null, null, strSheetName, null });

OleDbType[] exColTypes = new OleDbType[dt.Rows.Count];
string[] exColNames = new string[dt.Rows.Count];

foreach (DataRow row in dt.Rows)
{
int nColIndex = Convert.ToInt32(row[6]);
exColTypes[nColIndex - 1] = (OleDbType)row[11];
exColNames[nColIndex - 1] = row[3].ToString();
}

conn.Close();
printf("Test");
}