Feeds:
Posts
Comments

My Marriage Invitation

Invitation Card

Well, so many image formats are available in the world. Like BMP (Bitmap),TIFF (Tagged Image File Format ), JPG/JPEG (Joint Photographic Experts Group),GIF (Graphic Interchange Format),PNG (Portable Network Graphics) etc.

I already mentioned that, my current multimedia project gave me a lot of chance to improve my coding practice as well as to learn a lot of new things, like GDI,GDI+,Cryptographic services etc.

One of the requirement for me was to “Convert images between different formats”. Nice requirement :)

And I’m  in bloody confident that, I can complete my work within a day. And I started my job. But…..:(

I searched MSDN and found IPicture, (Nice COM). By using that, I load the image,resized the image, cropped, etc.. Then the main requirement is in front of the curtain. “Image conversion.” and I use the IPicture::SaveAsFile(). Then only i noticed the method thoroughly. “Saves the picture’s data into a stream in the same format that it would save itself into a file. Bitmaps use the BMP file format, metafiles the WMF format, and icons the ICO format “

So again google the keyword..

Then one of my friend suggested this page.. :)

Converting a BMP Image to a PNG Image http://msdn.microsoft.com/en-us/library/ms533837(VS.85).aspx

A very simple and nice article. by using that, we can convert the images between different formats.

code from MSDN

#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
   UINT  num = 0;          // number of image encoders
   UINT  size = 0;         // size of the image encoder array in bytes

   ImageCodecInfo* pImageCodecInfo = NULL;

   GetImageEncodersSize(&num, &size);
   if(size == 0)
      return -1;  // Failure

   pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
   if(pImageCodecInfo == NULL)
      return -1;  // Failure

   GetImageEncoders(num, size, pImageCodecInfo);

   for(UINT j = 0; j < num; ++j)
   {
      if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
      {
         *pClsid = pImageCodecInfo[j].Clsid;
         free(pImageCodecInfo);
         return j;  // Success
      }
   }

   free(pImageCodecInfo);
   return -1;  // Failure
}

INT main()

{

   // Initialize GDI+.

   GdiplusStartupInput gdiplusStartupInput;

   ULONG_PTR gdiplusToken;

   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   CLSID   encoderClsid;

   Status  stat;

   Image*   image = new Image(L”Bird.bmp”);

   // Get the CLSID of the PNG encoder.

   GetEncoderClsid(L”image/png”, &encoderClsid);

   stat = image->Save(L”Bird.png”, &encoderClsid, NULL);

   if(stat == Ok)

      printf(”Bird.png was saved successfully\n”);

   else

      printf(”Failure: stat = %d\n”, stat);

   delete image;

   GdiplusShutdown(gdiplusToken);

   return 0;

}

 

For retrieving the Class Identifier for an Encoder we can use the following formats.

  • image/bmp
  • image/jpeg
  • image/gif
  • image/tiff
  • image/png

So again curtain…

 

If you want to cross the sea, you have to step into the waves..

At first, the waves may distract you;

But gradually, you will subdue the fear within you.

For, no wave is mightier than the power of your mind.

 

for http://vctipsplusplus.wordpress.com/

BijU

Recently, I wanted to create a window using Win32. That was the first time, i created a window with Win32 :)

I successfully created the Window using CreateWindowEx(..).  The visaul appearance is same as MFC Dialog. 

Alas !! I faced one simple but serious problem. My Window looks white.

white1

I couldn’t change the background color.. :( … I tried a lot with the params and styles of CreateWindow(). Ooops.. :(

After that, I just go throgh Win32 documentation..hey one flag is there in the WNDCLASS structure.

xxxx.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_3DFACE);

:)

Now.. just look at my window.. Its pretty good na !!!

dlg

:)

Believe only what you see, what you test and judge to be true.

for http://vctipsplusplus.wordpress.com/

BijU

image

I got this thread from one of my senior, while discussing about our project. Till then, I didn’t noticed any differences between SHCreateDirectoryEx() and CreateDirectory(). But now.. Yes its is.. some .. lil difference is there.

just look at the function call

for eg:

if (CreateDirectory(”c:\\Test\\Test\\Test\\Test”,NULL))
        AfxMessageBox(”Created “);

if (ERROR_SUCCESS == SHCreateDirectoryEx(NULL,”c:\\Test\\Test\\Test\\Test”,NULL))
{
    AfxMessageBox(”Created”);
}

