Latest Entries »

String Conversion..

A very nice section under windows programming..
Every windows programmer may deals with UNICODE, ANSI like character encoding schemes..
And also, the conversion from Unicode to ANSI and vice versa..
Now I collect some stuffs for you..
Converting UNICODE string to ANSI strings..
You can convert a Unicode string to an ANSI string with the WideCharToMultiByte() API
The syntax is
int WideCharToMultiByte(
UINT CodePage,
DWORD dwFlags,
LPCWSTR lpWideCharStr,
int cchWideChar,
LPSTR lpMultiByteStr,
int cbMultiByte,
LPCSTR lpDefaultChar,
LPBOOL lpUsedDefaultChar
);
For example, we have our UNICODE string in wszUNICODEString, we want to convert that to ANSI string szANSIString.
char szANSIString [MAX_PATH];
WideCharToMultiByte ( CP_ACP,                // ANSI code page
WC_COMPOSITECHECK,     // Check for accented characters
wszUNICODEString,         // Source Unicode string
-1,                    // -1 means string is zero-terminated
szANSIString,          // Destination char string
sizeof(szANSIString),  // Size of buffer
NULL,                  // No default character
NULL );                // Don’t care about this flag
wcstombs()
Converts a sequence of wide characters to a corresponding sequence of multibyte characters.
Syntax is just
size_t wcstombs_s(
char *mbstr,
const wchar_t *wcstr,
size_t count
);
For eg:  wcstombs_s ( szANSIString, wszUNICODEString, sizeof(szANSIString) );
CString
Using CString class’s constructors and assignment  operators, we can convert UNICODE string to ANSI string.
Using constructor
CString strANSI_1 (wszUNICODEString);
Using Assignment Operator
CString strANSI_2;
strANSI_2 = wszUNICODEString;
ATL macros
To convert a Unicode string to ANSI, use the W2A() macro
#include <atlconv.h>
….
{
char szANSIString [MAX_PATH];
USES_CONVERSION;  // DeclareA very nice section under windows programming..
Every windows programmer may deals with UNICODE, ANSI like character encoding schemes..
And also, the conversion from Unicode to ANSI and vice versa..
Now I collect some stuffs for you..
Converting UNICODE string to ANSI strings..
You can convert a Unicode string to an ANSI string with the WideCharToMultiByte() API
The syntax is
int WideCharToMultiByte(
UINT CodePage,
DWORD dwFlags,
LPCWSTR lpWideCharStr,
int cchWideChar,
LPSTR lpMultiByteStr,
int cbMultiByte,
LPCSTR lpDefaultChar,
LPBOOL lpUsedDefaultChar
);
For example, we have our UNICODE string in wszUNICODEString, we want to convert that to ANSI string szANSIString.
char szANSIString [MAX_PATH];
WideCharToMultiByte ( CP_ACP,                // ANSI code page
WC_COMPOSITECHECK,     // Check for accented characters
wszUNICODEString,         // Source Unicode string
-1,                    // -1 means string is zero-terminated
szANSIString,          // Destination char string
sizeof(szANSIString),  // Size of buffer
NULL,                  // No default character
NULL );                // Don’t care about this flag
wcstombs()
Converts a sequence of wide characters to a corresponding sequence of multibyte characters.
Syntax is just
size_t wcstombs_s(
char *mbstr,
const wchar_t *wcstr,
size_t count
);
For eg:  wcstombs_s ( szANSIString, wszUNICODEString, sizeof(szANSIString) );
CString
Using CString class’s constructors and assignment  operators, we can convert UNICODE string to ANSI string.
Using constructor
CString strANSI_1 (wszUNICODEString);
Using Assignment Operator
CString strANSI_2;
strANSI_2 = wszUNICODEString;
ATL macros
To convert a Unicode string to ANSI, use the W2A() macro
#include <atlconv.h>
….
{
char szANSIString [MAX_PATH];
USES_CONVERSION;  // Declare local variable used by the macros.
lstrcpy ( szANSIString, W2A (wszUNICODEString) );
}
For every coin there is an another side also..
local variable used by the macros.
lstrcpy ( szANSIString, W2A (wszUNICODEString) );
}
For every coin there is an another side also..

