10. april 2002 - 14:30Der er
5 kommentarer og 1 løsning
Check om en process kører allerede..
Hej.
Jeg skal gøre følgende når jeg starter mit program: Check om den allerede kører. Hvis ja: se om den er minimeret. Hvis ja Maksimer den. Til sidst luk den nye startet version af programmet.(exit(0)) ==================
Jeg har en del af koden som kan gøre det første del af det jeg vil:
CString SemaphoreString = "TestProg"; CSingleLock *pLockObj; CSemaphore *pSyncSem; pSyncSem = new CSemaphore(1, 1, SemaphoreString); pLockObj = new CSingleLock(pSyncSem);
if (!pLockObj->Lock(0)) { CString Message("Prog is already running."); AfxMessageBox(Message); return FALSE; }
Det koden gører nu er at der popper messagebox op.. Men jeg vil ha at den maksimerer(hvis ndvendigt).
... Jeg har engang lavet noget der brugte "FindWindow" til at finde et vindue, med en bestemt overskrift... Hvis du bare kan få fat i et handle til vinduet, er det ikke noget problem at maksimere det...
The GetModuleHandle function returns a module handle for the specified module if the file has been mapped into the address space of the calling process.
HMODULE GetModuleHandle( LPCTSTR lpModuleName // address of module name to return handle for );
Return Values
If the function succeeds, the return value is a handle to the specified module.
<msdn> CWnd::FindWindow This method retrieves the top-level CWnd whose window class is specified by lpszClassName and whose window name, or title, is specified by lpszWindowName. This method does not search child windows.
static CWnd* PASCAL FindWindow( LPCTSTR lpszClassName, LPCTSTR lpszWindowName ); Parameters lpszClassName Points to a null-terminated string that specifies the window class name, a WNDCLASS structure. If the lpClassName parameter is NULL, then all class names result as a successful match. lpszWindowName Points to a null-terminated string that specifies the window name, the window title. If the lpWindowName parameter is NULL, then all window names result as a successful match. Return Value Identifies the window that has the specified class name and window name. It is NULL if no such window is found.
The CWnd* may be temporary and should not be stored for later use.
// Activate an application with a window with a specific class name. BOOL COneT32App::FirstInstance() { CWnd *pWndPrev, *pWndChild;
// Determine if a window with the class name exists... if (pWndPrev = CWnd::FindWindow(_T("MyNewClass"),NULL)) { // If so, does it have any popups? pWndChild = pWndPrev->GetLastActivePopup();
// If iconic, restore the main window. if (pWndPrev->IsIconic()) pWndPrev->ShowWindow(SW_RESTORE);
// Bring the main window or its popup to the foreground pWndChild->SetForegroundWindow();
// and you are done activating the other application. return FALSE; } </msdn>
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.