description from MSDN is like that for SHCreateDirectoryEX()

int SHCreateDirectoryEx(HWND hwnd, LPCTSTR pszPath, SECURITY_ATTRIBUTES *psa);

BOOL CreateDirectory(LPCTSTR lpPathName,LPSECURITY_ATTRIBUTES lpSecurityAttributes );

This function creates a file system folder whose fully qualified path is given by pszPath. If one or more of the intermediate folders do not exist, they will be created as well.

for CreateDirectory() the description is like this “ This function creates a new directory”

 

Hope now you noticed the difference from the description itself. :)

 

 

True commitment begins when we decide to do it anyway.

for http://vctipsplusplus.wordpress.com/

BijU

:)

The Windows registry is a database which stores settings and options for the operating system for Microsoft Windows 32-bit versions, 64-bit versions and Windows Mobile. It contains information and settings for all the hardware, software, users, and preferences of the PC. Whenever a user makes changes to “Control Panel” settings, or file associations, system policies, or installed software, the changes are reflected and stored in the registry.

image

Class CRegKey provides methods for manipulating values in the system registry.

Now I’m just explaining how to manipulate the Windows Registry using CRegkey Class.

How can we read/modify the data using CRegkey Class ?

You can read data from the registry using the following function

DWORD CRegTest::GetRegistryValue(LPCSTR lpSubKey,LPCSTR lpzValue,LPBYTE* pData)
{
HKEY hKey;
LONG iSuccess;
DWORD dwType=REG_BINARY;
DWORD dwSize=1024;

iSuccess = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0L,  KEY_ALL_ACCESS, &hKey);
if (iSuccess == ERROR_SUCCESS)
{
iSuccess = RegQueryValueEx(hKey, lpzValue, NULL, &dwType,NULL, &dwSize);
*pData = new BYTE[dwSize];
iSuccess = RegQueryValueEx(hKey, lpzValue, NULL, &dwType,*pData, &dwSize);
if (iSuccess == ERROR_SUCCESS)
{
return dwSize;
}
else
{
return 0;
}

}

RegCloseKey(hKey);

return 0;
}

Also, You can write data to the registry using the following function

void CRegTest::SetRegistry(LPCSTR lpRegistryKey,LPCSTR lpzValue,LPVOID lpData,DWORD dwSize)
{
// Add your source name as a subkey under the Application
HKEY hKey;
DWORD dwDisp = 0;
LPDWORD lpdwDisp = &dwDisp;
LONG iSuccess = RegCreateKeyEx( HKEY_LOCAL_MACHINE, lpRegistryKey, 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);

if(iSuccess == ERROR_SUCCESS)
{
if (iSuccess = RegSetValueEx(hKey,             // subkey handle
lpzValue,       // value name
0,                        // must be zero
REG_BINARY,            // value type
(BYTE*)lpData,dwSize))
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, “Error”, MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );

}
}
RegCloseKey(hKey);
}

OK..? Any doubts??

Then you can call the function like..

TCHAR lpRegistryKey[]     = _T(”SOFTWARE\\TestReg\\KeyVal”);
TCHAR lpzLicValue[]      = (”Key”);
TCHAR lpzModeValue[]     = (”Value”);
BYTE* pbRegVal = NULL;

DWORD dwDataLen1 = SetRegistryValue(lpRegistryKey,lpzLicValue,&pbRegVal);
if(0 == dwDataLen1)
return false;

// Now pbRegVal contains the data from the registry

// Delete the allocated memory
if (pbRegVal)
{
delete[] pbRegVal;
}

BYTE* pbData = NULL;
DWORD dwDataLen = GetRegistryValue(lpRegistryKey,lpzValue,&pbData);
// Now pbData contains the data from the registry

// Delete the allocated memory
if(pbData)
delete[] pbData;

ho..what a simple process na??

:)

Weakness of attitude becomes Weakness of character.

for http://vctipsplusplus.wordpress.com/

BijU

)

Center point of a Rectangle !!

 

Do you know how to calculate the center of a rectangle?

using simple maths and by knowing the coordinates of a rectangle, you can. :)

Before those calculation, just try the MFC method of CRect class. 

CRect::CenterPoint()

which returns a CPoint object that is the centerpoint of CRect.

for example

