"We are back" « oc.at

Program der andere programme schliest?

Nicky 20.05.2005 - 14:59 535 3
Posts

Nicky

Banned
Avatar
Registered: Feb 2004
Location: Wien
Posts: 58
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

Legend
undead
Avatar
Registered: Nov 2000
Location: Off the grid.
Posts: 6845
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

Administrator
Legends never die
Avatar
Registered: Aug 2003
Location: nö
Posts: 25541
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

Hoffnungsloser Optimist
Avatar
Registered: Mar 2000
Location: MeidLing
Posts: 11343
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;
}
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz