Program der andere programme schliest?

Seite 1 von 1 - Forum: Coding Stuff auf overclockers.at

URL: https://www.overclockers.at/coding-stuff/program_der_andere_programme_schliest_142767/page_1 - zur Vollversion wechseln!


Nicky schrieb am 20.05.2005 um 14:59

Seas, Ich schreib jetzt auf english sonst wirds mir zu kompl.

Ok, What I want to do is create a program that if I hit F1 (or any other key that i set) that it will exit certain programms.

So for instance. If I push F1 the program will exit limewire and bittorrent.

I know a good deal of java, c++ and a bit of visual basic so if anyone could help i would be most thankfull!

Mfg
Nicky


watchout schrieb am 20.05.2005 um 17:01

Well, I never push my buttons for something...

Whatsoever. What you want is to use the WinAPI:
The MSDN is a good reference... http://msdn.microsoft.com/library/d...i_reference.asp

*Hint*
http://msdn.microsoft.com/library/d...nateprocess.asp

hth


mat schrieb am 20.05.2005 um 17:26

nein, bitte nicht mit terminateprocess(). viel schöner wäre es dem fenster eine WM_QUIT message zu schicken. natürlich benötigt man fallbacks, weil anwendungen furchtbar programmiert sein können und zB die QUIT message abfangen usw. man könnte das quasi mit timeout machen, sowie der windowseigene "prozess-beenden dialog".

http://www.overclockers.at/showthre...threadid=136898
das ding hier macht schon einiges was du brauchen könntest (systray, window hook für abfangen des keys)


that schrieb am 21.05.2005 um 01:22

Korrekt schickt man einem Windows-Programm ein WM_CLOSE, wenn man es "sauber" beenden will.

Resources:
- hotkey.cpp from http://that.at to intercept global hotkeys
- Win32 APIs FindWindow and SendMessage

I also found this on my hard drive (just merge this nice little command line tool with the technology from hotkey.cpp):

Code: PHP
// closewnd.cpp - close specified windows

#include <windows.h>
#include <string.h>
#include <stdio.h>

static const char Helptext[] =
 "Window close utility, (c)that2001\n\n"
 "Syntax: closewnd <window title>\n";

BOOL CALLBACK EnumProc(HWND hwnd, LPARAM lParam)
{
  LPCSTR pszTitle = (LPCSTR) lParam;

  char sz[200];
  GetWindowText(hwnd, sz, sizeof(sz));
  if (IsWindowVisible(hwnd) && strstr(_strlwr(sz), pszTitle))
    PostMessage(hwnd, WM_CLOSE, 0, 0);

  return TRUE;
}

int main(int argc, char **argv)
{
  if (argc < 2) {
    printf(Helptext);
    return 1;
  }

  _strlwr(argv[1]);
  EnumWindows(EnumProc, (LPARAM) argv[1]);
  return 0;
}




overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025