Probleme avec CreateCompatibleBitmap

Résolu
cs_nikog Messages postés 2 Date d'inscription vendredi 3 mars 2006 Statut Membre Dernière intervention 18 avril 2008 - 18 avril 2008 à 16:24
cs_nikog Messages postés 2 Date d'inscription vendredi 3 mars 2006 Statut Membre Dernière intervention 18 avril 2008 - 18 avril 2008 à 17:43
bonjour a tous,

j'ai un probleme avec la source suivante:

while(true)
{
HWND hWndWindow = GetDesktopWindow();
HDC hDcWindow = GetWindowDC(hWndWindow);

int ScreenX = GetDeviceCaps(hDcWindow, HORZRES);
int ScreenY = GetDeviceCaps(hDcWindow, VERTRES);

HDC m_hDcBitmap = CreateCompatibleDC(hDcWindow);
if(!m_hDcBitmap) return 0;

HBITMAP hBitmap = CreateCompatibleBitmap(hDcWindow, ScreenX, ScreenY);
cout << "hBitmap " << hBitmap << endl;
Sleep(50);
}

Le probleme est que au début hBitmap renvoie une valeur mais au bout d'un moment il renvoie que des 0. esque la fonction "CreateCompatibleBitmap" s'épuiserai telle ? puije y procédé différement ?

merci d'avance de votre aide.

ps: je suis sous visual c++ 2008 express

2 réponses

cs_jfrancois Messages postés 482 Date d'inscription vendredi 26 août 2005 Statut Membre Dernière intervention 5 décembre 2009 2
18 avril 2008 à 17:26
Bonjour,

Il faut deleter ce qui est créé ! Il n'y a plus de hBitmap à zéro.

   while (true)
   {
      HWND hWndWindow = GetDesktopWindow();
      HDC hDcWindow = GetWindowDC(hWndWindow);
      int ScreenX = GetDeviceCaps(hDcWindow,HORZRES);
      int ScreenY = GetDeviceCaps(hDcWindow,VERTRES);
      HDC m_hDcBitmap = CreateCompatibleDC(hDcWindow);
        if (m_hDcBitmap == NULL) return 0;
        HBITMAP hBitmap = CreateCompatibleBitmap(hDcWindow,ScreenX,ScreenY);
          cout << "hBitmap " << hBitmap << endl;
        DeleteObject(hBitmap);
      DeleteDC(m_hDcBitmap);
      Sleep(50);
   }

Jean-François
3
cs_nikog Messages postés 2 Date d'inscription vendredi 3 mars 2006 Statut Membre Dernière intervention 18 avril 2008
18 avril 2008 à 17:43
merci infiniment sa marche enfin.
merci encore ^^.
0
Rejoignez-nous