Esempio n. 1
0
bool CCpDesktop::FirstInstance()
{
	// Determine if another window with our class name or caption exists...
	CString strCaption;
	strCaption.LoadString(GetTitleId());
	CWnd* pWndApp = CWnd::FindWindow(NULL, strCaption);
	if (!pWndApp)
		return true;

	// An instance of the app exists
	// Does it have any popups?
	CWnd* pPopupWnd = pWndApp->GetLastActivePopup();

	// Bring the main window to the top
	pWndApp->BringWindowToTop();
	pWndApp->SetForegroundWindow();

	// If iconic, restore the main window
	if (pWndApp->IsIconic())
		pWndApp->ShowWindow(SW_RESTORE);

	// If there was an active popup, bring it along too
	if (pPopupWnd && (pPopupWnd != pWndApp))
	{
		pPopupWnd->BringWindowToTop();
		pPopupWnd->SetForegroundWindow();
	}

	return false;
}
Esempio n. 2
0
LRESULT CSystemTray::OnTrayNotification(UINT wParam, LONG lParam) 
{
    //Return quickly if its not for this tray icon
    if (wParam != m_tnd.uID)
        return 0L;

    CMenu menu, *pSubMenu;
    CWnd* pTarget = AfxGetMainWnd();

    // Clicking with right button brings up a context menu
    if (LOWORD(lParam) == WM_RBUTTONUP)
    {    
        if (!menu.LoadMenu(m_tnd.uID)) return 0;
        if (!(pSubMenu = menu.GetSubMenu(0))) return 0;

        // Make chosen menu item the default (bold font)
        ::SetMenuDefaultItem(pSubMenu->m_hMenu, m_DefaultMenuItemID, m_DefaultMenuItemByPos);

        // Display and track the popup menu
        CPoint pos;
        GetCursorPos(&pos);

        pTarget->SetForegroundWindow();  
        ::TrackPopupMenu(pSubMenu->m_hMenu, 0, pos.x, pos.y, 0, 
                         pTarget->GetSafeHwnd(), NULL);

        // BUGFIX: See "PRB: Menus for Notification Icons Don't Work Correctly"
        pTarget->PostMessage(WM_NULL, 0, 0);

        menu.DestroyMenu();
    } 
    else if (LOWORD(lParam) == WM_LBUTTONDBLCLK) 
    {
        // double click received, the default action is to execute default menu item
        pTarget->SetForegroundWindow();  

        UINT uItem;
        if (m_DefaultMenuItemByPos)
        {
            if (!menu.LoadMenu(m_tnd.uID)) return 0;
            if (!(pSubMenu = menu.GetSubMenu(0))) return 0;
            uItem = pSubMenu->GetMenuItemID(m_DefaultMenuItemID);
        }
        else
            uItem = m_DefaultMenuItemID;
        
        pTarget->SendMessage(WM_COMMAND, uItem, 0);

        menu.DestroyMenu();
    }

    return 1;
}
void CTorchlightCamModDlg::OnContextMenu(CWnd *pWnd, CPoint pos)
{
	bool bExit = false;
	CMenu menu, *pSubMenu;
	CWnd* pTarget = AfxGetMainWnd();

	if (!menu.LoadMenu(IDR_SYSTRAY_MENU)) bExit = true;
	if (!bExit)
	{
		if (!(pSubMenu = menu.GetSubMenu(0))) bExit = true;
		if (!bExit)
		{
			//CWnd* pTarget = AfxGetMainWnd();

			// Make chosen menu item the default (bold font)

			menu.EnableMenuItem(IDC_ST_RESTORE, MF_GRAYED);

			if (m_mnuStatus.StartAsMinimized) menu.CheckMenuItem(IDC_ST_STARTASMINIMIZED, MF_CHECKED);
			if (m_mnuStatus.SpeedHigh) menu.CheckMenuItem(IDC_ST_SPEED_HIGH, MF_CHECKED);
			if (m_mnuStatus.SpeedNormal) menu.CheckMenuItem(IDC_ST_SPEED_NORMAL, MF_CHECKED);
			if (m_mnuStatus.SpeedLow) menu.CheckMenuItem(IDC_ST_SPEED_LOW, MF_CHECKED);

			// Display and track the popup menu
			pTarget->SetForegroundWindow();
			::TrackPopupMenu(pSubMenu->m_hMenu, 0, pos.x, pos.y, 0, pTarget->GetSafeHwnd(), NULL);

			//    // BUGFIX: See "PRB: Menus for Notification Icons Don't Work Correctly"
			//pTarget->PostMessage(WM_NULL, 0, 0);
			menu.DestroyMenu();
		}
	}

}
Esempio n. 4
0
BOOL CSingleCtrl::Check()
{
	CWnd *pPrevWnd = CWnd::GetDesktopWindow()->GetWindow(GW_CHILD);

	::CreateMutex(NULL, TRUE, m_sExeName.GetString());
	if (GetLastError() != ERROR_ALREADY_EXISTS)
		return TRUE;

	while (pPrevWnd)
	{
		if (::GetProp(pPrevWnd->GetSafeHwnd(), m_sExeName.GetString()))
		{
			TRACE("Check: %s found\r\n", m_sExeName.GetString());
			if (pPrevWnd->IsIconic()) {
				TRACE("Check: show it now\r\n");
				pPrevWnd->ShowWindow(SW_RESTORE);
			} else
				pPrevWnd->ShowWindow(SW_NORMAL);
			pPrevWnd->SetForegroundWindow();
			pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
			return FALSE;
		}

		pPrevWnd = pPrevWnd->GetWindow(GW_HWNDNEXT);
	}

	TRACE("Could not find previous instance main window!\r\n");
	return FALSE;
}
Esempio n. 5
0
BOOL CALLBACK EnumWindowsProc(HWND hwnd/*当前找到的窗口句柄*/, LPARAM lParam/*自定义参数*/)  //枚举当前窗口
{
	TCHAR tcClass[256];
	LPWSTR  pStr = (LPWSTR)lParam;
	HWND htmpWnd = NULL;
	::GetClassName(hwnd, tcClass, 255);

	DWORD dwProcessID;
	TCHAR szProcessName[260] = { 0 };
	GetWindowThreadProcessId(hwnd, &dwProcessID);
	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessID);

	GetModuleFileNameEx(hProcess, NULL, szProcessName, MAX_PATH);

	if (strstr(szProcessName, _T("\\PaperEditor.exe")) != NULL)
	{
		CWnd * pWndPrev = CWnd::FromHandle(hwnd);
		pWndPrev = pWndPrev->GetParent();
		if (pWndPrev != NULL)
		{
			CWnd * pWndChild = pWndPrev->GetLastActivePopup();
			if (pWndPrev->IsIconic())
				pWndPrev->ShowWindow(SW_RESTORE);
			pWndChild->SetForegroundWindow();
		}
	}
	return TRUE;
}
Esempio n. 6
0
void CScoreView::SetupRgn(CDC *pDC,CSkinImage bImage,COLORREF TransColor)
{
	//bImage.GetWidth()/5;
	tagImageLoadInfo ImageIDB;
	bImage.GetLoadInfo(ImageIDB);
	CBitmap cBitmap;
	cBitmap.LoadBitmap(ImageIDB.uResourceID);//这个BITMAP是5倍长的,所以会有问题死机。
	CDC memDC;
	//创建与传入DC兼容的临时DC
	memDC.CreateCompatibleDC(pDC);

	CBitmap *pOldMemBmp=NULL;
	//将位图选入临时DC
	pOldMemBmp=memDC.SelectObject(&cBitmap);

	CRgn wndRgn;
	//创建总的窗体区域,初始region为0
	wndRgn.CreateRectRgn(0,0,0,0);


	BITMAP bit;   
	cBitmap.GetBitmap (&bit);//取得位图参数,这里要用到位图的长和宽     

	int y;
	for(y=0;y<=bit.bmHeight  ;y++)
	{
		CRgn rgnTemp; //保存临时region

		int iX = 0;
		do
		{
			//跳过透明色找到下一个非透明色的点.
			while (iX <= bit.bmWidth  && memDC.GetPixel(iX, y) == TransColor)
				iX++;

			//记住这个起始点
			int iLeftX = iX;

			//寻找下个透明色的点
			while (iX <= bit.bmWidth  && memDC.GetPixel(iX, y) != TransColor)
				++iX;

			//创建一个包含起点与重点间高为1像素的临时“region”
			rgnTemp.CreateRectRgn(iLeftX, y, iX, y+1);

			//合并到主"region".
			wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_OR);

			//删除临时"region",否则下次创建时和出错
			rgnTemp.DeleteObject();
		}while(iX <bit.bmWidth );
		iX = 0;
	}
	if(pOldMemBmp)
		memDC.SelectObject(pOldMemBmp);
	CWnd * pWnd = pDC->GetWindow();
	pWnd->SetWindowRgn(wndRgn,TRUE);
	pWnd->SetForegroundWindow();   
} 
Esempio n. 7
0
void CScoreView::SetupRgn(CDC *pDC,				//窗体的DC指针
						  CBitmap &cBitmap,		//含有窗体形状的位图对象
						  // CSkinImage skinImage,
						  COLORREF TransColor)	//透明色
{

	CDC memDC;
	//创建与传入DC兼容的临时DC
	memDC.CreateCompatibleDC(pDC);

	CBitmap *pOldMemBmp=NULL;
	//将位图选入临时DC
	pOldMemBmp=memDC.SelectObject(&cBitmap);

	CRgn wndRgn;
	//创建总的窗体区域,初始region为0
	wndRgn.CreateRectRgn(0,0,0,0);


	BITMAP bit;   
	cBitmap.GetBitmap (&bit);//取得位图参数,这里要用到位图的长和宽     

	int y;
	for(y=0;y<=bit.bmHeight  ;y++)
	{
		CRgn rgnTemp; //保存临时region

		int iX = 0;
		do
		{
			//跳过透明色找到下一个非透明色的点.
			while (iX <= bit.bmWidth  && memDC.GetPixel(iX, y) == TransColor)
				iX++;

			//记住这个起始点
			int iLeftX = iX;

			//寻找下个透明色的点
			while (iX <= bit.bmWidth  && memDC.GetPixel(iX, y) != TransColor)
				++iX;

			//创建一个包含起点与重点间高为1像素的临时“region”
			rgnTemp.CreateRectRgn(iLeftX, y, iX, y+1);

			//合并到主"region".
			wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_OR);

			//删除临时"region",否则下次创建时和出错
			rgnTemp.DeleteObject();
		}while(iX <bit.bmWidth );
		iX = 0;
	}
	if(pOldMemBmp)
		memDC.SelectObject(pOldMemBmp);
	//HRGN wndRgn=skinImage.CreateImageRegion(RGB(255,0,255));
	CWnd * pWnd = pDC->GetWindow();
	pWnd->SetWindowRgn(wndRgn,TRUE);    
	pWnd->SetForegroundWindow();    
}
Esempio n. 8
0
void CProgressWnd::OnCancel() 
{
    m_bCancelled = TRUE;
    Hide();

    if (m_bModal)
        SendMessage(WM_CLOSE);

    CWnd *pWnd = AfxGetMainWnd();
    if (pWnd && ::IsWindow(pWnd->m_hWnd))
        pWnd->SetForegroundWindow();
}
Esempio n. 9
0
// Activate the Previous Instance of our Application.
HWND CInstanceChecker::ActivatePreviousInstance()
{
  //Try to open the previous instances MMF
  HANDLE hPrevInstance = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, GetMMFFilename());
  if (hPrevInstance)
  {
    // Open up the MMF
    int nMMFSize = sizeof(CWindowInstance);
    CWindowInstance* pInstanceData = (CWindowInstance*) ::MapViewOfFile(hPrevInstance, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, nMMFSize);
    if (pInstanceData != NULL) //Opening the MMF should work
    {
      // Lock the data prior to reading from it
      CSingleLock dataLock(&m_instanceDataMutex, TRUE);

      //activate the old window
      ASSERT(pInstanceData->hMainWnd); //Something gone wrong with the MMF
      HWND hWindow = pInstanceData->hMainWnd;

      if (hWindow)
      {
        CWnd wndPrev;
        wndPrev.Attach(hWindow);
        CWnd* pWndChild = wndPrev.GetLastActivePopup();

        // Restore the focus to the previous instance and bring it to the foreground
        if (wndPrev.IsIconic())
          wndPrev.ShowWindow(SW_RESTORE);
        pWndChild->SetForegroundWindow();

        //Detach the CWnd we were using
        wndPrev.Detach();
      }

      //Unmap the MMF we were using
      ::UnmapViewOfFile(pInstanceData);

      //Close the file handle now that we 
      ::CloseHandle(hPrevInstance);

      //return the Window handle of the previous instance
      return hWindow;
    }

    //Close the file handle now that we 
    ::CloseHandle(hPrevInstance);

    //When we have activate the previous instance, we can release the lock
    ReleaseLock();
  }

  return NULL;
}
Esempio n. 10
0
void CDlgSuspension::OnNcLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default	
	CWnd *pParent = GetParent();
	ASSERT(pParent);
	
	if(!pParent->IsWindowVisible())
		pParent->ShowWindow(SW_SHOW);

	pParent->SetForegroundWindow();

	CDialog::OnNcLButtonDblClk(nFlags, point);
}
Esempio n. 11
0
//bi.pidRoots was set,only dir and subdir can appear in the dialog.//ParsePidlFromPath convet path to pidroot
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
    if (uMsg==BFFM_INITIALIZED) {
        CWnd *pDlg = CWnd::FromHandle(hwnd);
        pDlg->CenterWindow(CWnd::FromHandle(GetDesktopWindow()));
        pDlg->SetForegroundWindow();
        CString strInitialDir;
        strInitialDir = (LPTSTR)lpData;
        if (!strInitialDir.IsEmpty()) {
            ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,lpData);
        }
    }
    return 0;
}
/******************************************************************************
Function Name  :  OnClose
Input(s)       :
Output         :  void
Functionality  :
Member of      :  CTSExecutorChildFrame
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  28/04/2011
Modifications  :
Code Tag       :
******************************************************************************/
void CTSExecutorChildFrame::OnClose()
{
    WINDOWPLACEMENT wndPlcmnt;

    GetWindowPlacement(&wndPlcmnt);

    wndPlcmnt.showCmd = SW_HIDE;

    SetWindowPlacement(&wndPlcmnt);
    CWnd* pActivateWnd =   GetNextWindow();
    pActivateWnd->SetForegroundWindow();
    pActivateWnd->SetFocus();
    ShowWindow(SW_HIDE);
}
Esempio n. 13
0
LRESULT CTrayIcon::OnTrayNotification(WPARAM wParam,LPARAM lParam)
{
	//在这里执行消息映射
	CWnd* pTarget = AfxGetMainWnd();
	//
	//	处理鼠标右键单击事件
	//
	if(LOWORD(lParam) == WM_LBUTTONDBLCLK)
	{
		pTarget->SetForegroundWindow();
		pTarget->ShowWindow(SW_SHOW);
	}

	return 1;
}	
Esempio n. 14
0
BOOL CWinAppSingle::OnAnotherInstanceMessage( LPMSG pMsg )
{
	// Get command line arguments (if any) from new instance.
	
	BOOL bShellOpen = FALSE;
	
	if( pMsg->wParam != NULL ) 
	{
		::GlobalGetAtomName( (ATOM)pMsg->wParam, m_lpCmdLine, _MAX_FNAME );			
		::GlobalDeleteAtom(  (ATOM)pMsg->wParam );		
		bShellOpen = TRUE;		
	}
	
	// If got valid command line then try to open the document -
	// CDocManager will popup main window itself. Otherwise, we
	// have to popup the window 'manually' :

	if( m_pDocManager != NULL && bShellOpen ) 
	{
		CWaitCursor wait;		
		m_pDocManager->OpenDocumentFile( m_lpCmdLine );
	}
	else if( ::IsWindow( m_pMainWnd->GetSafeHwnd() ) )
	{
		// Does the main window have any popups ? If has, 
		// bring the main window or its popup to the top
		// before showing:

		CWnd* pPopupWnd = m_pMainWnd->GetLastActivePopup();
		pPopupWnd->BringWindowToTop();

		// If window is not visible then show it, else if
		// it is iconic, restore it:

		if( !m_pMainWnd->IsWindowVisible() )
			m_pMainWnd->ShowWindow( SW_SHOWNORMAL ); 
		else if( m_pMainWnd->IsIconic() )
			m_pMainWnd->ShowWindow( SW_RESTORE );
		
		// And finally, bring to top after showing again:

		pPopupWnd->BringWindowToTop();
		pPopupWnd->SetForegroundWindow(); 
	}
	
	return TRUE;
}
void CProgressWnd::OnCancel() 
{
    if (m_bEnableCancel)
    {
        if (m_bPersistantPosition)
            SaveCurrentSettings();

        m_bCancelled = TRUE;
        Hide();

        if (m_bModal)
            PostMessage(WM_CLOSE);

        CWnd *pWnd = AfxGetMainWnd();
        if (pWnd && ::IsWindow(pWnd->m_hWnd))
            pWnd->SetForegroundWindow();
    }
}
Esempio n. 16
0
bool CEtsEodManagerApp::_IsFirstInstance()
{
	CWnd* pWndPrev = CWnd::FindWindow(g_cszMainFrameClassName, NULL);

	if(pWndPrev)
	{
		CWnd* pWndChild = pWndPrev->GetLastActivePopup();

		if(pWndPrev->IsIconic())
			pWndPrev->ShowWindow(SW_RESTORE);
		else if(!pWndPrev->IsWindowVisible())
			pWndPrev->ShowWindow(SW_SHOW);

		pWndChild->SetForegroundWindow();
		return false;
	}

	return true;
}
Esempio n. 17
0
BOOL CFileManagerApp::InitInstance()
{
	// InitCommonControls() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	InitCommonControls();

	CWinApp::InitInstance();
#if CONSOLE_WND
	InitConsoleWindow();
#endif

	AfxEnableControlContainer();
	LogTools::InitZToolsLog();
	CCrashHandler ch;
	ch.SetProcessExceptionHandlers();
	ch.SetThreadExceptionHandlers();

	globalData.SetDPIAware ();
	ProcessCmd();
	HANDLE hMetux = CreateMutex(NULL,TRUE,"FileManager_Sqlite3");
	if (hMetux)
	{
		if(ERROR_ALREADY_EXISTS==GetLastError())
		{
			CloseHandle(hMetux);
			CWnd * pDeskTopWnd = CWnd::GetDesktopWindow();
			CWnd *pFind = pDeskTopWnd->GetWindow(GW_CHILD);
			while(pFind)
			{
				if (::GetProp(pFind->m_hWnd,m_pszExeName))
				{
					if (::IsIconic(pFind->m_hWnd))
						pFind->ShowWindow(SW_RESTORE); // 如果主窗口已经最小话,则恢复其大小
					pFind->ShowWindow(SW_SHOW);
					pFind->SetForegroundWindow();
					::SetForegroundWindow(::GetLastActivePopup(pFind->m_hWnd));
					return FALSE; // 前一个运行实例已经存在,退出本实例
				}
				pFind = pFind->GetWindow(GW_HWNDNEXT);
			}
		}
	}

	CFileManagerDlg dlg;
	dlg.m_bRunAtBack = m_bRunAtBack;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	BCGCBProCleanUp ();
	CloseHandle(hMetux);
	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
Esempio n. 18
0
//Activate the Previous Instance of our Application.
HWND CInstanceChecker::ActivatePreviousInstance(LPCTSTR lpCmdLine, ULONG_PTR dwCopyDataItemData, DWORD dwTimeout)
{
  //What will be the return value from this function (assume the worst)
  HWND hWindow = NULL;

  //Try to open the previous instances MMF
  HANDLE hPrevInstance = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, GetMMFFilename());
  if (hPrevInstance)
  {
    //Open up the MMF
    int nMMFSize = sizeof(CWindowInstance);
    CWindowInstance* pInstanceData = static_cast<CWindowInstance*>(MapViewOfFile(hPrevInstance, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, nMMFSize));
    if (pInstanceData) //Opening the MMF should work
    {
      //Lock the data prior to reading from it
      CSingleLock dataLock(&m_instanceDataMutex, TRUE);

      //activate the old window
      ASSERT(pInstanceData->hMainWnd); //Something gone wrong with the MMF
      hWindow = pInstanceData->hMainWnd;
	  if (::IsWindow(hWindow))
      {
        CWnd wndPrev;
        wndPrev.Attach(hWindow);
        CWnd* pWndChild = wndPrev.GetLastActivePopup();

        //Restore the focus to the previous instance and bring it to the foreground
        if (wndPrev.IsIconic())
          wndPrev.ShowWindow(SW_RESTORE);

        if (pWndChild)
          pWndChild->SetForegroundWindow();

        if (lpCmdLine)
        {  
          //Send the current apps command line to the previous instance using WM_COPYDATA
          COPYDATASTRUCT cds;
          cds.dwData = dwCopyDataItemData;
          DWORD dwCmdLength = static_cast<DWORD>(_tcslen(lpCmdLine) + 1);
          cds.cbData = dwCmdLength * sizeof(TCHAR); 
          TCHAR* pszLocalCmdLine = new TCHAR[dwCmdLength]; //We use a local buffer so that we can specify a constant parameter
                                                           //to this function
        #if (_MSC_VER >= 1400)
          _tcscpy_s(pszLocalCmdLine, dwCmdLength, lpCmdLine);
        #else                                                 
          _tcscpy(pszLocalCmdLine, lpCmdLine);
        #endif
          cds.lpData = pszLocalCmdLine;
          CWnd* pMainWindow = AfxGetMainWnd();
          HWND hSender = NULL;
          if (pMainWindow)
            hSender = pMainWindow->GetSafeHwnd();

          //Send the message to the previous instance. Use SendMessageTimeout instead of SendMessage to ensure we 
          //do not hang if the previous instance itself is hung
          DWORD_PTR dwResult = 0;
          if (SendMessageTimeout(hWindow, WM_COPYDATA, reinterpret_cast<WPARAM>(hSender), reinterpret_cast<LPARAM>(&cds),
                                 SMTO_ABORTIFHUNG, dwTimeout, &dwResult) == 0)
          {
            //Previous instance is not responding to messages
            hWindow = NULL;
          }

          //Tidy up the heap memory we have used
          delete [] pszLocalCmdLine;
        }

        //Detach the CWnd we were using
        wndPrev.Detach();
      }

      //Unmap the MMF we were using
      UnmapViewOfFile(pInstanceData);
    }

    //Close the file handle now that we 
    CloseHandle(hPrevInstance);

    //When we have activate the previous instance, we can release the lock
    ReleaseLock();
  }

  return hWindow;
}
Esempio n. 19
0
BOOL CAccountApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();


	AfxEnableControlContainer();

	// Create the shell manager, in case the dialog contains
	// any shell tree view or shell list view controls.
	CShellManager *pShellManager = new CShellManager;

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));


	HANDLE hEvent;
	UINT   cTries = 0;
	// Create a named event
	hEvent = CreateEvent(NULL, TRUE, FALSE, _T("兰新高铁网管台帐"));
	if (hEvent != NULL)
	{ 
		// If the event already existed, that means there's another copy of our app
		// already running
		if (GetLastError() == ERROR_ALREADY_EXISTS)
		{
			do
			{
				// Just in case the other window needs to finish initialization
				Sleep(cTries ? 250 : 0);

				// Try to find the other application window
				CWnd* pwnd = CWnd::FindWindow(NULL,_T("兰新高铁网管台帐"));
				if(pwnd)
				{
					CWnd* pwndLast = pwnd->GetLastActivePopup();
					if(!pwndLast)
					{
						exit(1);
						return FALSE;
					}

					pwndLast->SetForegroundWindow();
					exit(1);
					return FALSE;
				}
			}
			while (++cTries < 2);  // only try twice

			// If we didn't find the window, the other application was probably
			// shutting down, so we'll just continue
		}
	}


	getAppCurDir(m_exeFullPath);

	CAccountDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Delete the shell manager created above.
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
Esempio n. 20
0
CPrivateChatFrame* CChatWindows::OpenPrivate(GGUID* pGUID, SOCKADDR_IN* pHost, BOOL bMustPush, PROTOCOLID nProtocol, SOCKADDR_IN* pServer)
{
	CPrivateChatFrame* pFrame = NULL;

	ASSERT ( pHost != NULL );

	if ( ( nProtocol == PROTOCOL_BT ) || ( nProtocol == PROTOCOL_FTP ) )
		return NULL;

	if ( ! MyProfile.IsValid() )
	{
		CString strMessage;
		LoadString( strMessage, IDS_CHAT_NEED_PROFILE );
		if ( AfxMessageBox( strMessage, MB_YESNO|MB_ICONQUESTION ) == IDYES )
			AfxGetMainWnd()->PostMessage( WM_COMMAND, ID_TOOLS_PROFILE );
		return NULL;
	}

	if ( nProtocol == PROTOCOL_ED2K )
	{
		CEDClient* pClient;

		// First, check if it's a low ID user on another server. 
		if ( bMustPush && pServer ) 
		{
			// It's a firewalled user (Low ID). If they are using another server, we 
			// can't (shouldn't) contact them. (It places a heavy load on the ed2k servers)
			CSingleLock pLock1( &Network.m_pSection );
			if ( ! pLock1.Lock( 250 ) ) return NULL;
			if ( Neighbours.Get( &pServer->sin_addr ) == NULL ) return NULL;
			pLock1.Unlock();
		}

		// ED2K chat is handled by the EDClient section. (Transfers)
		// We need to find (or create) an EDClient to handle this chat session, since everything 
		// on ed2k shares a TCP link.

		// First, lock the section to prevent a problem with other threads
		CSingleLock pLock( &Transfers.m_pSection );
		if ( ! pLock.Lock( 250 ) ) return NULL;

		// We need to connect to them, so either find or create an EDClient
		if ( pServer )
			pClient = EDClients.Connect(pHost->sin_addr.S_un.S_addr, pHost->sin_port, &pServer->sin_addr, pServer->sin_port, pGUID );
		else
			pClient = EDClients.Connect(pHost->sin_addr.S_un.S_addr, pHost->sin_port, NULL, 0, pGUID );
		// If we weren't able to create a client (Low-id and no server), then exit.
		if ( ! pClient ) return NULL;
		// Have it connect (if it isn't)
		if ( ! pClient->m_bConnected ) pClient->Connect();
		// Tell it to start a chat session as soon as it's able
		pClient->OpenChat();
		pLock.Unlock();

		// Check for / make active any existing window
		pFrame = FindPrivate( &pHost->sin_addr );
		// Check for an empty frame
		if ( pFrame == NULL )
		{
			if ( bMustPush ) pFrame = FindED2KFrame( pHost->sin_addr.S_un.S_addr, pServer );
			else pFrame = FindED2KFrame( pHost );
		}
		if ( pFrame != NULL ) 
		{
			// Open window if we found one
			CWnd* pParent = pFrame->GetParent();
			if ( pParent->IsIconic() ) pParent->ShowWindow( SW_SHOWNORMAL );
			pParent->BringWindowToTop();
			pParent->SetForegroundWindow();
			// And exit
			return pFrame;
		}
		// Open an empty (blank) chat frame. This is totally unnecessary- The EDClient will open 
		// one as required, but it looks better to open one here.
		pFrame = new CPrivateChatFrame();
		// Set name (Also used to match incoming connection)
		if ( bMustPush && pServer ) // Firewalled user (Low ID)
		{
			pFrame->m_sNick.Format( _T("%lu@%s:%hu"),
			pHost->sin_addr.S_un.S_addr,
			(LPCTSTR)CString( inet_ntoa( pServer->sin_addr ) ),
			pServer->sin_port );
		}
		else	// Regular user (High ID)
		{
			pFrame->m_sNick.Format( _T("%s:%hu"), (LPCTSTR)CString( inet_ntoa( pHost->sin_addr ) ), pHost->sin_port );
		}

		// Open window
		CWnd* pParent = pFrame->GetParent();
		if ( pParent->IsIconic() ) pParent->ShowWindow( SW_SHOWNORMAL );
		pParent->BringWindowToTop();
		pParent->SetForegroundWindow();
		// Put a 'connecting' message in the window
		CString strMessage, strConnecting;
		LoadString( strConnecting, IDS_CHAT_CONNECTING_TO );
		strMessage.Format( strConnecting, pFrame->m_sNick );
		pFrame->OnStatusMessage( 0, strMessage );

		return pFrame;
	}

	if ( pGUID != NULL ) pFrame = FindPrivate( pGUID );
	if ( pFrame == NULL ) pFrame = FindPrivate( &pHost->sin_addr );
	
	if ( pFrame == NULL )
	{
		pFrame = new CPrivateChatFrame();
		pFrame->Initiate( pGUID, pHost, bMustPush );	
	}

	pFrame->PostMessage( WM_COMMAND, ID_CHAT_CONNECT );
	
	CWnd* pParent = pFrame->GetParent();
	if ( pParent->IsIconic() ) pParent->ShowWindow( SW_SHOWNORMAL );
	pParent->BringWindowToTop();
	pParent->SetForegroundWindow();

	return pFrame;
}
Esempio n. 21
0
BOOL Cwinlirc::InitInstance()
{   
	AfxInitRichEdit();
	
	if((m_lpCmdLine[0]=='/' || m_lpCmdLine[0]=='-') 
	&& (m_lpCmdLine[1]=='d' || m_lpCmdLine[1]=='D'))
		debug=true;
	else
		debug=false;

	if(debug)
	{
#ifndef _DEBUG
		/* see where they want to save it */
		CFileDialog fd(FALSE,".txt","wldebug.txt",
			OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY,
			"Text Files (*.txt)|*.txt|All Files (*.*)|*.*||",
			NULL);
		fd.m_ofn.lpstrTitle="Save debugging information to...";
		if(fd.DoModal()==IDCANCEL)
		{
			MessageBox(NULL,"Debugging disabled.\n","WinLIRC",MB_OK);
			debug=false;
		}
		else
		{
			if((debugfile=fopen(fd.GetPathName(),"w"))==NULL)
			{
				MessageBox(NULL,"Could not create debug file;\ndebugging disabled.",
					"WinLIRC",MB_OK);
				debug=false;
			}
		}
#endif
	}

	DEBUG("Checking for other instances...\n");
	if(!CreateMutex(0,FALSE,"WinLIRC Multiple Instance Lockout") ||
		GetLastError()==ERROR_ALREADY_EXISTS)
	{
		HWND tmp;
		tmp=FindWindow(NULL,"WinLIRC");
		if(tmp==NULL)
		{
			MessageBox(NULL,"WinLIRC is already running","WinLIRC",MB_OK);
		}
		else
		{
			// bring it to the top
			CWnd winlirc;
			winlirc.Attach(tmp);
			CWnd *last=winlirc.GetLastActivePopup();
			if(!winlirc.IsWindowVisible())
				winlirc.ShowWindow(SW_SHOW);
			winlirc.SetForegroundWindow();
			last->SetForegroundWindow();
			winlirc.Detach();
		}
		return FALSE;
	}

	DEBUG("Setting process and thread priorities...\n");
	/* Process initialization and sanity checks */
	if(SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS)==0
	|| SetThreadPriority(THREAD_PRIORITY_IDLE)==0)
	{
		MessageBox(NULL,"Could not set thread priority.","WinLIRC",MB_OK|MB_ICONERROR);
		return FALSE;
	}
	
	DEBUG("Checking for high-resolution timer...\n");
	__int64 x=0;
	if(QueryPerformanceFrequency((LARGE_INTEGER *)&x)!=TRUE || x==0)
	{
		MessageBox(NULL,"This system does not support a high-resolution timer."
			       "Sorry.","WinLIRC",MB_OK|MB_ICONERROR);
		return FALSE;
	}

	DEBUG("Starting server...\n");
	server=NULL;
	if((server=new Cserver)==NULL)
	{
		MessageBox(NULL,"Could not create server object.\n","WinLIRC",MB_OK|MB_ICONERROR);
		if(server!=NULL) { delete server; server=NULL; dlg=NULL; }
		return FALSE;
	}

	if(server->init()==false)
	{
		MessageBox(NULL,"Could not start server.","WinLIRC",MB_OK|MB_ICONERROR);
		if(server!=NULL) { delete server; server=NULL; dlg=NULL; }
		return FALSE;
	}
	

	DEBUG("Creating main dialog...\n");
	if((dlg=new Cdrvdlg)==NULL || dlg->Create(IDD_DIALOG,NULL)==0)
	{
		MessageBox(NULL,"Could not create dialog boxes.\n","WinLIRC",MB_OK|MB_ICONERROR);
		if(dlg!=NULL) { delete dlg; dlg=NULL; }
		if(server!=NULL) { delete server; server=NULL; dlg=NULL; }
		return FALSE;
	}

	dlg->ShowWindow(SW_HIDE);
	dlg->UpdateWindow();
	m_pMainWnd=dlg;
	
	return TRUE;
	
}
Esempio n. 22
0
BOOL Cwinlirc::InitInstance() {

	AfxInitRichEdit();

#ifdef _DEBUG
	RedirectIOToConsole();
#endif

	// set current directory for plugins from exe path

	{
		//=====================
		CString	fullPath;
		int		indexOfLastSep;
		//=====================

		GetModuleFileName(nullptr, fullPath.GetBufferSetLength(MAX_PATH+1), MAX_PATH);
		indexOfLastSep = fullPath.ReverseFind(_T('\\'));
		
		if(!SetCurrentDirectory(fullPath.Left(indexOfLastSep) + _T("\\plugins\\"))) {
			SetCurrentDirectory(fullPath.Left(indexOfLastSep) + _T("\\"));
		}
	}

	config.readINIFile();

	//
	// command line stuff
	//

	if(_tcsstr(m_lpCmdLine,_T("/e")) || _tcsstr(m_lpCmdLine,_T("/E"))) {
		config.exitOnError = TRUE;
	}

	if(_tcsstr(m_lpCmdLine,_T("/t")) || _tcsstr(m_lpCmdLine,_T("/T"))) {
		config.showTrayIcon = FALSE;
	}

	CString mutexName;
	mutexName.Format(_T("WinLIRC Multiple Instance Lockout_%i"),config.serverPort);

	if(!CreateMutex(0,FALSE,mutexName) || GetLastError()==ERROR_ALREADY_EXISTS) {

		//=======
		HWND tmp;
		//=======

		tmp=FindWindow(nullptr,_T("WinLIRC"));

		if(!tmp)
		{
			MessageBox(nullptr,_T("WinLIRC is already running"),_T("WinLIRC"),MB_OK);
		}
		else
		{
			// bring it to the top

			//===========
			CWnd winlirc;
			CWnd *last;
			//===========

			winlirc.Attach(tmp);

			last = winlirc.GetLastActivePopup();

			if(!winlirc.IsWindowVisible()) {
				winlirc.ShowWindow(SW_SHOW);
			}

			winlirc.SetForegroundWindow();
			last->SetForegroundWindow();

			winlirc.Detach();
		}
		return FALSE;
	}

	//
	//Process initialization and sanity checks
	//
	if(SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS)==0 || SetThreadPriority(THREAD_PRIORITY_IDLE)==0) {
		MessageBox(nullptr,_T("Could not set thread priority."),_T("WinLIRC"),MB_OK|MB_ICONERROR);
		return FALSE;
	}
	
	if(server.startServer()==false) {
		MessageBox(nullptr,_T("Server could not be started. Try checking the port."),_T("WinLIRC"),MB_OK|MB_ICONERROR);
	}

	WL_DEBUG("Creating main dialog...\n");

	dlg = new Cdrvdlg();

	if(!dlg->Create(IDD_DIALOG,nullptr)) {
		delete dlg;
		dlg = nullptr;
		MessageBox(nullptr,_T("Program exiting."),_T("WinLIRC"),MB_OK|MB_ICONERROR);
		return FALSE;
	}

	dlg->ShowWindow(SW_HIDE);	
	dlg->UpdateWindow();
	m_pMainWnd = dlg;
	
	return TRUE;
}