Monday, June 21, 2010

The goldmine for mfc, atl, java

http://mfcgoldmine.uuuq.com/Convert/index.html

Monday, June 14, 2010

Syntax coloring text editor

www.scintilla.org

Thursday, June 10, 2010

Sample Batch file

::
::
::
@setlocal
@echo on
::
set DIRNAME=%~dp0
::
::
echo Creating Shortcut

:: To Show all param just echo %*

echo %DIRNAME%VisualHost_CreateShortcut.bat %*
::

PAUSE
::
::
endlocal


@echo off
echo -----------------------------------
echo Shortcut Name : %1
echo Shortcut Path : %2
echo Icon Path : %3
echo Launcher File : %4
echo ActiveConfig : %5
echo ActiveConfig Name : %6
echo ActiveContext : %7
echo ActiveContext Name: %8
echo -----------------------------------
set /p name= What is your name?

Wednesday, June 9, 2010

Compact the text to fit in a rectangle

void CompactText(CFont* pFont, CRect rcText, CString& strText)
{
CRect rcClient;
CClientDC clientDC(NULL);
CDC memDC;
CBitmap bmp;
CBitmap* pBmpOld;
CFont* pFontOld;

if(pFont == NULL)
return;

memDC.CreateCompatibleDC(&clientDC);
bmp.CreateCompatibleBitmap(&clientDC, rcText.Width(), rcText.Height());

pBmpOld = memDC.SelectObject(&bmp);
pFontOld = memDC.SelectObject(pFont);

UINT nFlag = DT_NOPREFIX DT_MODIFYSTRING DT_END_ELLIPSIS DT_SINGLELINE;
memDC.DrawText(strText, rcText, nFlag);

if(pBmpOld != NULL)
memDC.SelectObject(pBmpOld);

if(pFontOld != NULL)
memDC.SelectObject(pFontOld);
}
Others API releted to it:
PathCompactPath
CDC::GetTextExtent

Tuesday, February 2, 2010

Do something while executing a process

// Create the process
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

BOOL bCreate;

bCreate = CreateProcess(szProcessName, szCmdLine, NULL, NULL, TRUE,
CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,NULL, szProcessPath, &si, &pi);

// Wait for the end of the process
while(WaitForSingleObject(pi.hProcess, 250) == WAIT_TIMEOUT)
{
//Do something here
}

// Terminate the process
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

Tuesday, December 29, 2009

Create window at maximized or minimized state

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{

if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= WS_MAXIMIZE; // for minimized WS_MINIMIZE
return TRUE;
}

Wednesday, September 16, 2009

Retrieve icon from an exe file

Retrieve icon from an exe file:

void GetProgramInfo(const CString& strProgramPath, SHFILEINFO* psfi)
{
if(psfi == NULL)
return;
ZeroMemory(psfi, sizeof(SHFILEINFO));
HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo((LPCTSTR)strProgramPath, FILE_ATTRIBUTE_NORMAL,
psfi, sizeof(SHFILEINFO),SHGFI_SMALLICON SHGFI_SYSICONINDEX
SHGFI_DISPLAYNAME SHGFI_USEFILEATTRIBUTES);
if(psfi->iIcon != 0)
psfi->hIcon = ImageList_GetIcon(hImageList, psfi->iIcon, ILD_NORMAL);
}