removeTitle et GetLastError

removeTitle et GetLastError - C - Programmation

Marsh Posté le 13-01-2012 à 16:45:23    

Bonjour,
 
je rencontre un problème avec la fonction SetWindowLong() quand je veux enlever la barre de titre de certaines fenêtres.
Sur certain PC (de mon entreprise) la fonction marche, sur certain ça ne marche pas.
J'ai ajouté dans le code un GetLastError() histoire de cibler le problème mais j'ai toujours 0 comme erreur (que le SetWindowLong() marche ou pas)
 
J'appelle mon .exe (généré avec VisuelStudio) depuis un .bat avec 2 paramètres (ex: removeTitle.exe DU1 RESIZE)
 
Ma question est: pourquoi j'ai toujours 0 en code erreur et pourquoi le SetWindowLong() marche sur certain pc et pas sur d'autre.
 
Voici mon code:

Code :
  1. #include <stdio.h>
  2. #include <windows.h>
  3. // Programme permettant de supprimer la barre de titre  
  4. // des fenetres VAPS pour le projet EIS2
  5. int Resizable = FALSE;
  6. int main(int argc, char *argv[], char *envp[])
  7. {
  8. char   cWindowName[256];
  9. HWND   hWindow;
  10. LONG   current_style, new_style;
  11. LONG_PTR style;
  12. if (argc < 2)
  13. {
  14.  printf("Usage : %s titre\n", argv[0]);
  15.  return (0);
  16. }
  17. strcpy(cWindowName, argv[1]);
  18. if (argc == 3)
  19. {
  20.  if (strcmp (argv[2], "RESIZE" ) == 0)
  21.   Resizable = TRUE;
  22.  else
  23.   Resizable = FALSE;
  24. }
  25. else
  26. {
  27.  Resizable = FALSE;
  28. }
  29. hWindow = FindWindow(NULL, cWindowName);
  30. if (hWindow)
  31. {
  32.  printf("Found window %s\n", cWindowName);
  33.  current_style = GetWindowLong (hWindow, GWL_STYLE);
  34.  printf("Current style of the window = %x\n", current_style);
  35.  // Suppression titre fenetre seulement
  36.  if (Resizable)
  37.   new_style = WS_VISIBLE | WS_DLGFRAME | WS_CLIPSIBLINGS | WS_THICKFRAME;
  38.  else
  39.   new_style = WS_VISIBLE | WS_DLGFRAME | WS_CLIPSIBLINGS;
  40.  //SetLastError(0);
  41.  style = SetWindowLongPtr(hWindow, GWL_STYLE, new_style);
  42.  printf("Error=%lu\n", style);
  43.  printf("Send new style to the window = %x\n", new_style);
  44. }
  45. else
  46. {
  47.  printf("Error, window %s not found ...\n", cWindowName);
  48. }
  49. }

Reply

Marsh Posté le 13-01-2012 à 16:45:23   

Reply

Marsh Posté le 13-01-2012 à 18:23:57    

Hmm, en général, lorsqu'on joue avec les styles des fenêtres, on modifie la valeur de GWL_STYLE, plutôt que d'assigner une nouvelle valeur. Cela dit, je ne suis pas sûr que c'est la cause du problème... À tout hasard, c'est quoi la config du PC où ça merde (xp, 7, vista? thème activé ?).

Code :
  1. #include <stdio.h>
  2. #include <windows.h>
  3. // Programme permettant de supprimer la barre de titre
  4. // des fenetres VAPS pour le projet EIS2
  5. int Resizable = FALSE;
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     char   cWindowName[256];
  10.     HWND   hWindow;
  11.     LONG   current_style, new_style;
  12.     LONG_PTR style;
  13.     if (argc < 2)
  14.     {
  15.         printf("Usage : %s titre\n", argv[0]);
  16.         return (0);
  17.     }
  18.  
  19.     strcpy(cWindowName, argv[1]);
  20.     if (argc == 3)
  21.         Resizable = strcmp(argv[2], "RESIZE" ) == 0;
  22.  
  23.     hWindow = FindWindow(NULL, cWindowName);
  24.     if (hWindow)
  25.     {
  26.         printf("Found window %s\n", cWindowName);
  27.         current_style = GetWindowLong (hWindow, GWL_STYLE);
  28.         printf("Current style of the window = %x\n", current_style);
  29.         // Suppression titre fenetre seulement
  30.         new_style = current_style & ~WS_OVERLAPPEDWINDOW;
  31.         if (Resizable) new_style |= WS_THICKFRAME;
  32.         //SetLastError(0);
  33.         style = SetWindowLongPtr(hWindow, GWL_STYLE, new_style);
  34.         printf("Error=%lu\n", style);
  35.         printf("Send new style to the window = %x\n", new_style);
  36.     }
  37.     else
  38.     {
  39.         printf("Error, window %s not found ...\n", cWindowName);
  40.     }
  41.     return 0;
  42. }

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed