Search This Blog

Wednesday, September 23, 2009

Finding current , previous and next date/time using COleDateTime



COleDateTime currdate;
COleDateTime prevdate;
COleDateTime nextday;
currdate = COleDateTime::GetCurrentTime();
CString csTime= currdate.Format(); //current date and time

COleDateTimeSpan span(1,0,0,0);

int nDay = currdate.GetDay(); //current day

prevdate = currdate - span;
nextday = currdate + span;

int nPrevDay = prevdate.GetDay(); //yesterday or Previous day

int nNextDay = nextday.GetDay(); //next day

Tuesday, September 22, 2009

Creating SDI application with List View



// MainFrm.h

CSplitterWnd m_splitwnd;



//MainFrm.pp
//Override OnCreateClient using properties in classview
//CLeftView and CRightView are the class should be derived from any of view class
//like CTreeView, CListView, CFormView
// Here CRightView derived from CListView

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// Add following Code
if(!m_splitwnd.CreateStatic(this,1,2))
return FALSE;

if(!m_splitwnd.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(200,200),pContext) ||
!m_splitwnd.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(100,200),pContext) )
{
m_splitwnd.DestroyWindow();
return FALSE;
}
// End


return CFrameWndEx::OnCreateClient(lpcs, pContext);
}



// RightView.cpp : implementation file
//in CRightView Class add WM_CREATE message

int CRightView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;

GetListCtrl().DeleteAllItems();

CListCtrl &mylist =this->GetListCtrl();

ModifyStyle(NULL, LVS_REPORT , 0);
mylist.SetExtendedStyle( mylist.GetExtendedStyle() |LVS_EX_CHECKBOXES| LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_TWOCLICKACTIVATE | LVS_EX_SUBITEMIMAGES );

mylist.InsertColumn(0, _T("S.No"),LVCFMT_LEFT| LVCF_TEXT);
mylist.InsertColumn(1, _T("Name"), LVCFMT_LEFT| LVCF_TEXT);
mylist.InsertColumn(2, _T("Country"), LVCFMT_LEFT| LVCF_TEXT);
mylist.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
mylist.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
mylist.SetColumnWidth(2, 100);

/*
mylist.InsertItem( 0, _T(""));
mylist.SetItemText( 0, 0, _T("1") );
mylist.SetItemText( 0, 1, _T("John") );
mylist.SetItemText( 0, 2, _T("India") );
*/


return 0;
}

Monday, September 21, 2009

Removing Duplicates from STL Vector


#include <vector>
#include <algorithm>
using namespace std;
// Add this header files


vector<CString> vNames;
vector<CString> ::iterator vItr;
CString csName;

vNames.push_back("John");
vNames.push_back("Victor");
vNames.push_back("Nancy");
vNames.push_back("William");
vNames.push_back("Nancy");
sort(vNames.begin(),vNames.end());
vNames.erase(unique(vNames.begin(),vNames.end()),vNames.end());

for(vItr=vNames.begin();vItr!=vNames.end();vItr++)
{
csName=(*vItr);
//TRACE(csName);
//AfxMessageBox(csName);
}

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);
}
}
}