Console Application immer im Focus
-
Hi, ich denk der Titel sagt schon alles.
Ich möchte die Windows-Konsole immer im Focus haben das heißt, wenn ich mit dem Maus-Cursor woanders hinklicke (außerhalb der Konsole) soll sie immer noch im Focus sein (also aktiv). Wie stelle ich das an??
-
Das gehört wohl eher in das WinAPI Forum, aber egal:
http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx
-
Bei mir funzt das nicht so

SetConsoleTitle("Test"); HWND hWnd = ::FindWindow(NULL,"Test.exe"); SetForegroundWindow(hWnd);wenn ich z. B. auf den Desktop klicke ist der Focus wieder weg (es ist nicht mehr aktiv)
Bitte um HilfeEs kann auch über alle anderen Fenster drüber sein, Hauptsache es ist immer aktiv
-
Das müsstest du mehrmals aufrufen. Ich denke, dass du eher so etwas brauchst:
http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx
Bin mir jetzt aber nicht sicher, was du genau willst..
-
GetConsoleHandle
GetWindowLong
SetWindowLongWM_KILLFOCUS
WM_SETFOCUS
-
// http://support.microsoft.com/kb/124103 HWND GetConsoleHwnd(void) { static const int MY_BUFSIZE = 1024; // Buffer size for console window titles. HWND hwndFound; // This is what is returned to the caller. char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated // WindowTitle. char pszOldWindowTitle[MY_BUFSIZE]; // Contains original // WindowTitle. // Fetch current window title. GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE); // Format a "unique" NewWindowTitle. wsprintf(pszNewWindowTitle, "%d/%d", GetTickCount(), GetCurrentProcessId()); // Change current window title. SetConsoleTitle(pszNewWindowTitle); // Ensure window title has been updated. Sleep(40); // Look for NewWindowTitle. hwndFound=FindWindow(NULL, pszNewWindowTitle); // Restore original window title. SetConsoleTitle(pszOldWindowTitle); return(hwndFound); } void SetTopMostWindow( HWND hWnd, bool topmost ) { if ( topmost ) { SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); } else { SetWindowPos( hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); } }
-
Weitere Vorschläge sind gern erwünscht

-
D4rK3y schrieb:
Weitere Vorschläge sind gern erwünscht

lol, soll doch ein schlechter Witz sein ne?
David_pb hat dir schon die Lösung gesagt.
Das könnte man schon als C&&P nehmen.
-
Tippgeber schrieb:
GetConsoleHandle
GetWindowLong
SetWindowLongWM_KILLFOCUS
WM_SETFOCUSIch muss mich korrigieren es heißt nicht GetConsoleHandle, sondern GetConsoleWindow