IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Discussion :

screenshot zone precise


Sujet :

Windows

  1. #1
    Membre du Club
    Inscrit en
    Juillet 2006
    Messages
    79
    Détails du profil
    Informations forums :
    Inscription : Juillet 2006
    Messages : 79
    Points : 46
    Points
    46
    Par défaut screenshot zone precise
    Bonjour à tous,

    Je cherche depuis plusieurs mois à faire un programme qui puisse faire un imprim ecran d'une zone précise, j'ai réussi avec l'aide d'un membre du forum à développer le programme suivant qui fait un imprim ecran de la fenêtre qui est au premier plan, de plus on peut indiquer la largeur et la hauteur de l'imprim ecran à partir du coin en haut à gauche de la fenêtre, mais maintenant ce que je voudrais faire, c'est un screenshot mais à partir d'un point choisit et non uniquement à partir du coin en haut à gauche, un screenshoot d'une zone choisie entièrement .

    Comment puis je faire ???

    Modifier le programme suivant ou un nouveau programme ??

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    #include <stdio.h>
    #include <conio.h>
    #include <windows.h>
    
    int hwnd_to_bmp(HWND hwnd, char *pszflname)
    {
      HDC memdc;
      HANDLE hfl;
      DWORD dwBytes, dwNumColors;
      void *pBits;
      HBITMAP hbmp;
      BITMAPFILEHEADER fileheader;
      BITMAPINFOHEADER infoheader;
      RGBQUAD colors[256];
      BITMAPINFO bmpinfo;
      HGDIOBJ hret;
      RECT rct;
    
    
      HDC hdc = GetDC(hwnd);
      printf("le handle de la fenêtre au premier plan est : 0x%X\n",hdc);
      printf("le chemin est pszflname : %s\n",pszflname);
    
    
      GetWindowRect(hwnd, &rct);
     // rct.bottom -= rct.top + 50;
     // rct.right -= rct.left + 15;
      rct.bottom -= rct.top + 300;
      rct.right -= rct.left + 600;
      rct.top = GetDeviceCaps(hdc, BITSPIXEL);
      if(rct.top <= 8)
        dwNumColors = 256;
      else
        dwNumColors = 0;
      if(!(memdc = CreateCompatibleDC(hdc)))
        goto relHwndDc;
    
      bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
      bmpinfo.bmiHeader.biWidth = rct.right;
      bmpinfo.bmiHeader.biHeight = rct.bottom;
      bmpinfo.bmiHeader.biPlanes = 1;
      bmpinfo.bmiHeader.biBitCount = (WORD) rct.top;
      bmpinfo.bmiHeader.biCompression = BI_RGB;
      bmpinfo.bmiHeader.biSizeImage = 0;
      bmpinfo.bmiHeader.biXPelsPerMeter = 0;
      bmpinfo.bmiHeader.biYPelsPerMeter = 0;
      bmpinfo.bmiHeader.biClrUsed = dwNumColors;
      bmpinfo.bmiHeader.biClrImportant = dwNumColors;
      hbmp = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);
    
      if(!hbmp) goto errato;
      hret = SelectObject(memdc, hbmp);
      if(!hret || (hret == HGDI_ERROR)) goto errato;
    
      if(!BitBlt(memdc, 0, 0, rct.right, rct.bottom, hdc, 0, 0, SRCCOPY)) goto errato;
      if(dwNumColors)
        dwNumColors = GetDIBColorTable(memdc, 0, dwNumColors, colors);
    
      fileheader.bfType = 0x4D42;
      rct.left = dwNumColors * sizeof(RGBQUAD);
      fileheader.bfSize = ((rct.right * rct.bottom * rct.top) >> 3) + rct.left + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
      fileheader.bfReserved1 = fileheader.bfReserved2 = 0;
      fileheader.bfOffBits = rct.left + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
      infoheader.biSize = sizeof(BITMAPINFOHEADER);
      infoheader.biWidth = rct.right;
      infoheader.biHeight = rct.bottom;
      infoheader.biPlanes = 1;
      infoheader.biBitCount = (WORD) rct.top;
      infoheader.biCompression = BI_RGB;
      infoheader.biSizeImage = infoheader.biClrImportant = 0;
      infoheader.biXPelsPerMeter = infoheader.biYPelsPerMeter = 0;
      infoheader.biClrUsed = dwNumColors;
    
      hfl = CreateFile(pszflname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
      if (hfl == INVALID_HANDLE_VALUE) {DeleteObject(hbmp); goto errato;}
      WriteFile(hfl, &fileheader, sizeof(BITMAPFILEHEADER), &dwBytes, 0);
      WriteFile(hfl, &infoheader, sizeof(BITMAPINFOHEADER), &dwBytes, 0);
      if(!dwNumColors)
        WriteFile(hfl, colors, rct.left, &dwBytes, 0);
      WriteFile(hfl, pBits, (rct.right * rct.bottom * rct.top) >> 3, &dwBytes, 0);
      CloseHandle(hfl);
      DeleteObject(hbmp);
      DeleteDC(memdc);
      return 1;
      errato:
      DeleteDC(memdc);
      relHwndDc:
      ReleaseDC(hwnd, hdc); return 0;
    } 
    
    void main (void)
    {
    HWND hFore = GetForegroundWindow();
    hwnd_to_bmp(hFore,"C:/test1.bmp");
    }
    merci d'avance pour votre aide !!

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 578
    Points
    41 578
    Par défaut
    Une fois que tu as choisi la taille de la sous-image à sauvegarder, le placement est très facile: Il suffit de régler convenablement les paramètres 6 et 7 (nXSrc et nYSrc) de BitBlt()...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Zone tracée à l'écran pour screenshot
    Par SheikYerbouti dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 12/11/2012, 14h41
  2. Rafraichement page sauf zone precise
    Par klimero dans le forum Langage
    Réponses: 1
    Dernier message: 20/06/2008, 16h36
  3. imprim ecran zone precise
    Par nicolovitch dans le forum Windows
    Réponses: 4
    Dernier message: 27/04/2007, 15h47
  4. Comment defiler une BufferedImage a partir d'une zone precise
    Par jlassiramzy dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 12/08/2006, 12h45
  5. Réponses: 13
    Dernier message: 29/03/2006, 21h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo