From: João Neto on
On 20 out, 14:09, Paul <energymo...(a)gmail.com> wrote:
> Hi,
>
> SetPixel on Vista is acting strange. Certain areas it cannot draw on.
> If I draw the entire window, then we can see the areas it can draw to,
> which is vertical areas/bars that are a few hundred pixels wide. The
> code works fine on my XP PC. So I thought there might be some window
> app behind it preventing it from drawing in certain areas, but found
> nothing. Changing the desktop to a solid color did nothing. Any ideas
> what could be causing this? Here's the code,
>
> void CTest1View::OnPaint()
> {
>         CPaintDC dc(this); // device context for painting
>         if(IsIconic()){
>                 return;
>         }
>         long x,y;
>         for(y=0; y < 1024; y++) {
>                 for(x=0; x < 1024; x++) {
>                         dc.SetPixel(x,y,0xff);
>                 }
>         }
>
> }
>
> and another example,
>
> void CTest2View::OnPaint()
> {
>         CPaintDC dc(this); // device context for painting
>         if(IsIconic()){
>                 return;
>         }
>         long x,y;
>         PAINTSTRUCT ps;
>         BeginPaint(&ps);
>         for(y=0; y < 1024; y++) {
>                 for(x=0; x < 1024; x++) {
>                         dc.SetPixel(x,y,0xff);
>                 }
>         }
>         EndPaint(&ps);
>
> }
>
> Also I tried dc,
> int save = dc.SaveDC(); // place this near start of code
> ...
> dc.RestoreDC(save); // place this near end of code
>
> Also I tried calling OnDraw the common way within OnPaint-- same
> results.
>
> I've tried everything I know. Change the window size. Regardless, the
> above code always draws vertical bars that are black, white, black,
> white, about ~ 200 pixels per bar.
>
> Thanks for any suggestions.
> Paul

Try this... works fine for me !
/* SetPixel problem with Vista:
(found here : http://www.codeproject.com/Messages/2515738/Re-Strange-bug-in-SetPixel-in-Visual-Cplusplus-pro.aspx)
I have hacked a temporary solution, thus, but I would prefer a proper
permanent solution:
*/
void Set_Pixel(HDC dc,int x,int y,COLORREF c);
#define SetPixel(dc,x,y,c) Set_Pixel(dc,x,y,c)

/*-----*/
void Set_Pixel(HDC dc,int x,int y,COLORREF c)
{
HPEN p=CreatePen(PS_SOLID,1,c),q;
q=(HPEN)SelectObject(dc,p);
MoveToEx(dc,x,y,0);
LineTo(dc,x,y+1);
SelectObject(dc,q);
DeleteObject(p);
}
From: Paul on
On Nov 21, 3:56 pm, João Neto <jsa...(a)zipmail.com.br> wrote:
> On 20 out, 14:09, Paul <energymo...(a)gmail.com> wrote:
>
>
>
> > Hi,
>
> > SetPixel on Vista is acting strange. Certain areas it cannot draw on.
> > If I draw the entire window, then we can see the areas it can draw to,
> > which is vertical areas/bars that are a few hundred pixels wide. The
> > code works fine on my XP PC. So I thought there might be some window
> > app behind it preventing it from drawing in certain areas, but found
> > nothing. Changing the desktop to a solid color did nothing. Any ideas
> > what could be causing this? Here's the code,
>
> > void CTest1View::OnPaint()
> > {
> >         CPaintDC dc(this); // device context for painting
> >         if(IsIconic()){
> >                 return;
> >         }
> >         long x,y;
> >         for(y=0; y < 1024; y++) {
> >                 for(x=0; x < 1024; x++) {
> >                         dc.SetPixel(x,y,0xff);
> >                 }
> >         }
>
> > }
>
> > and another example,
>
> > void CTest2View::OnPaint()
> > {
> >         CPaintDC dc(this); // device context for painting
> >         if(IsIconic()){
> >                 return;
> >         }
> >         long x,y;
> >         PAINTSTRUCT ps;
> >         BeginPaint(&ps);
> >         for(y=0; y < 1024; y++) {
> >                 for(x=0; x < 1024; x++) {
> >                         dc.SetPixel(x,y,0xff);
> >                 }
> >         }
> >         EndPaint(&ps);
>
> > }
>
> > Also I tried dc,
> > int save = dc.SaveDC(); // place this near start of code
> > ...
> > dc.RestoreDC(save); // place this near end of code
>
> > Also I tried calling OnDraw the common way within OnPaint-- same
> > results.
>
> > I've tried everything I know. Change the window size. Regardless, the
> > above code always draws vertical bars that are black, white, black,
> > white, about ~ 200 pixels per bar.
>
> > Thanks for any suggestions.
> > Paul
>
> Try this... works fine for me !
> /* SetPixel problem with Vista:
> (found here :http://www.codeproject.com/Messages/2515738/Re-Strange-bug-in-SetPixe...)
> I have hacked a temporary solution, thus, but I would prefer a proper
> permanent solution:
> */
> void Set_Pixel(HDC dc,int x,int y,COLORREF c);
> #define SetPixel(dc,x,y,c) Set_Pixel(dc,x,y,c)
>
> /*-----*/
> void Set_Pixel(HDC dc,int x,int y,COLORREF c)
> {
>         HPEN p=CreatePen(PS_SOLID,1,c),q;
>         q=(HPEN)SelectObject(dc,p);
>         MoveToEx(dc,x,y,0);
>         LineTo(dc,x,y+1);
>         SelectObject(dc,q);
>         DeleteObject(p);
>
> }


Nice! Thanks, I see no reason why that would not work. :-)

Regards,
Paul