CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    hmm actually this may be harder than I thought... The headers are part of the platform SDK. but I'm not sure microsoft still distributes platform SDK's compatible with VC6.
    THe newer ones won't work for sure because VC6 isn't c++ standards compliant.

    You really should consider upgrading to a newer version of VC.
    In any case, even if you do find a platform SDK with GDI+ support that works for VC6. CImage (an MFC class) won't work on VC6. you can use the GDI+ primitives of course.

  2. #17
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: stop Refreshing of images drawn by setpixel() and saving it how to do?

    since all you need of gdi+ is the bitmap thing... this'll probably be easier to get to work using the CreateDIBSection() solution instead.

    Create a new project.
    Set the type to SDI.
    Set the view type to CScrollview

    Open the view header and add the following 2 members.
    CBitmap m_Bmp;
    DWORD* m_pdwBits;
    In the OnDraw() you add this code
    	CDC dcMem;
    	CBitmap* pOldBmp = dcMem.SelectObject(&m_bmp);
    	BITMAP bmpInfo;
    	pDC->BitBlt(0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,&dcMem, 0,0, SRCCOPY);

    In the OnInitialUpdate() set the sizeTotal variable to the desired size (600x600) and add following bit of code:
    	BITMAPINFO bmi; 
    	memset(&bmi, 0, sizeof(BITMAPINFO)); 
    	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
    	bmi.bmiHeader.biWidth = sizeTotal.cx; 
    	bmi.bmiHeader.biHeight = -sizeTotal.cy; // top-down
    	bmi.bmiHeader.biPlanes = 1; 
    	bmi.bmiHeader.biBitCount = 32; 
    	bmi.bmiHeader.biCompression = BI_RGB; 
    	m_bmp.Attach( CreateDIBSection( *GetDC(), &bmi, DIB_RGB_COLORS, (void**)&m_pdwBits, NULL, NULL) );
    	ZeroMemory(m_pdwBits, sizeof(sizeTotal.cx*sizeTotal.cy*sizeof(DWORD)));

    You can then use the m_pdwBits variable as a simple bitmap. each "pixel" is a 32bit RGB pixel in ARGB format.
    to set a pixel at 100x50 to purple.
    m_pdwBits[ 100*600 + 50 ] = 0x00FF00FF; // set red and blue to 255.

    be careful not to write outside of your given size.
    With the above code, 0,0 of the bitmap will be located at the top left of the window, with increasing Y pointing downward
    If you'd like it at the bottom left with increasing Y going upward. set biHeight to the poxitive value rather than the negative one.

    When you have made changes to the bitmap and want to see them. Invalidate the window with Invalidate();

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.