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 :

imprim ecran 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 imprim ecran zone precise
    bonjour,

    J'ai un probleme, je voudrais faire un imprim ecran mais uniquement d'une zone précise de mon ecran, je ne sais pas du tout comment faire, si quelqu'un pouvait m'aider.

    J'imagine utilisé la fonction :
    HWND hWnd = GetDesktopWindow();
    HDC hDC = GetDC(hWnd);
    mais je ne sais pas...

    Merci d'avance pour votre aide !!

  2. #2
    Nouveau membre du Club
    Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2006
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2006
    Messages : 41
    Points : 38
    Points
    38
    Par défaut
    J'ai déjà eut besoin d'utilisé ces fonctions, j'ai pris ma source dans un forum de codeguru (http://www.codeguru.com/forum/showthread.php?t=353383)

    tu n'as qu'à modifier RECT rc pour y mettre les bonnes valeurs.

    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
    RECT rc;
    HWND hWnd = // met ici lw hwnd de ta fenêtre
    ::GetWindowRect (hWnd,&rc); 
    HDC hDC = ::GetDC(0);
    HDC memDC = ::CreateCompatibleDC ( hDC );
    HBITMAP memBM = ::CreateCompatibleBitmap ( hDC, rc.right-rc.left, rc.bottom-rc.top );
    HBITMAP OldBM = (HBITMAP)::SelectObject(memDC, memBM );
    ::BitBlt( memDC, 0, 0, rc.right-rc.left, rc.bottom-rc.top , hDC, rc.left, rc.top , SRCCOPY );
    
    int Bps = ::GetDeviceCaps(hDC,BITSPIXEL);
    int Width  = rc.right-rc.left;
    int Height  = rc.bottom-rc.top;
    
    int size = Bps/8 * ( Width * Height );
    BYTE *lpBits = new BYTE[size];
    
    ::GetBitmapBits( memBM, size, lpBits );
    
    // lpbits is byte pointer to the screen u wanted to capture!
    // do with it whatever you want :-)
    
    delete [] lpBits;
    ::SelectObject(hDC, OldBM);
    ::DeleteObject(memBM);
    ::DeleteDC(memDC);
    ::ReleaseDC( 0, hDC );

    J'espère que ca t'aidera =)

  3. #3
    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
    Merci pour ton aide, malheureusement je ne connais que le langage C et non C++, du coup j’ai des erreurs dans ton code C++ que je ne sais pas corriger, pourrais tu m’indiquer la source complète pour cette manip (déclaration des variables, fonctions…)…

    Merci d’avance pour ton aide !!

  4. #4
    Nouveau membre du Club
    Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2006
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2006
    Messages : 41
    Points : 38
    Points
    38
    Par défaut
    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
    int hwnd_to_bmp(HWND hwnd, char *pszflname)
    {
      HDC memdc, hdc;
      HANDLE hfl;
      DWORD dwBytes, dwNumColors;
      void *pBits;
      HBITMAP hbmp;
      BITMAPFILEHEADER fileheader;
      BITMAPINFOHEADER infoheader;
      RGBQUAD colors[256];
      BITMAPINFO bmpinfo;
      HGDIOBJ hret;
      RECT rct;
    
      hdc= hDC;
      GetWindowRect(hwnd, &rct);
      rct.bottom -= rct.top + 50;
      rct.right -= rct.left + 15;
      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;
    } // hwnd_to_bmp
    ca devrait marché

  5. #5
    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
    merci beaucoup pour ton aide, mais il me reste quand même un petit problème, le voila :

    Lors de la compilation de ton code, il m'indique une erreur de compilation, il m'indique que la variable hDC n'est pas déclarée, ce qui est le cas, est-ce que ce code est correct, il n'y aurait pas une erreur de code ??

    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
    int hwnd_to_bmp(HWND hwnd, char *pszflname)
    {
      HDC memdc, hdc;
      HANDLE hfl;
      DWORD dwBytes, dwNumColors;
      void *pBits;
      HBITMAP hbmp;
      BITMAPFILEHEADER fileheader;
      BITMAPINFOHEADER infoheader;
      RGBQUAD colors[256];
      BITMAPINFO bmpinfo;
      HGDIOBJ hret;
      RECT rct;
    
      hdc= hDC;                //c'est ici que se trouve l'erreur.....
      GetWindowRect(hwnd, &rct);
      rct.bottom -= rct.top + 50;      //ce sont ces valeurs à changer pour modifier la taille du rectangle à shooter ??
      rct.right -= rct.left + 15;
      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;
    } // hwnd_to_bmp
    d'autre part, comment fonctionne (vite fait) ton programme, tu crée un .bmp dans le dossier ou se trouve le .exe ??

    Merci encore pour ton aide.

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

Discussions similaires

  1. [FLASH MX] imprimer une zone flash besoin d'aide
    Par monsieuroudoudou dans le forum Flash
    Réponses: 4
    Dernier message: 22/12/2005, 16h25
  2. Imprimer une zone prédéfini
    Par lepierre dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 02/11/2005, 15h37
  3. bouton imprimer sur imprimante precise!
    Par NoobX dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 10/10/2005, 12h59
  4. Stocker un imprim ecran sous bmp avec l'api windows
    Par Tofalu dans le forum Windows
    Réponses: 7
    Dernier message: 04/05/2005, 12h32
  5. Capture image par imprime ecran
    Par tomnie dans le forum Applications et environnements graphiques
    Réponses: 9
    Dernier message: 14/04/2004, 10h02

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