A very nice section under windows programming..

Every windows programmer may deals with UNICODE, ANSI like character encoding schemes..

And also, the conversion from Unicode to ANSI and vice versa..

Now I collect some stuffs for you..

Converting UNICODE string to ANSI strings..

You can convert a Unicode string to an ANSI string with the WideCharToMultiByte() API

The syntax is

int WideCharToMultiByte(
  UINT CodePage, 
  DWORD dwFlags, 
  LPCWSTR lpWideCharStr,
  int cchWideChar, 
  LPSTR lpMultiByteStr, 
  int cbMultiByte,
  LPCSTR lpDefaultChar,    
  LPBOOL lpUsedDefaultChar
);

For example, we have our UNICODE string in wszUNICODEString, we want to convert that to ANSI string szANSIString.

char szANSIString [MAX_PATH];
 WideCharToMultiByte ( CP_ACP,                // ANSI code page
                          WC_COMPOSITECHECK,     // Check for accented characters
                          wszUNICODEString,         // Source Unicode string
                          -1,                    // -1 means string is zero-terminated
                          szANSIString,          // Destination char string
                          sizeof(szANSIString),  // Size of buffer
                          NULL,                  // No default character
                          NULL );                // Don't care about this flag

wcstombs()

Converts a sequence of wide characters to a corresponding sequence of multibyte characters.

Syntax is just

size_t wcstombs_s(
   char *mbstr,
   const wchar_t *wcstr,
   size_t count 
);

For eg:

 wcstombs_s ( szANSIString, wszUNICODEString, sizeof(szANSIString) );

CString

Using CString class’s constructors and assignment  operators, we can convert UNICODE string to ANSI string.

Using constructor:

CString strANSI_1 (wszUNICODEString);

Using Assignment Operator

CString strANSI_2;
strANSI_2 = wszUNICODEString;

ATL macros

To convert a Unicode string to ANSI, use the W2A() macro

#include <atlconv.h>
….
{
char szANSIString [MAX_PATH];
USES_CONVERSION;  // Declare local variable used by the macros.
    lstrcpy ( szANSIString, W2A (wszUNICODEString) );
}

for https://vctipsplusplus.wordpress.com/

BijU

Make the best of lifes moments !!

What really matters at the end of the day is if you made the best use of time,
and done everything that you needed to do.

Don’t sit just there waiting, You only live once!

Hi all,

Do you know, how to get  information about, the MFC version we are using?

Please follow these steps:

1. Locate the file afxver_.h (It is in the folder  “include”)

2. Check the value of symbolic constant  _MFC_VER

3. 🙂 That value is the MFC version number…

for eg:

#define _MFC_VER 0x0800 // Microsoft Foundation Classes version 8.00

for https://vctipsplusplus.wordpress.com/

BijU

When you’re in great distress,
call for God’s help from the very core of your heart.
Be sincere, Pray fervently.
You will get His help.

Hi all,

Today i’m talking about a nice utility, that I found during my googling.

RegDllView

It is a very simple and is very useful for all Windows programmers. During the development/unit testing/debugging of various types of DLLs, it is very useful tool.

RegDllView is a small utility that displays the list of all registered dll/ocx/exe files (COM registration). For each registered file, you can view the last date/time that it was registered, and the list of all registration entries (CLSID/ProgID).
RegDllView also allows you to unregister dll/ocx files that you don’t need on your system anymore. If you have dll/ocx files that don’t exist on your system anymore, but their registration entries are still exist in your Registry, you can manually remove these entries by using ‘Delete All Entries For Selected Files’ option.

regdllview

You can download the same from http://www.nirsoft.net/utils/regdllview.zip

for https://vctipsplusplus.wordpress.com/

BijU

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 https://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 https://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 https://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 https://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 https://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 https://vctipsplusplus.wordpress.com/

BijU