cambalinho 142 Practically a Posting Shark

i belive that i can't format the pen, because it's my networking pen(net everyhere).
how can i edit the autorun.inf file? i tryied that, but without sucess :(
seems the pen is blocked or something

cambalinho 142 Practically a Posting Shark

instead a letter can i use a program name or pen 'ID'?

cambalinho 142 Practically a Posting Shark

i'm sorry, i don't have sure if we are in same page :(
when i connect the USB pen(my network) the Kanguru software is automatic executed. i want avoid that, but i can't change the autorun file.

cambalinho 142 Practically a Posting Shark

if i take off the Region code, the ToolTip is showed:

BYTE* Get24BitPixels(HBITMAP pBitmap, WORD *pwWidth, WORD *pwHeight)
{
  // a bitmap object just to get bitmap width and height
    BITMAP bmpBmp;

  // pointer to original bitmap info
    LPBITMAPINFO pbmiInfo;

  // bitmap info will hold the new 24bit bitmap info
  BITMAPINFO bmiInfo;

  // width and height of the bitmap
  WORD wBmpWidth, wBmpHeight;

  // ---------------------------------------------------------
  // get some info from the bitmap
  // ---------------------------------------------------------
    GetObject(pBitmap, sizeof(bmpBmp),&bmpBmp);
  pbmiInfo   = (LPBITMAPINFO)&bmpBmp;

  // get width and height
    wBmpWidth  = (WORD)pbmiInfo->bmiHeader.biWidth;
    wBmpWidth -= (wBmpWidth%4);                       // width is 4 byte boundary aligned.
    wBmpHeight = (WORD)pbmiInfo->bmiHeader.biHeight;

  // copy to caller width and height parms
  *pwWidth  = wBmpWidth;
  *pwHeight = wBmpHeight;
  // ---------------------------------------------------------

    // allocate width * height * 24bits pixels
  BYTE *pPixels = new BYTE[wBmpWidth*wBmpHeight*3];
    if (!pPixels) return NULL;

  // get user desktop device context to get pixels from
    HDC hDC = GetWindowDC(NULL);

  // fill desired structure
    bmiInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmiInfo.bmiHeader.biWidth = wBmpWidth;
    bmiInfo.bmiHeader.biHeight = -wBmpHeight;
    bmiInfo.bmiHeader.biPlanes = 1;
    bmiInfo.bmiHeader.biBitCount = 24;
    bmiInfo.bmiHeader.biCompression = BI_RGB;
    bmiInfo.bmiHeader.biSizeImage = wBmpWidth*wBmpHeight*3;
    bmiInfo.bmiHeader.biXPelsPerMeter = 0;
    bmiInfo.bmiHeader.biYPelsPerMeter = 0;
    bmiInfo.bmiHeader.biClrUsed = 0;
    bmiInfo.bmiHeader.biClrImportant = 0;

  // get pixels from the original bitmap converted to 24bits
  int iRes = GetDIBits(hDC,pBitmap,0,wBmpHeight,(LPVOID)pPixels,&bmiInfo,DIB_RGB_COLORS);

  // release the device context
    ReleaseDC(NULL,hDC);

  // if failed, cancel the operation.
    if (!iRes)
  {
    delete[] pPixels;
    return NULL;
  };

  // return the pixel array
    return pPixels;
}

HRGN RegionbyBitmap(HBITMAP pBitmap,COLORREF clrTransparent=-1 )
{
    BYTE jTranspR = GetRValue(clrTransparent), jTranspG=GetGValue(clrTransparent), jTranspB=GetBValue(clrTransparent);
  // bitmap width and height
  WORD wBmpWidth,wBmpHeight;

  // the final region and …
cambalinho 142 Practically a Posting Shark

i have 1 pen drive, that is my network. how can i disable, these pen(but not all pens) or program been automatic executed?
(the windows connect to network automatic, so i don't need the program been executed)

cambalinho 142 Practically a Posting Shark

from MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd145213%28v=vs.85%29.aspx
"An application returns zero if it processes this message."
see these code on my label control:

case WM_PAINT:
            {
                PAINTSTRUCT test;
                BeginPaint(inst->hwnd, &test);
                image imglabel(inst->imgtest.width(),inst->imgtest.height());
                brush brshbackcolor(inst->clrBackColor);
                imglabel.Backcolor=inst->clrBackColor;
                brush brshTransparent;
                FillRect(imglabel,&test.rcPaint,brshbackcolor);
                if(inst->imgtest.haveimage())
                    DrawHICONtoHDC(imglabel, inst->imgtest);
                imglabel.DrawText(inst->strCaption);
                pen penColor(1,2,RGB(0,255,0));
                penColor.ToDC(imglabel);
                imglabel.DrawRectangle(10,10,10,10);
                pen penColor2(1,2,RGB(255,0,0));
                penColor2.ToDC(imglabel);
                imglabel.DrawLine(0,0,20,20);
                pen penColor3(1,2,RGB(0,0,255));
                penColor3.ToDC(imglabel);
                //brshTransparent.ToDC(imglabel);
                imglabel.DrawEllipse(0,0,20,20);
                //imglabel.DrawLine(0,0,20,20);
                if(inst->blnBorder==true)
                    DrawEdge(imglabel, &test.rcPaint,BDR_SUNKENINNER | BDR_RAISEDOUTER,BF_RECT);
                if(inst->blnTransparent==true)
                {
                     //destroy the region
                    SetWindowRgn(inst->hwnd,NULL,FALSE);

                    //draw the image transparent
                    TransparentBlt(test.hdc,0,0,test.rcPaint.right,test.rcPaint.bottom,imglabel,0,0, test.rcPaint.right ,test.rcPaint.bottom, inst->clrBackColor);



                    //Create and set them region
                    inst->LabelRegion=RegionbyBitmap(imglabel, inst->clrBackColor);
                    SetWindowRgn(inst->hwnd,inst->LabelRegion,FALSE);
                }
                else
                {
                    SetWindowRgn(inst->hwnd,NULL,FALSE);
                    BitBlt(test.hdc,0,0,imglabel.width(),imglabel.height(),imglabel,0,0,SRCCOPY);
                }
                EndPaint(inst->hwnd, &test);
                return 0;
            }
            break;

some code can be confused, but like you see, i return 0.
but the ToolTip is blocked :(
if i put the label hidded, the ToolTip is showed. seems that i have here a problem. can anyone advice me?

cambalinho 142 Practically a Posting Shark

thanks for all. thank you

cambalinho 142 Practically a Posting Shark

just the partitions. now, seems, that i fix the problem. maybe was a key locked or damage. i press some keys and now isn't showed.
but you are speaking about Reset the BIOS. i don't know do that. can you explain how to do that?

cambalinho 142 Practically a Posting Shark

i belive that my brother found a virus\spyware. i even formated the laptop and continues there :(
my problem is: the help window is allways opening. i have problems using the laptop :(
ca anyone help me?

cambalinho 142 Practically a Posting Shark

my Region bitmap way uses the CreateRectRgn() and CombineRgn() functions.
my question is: is more faster use the CreatePolygonRgn() with POINT array object?

cambalinho 142 Practically a Posting Shark

yes.. or i receive the child control or a black rectangle(depending if the child control is visible or not)

cambalinho 142 Practically a Posting Shark

sorry.. in both i mean HDC.

cambalinho 142 Practically a Posting Shark

how can i copy the parent background(DC) control to child control DC?

cambalinho 142 Practically a Posting Shark

why WS_CLIPCHILDREN style don't let the child control been clear?
the WS_CLIPCHILDREN style avoid the flickers. but don't let clear the control :(
why i can't clear the control(before WM_PAINT message)?

cambalinho 142 Practically a Posting Shark

finally works ;)

case 0x00FE:
                {

                    if(wParam==1)
                    {
                        SetWindowText(inst->hwnd,"enter device");
                    }
                    else if(wParam==2)
                    {
                        SetWindowText(inst->hwnd,"exit device");
                    }


                    return 0;
                }
                break;

                case WM_CREATE:
                {
                    if(WindowMain == NULL || WindowMain ==GetDesktopWindow())
                        WindowMain = HandleWindow;

                    SetTimer(inst->hwnd,JoystickTimer,150,NULL);
                    SetTimer(inst->hwnd,KeyBoardTimer,150,NULL);

                    RAWINPUTDEVICE rid;

                    rid.usUsagePage = 1 ;
                    rid.usUsage     = 4; // Joystick
                    rid.dwFlags     = 0x00002000;
                    rid.hwndTarget  = inst->hwnd;

                    if(!RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)))
                        SetWindowText(inst->hwnd,"error");
                }
                break;

how use the GetRawInputDeviceInfo() for test if a joystick is connected to pc?

cambalinho 142 Practically a Posting Shark

for use the WM_INPUT_DEVICE_CHANGE message, i must use the RegisterRawInputDevices() : https://msdn.microsoft.com/en-us/library/windows/desktop/ms645591%28v=vs.85%29.aspx

see the 'Community Additions'.
so i did:

case WM_CREATE:
                {
                    if(WindowMain == NULL || WindowMain ==GetDesktopWindow())
                        WindowMain = HandleWindow;

                    SetTimer(inst->hwnd,JoystickTimer,150,NULL);
                    SetTimer(inst->hwnd,KeyBoardTimer,150,NULL);

                    RAWINPUTDEVICE rid;

                    rid.usUsagePage = 1;
                    rid.usUsage     = 4; // Joystick
                    rid.dwFlags     = 0;
                    rid.hwndTarget  = inst->hwnd;

                    if(!RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)))
                        SetWindowText(inst->hwnd,"error");
                }
                break;


                case 0x00FE: //#define WM_INPUT_DEVICE_CHANGE          0x00FE
                {
                    SetWindowText(inst->hwnd,"enter device");

                    return 0;
                }
                break;

i'm using windows 7. but the message isn't activated when i connect or disconnect a device :(

cambalinho 142 Practically a Posting Shark

USB

cambalinho 142 Practically a Posting Shark

i have notice that using the joyGetPosEx() function, when the joystick isn't connected, that the memory, that the application uses, is increasing.
so is there another way just for see if 1 joystick is connected to pc?

cambalinho 142 Practically a Posting Shark

heres the entire class:

class image
{
private:
    ULONG_PTR m_gdiplusToken;
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    HDC hdcimage=CreateCompatibleDC(NULL);
    HGDIOBJ obj=NULL;
    HBITMAP btBitmap=NULL;
    Image *img;
    bool isimgused=false;
    bool isGDIPLUSIniciated=false;
    int imageheight=0;
    int imageweight=0;
    int framecount=0;
    int intSelectFrame=0;
    int framedelay=0;
    string strfilename="";
    Gdiplus::Color clrBackColor=Gdiplus::Color::Transparent;
    HDC hdcwindow;
    bool blnTransparent=true;

    void readimagefile(string filename)
    {
        if (isimgused==true)
            delete img;
        strfilename=filename;
        if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
        {
            isimgused=false;
            //create the transparent icon handle
            HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
            ICONINFO ii;
            BOOL fResult = GetIconInfo(hicon, &ii);
            if (fResult)
            {
                BITMAP bm;
                fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
                if (fResult)
                {
                    imageweight= bm.bmWidth;
                    imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
                }
                if (ii.hbmMask) DeleteObject(ii.hbmMask);
                if (ii.hbmColor) DeleteObject(ii.hbmColor);
            }
            btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
            obj = SelectObject(hdcimage, btBitmap);//add the bitmap to memory DC
            DrawIconEx(hdcimage,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);//draw the icon to DC with right size
            //seems the DrawIcon(), always, draw it with 32X32 size
            framecount=1;
            DestroyCursor(hicon);
        }
        else
        {
            isimgused=true;
            Gdiplus::Image img2(towstring(filename).c_str());
            imageweight=img2.GetWidth();
            imageheight=img2.GetHeight();
            btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);
            obj = SelectObject(hdcimage, btBitmap);
            Gdiplus::Graphics graphics(hdcimage);
            graphics.DrawImage(&img2, 0,0,imageweight,imageheight);

            UINT count = 0;
            count = img2.GetFrameDimensionsCount();
            GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*count);
            img2.GetFrameDimensionsList(pDimensionIDs, count);
            framecount=img2.GetFrameCount(&pDimensionIDs[0]);
            framedelay =img2.GetPropertyItemSize(PropertyTagFrameDelay);
            img=new Image(towstring(filename).c_str());
            isimgused=true;
            free(pDimensionIDs);
        }
    }

    HICON HICONFromHBITMAP(HBITMAP bitmap)
    {
        BITMAP bmp;
        GetObject(bitmap, sizeof(BITMAP), &bmp);
        HBITMAP hbmMask = CreateCompatibleBitmap(GetDC(NULL), bmp.bmWidth, bmp.bmHeight);

        ICONINFO ii = {0};
        ii.fIcon    = TRUE;
        ii.hbmColor = bitmap;
        ii.hbmMask  = hbmMask;

        HICON hIcon = CreateIconIndirect(&ii);
        DeleteObject(hbmMask);

        return hIcon;
    }

public:

    image()
    {
        if (isimgused==true)
            delete img;
        isimgused=false;
        if(isGDIPLUSIniciated==false)
        {
            Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
            isGDIPLUSIniciated=true;
        }

        btBitmap=CreateCompatibleBitmap(hdcimage,1,1);
        obj = SelectObject(hdcimage, btBitmap);
        imageheight=1;
        imageweight=1;
    }

    image(HDC hdcWindow)
    {
        if (isimgused==true) …
cambalinho 142 Practically a Posting Shark

how avoid memory leaks?
from here: http://www.winprog.org/tutorial/bitmaps.html
i learned:

GetDC() - ReleaseDC()
BeginPaint() - EndPaint()
CreateCompatibleDC() - DeleteDC() 

i must get the old selected object. select it when isn't needed and then delete it.
so seen these constructor and desctructor:

image(const int width, const int height)
    {
        if (isimgused==true)
            delete img;
        isimgused=false;
        if(isGDIPLUSIniciated==false)
        {
            Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
            isGDIPLUSIniciated=true;
        }
        SelectObject(hdcimage, obj);
        DeleteObject(btBitmap);
        DeleteObject(obj);
        DeleteDC(hdcimage);
        hdcimage = CreateCompatibleDC(NULL);
        btBitmap = CreateBitmap(width,height,1,32,NULL);
        obj = SelectObject(hdcimage, btBitmap);
        framecount=1;
        imageheight=height;
        imageweight=width;
    }

~image()
    {
        if(isimgused==true)
            delete img;
        if(isGDIPLUSIniciated==true)
            Gdiplus::GdiplusShutdown(m_gdiplusToken);
        SelectObject(hdcimage, obj);
        DeleteObject(btBitmap);
        DeleteDC(hdcimage);
    }

and these function:

void DrawHICONtoHDC(HDC hdc, HICON hIcon, int PosX=0, int PosY=0)
{
    BITMAP BMInf;
    ICONINFO    csII;
    GetIconInfo(hIcon, &csII);
    GetObject(csII.hbmColor, sizeof(BMInf), &BMInf);
    HDC MemDCExercising = CreateCompatibleDC(hdc);
    HBITMAP hBitmap=CreateBitmap(BMInf.bmWidth ,BMInf.bmHeight,1,32,0);
    HBITMAP oldbitmap =(HBITMAP) SelectObject(MemDCExercising, hBitmap);
    DrawIcon(MemDCExercising,0,0,hIcon);
    TransparentBlt(hdc, PosX, PosY, BMInf.bmWidth , BMInf.bmHeight, MemDCExercising, 0, 0,BMInf.bmWidth , BMInf.bmHeight,GetPixel(MemDCExercising,BMInf.bmWidth-1,BMInf.bmHeight-1) );
    SelectObject(MemDCExercising,oldbitmap);
    DeleteDC(MemDCExercising);
    DeleteObject(oldbitmap);
    ::DeleteObject(csII.hbmColor);
    ::DeleteObject(csII.hbmMask);
    DestroyIcon(hIcon);
    DeleteObject(hBitmap);
}

what i'm doing wrong?
from a windows tool: the HDC, HBITMAP, HPEN, HBRUSH continue been created, instead delete the old one when isn't needed

cambalinho 142 Practically a Posting Shark

i did another test. if i comment all message, the error never happens. so i'm doing some error on sending the WM_DRAWITEM message.
is there another way for send it?

cambalinho 142 Practically a Posting Shark

how send a message with WM_DRAWITEM message?
heres my actual code on parent window:

case WM_DRAWITEM:
                {
                    DRAWITEMSTRUCT *test=(DRAWITEMSTRUCT*) lParam;
                    /*if(test->CtlType==ODT_MENU)
                    {
                        MENUITEMINFO menuInfo;
                        menuInfo.cbSize = sizeof(MENUITEMINFO);
                        menuInfo.fMask=MIIM_DATA;
                        if(GetMenuItemInfo((HMENU)test->hwndItem,(UINT) test->itemID, TRUE, &menuInfo )!=0)
                        {
                            Menu *mMenu = (Menu *) menuInfo.dwItemData;
                            if(mMenu!=NULL)
                                if(mMenu->DrawItem!=NULL)
                                    //mMenu->DrawItem();
                                else
                                {

                                }
                        }

                    }
                    else
                    {
                        SendMessage(test->hwndItem, WM_DRAWITEM, wParam, lParam);
                    }*/
                    if(test->hwndItem!=inst->hwnd)
                        SendMessage(test->hwndItem, WM_DRAWITEM, wParam, lParam);
                    return TRUE;
                }
                break;

i did some tests and i notice if i take off these message, the timer works normaly. so, maybe, i have mistake something here.
i need some advices

cambalinho 142 Practically a Posting Shark

i belive that i understand what you mean. now i must understand how use DIB's. isn't easy :(
can i do mask using the BitBlt()?(with same image)

cambalinho 142 Practically a Posting Shark

i have another error that i don't understand:
1 - the timers works perfetly and show the animations;
2 - after sometime, or the timers stop or o lose the original HDC.
see the my image class, what you can tell me?

cambalinho 142 Practically a Posting Shark

think in these way: the eyes have the blue color, the backcolor is blue. so how can i change the backcolor without change the image\eye?
(these is just an exemple for trying explain)

cambalinho 142 Practically a Posting Shark

thanks for all... seems ok now ;)

cambalinho 142 Practically a Posting Shark

triumphost: why i did:

image (const image &cSource)
    {
        if(isGDIPLUSIniciated==false)
        {
            Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
            isGDIPLUSIniciated=true;
        }
        readimagefile(cSource.strfilename);
        BitBlt(hdcimage,0,0,imageweight,imageheight,cSource.hdcimage,0,0,SRCCOPY);
    }

    image& operator= (const image &cSource)
    {
        if(isGDIPLUSIniciated==false)
        {
            Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
            isGDIPLUSIniciated=true;
        }
        readimagefile(cSource.strfilename);
        BitBlt(hdcimage,0,0,imageweight,imageheight,cSource.hdcimage,0,0,SRCCOPY);
        return *this;
    }

?
1 - the GDIPLUS::Image don't read some files(like *.cur);
2 - i only can use the Clone() when the img is initializate.

cambalinho 142 Practically a Posting Shark

heress the class otimizated:

class image
{
private:
    ULONG_PTR m_gdiplusToken;
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    HDC hdcimage=CreateCompatibleDC(NULL);
    HGDIOBJ obj=NULL;
    HBITMAP btBitmap=NULL;
    Image *img;
    bool isimgused=false;
    bool isGDIPLUSIniciated=false;
    int imageheight=0;
    int imageweight=0;
    int framecount=0;
    int intSelectFrame=0;
    int framedelay=0;
    string strfilename="";
    Gdiplus::Color clrBackColor=Gdiplus::Color::Transparent;
    HDC hdcwindow;
    bool blnTransparent=true;

    void readimagefile(string filename)
    {
        if (isimgused==true)
            delete img;
        DeleteObject(btBitmap);
        DeleteObject(obj);
        strfilename=filename;
        if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
        {
            isimgused=false;
            //create the transparent icon handle
            HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
            ICONINFO ii;
            BOOL fResult = GetIconInfo(hicon, &ii);
            if (fResult)
            {
                BITMAP bm;
                fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
                if (fResult)
                {
                    imageweight= bm.bmWidth;
                    imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
                }
                if (ii.hbmMask) DeleteObject(ii.hbmMask);
                if (ii.hbmColor) DeleteObject(ii.hbmColor);
            }
            btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
            obj = SelectObject(hdcimage, btBitmap);//add the bitmap to memory DC
            DrawIconEx(hdcimage,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);//draw the icon to DC with right size
            //seems the DrawIcon(), always, draw it with 32X32 size
            framecount=1;
            DestroyCursor(hicon);
        }
        else
        {
            isimgused=true;
            Gdiplus::Image img2(towstring(filename).c_str());
            imageweight=img2.GetWidth();
            imageheight=img2.GetHeight();
            btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);
            obj = SelectObject(hdcimage, btBitmap);
            Gdiplus::Graphics graphics(hdcimage);
            graphics.DrawImage(&img2, 0,0,imageweight,imageheight);

            UINT count = 0;
            count = img2.GetFrameDimensionsCount();
            GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*count);
            img2.GetFrameDimensionsList(pDimensionIDs, count);
            framecount=img2.GetFrameCount(&pDimensionIDs[0]);
            framedelay =img2.GetPropertyItemSize(PropertyTagFrameDelay);
            img=new Image(towstring(filename).c_str());
            isimgused=true;
            free(pDimensionIDs);
        }
    }

    HICON HICONFromHBITMAP(HBITMAP bitmap)
    {
        BITMAP bmp;
        GetObject(bitmap, sizeof(BITMAP), &bmp);
        HBITMAP hbmMask = CreateCompatibleBitmap(GetDC(NULL), bmp.bmWidth, bmp.bmHeight);

        ICONINFO ii = {0};
        ii.fIcon    = TRUE;
        ii.hbmColor = bitmap;
        ii.hbmMask  = hbmMask;

        HICON hIcon = CreateIconIndirect(&ii);
        DeleteObject(hbmMask);

        return hIcon;
    }

public:

    image()
    {
        if (isimgused==true)
            delete img;
        isimgused=false;
        if(isGDIPLUSIniciated==false)
        {
            Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
            isGDIPLUSIniciated=true;
        }

        btBitmap=CreateCompatibleBitmap(hdcimage,1,1);
        obj = SelectObject(hdcimage, btBitmap);
        imageheight=1;
        imageweight=1;
    }

    image(HDC hdcWindow)
    { …
cambalinho 142 Practically a Posting Shark

sorry david... i'm confused. i'm destroying them on class destructor, right?

cambalinho 142 Practically a Posting Shark

dani: same happens with the little chat window.. if you need, i can show a print screen.
thanks for all

cambalinho 142 Practically a Posting Shark

finally i fix it, now i use the new keyword and i can delete:

class image
{
private:
    ULONG_PTR m_gdiplusToken;
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    HDC hdcimage=CreateCompatibleDC(NULL);
    HGDIOBJ obj=NULL;
    HBITMAP btBitmap=NULL;
    Image *img;
    bool isimgused=false;
    int imageheight=0;
    int imageweight=0;
    int framecount=0;
    int intSelectFrame=0;
    int framedelay=0;
    string strfilename="";
    Gdiplus::Color clrBackColor=Gdiplus::Color::Transparent;
    HDC hdcwindow;
    bool blnTransparent=true;

    HICON HICONFromHBITMAP(HBITMAP bitmap)
    {
        BITMAP bmp;
        GetObject(bitmap, sizeof(BITMAP), &bmp);
        HBITMAP hbmMask = CreateCompatibleBitmap(GetDC(NULL), bmp.bmWidth, bmp.bmHeight);

        ICONINFO ii = {0};
        ii.fIcon    = TRUE;
        ii.hbmColor = bitmap;
        ii.hbmMask  = hbmMask;

        HICON hIcon = CreateIconIndirect(&ii);
        DeleteObject(hbmMask);

        return hIcon;
    }

public:

    image()
    {
        if (isimgused==true)
            delete img;
        isimgused=false;
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        btBitmap=CreateCompatibleBitmap(hdcimage,1,1);
        obj = SelectObject(hdcimage, btBitmap);
        imageheight=1;
        imageweight=1;
    }

    image(HDC hdcWindow)
    {
        if (isimgused==true)
            delete img;
        isimgused=false;
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        hdcwindow=hdcWindow;
    }

    image(const int width, const int height)
    {
        if (isimgused==true)
            delete img;
        isimgused=false;
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        hdcimage = CreateCompatibleDC(NULL);
        btBitmap = CreateBitmap(width,height,1,32,NULL);
        obj = SelectObject(hdcimage, btBitmap);
        framecount=1;
        imageheight=height;
        imageweight=width;
    }

    image( const string & filename)
    {
        if (isimgused==true)
            delete img;
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        strfilename=filename;
        if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
        {
            isimgused=false;
            //create the transparent icon handle
            HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
            ICONINFO ii;
            BOOL fResult = GetIconInfo(hicon, &ii);
            if (fResult)
            {
                BITMAP bm;
                fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
                if (fResult)
                {
                    imageweight= bm.bmWidth;
                    imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
                }
                if (ii.hbmMask) DeleteObject(ii.hbmMask);
                if (ii.hbmColor) DeleteObject(ii.hbmColor);
            }
            btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
            obj = SelectObject(hdcimage, btBitmap);//add the bitmap to memory DC
            DrawIconEx(hdcimage,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);//draw the icon to DC with right size
            //seems the DrawIcon(), always, …
cambalinho 142 Practically a Posting Shark

triumphost: if so.. why i get the HDC result correct?
StuXYZ: thanks for all. it's fixed now, but i want avoid the 'const' and the '&' on Picture() function header. and yes i have several mistakes. i don't use the 'delete', because i get a memory leak too

cambalinho 142 Practically a Posting Shark
  • so, using my new class's, must add 'const' and adress operator?
  • thanks for that error(pixels). but i get memory errors(when i execute the program) :(
cambalinho 142 Practically a Posting Shark

heres my image class:

class image
{
private:
    ULONG_PTR m_gdiplusToken;
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    HDC hdcimage=CreateCompatibleDC(NULL);
    HGDIOBJ obj=NULL;
    HBITMAP btBitmap=NULL;
    Image *img;
    bool isimgused=false;
    int imageheight=0;
    int imageweight=0;
    int framecount=0;
    int intSelectFrame=0;
    int framedelay=0;
    string strfilename="";
    Gdiplus::Color clrBackColor=Gdiplus::Color::Transparent;
    HDC hdcwindow;
    bool blnTransparent=true;

    HICON HICONFromHBITMAP(HBITMAP bitmap)
    {
        BITMAP bmp;
        GetObject(bitmap, sizeof(BITMAP), &bmp);
        HBITMAP hbmMask = CreateCompatibleBitmap(GetDC(NULL), bmp.bmWidth, bmp.bmHeight);

        ICONINFO ii = {0};
        ii.fIcon    = TRUE;
        ii.hbmColor = bitmap;
        ii.hbmMask  = hbmMask;

        HICON hIcon = CreateIconIndirect(&ii);
        DeleteObject(hbmMask);

        return hIcon;
    }

public:

    image()
    {
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        btBitmap=CreateCompatibleBitmap(hdcimage,1,1);
        obj = SelectObject(hdcimage, btBitmap);
        imageheight=1;
        imageweight=1;
    }

    image(HDC hdcWindow)
    {
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        hdcwindow=hdcWindow;
    }

    image(const int width, const int height)
    {
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        hdcimage = CreateCompatibleDC(NULL);
        btBitmap = CreateBitmap(width,height,1,32,NULL);
        obj = SelectObject(hdcimage, btBitmap);
        framecount=1;
        imageheight=height;
        imageweight=width;
    }

    image( const string & filename)
    {
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        strfilename=filename;
        if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
        {
            //create the transparent icon handle
            HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
            ICONINFO ii;
            BOOL fResult = GetIconInfo(hicon, &ii);
            if (fResult)
            {
                BITMAP bm;
                fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
                if (fResult)
                {
                    imageweight= bm.bmWidth;
                    imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
                }
                if (ii.hbmMask) DeleteObject(ii.hbmMask);
                if (ii.hbmColor) DeleteObject(ii.hbmColor);
            }
            btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
            obj = SelectObject(hdcimage, btBitmap);//add the bitmap to memory DC
            DrawIconEx(hdcimage,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);//draw the icon to DC with right size
            //seems the DrawIcon(), always, draw it with 32X32 size
            framecount=1;
            DestroyCursor(hicon);
        }
        else
        {
            isimgused=true;
            Gdiplus::Image img2(towstring(filename).c_str());
            btBitmap=CreateBitmap(img2.GetWidth(),img2.GetHeight(),1,32,NULL);
            obj = SelectObject(hdcimage, btBitmap);
            Gdiplus::Graphics graphics(hdcimage);
            graphics.DrawImage(&img2, 0, 0, img2.GetWidth(), img2.GetHeight());
            imageweight=img2.GetWidth();
            imageheight=img2.GetHeight();
            UINT count = …
cambalinho 142 Practically a Posting Shark

i avoid some flicker, but not all:

RedrawWindow(hwnd,&d,nullptr,RDW_UPDATENOW);

i can't use the WS_CLIPCHILDREEN on parent, or the RedrawWindow() don't clean the control. but i accept sugestions

cambalinho 142 Practically a Posting Shark

the problem was not the button, but the label.
heres how i get the control size:

//getting the text rectangle size
            RECT textrect={0};            
            DrawText (GetDC(hwnd),strCaption.c_str(),strCaption.size(),&textrect,DT_CALCRECT);

            //testing the image size
            //i add more 7 for get size for draw a border or something
            if(imgtest.haveimage())
            {
                if((textrect.bottom-textrect.top)<imgtest.height())
                    intHeight=imgtest.height()+7;
                if((textrect.right-textrect.left)<imgtest.width())
                    intWidth=imgtest.width()+7;
            }
            else
            {
                intHeight=textrect.bottom+7;
                intWidth=textrect.right+7;
            }

            //resize the control
            SetWindowPos(hwnd, 0, 0, 0,intWidth,intHeight,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCOPYBITS);

i have 1 question: how can i get the border size?

cambalinho 142 Practically a Posting Shark

i have seen that the problem is fixed. thanks for all. realy.. thanks

cambalinho 142 Practically a Posting Shark

the control have the WS_TRANSPARENT style. and:

case WM_ERASEBKGND:
            {
                return TRUE;
            }
            break;
            case WM_CTLCOLORSTATIC:
            {
                return (LRESULT)GetStockObject(NULL_BRUSH);
            }
            break;
            case WM_DRAWITEM:
            {
                DRAWITEMSTRUCT *test=(DRAWITEMSTRUCT*) lParam;
                image imglabel(test->rcItem.right-test->rcItem.left,test->rcItem.bottom-test->rcItem.top);
                if(inst->blnTransparent!=true)
                    FillRect(test->hDC,&test->rcItem, CreateSolidBrush(inst->clrBackColor));
                else
                    FillRect(test->hDC,&test->rcItem,(HBRUSH) GetStockObject(NULL_BRUSH));
                FillRect(imglabel,&test->rcItem,CreateSolidBrush(inst->clrBackColor));
                if(inst->imgtest.haveimage())
                    DrawHICONtoHDC(imglabel, inst->imgtest,1,1);
                SetBkMode(imglabel,TRANSPARENT);
                char *text=(char*)inst->strCaption.c_str();
                SetTextColor(imglabel,inst->clrTextColor );
                DrawTextEx(imglabel,text,-1,&test->rcItem,DT_LEFT,NULL);
                if(inst->blnBorder==true)
                    DrawEdge(imglabel, &test->rcItem,BDR_SUNKENINNER | BDR_RAISEDOUTER,BF_RECT);
                imglabel.Backcolor=inst->clrBackColor;
                TransparentBlt(test->hDC,0,0,test->rcItem.right,test->rcItem.bottom,imglabel,0,0,test->rcItem.right,test->rcItem.bottom, inst->clrBackColor);
                return TRUE;
            }
            break;

these code is what show us the label transparent.
now with click i did these:

case BN_CLICKED:
                    {
                        HDC Hdc=GetDC(inst->hwnd);
                        POINT curpos;
                        GetCursorPos(&curpos);
                        ScreenToClient(inst->hwnd,&curpos);
                        if(GetPixel(Hdc,curpos.x ,curpos.x)!=CLR_INVALID && inst->blnTransparent==true)
                            inst->MouseClick();
                        else if(inst->blnTransparent==false)
                            inst->MouseClick();
                        ReleaseDC(inst->hwnd,Hdc);
                    }
                    break;

(my label is the win32 button class)
when the control is transparent the pixel(backcolor) isn't showed. but how can i test that pixels?
that code works, but it's instable(works sometimes) :(

cambalinho 142 Practically a Posting Shark

thanks i. and continue with nice work ;)

cambalinho 142 Practically a Posting Shark

i have advertisement problem.
please see these image:
https://onedrive.live.com/?cid=C3EF456E15C8DEB6&id=C3EF456E15C8DEB6!1268&v=3
how can i write if the advertisements are on front of little code window?
thanks for all

cambalinho 142 Practically a Posting Shark
HWND WindowMain=GetDesktopWindow();
cambalinho 142 Practically a Posting Shark

i found the problem:

case WM_PAINT:
            {
                return 0;
            }
            break;

how these return value on WM_PAINT message can 'stop' the timer?

cambalinho 142 Practically a Posting Shark

confused: if i minimizate the form, why the timer is working?
(i know these, because after restaure the form, the image is changed)
seems that i must give up on SetTimer() or i realy have 1 problem with FormActivated and/or message loop

cambalinho 142 Practically a Posting Shark

for child controls get the WM_CREATE message ;)
or isn't needed?

cambalinho 142 Practically a Posting Shark

when the form is activated:

case WM_ACTIVATE:
                {
                    if (wParam==WA_INACTIVE)
                    {
                        SetWindowText(inst->hwnd,"unactivated");
                        FormActivated = NULL;
                    }
                    else
                    {
                        SetWindowText(inst->hwnd,"activated");
                        FormActivated = inst->hwnd;
                    }

                    return 0;
                }
                break;

when i create the timer:

case WM_CREATE:
                {
                    if(WindowMain == NULL || WindowMain ==GetDesktopWindow())
                    {
                         WindowMain = HandleWindow;
                    }
                    SetTimer(inst->hwnd,JoystickTimer,150,NULL);
                    SetTimer(inst->hwnd,KeyBoardTimer,150,NULL);
                    SendMessage((HWND)lParam , WM_CREATE, wParam, lParam);
                }
                break;

so why the WM_TIMER isn't activated? why i get invalid handle?

WPARAM MessageLoop()
{
    MSG msgEvents;
    while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
    {
        if (!IsDialogMessage(FormActivated, &msgEvents))
        {
           TranslateMessage(&msgEvents);
           DispatchMessage(&msgEvents);
        }
    }
    return msgEvents.wParam;
}
cambalinho 142 Practically a Posting Shark

i can use my image for Double Buffering easy. and only, in the end, i change the new image:

//the animation timer:
animation.timerprocedure=[this]()
           {
                static int a;
                a=a+1;
                if(a==imgtest.FramesCount)
                    a=0;
                imgtest.SelectFrame=a;
                RECT d;
                GetClientRect(hwnd,&d);
                RedrawWindow(hwnd,&d,nullptr,RDW_ERASE| RDW_INVALIDATE);
           };
//drawing the static control:
case WM_ERASEBKGND:
            {
                return TRUE;
            }
            break;
            case WM_CTLCOLORSTATIC:
            {
                return (LRESULT)GetStockObject(NULL_BRUSH);
            }
            break;
            case WM_DRAWITEM:
            {

                DRAWITEMSTRUCT *test=(DRAWITEMSTRUCT*) lParam;
                image imglabel(test->rcItem.right-test->rcItem.left,test->rcItem.bottom-test->rcItem.top);
                if(inst->blnTransparent!=true)
                    FillRect(test->hDC,&test->rcItem, CreateSolidBrush(inst->clrBackColor));
                else
                    FillRect(test->hDC,&test->rcItem,(HBRUSH) GetStockObject(NULL_BRUSH));
                FillRect(imglabel,&test->rcItem,CreateSolidBrush(inst->clrBackColor));
                if(inst->imgtest.haveimage())
                    DrawHICONtoHDC(imglabel, inst->imgtest,1,1);
                SetBkMode(imglabel,TRANSPARENT);
                char *text=(char*)inst->strCaption.c_str();
                SetTextColor(imglabel,inst->clrTextColor );
                DrawTextEx(imglabel,text,-1,&test->rcItem,DT_LEFT,NULL);
                if(inst->blnBorder==true)
                    DrawEdge(imglabel, &test->rcItem,BDR_SUNKENINNER | BDR_RAISEDOUTER,BF_RECT);
                imglabel.Backcolor=inst->clrBackColor;
                TransparentBlt(test->hDC,0,0,test->rcItem.right,test->rcItem.bottom,imglabel,0,0,test->rcItem.right,test->rcItem.bottom, inst->clrBackColor);//draw the image to static
            }
            break;

so how can i avoid the flicker?
i use the double buffer

cambalinho 142 Practically a Posting Shark

how can i avoid the flicker?

cambalinho 142 Practically a Posting Shark

now works fine..thanks for all ;)

RECT d;
                GetClientRect(hwnd,&d);
                RedrawWindow(hwnd,&d,nullptr,RDW_ERASE);

triumphost: please can you tell me the diference between that 4 functions?
(include the TRUE\FALSE of the Invalidate)

cambalinho 142 Practically a Posting Shark

i did that triumphost. but now i know why isn't working. the STATIC control is like a draw text, on form\window paint message.
so i will create another control, like button, and then maybe i can resolve it ;)

cambalinho 142 Practically a Posting Shark

i'm sorry.. what code is that? i'm in right sub-forum, i think