Click here to Skip to main content
16,005,389 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to create resizable Propertysheet in MFC VC++ (7.1, 8.0 or above) Pin
maheshbhoir.home13-Oct-08 21:57
maheshbhoir.home13-Oct-08 21:57 
GeneralRe: How to create resizable Propertysheet in MFC VC++ (7.1, 8.0 or above) Pin
KarstenK13-Oct-08 22:20
mveKarstenK13-Oct-08 22:20 
GeneralRe: How to create resizable Propertysheet in MFC VC++ (7.1, 8.0 or above) Pin
maheshbhoir.home13-Oct-08 22:50
maheshbhoir.home13-Oct-08 22:50 
GeneralRe: How to create resizable Propertysheet in MFC VC++ (7.1, 8.0 or above) Pin
David Crow14-Oct-08 3:54
David Crow14-Oct-08 3:54 
Questionglass Pin
Sarriss13-Oct-08 2:35
Sarriss13-Oct-08 2:35 
AnswerRe: glass Pin
KarstenK13-Oct-08 3:56
mveKarstenK13-Oct-08 3:56 
GeneralRe: glass Pin
Sarriss13-Oct-08 4:32
Sarriss13-Oct-08 4:32 
GeneralRe: glass Pin
enhzflep13-Oct-08 6:32
enhzflep13-Oct-08 6:32 
Well it's not going to be particularly hard, though it will take more than 2 seconds.

The basic steps you need are.

1. Make bitmap of screen underneath window
2. Blur this bitmap
3. Desaturate the image
4. Colorize the image
5. Create a new bitmap, the size of your window
6. Fill with a solid colour
7. Using the image from step#4 as a brush & some regions, copy to bitmap from step5
8. draw client area etc into bitmap from step5
9. Throw the thing onto the screen.


Here's a function that will do the blurring for you. You should call it with a convolution filter.
I forget now, though I seem to remember that the function may only work on images created with CreateDIBSection - any other image type and the app crashes.


As for the desaturation and colourizing - you'll need to work in either the HSV or HSL colorspace to do that - RGB just isn't suited to perceptual changes like the ones you need here.


Examples:

// medium blur
double BlurFilter1[] =
{
     0, 1, 1, 1, 0,
     1, 1, 1, 1, 1,
     1, 1, 1, 1, 1,
     1, 1, 1, 1, 1,
     0, 1, 1, 1, 0,
}; factor = 1.0/21.0; bias = 0.0;
filterBitmap(target, BlurFilter1, 5, 5, 1.0/21.0);

// light blur
double BlurFilter2[] =
{
     0, 1, 0,
     1, 1, 1,
     0, 1, 0,
}; factor = 1.0/5.0; bias = 0.0;
filterBitmap(target, BlurFilter2, 3, 3, 1.0/5.0);

// diagonal medium motion blur
double motionBlurFilter1[] =
{
     1, 0, 0, 0, 0,
     0, 1, 0, 0, 0,
     0, 0, 1, 0, 0,
     0, 0, 0, 1, 0,
     0, 0, 0, 0, 1,
}; factor = 1.0/5.0; bias = 0.0;
filterBitmap(target, motionBlurFilter1, 5, 5, 1.0/5.0);

// horizontal medium motion blur
double motionBlurFilter2[] = 
{
     1, 1, 1, 1, 1,
} factor = 1.0/5.0; bias = 0.0;
filterBitmap(target, motionBlurFilter2, 5, 1, 1.0/5.0);

/ vertical medium motion blur
double motionBlurFilter3[] = 
{
     1,
     1,
     1,
     1,
     1,
} factor = 1.0/5.0; bias = 0.0;
filterBitmap(target, motionBlurFilter3, 1, 5, 1.0/5.0);

// darken to 90% of current
double darkenFilter[] =
{
     1,
} factor = 0.9/1.0; bias = 0.0;
filterBitmap(target, darkenFilter, 1, 1, 0.9/1.0);