CRect rect;
GetWindowRect(&rect);
CPoint cPoint;
cPoint = rect.CenterPoint();

//cPoint.x will returns the Center x coordinate and cPoint.y returns the Center y coordinate

Keep doing your part and leave the rest to God.

 

for http://vctipsplusplus.wordpress.com/

BijU

 

:)

Most of the C++ programmers are familiar with vector. Vectors are a kind of sequence containers. As such, their elements are ordered following a strict linear sequence.

Vectors have their elements stored in contiguous storage locations. So their elements can only be accessed by iterators and offsets.

 

For example, I have one structure like

 

struct Info

{

      DWORD dwRollNo;

      char szName[65];

};

Also I have one vector like this..

 

typedef vector< Info *> INFO;

 

By using vector::push_back() or vector::push_front(), we can insert data into the structure.. That’s a simple thing.

 

Here we insert some data to the vector.

 

INFO* studentInfo;

for(…….)

{

            studentInfo ->push_back(….);

}

 

How can we iterate through the above structure?

 One way is like this.. J

 

INFO studentInfo;

INFO::iterator sIter;

 

for (sIter = detailsList.begin( ); sIter!= detailsList.end( ); sIter ++ )

      {

            Info* sValues = (Info *)(*sIter);

            MessageBox(sValues ->szName);

      }

 

You’re not free unless you follow your heart!!!

for http://vctipsplusplus.wordpress.com/

BijU

My B’day..

Hi,

On 11th October 2008, I celebrated my 25th B’day.. :)

With my friends, I celebrated the same on 14th October. This B’day made me so happy. They gave me very nice gifts . Yes.. My friends know me very well..

Thank you my dears .. Thank you very much..

B'day Cake

B

Regards,

BijU

Properties Dialog Box

All of the windows operating system users are very familiar with the following dialog box.

Yes.. this is the Properties Dialog Box, obtained by Right clicking a file or folder.

How can we invoke those in a program? We can. By using Windows Shell APIs.

Why we program the shell ? Simple, but a reasonable question. :)

An answer from the author of  “Visual C++ Windows Shell Programming” Mr.DINO ESPOSITO “To Make our application better and richer”

(Do you think, this is the only way to make our application better and richer? Hey .. no.. :)  )

Sample code for displaying the properties dialog box is shown below.

      SHELLEXECUTEINFO Sei;

      ZeroMemory(&Sei,sizeof(SHELLEXECUTEINFO));

      Sei.cbSize = sizeof(SHELLEXECUTEINFO);

      Sei.lpFile = “C:\\Record004.mp3″;

      Sei.nShow = SW_SHOW;

      Sei.fMask = SEE_MASK_INVOKEIDLIST;

      Sei.lpVerb = “Properties”;

      ShellExecuteEx(&Sei);

:)

 

“never expect yourself to be given a good value create a value of your own”

for http://vctipsplusplus.wordpress.com/

BijU

Do you know what is meant by HASH?

A fixed-size result obtained by applying a mathematical function (the hashing algorithm) to an arbitrary amount of data. (from MSDN)

We can create hashes by using Microsoft Crypto APIs.

I’m now explaining the procedures for making hash of a data using MS Crypto APIs.

  • Acquire access to key container

Use the API CryptAcquireContext()

  • Create an empty hash object

Use the API CryptCreateHash()

  • Hold the Data to in a byte array
  • Add the Data buffer to the Hash

Use the API CryptHashData()

  • Read the length of the Hashed Data

Use the API CryptGetHashParam()

  • For example

      DWORD dwCount = sizeof(DWORD);
      DWORD dwHashLen;
      if(!CryptGetHashParam(m_hHash, HP_HASHSIZE, (BYTE *)&dwHashLen, &dwCount, 0))
      {
            TRACE(_T(”Error during CryptGetHashParam.\n”));
            return false;
      }

Now the dwHashLen variable holding the Length

  • Get the Hashed data

BYTE *pbHash = new BYTE[dwHashLen];
if(!CryptGetHashParam(m_hHash, HP_HASHVAL, pbHash, &dwHashLen, 0))
{
            TRACE(_T(”Error during CryptGetHashParam.\n”));
            return false;
}

           After that , pbHash hold the hashed data. :)

Now this seems so simple right…?

Start programming using MS Crypto APIs.. :)

Older Posts »