Bitmap als Button



  • Hallo,
    ich möchten dem so eigefügten Bitmap die Funktion eines Buttons geben;d.h.
    wenn ich draufklicke dann müßte ich eine Funktion aufrufen können.

    Kann mir jemand helfen ?

    CString szFilename5_5 = "5_5.BMP";

    HBITMAP hBmp5_5 = (HBITMAP)::LoadImage(NULL,szFilename5_5, IMAGE_BITMAP,0,0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);

    CBitmap bmp5_5;
    bmp5_5.Attach(hBmp5_5);

    CClientDC dc5_5(this);
    CDC bmDC5_5;
    bmDC5_5.CreateCompatibleDC(&dc5_5);
    CBitmap *pOldbmp5_5 = bmDC5_5.SelectObject(&bmp5_5);

    BITMAP bi5_5;
    bmp5_5.GetBitmap(&bi5_5);

    dc5_5.BitBlt(775,250,bi5_5.bmWidth,bi5_5.bmHeight,&bmDC5_5,0,0,SRCCOPY);

    bmDC5_5.SelectObject(pOldbmp5_5);



  • Da musste eine Klasse von CStatic ableiten, die virtuelle methode presubclasswindow überschreiben, davon eine Variable erstellen und diese deiner bitmap zuordnen. -msdn-



  • Hier etwas Code:

    // headerfile
    /*****************************************************************************
    
    ******************************************************************************/
    
    #ifndef _CSTATICBUTTON_H_
    #define _CSTATICBUTTON_H_
    
    /*****************************************************************************/
    
    #if _MSC_VER > 1000
    #pragma once
    #endif 
    
    /*****************************************************************************/
    
    /*****************************************************************************/
    
    class CStaticButton : public CStatic  
    {
    public:
        CStaticButton();
        virtual ~CStaticButton();
        virtual void PreSubclassWindow();
    };
    
    /*****************************************************************************/
    
    #endif 
    
    /*****************************************************************************/
    /*****************************************************************************/
    /*****************************************************************************/
    
    // cpp file
    /*****************************************************************************
    
    ******************************************************************************/
    
    #include "stdafx.h"
    #include "DeinDialog.h"
    #include "StaticButton.h"
    
    //*****************************************************************************
    //
    //*****************************************************************************
    CStaticButton::CStaticButton()
    {
    
    }
    
    //*****************************************************************************
    //
    //*****************************************************************************
    CStaticButton::~CStaticButton()
    {
    
    }
    
    //*****************************************************************************
    //
    //*****************************************************************************
    
    void CStaticButton::PreSubclassWindow()
    {
        ModifyStyle(0,SS_NOTIFY);
    }
    
    //*****************************************************************************
    //*****************************************************************************
    //*****************************************************************************
    

    also nochmal: bildresource mit resourceneditor erstellen, dem Bild eine membervariable vom Type CStaticButton zuweisen, thats it !


Anmelden zum Antworten