Search This Blog

Thursday, September 17, 2009

ExtractIcon of other application

The ExtractIcon function retrieves a handle to an icon from the specified executable file, DLL, or icon file.

HICON hIcon;
hIcon = ExtractIcon( AfxGetApp()->m_hInstance, "C:\\WINDOWS\\system32\\calc.exe", 0 );
SetIcon( hIcon, FALSE );

//You must destroy the icon handle returned by ExtractIcon by calling the DestroyIcon //function.
DestroyIcon(hIcon);

Change or Hide Start button name windows XP



void ChangeOrHideStartButton()
{
HWND hSysTrayWnd = ::FindWindow( "Shell_TrayWnd", 0 );
if( hSysTrayWnd )
{
// Get the start button
HWND hStartBtn = ::FindWindowEx( hSysTrayWnd, 0, "Button", "Start" );
if( hStartBtn )
{
// Hide the start button if shown or show if hidden
if( ::IsWindowVisible( hStartBtn ))
{
::ShowWindow( hStartBtn, SW_HIDE );
}
else
{
::ShowWindow( hStartBtn, SW_SHOW );
//To change name
::SetWindowText(hStartBtn,"Your Name");
}
}

}
}

Monday, September 7, 2009

To Read all section and keys in an Ini File



void ReadSectionsAndKeys(CString csPath)
{
char lpszReturnBuffer[MAX_PATH];
char* pNextSection = NULL;
GetPrivateProfileSectionNames(lpszReturnBuffer,MAX_PATH,csPath);
pNextSection = lpszReturnBuffer;
//TRACE("Section: %s\n", pNextSection);
//printf("Section: %s\n", pNextSection);
// for keys
int nPos=-1;
char lpszKeyNames[8192];
DWORD dSize;
dSize = sizeof(lpszKeyNames);
CString csNameandValue(""), csKey(""),csValue("");
//

while (*pNextSection != 0x00)
{
GetPrivateProfileSection( pNextSection, lpszKeyNames , dSize , csPath );
char *pKeyName = lpszKeyNames;

while (*pKeyName != 0x00)
{
nPos = -1;
if(*pKeyName != 0x00)
{
//TRACE("Keys: %s\n", pKeyName);
csNameandValue = pKeyName;
if((nPos = csNameandValue.Find("=")) > -1)
{
csKey = csNameandValue.Left(nPos);
csValue=csNameandValue.Mid(nPos+1);
}
}
pKeyName = pKeyName + strlen(pKeyName) + 1;
}
pNextSection = pNextSection + strlen(pNextSection) + 1;
if(*pNextSection != 0x00)
{
//TRACE("Section: %s\n", pNextSection);
}
}
}

Friday, August 21, 2009

Get the User App Data Directory



#include <shlobj.h>

char path[_MAX_PATH];

//Get the User App Data Directory
SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA,NULL,0,path);

//Get the Common App Data Directory
SHGetFolderPath(NULL,CSIDL_COMMON_APPDATA,NULL,0,path);

Tuesday, August 11, 2009

To Close SDI/MDI Application Programmatically

AfxGetMainWnd()->PostMessage(WM_CLOSE);

To lock your machine programmatically

To lock your machine programmatically you can use the API LockWorkStation().

Syntax
C++

BOOL WINAPI LockWorkStation(void);


//Code:
if( !LockWorkStation())
{
// Failed to lock the machine
}

This function has the same result as pressing Ctrl+Alt+Del and clicking Lock Workstation. To unlock the workstation, the user must log in. There is no function you can call to determine whether the workstation is locked.

Monday, July 20, 2009

VC++ code to copy/move records from one database in to another database having the same table.

Download Library and header files from below link:
http://www.codeproject.com/KB/database/CppSQLite.aspx



int CopyMoveDBTable( LPCTSTR lpcSourceDBPath ,LPCTSTR lpcSourceTable , LPCTSTR lpcTargetDBPath ,LPCTSTR lpcTargetTable ,LPCTSTR lpcCriteria ,BOOL bCopy)
{

     CppSQLite3DB* m_db;    
     try
     {
          CString csQuery;              
          m_db=new CppSQLite3DB();         
          m_db->open(lpcSourceDBPath);          
         
          csQuery.Format( "Attach '%s' as sourcedbTable;",lpcTargetDBPath);
          m_db->execDML(csQuery);
          m_db->execDML("begin transaction");
          csQuery.Format( "insert into sourcedbTable.%s select * from main.%s %s ;",lpcSourceTable,lpcTargetTable,lpcCriteria);
          m_db->execDML("commit transaction");
          //insert into sourcedbTable.emptable select * from main.embdb where empid < 1 ;");
          m_db->execDML(csQuery);
          if(bCopy==FALSE)
          {
               m_db->execDML("begin transaction");
               csQuery.Format( "delete from main.%s %s ;",lpcSourceTable,lpcCriteria);
               m_db->execDML(csQuery);
               m_db->execDML("commit transaction");
          }
          csQuery.Format( "DETACH sourcedbTable;");
          m_db->execDML(csQuery);
         
          m_db->close();         
     }

     catch (CppSQLite3Exception& e)
     {
          delete m_db;
         
          AfxMessageBox( e.errorMessage());
          return -1;
     }
     delete m_db;
    
     return 1;

}    

EXample:

     CString csDBPath,csMirrorDB,csTable,csCriteria;
     BOOL bCopy=FALSE;
     csDBPath= "c:\\DatabaseSqlite\\Employee.db";
     csMirrorDB= "c:\\DatabaseSqlite\\Employeemirror.db";
     csTable="EmpTable";
     csCriteria="where empId>5";
     CopyMoveDBTable( csDBPath,csTable, csMirrorDB ,csTable ,csCriteria ,bCopy);