// filters a 24 bit bitmap - image must be created via a call to CreateDIBSection
void filterBitmap(HBITMAP target, double *filter, int filterWidth, int filterHeight, double factor, double bias=0.0)
{
    HBITMAP resultBmp;
    BITMAP bmInfo;
    int x, y, filterX, filterY;
    int bmpWidth, bmpHeight;
//    double factor = 0;
//    double bias = 0.0;
    unsigned char *srcImage, *dstImage;
    int bytesPerRow;
    HDC srcDC, destDC;
    HBITMAP bm1, bm2;
    int i;

//    for (i=0; i<filterwidth*filterheight;i++)
//        factor += filter[i];
//    factor = 1.0 / factor;

    // get dimensions
    GetObject(target, sizeof(bmInfo), &bmInfo);
    bmpWidth = bmInfo.bmWidth;
    bmpHeight = bmInfo.bmHeight;

    // get pointer to bitmap bits
    srcImage = (unsigned char*)bmInfo.bmBits;

    // calc width in bytes of word-aligned scanlines
    bytesPerRow = bmpWidth;
    bytesPerRow *= 3;
    if (bytesPerRow %2)
        bytesPerRow ++;

    // create temp bitmap
    resultBmp = CreateCompatibleBitmap(GetDC(0), bmpWidth, bmpHeight);

    // get pointer to bitmap bits
    GetObject(target, sizeof(bmInfo), &bmInfo);
    dstImage = (unsigned char*)bmInfo.bmBits;

    srcDC = CreateCompatibleDC(GetDC(0));
    destDC =  CreateCompatibleDC(GetDC(0));

    bm1 = (HBITMAP)SelectObject(srcDC, target);
    bm2 = (HBITMAP)SelectObject(destDC, resultBmp);

    for (x=0; x<bmpWidth; x++)
    for (y=0; y<<bmpheight;y++)
    {
        double red=0.0, green=0.0, blue=0.0;
        //multiply every value of the filter with corresponding image pixel
        for(filterX = 0; filterX < filterWidth; filterX++)
        for(filterY = 0; filterY < filterHeight; filterY++)
        {
            int imageX = (x - filterWidth / 2 + filterX + bmpWidth) % bmpWidth;
            int imageY = (y - filterHeight / 2 + filterY + bmpHeight) % bmpHeight;

            red += srcImage[imageX*3 + bytesPerRow*imageY + 2] * filter[filterX +filterWidth*filterY];
            green += srcImage[imageX*3 + bytesPerRow*imageY + 1] * filter[filterX + filterWidth*filterY];
            blue += srcImage[imageX*3 + bytesPerRow*imageY + 0] * filter[filterX + filterWidth*filterY];
        }
        //truncate values smaller than zero and larger than 255
        dstImage[x*3 + bytesPerRow*y + 2] = min(max((int)(factor * red + bias), 0), 255);
        dstImage[x*3 + bytesPerRow*y + 1] = min(max((int)(factor * green + bias), 0), 255);
        dstImage[x*3 + bytesPerRow*y + 0] = min(max((int)(factor * blue + bias), 0), 255);

        //abs values smaller than zero and trunc larger than 255
//        dstImage[x*3 + bytesPerRow*y + 2] = min(abs(int(factor * red + bias)), 255);
//        dstImage[x*3 + bytesPerRow*y + 1] = min(abs(int(factor * green + bias)), 255);
//        dstImage[x*3 + bytesPerRow*y + 0] = min(abs(int(factor * blue + bias)), 255);
    }
    BitBlt(destDC, 0,0, bmpWidth, bmpHeight, srcDC, 0, 0, SRCCOPY);
    DeleteObject(resultBmp);
    SelectObject(srcDC, bm1);
    SelectObject(destDC, bm2);
    DeleteDC(srcDC);
    DeleteDC(destDC);
}

QuestionSet FileSize Pin
MsmVc13-Oct-08 2:19
MsmVc13-Oct-08 2:19 
AnswerRe: Set FileSize Pin
Michael Schubert13-Oct-08 2:22
Michael Schubert13-Oct-08 2:22 
GeneralRe: Set FileSize Pin
MsmVc13-Oct-08 2:27
MsmVc13-Oct-08 2:27 
GeneralRe: Set FileSize Pin
Michael Schubert13-Oct-08 2:35
Michael Schubert13-Oct-08 2:35 
GeneralRe: Set FileSize Pin
MsmVc13-Oct-08 2:43
MsmVc13-Oct-08 2:43 
GeneralRe: Set FileSize Pin
David Crow13-Oct-08 3:26
David Crow13-Oct-08 3:26 
AnswerRe: Set FileSize Pin
CPallini13-Oct-08 2:59
mveCPallini13-Oct-08 2:59 
AnswerRe: Set FileSize Pin
Hamid_RT13-Oct-08 8:02
Hamid_RT13-Oct-08 8:02 
GeneralRe: Set FileSize Pin
MsmVc13-Oct-08 18:54
MsmVc13-Oct-08 18:54 
GeneralRe: Set FileSize Pin
Hamid_RT13-Oct-08 19:32
Hamid_RT13-Oct-08 19:32 
GeneralRe: Set FileSize Pin
VCSprog13-Oct-08 19:54
VCSprog13-Oct-08 19:54 
GeneralRe: Set FileSize Pin
Hamid_RT13-Oct-08 20:45
Hamid_RT13-Oct-08 20:45 
GeneralRe: Set FileSize Pin
Hamid_RT14-Oct-08 19:59
Hamid_RT14-Oct-08 19:59 
GeneralRe: Set FileSize Pin
David Crow14-Oct-08 3:56
David Crow14-Oct-08 3:56 
QuestionShortcut for select all e.i Ctrl+A not working Pin
Le@rner13-Oct-08 2:13
Le@rner13-Oct-08 2:13 
AnswerRe: Shortcut for select all e.i Ctrl+A not working Pin
PJ Arends13-Oct-08 7:36
professionalPJ Arends13-Oct-08 7:36 
AnswerRe: Shortcut for select all e.i Ctrl+A not working Pin
Iain Clarke, Warrior Programmer13-Oct-08 17:56
Iain Clarke, Warrior Programmer13-Oct-08 17:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.