프로그래밍/c++2013. 4. 26. 11:50

 

int findProcID( CString strProcName )

{

int nProcID = 0;

strProcName .MakeUpper(); // 문자열 비교를 하기전 강제로 모두 대문자로 바꿔줌.

HANDLE hSnapshot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 );

if ( (int)hSnapshot != -1 )
{

PROCESSENTRY32 pe32 ;
pe32.dwSize=sizeof(PROCESSENTRY32);
BOOL bContinue ;
CString tempProcessName;

if ( Process32First ( hSnapshot, &pe32 ) )
{

//프로세스 목록 검색 시작
do
{

tempProcessName = pe32.szExeFile; //프로세스 목록 중 비교할 프로세스 이름;
tempProcessName.MakeUpper();
if( ( tempProcessName.Find(strProcName , 0) != -1 ) )
{

HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, 0, pe32.th32ProcessID ); //프로세스 핸들 얻기
if( hProcess )
{

       nProcID = pe32.th32ProcessID;

// 응용해서 프로세스 핸들도 리턴이 가능하다.


}

}
bContinue = Process32Next ( hSnapshot, &pe32 );

} while ( bContinue );

}
CloseHandle( hSnapshot );

}

return nProcID ;

}



Posted by GaePein
프로그래밍/c++2013. 4. 26. 11:38

BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
 // base class does the real work

 if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
 {
  return FALSE;
 }


 // enable customization button for all user toolbars
 BOOL bNameValid;
 CString strCustomize;
 bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
 ASSERT(bNameValid);

 for (int i = 0; i < iMaxUserToolbars; i ++)
 {
  CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i);
  if (pUserToolbar != NULL)
  {
   pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
  }
 }

// 프로그래머가 임의로 수정한 MFC ui를 수정하기 위해서는 레지스트리를 변경해줘야 하는 번거로움이 있는데

// 아래와 같은 소스 두줄이면 말끔히 해결!!

// 참고 : http://blog.naver.com/PostView.nhn?blogId=m1122314&logNo=30125697756 

m_wndMenuBar.RestoreOriginalstate();
m_wndToolBar.RestoreOriginalstate();

 return TRUE;
}



Posted by GaePein