Terminer un processus

cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 - 3 févr. 2004 à 19:59
cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 - 4 févr. 2004 à 18:22
Bonjour a tous,
voila j'essaie de fermer un processus (celui de MSN Messenger), j'ai donc fait comme ceci:

TerminateProcess((FindWindow("msnmsgr.exe", NULL)), NULL);


seulement rien ne se produit, est ce que quelqu'un pourrait me dire pourquoi?
Merci par avance...
Bob...

"La chance accorde ses faveur aux esprits avertis..."

24 réponses

cs_Nebula Messages postés 787 Date d'inscription samedi 8 juin 2002 Statut Membre Dernière intervention 7 juin 2007 2
3 févr. 2004 à 22:08
Hum, j'ai fermé deux sous-fenetres de MSN, il a pas aimé...

Je reboote et je continue mes tests !
Mais ce code est correct et fonctionne chez moi, quand la fenetre de MSN n'est pas réduite :
#include <stdio.h>
#include <windows.h>

HWND MSN = NULL;

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) {
  BYTE buffer[255];
  ZeroMemory(buffer, 255);
  GetWindowText(hWnd, buffer, 254);
  if(lstrcmp(buffer, "MSN Messenger") == 0) {
    MSN = hWnd;
    return FALSE;
  }
  return TRUE;
}

int main(void) {
  EnumWindows(EnumWindowsProc, 0);
  fprintf(stderr, "Handle de MSN Messenger: 0x%08X\n", (unsigned int) MSN);
  SendMessage(MSN, WM_CLOSE, 0, 0);
  return 0;
}


Le savoir ne vaut quelque chose que s'il est partagé par tous.
0
cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 9
3 févr. 2004 à 22:18
tiens voici le code complet de mon programme:

#include <windows.h>
#include "resource.h"

#define WM_TRAY_ICONE (WM_USER + 1)
#define bnuSWOW_APP (WM_USER + 2)

HINSTANCE hInst;
HWND MSN;
BOOL AffichageMenu = FALSE;
BOOL MSN_Enable = FALSE;

BOOL AddIcone(HINSTANCE hInst, HWND hWnd, UINT id, LPTSTR IconName, char *infobulle)
{
BOOL res;

NOTIFYICONDATA trid;

trid.cbSize = sizeof(NOTIFYICONDATA);
trid.hWnd = hWnd;
trid.uID = id;
trid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
trid.uCallbackMessage = WM_TRAY_ICONE;
trid.hIcon = LoadIcon(hInst, IconName);

if (infobulle)
lstrcpyn(trid.szTip, infobulle, sizeof(trid.szTip));
else
trid.szTip[0] = '\0';

res = Shell_NotifyIcon(NIM_ADD, &trid);

return res;
}

BOOL RetIcone(HWND hWnd, UINT id)
{
BOOL res;

NOTIFYICONDATA trid;
trid.cbSize = sizeof(NOTIFYICONDATA);
trid.hWnd = hWnd;
trid.uID = id;

res = Shell_NotifyIcon(NIM_DELETE, &trid);

return res;
}

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
BYTE buffer[255];
ZeroMemory(buffer, 255);

GetWindowText(hWnd, (LPTSTR) buffer, 13);

if(lstrcmp((LPTSTR) buffer, "MSN Messenger") == 0) 
{
MSN = hWnd;
return FALSE;
}

return TRUE;
}

BOOL CALLBACK MainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
SetClassLong(hWnd, GCL_HICON, (long)LoadIcon(hInst, (LPCTSTR)IDI_ICON));
AddIcone(hInst, hWnd, 2, MAKEINTRESOURCE(IDI_ICON), "Util MSN");
SetTimer(hWnd, NULL, 2000, NULL);
break;

case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDCANCEL:
{
RetIcone(hWnd, 2);
KillTimer(hWnd, NULL);
EndDialog(hWnd, FALSE);
return TRUE;
}

case ID_TRAY_ITEM_1:
{
MessageBox(hWnd, "Util MSN par Jérémy Decool", "Information", MB_OK | MB_ICONINFORMATION);
return TRUE;
}

case ID_TRAY_ITEM_2:
{
// code pour fermer msn
return TRUE;
}

case ID_TRAY_ITEM_3:
{
SendMessage(hWnd, WM_COMMAND, IDCANCEL, 0);
return TRUE;
}
}
}

case WM_TRAY_ICONE:
{
if(AffichageMenu || (lParam != WM_RBUTTONUP && lParam != WM_LBUTTONDBLCLK))
return FALSE;

HMENU menu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENUTRAY));

if(!menu)
return FALSE;

HMENU submenu = GetSubMenu(menu, 0);

if(!submenu)
return FALSE;

if(lParam == WM_RBUTTONUP)
{
AffichageMenu = TRUE;
POINT mouse;
GetCursorPos(&mouse);
SetMenuDefaultItem(submenu, ID_TRAY_ITEM_1, FALSE);
SetForegroundWindow(hWnd);
TrackPopupMenu(submenu, TPM_RETURNCMD || TPM_RIGHTALIGN, mouse.x, mouse.y, 0, hWnd, NULL);
DestroyMenu(submenu);
DestroyMenu(menu);

return TRUE;
}
else
{
SendMessage(hWnd, WM_COMMAND, ID_TRAY_ITEM_1, 0);

return TRUE;
}
}

case WM_TIMER:
EnumWindows(EnumWindowsProc, NULL);
SendMessage(MSN, WM_CLOSE, 0, 0);
break;

default:
return FALSE;
}

return TRUE;
}

BOOL CALLBACK DemDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  switch(msg) 
  {
case WM_INITDIALOG:
      PostMessage(hWnd, bnuSWOW_APP, 0, 0);
      return TRUE;

    case bnuSWOW_APP:
  DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_MAIN), hWnd, MainDlgProc, 0);
      EndDialog(hWnd, 0);
  }
  return 0;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
hInst = hInstance;

DialogBox(hInst, MAKEINTRESOURCE(IDD_DEM), 0, (DLGPROC)DemDlgProc);

return 0;
}


moi j'en ai marre de chercher pour ce soir de plus je suis fatigué je continuerai a regarder ca demain...
tiens au fait pendant que j'y suis j'ai un autre probleme mineur qui apparait c'est que je peux faire apparaitre le menu qu'une seul fois kan je clique avec le bouton droit de la souris dans l'icone qui se situe dans la systray...
Bob...

"La chance accorde ses faveur aux esprits avertis..."
0
cs_Nebula Messages postés 787 Date d'inscription samedi 8 juin 2002 Statut Membre Dernière intervention 7 juin 2007 2
3 févr. 2004 à 23:28
J'ai résolu tous tes soucis (enfin, je crois)

http://www.cppfrance.com/code.aspx?ID=20117

Le savoir ne vaut quelque chose que s'il est partagé par tous.
0
cs_LordBob Messages postés 2865 Date d'inscription samedi 2 novembre 2002 Statut Membre Dernière intervention 11 mai 2009 9
4 févr. 2004 à 18:22
ok merci pour ta source...
Bob...

"La chance accorde ses faveur aux esprits avertis..."
0
Rejoignez-nous