
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
Posted in Visual C++ | Tagged BMP TO GIF, BMP to JPEG/JPG, BMP to PNG, BMP TO TIFF, Different Image Conversion Techniques, GIF to BMP, GIF to JPG, GIF to PNG, image conversion C++, image conversion GDI+, image conversion VC++, JPG to BMP, JPG to PNG | Leave a Comment »
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.

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 !!!

Believe only what you see, what you test and judge to be true.
for http://vctipsplusplus.wordpress.com/
BijU
Posted in Visual C++ | Tagged .hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_3DFACE);, Changing the background color of window created with createwindowEx(), CreateWindowEx(), hbrBackground, winodow background color | Leave a Comment »
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
Posted in Visual C++ | Tagged CreateDirectory, Creating intermediate folders, Creating the folder structure, SHCreateDirectory, using CreateDirectory API, using SHCreateDirectory API | 1 Comment »
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.
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
![]()
Posted in Visual C++ | Tagged Get value from registry, Get value from windows registry, Manipulating values in the system registry, read value from registry, read value from windows registry, Set value to registry, Set value to windows registry, store value to registry, store value to winodws registry | Leave a Comment »
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
Posted in Visual C++ | Tagged center of a rect, center of a rectangle, center of a rectangle MFC VC++, center of a window, Center of a window MFC, Center of a window VC++, CenterPoint() | Leave a Comment »
Posted in Visual C++ | Leave a Comment »
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
Posted in Visual C++ | Tagged File Properties Dialog Box, Folder Properties Dialog Box, Properties Dialog Box, Shell APIs, ShellExecuteEx | Leave a Comment »
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..
Posted in Visual C++ | Tagged CryptAcquireContext, CryptGetHashParam, Hash using MS Crypto APIs, Hash using VC++, Hashing in MFC, Making Hash of a Data using Microsoft Crypto APIs | Leave a Comment »

