Dessiner un pixel sur le bureau

Résolu
debutant VB Messages postés 93 Date d'inscription lundi 3 juillet 2006 Statut Membre Dernière intervention 25 juin 2010 - 6 mai 2007 à 15:08
debutant VB Messages postés 93 Date d'inscription lundi 3 juillet 2006 Statut Membre Dernière intervention 25 juin 2010 - 6 mai 2007 à 16:14
Bonjour tout le monde.
Je débute en C++, et j'ai un petit problème :
J'ai fait un petit programme qui devrai dessiner un point rouge sur le bureau
mais ça ne marche pas :
[Linker error] undefined reference to [mailto:'SetPixel@16' 'SetPixel@16']
Voici mon code : "
#include <stdio.h>
#include <windows.h>


struct COORDS_2D_INT
{
       int x;
       int y;
};


struct COULEUR
{
       int r;
       int g;
       int b;
};


struct setPixStruct
{
       COORDS_2D_INT position;
       COULEUR color;
};


COORDS_2D_INT TOP_LEFT_SCREEN;
COORDS_2D_INT SCREEN_SIZE;
COULEUR BACK_COLOR;


void initialize(void);
void setPix(setPixStruct);


void initialize(void)
{       TOP_LEFT_SCREEN.x 100; TOP_LEFT_SCREEN.y 100;       SCREEN_SIZE.x 100; SCREEN_SIZE.y 100;       BACK_COLOR.r 0; BACK_COLOR.g 0; BACK_COLOR.b = 0;
}


void setPix(setPixStruct Pixel)
{
       if ((!(Pixel.position.x < SCREEN_SIZE.x)) || (!(Pixel.position.y < SCREEN_SIZE.y)))
       {
              return;
       }
       HDC hDC = GetDC(0);
       SetPixel(hDC, Pixel.position.x + TOP_LEFT_SCREEN.x, Pixel.position.y + TOP_LEFT_SCREEN.y, (Pixel.color.r + (Pixel.color.g * 256) + (Pixel.color.b * 256 * 256)));
       ReleaseDC(0,hDC);
       return;
}


int main(void)
{
    initialize();
    setPixStruct myPix;
    myPix.position.x = 1;
    myPix.position.y = 1;
    COULEUR mCoul;
    mCoul.r = 255;
    mCoul.g = 0;
    mCoul.b = 0;
    myPix.color = mCoul;
    setPix(myPix);
    return 0;
}
"
Apparemment, c'est la fonction setPix() qui ne marche pas, mais pourquoi ???
Merci d'avance pour la réponse.

2 réponses

24Karas Messages postés 233 Date d'inscription jeudi 4 juillet 2002 Statut Membre Dernière intervention 5 juillet 2008
6 mai 2007 à 16:02
peut-etre ça pourra aider ...

#include <windows.h>
int main(void)
{
    int        iX;
    int        iY;
    HWND    hDesk;
      HDC        hDC;

    hDesk    = GetDesktopWindow();
    hDC        = GetWindowDC(hDesk);
    for (iX=0;iX<100;iX++)
        for (iY=0;iY<100;iY++)
            SetPixel(hDC,iX,iY,RGB(255,0,0));
    ReleaseDC(hDesk,hDC);

    return 0;
}

++
3
debutant VB Messages postés 93 Date d'inscription lundi 3 juillet 2006 Statut Membre Dernière intervention 25 juin 2010
6 mai 2007 à 16:14
Ah, merci, en fait mon programme marchait,
mais il fallait que je fasse Option du projet>Win32 GUI.
(Le programme de 24Karas ne marchait pas non-plus, ça m'a fait comprendre le bug)
Merci quand même.

+
0
Rejoignez-nous