Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. can anyone convert this MFC code to WIN32 code please help

can anyone convert this MFC code to WIN32 code please help

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G goldenrose9

    .

    Some Day I Will Prove MySelf :: GOLD

    modified on Monday, March 21, 2011 2:13 PM

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #3

    The majority of MFC class methods have equivalents in Win32; check the documentation on MSDN for any extra parameters needed. The CDC and CBitmap objects would be replaced by HDC and HBITMAP handles. It is simply a matter of reading the documentation and modifying the code according to the correct rules.

    I must get a clever new signature for 2011.

    G 1 Reply Last reply
    0
    • L Lost User

      The majority of MFC class methods have equivalents in Win32; check the documentation on MSDN for any extra parameters needed. The CDC and CBitmap objects would be replaced by HDC and HBITMAP handles. It is simply a matter of reading the documentation and modifying the code according to the correct rules.

      I must get a clever new signature for 2011.

      G Offline
      G Offline
      goldenrose9
      wrote on last edited by
      #4

      sir, i had try to convert the above code. but this code doesn't work at all. please check it.

      COLORREF m_crBlack;
      COLORREF m_crWhite;

      int Height();
      int Width();
      void InitBMP();
      void DrawTransparent(HDC* pDC, int x, int y, COLORREF crColour);

      void InitBMP()
      {
      m_crBlack = 0;
      m_crWhite = RGB(255,255,255);
      }
      int Width()
      {
      BITMAP bm={0};
      //SIZE lp ={0};
      //GetBitmapDimensionEx(bm,&lp);
      //return lp.cx;
      GetObject(&bm,sizeof(BITMAP),&bm);
      return bm.bmWidth;
      }
      int Height()
      {
      BITMAP bm={0};
      //SIZE lp={0};
      //GetBitmapDimensionEx(bm,&lp);
      //return lp.cy;
      GetObject(&bm, sizeof(BITMAP),&bm);
      return bm.bmHeight;
      }
      void DrawTransparent(HDC pDC, int x, int y, COLORREF crColour)
      {
      COLORREF croldBack = SetBkColor(pDC,m_crWhite);
      COLORREF croldText = SetTextColor(pDC,m_crBlack);

      //create two memory dcs for the image and the mask;
      HDC dcImage = CreateCompatibleDC(pDC);
      HDC dcTrans = CreateCompatibleDC(pDC);
      
      
      //Select the image into the appropriate dc
      HBITMAP pOldBitmapImage = NULL;
      SelectObject(dcImage,pOldBitmapImage);
      //SelectObject(dcImage,this);
      
      //create the mask bitmap
      HBITMAP bitmapTrans = NULL;
      int nWidth = Width();
      int nHeight =Height();
      
      bitmapTrans = CreateBitmap(nWidth,nHeight,1,1,NULL);
      
      //select the mast bitmap into the appropriate dc
      HBITMAP pOldBitmapTrans= NULL;
      SelectObject(dcTrans,bitmapTrans);
      
      //Build mask based on transparent color	
      SetBkColor(dcImage,crColour);
      BitBlt(dcTrans,0,0,nWidth,nHeight,dcImage,0,0,SRCCOPY);
      
      //Do the work true mask method
      BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT);
      BitBlt(pDC,x,y,nWidth,nHeight,dcTrans,0,0,SRCAND);
      BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT);
      
      //Restore Settings
      SelectObject(dcImage,pOldBitmapImage);
      SelectObject(dcTrans,pOldBitmapTrans);
      SetBkColor(pDC,croldBack);
      SetTextColor(pDC,croldText);
      

      }

      Some Day I Will Prove MySelf :: GOLD

      L 2 Replies Last reply
      0
      • G goldenrose9

        sir, i had try to convert the above code. but this code doesn't work at all. please check it.

        COLORREF m_crBlack;
        COLORREF m_crWhite;

        int Height();
        int Width();
        void InitBMP();
        void DrawTransparent(HDC* pDC, int x, int y, COLORREF crColour);

        void InitBMP()
        {
        m_crBlack = 0;
        m_crWhite = RGB(255,255,255);
        }
        int Width()
        {
        BITMAP bm={0};
        //SIZE lp ={0};
        //GetBitmapDimensionEx(bm,&lp);
        //return lp.cx;
        GetObject(&bm,sizeof(BITMAP),&bm);
        return bm.bmWidth;
        }
        int Height()
        {
        BITMAP bm={0};
        //SIZE lp={0};
        //GetBitmapDimensionEx(bm,&lp);
        //return lp.cy;
        GetObject(&bm, sizeof(BITMAP),&bm);
        return bm.bmHeight;
        }
        void DrawTransparent(HDC pDC, int x, int y, COLORREF crColour)
        {
        COLORREF croldBack = SetBkColor(pDC,m_crWhite);
        COLORREF croldText = SetTextColor(pDC,m_crBlack);

        //create two memory dcs for the image and the mask;
        HDC dcImage = CreateCompatibleDC(pDC);
        HDC dcTrans = CreateCompatibleDC(pDC);
        
        
        //Select the image into the appropriate dc
        HBITMAP pOldBitmapImage = NULL;
        SelectObject(dcImage,pOldBitmapImage);
        //SelectObject(dcImage,this);
        
        //create the mask bitmap
        HBITMAP bitmapTrans = NULL;
        int nWidth = Width();
        int nHeight =Height();
        
        bitmapTrans = CreateBitmap(nWidth,nHeight,1,1,NULL);
        
        //select the mast bitmap into the appropriate dc
        HBITMAP pOldBitmapTrans= NULL;
        SelectObject(dcTrans,bitmapTrans);
        
        //Build mask based on transparent color	
        SetBkColor(dcImage,crColour);
        BitBlt(dcTrans,0,0,nWidth,nHeight,dcImage,0,0,SRCCOPY);
        
        //Do the work true mask method
        BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT);
        BitBlt(pDC,x,y,nWidth,nHeight,dcTrans,0,0,SRCAND);
        BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT);
        
        //Restore Settings
        SelectObject(dcImage,pOldBitmapImage);
        SelectObject(dcTrans,pOldBitmapTrans);
        SetBkColor(pDC,croldBack);
        SetTextColor(pDC,croldText);
        

        }

        Some Day I Will Prove MySelf :: GOLD

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #5

        goldenrose9 wrote:

        but this code doesn't work at all.

        May I suggest you try using your debugger to find out why.

        I must get a clever new signature for 2011.

        1 Reply Last reply
        0
        • G goldenrose9

          sir, i had try to convert the above code. but this code doesn't work at all. please check it.

          COLORREF m_crBlack;
          COLORREF m_crWhite;

          int Height();
          int Width();
          void InitBMP();
          void DrawTransparent(HDC* pDC, int x, int y, COLORREF crColour);

          void InitBMP()
          {
          m_crBlack = 0;
          m_crWhite = RGB(255,255,255);
          }
          int Width()
          {
          BITMAP bm={0};
          //SIZE lp ={0};
          //GetBitmapDimensionEx(bm,&lp);
          //return lp.cx;
          GetObject(&bm,sizeof(BITMAP),&bm);
          return bm.bmWidth;
          }
          int Height()
          {
          BITMAP bm={0};
          //SIZE lp={0};
          //GetBitmapDimensionEx(bm,&lp);
          //return lp.cy;
          GetObject(&bm, sizeof(BITMAP),&bm);
          return bm.bmHeight;
          }
          void DrawTransparent(HDC pDC, int x, int y, COLORREF crColour)
          {
          COLORREF croldBack = SetBkColor(pDC,m_crWhite);
          COLORREF croldText = SetTextColor(pDC,m_crBlack);

          //create two memory dcs for the image and the mask;
          HDC dcImage = CreateCompatibleDC(pDC);
          HDC dcTrans = CreateCompatibleDC(pDC);
          
          
          //Select the image into the appropriate dc
          HBITMAP pOldBitmapImage = NULL;
          SelectObject(dcImage,pOldBitmapImage);
          //SelectObject(dcImage,this);
          
          //create the mask bitmap
          HBITMAP bitmapTrans = NULL;
          int nWidth = Width();
          int nHeight =Height();
          
          bitmapTrans = CreateBitmap(nWidth,nHeight,1,1,NULL);
          
          //select the mast bitmap into the appropriate dc
          HBITMAP pOldBitmapTrans= NULL;
          SelectObject(dcTrans,bitmapTrans);
          
          //Build mask based on transparent color	
          SetBkColor(dcImage,crColour);
          BitBlt(dcTrans,0,0,nWidth,nHeight,dcImage,0,0,SRCCOPY);
          
          //Do the work true mask method
          BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT);
          BitBlt(pDC,x,y,nWidth,nHeight,dcTrans,0,0,SRCAND);
          BitBlt(pDC,x,y,nWidth,nHeight,dcImage,0,0,SRCINVERT);
          
          //Restore Settings
          SelectObject(dcImage,pOldBitmapImage);
          SelectObject(dcTrans,pOldBitmapTrans);
          SetBkColor(pDC,croldBack);
          SetTextColor(pDC,croldText);
          

          }

          Some Day I Will Prove MySelf :: GOLD

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #6

          In your Height and Width functions, the first argument to GetObject should be a HBITMAP, not a BITMAP*. Judging from your original post, the HBITMAP to use would be pOldBitmapImage. In the second post, you assign NULL to this, which is inconsistent with what you do in your original post; you'd want to get the HBITMAP from dcImage and put that in pOldBitmapImage.

          1 Reply Last reply
          0
          • G goldenrose9

            .

            Some Day I Will Prove MySelf :: GOLD

            modified on Monday, March 21, 2011 2:13 PM

            H Offline
            H Offline
            Hans Dietrich
            wrote on last edited by
            #7

            Why not just use the TransparentBlt function?

            Best wishes, Hans


            [Hans Dietrich Software]

            G 1 Reply Last reply
            0
            • H Hans Dietrich

              Why not just use the TransparentBlt function?

              Best wishes, Hans


              [Hans Dietrich Software]

              G Offline
              G Offline
              goldenrose9
              wrote on last edited by
              #8

              never tried sir, can you provide a small sample.

              Some Day I Will Prove MySelf :: GOLD

              H 1 Reply Last reply
              0
              • G goldenrose9

                never tried sir, can you provide a small sample.

                Some Day I Will Prove MySelf :: GOLD

                H Offline
                H Offline
                Hans Dietrich
                wrote on last edited by
                #9

                google for it, you will find lots.

                Best wishes, Hans


                [Hans Dietrich Software]

                G 1 Reply Last reply
                0
                • H Hans Dietrich

                  google for it, you will find lots.

                  Best wishes, Hans


                  [Hans Dietrich Software]

                  G Offline
                  G Offline
                  goldenrose9
                  wrote on last edited by
                  #10

                  nice joke.... Google. anyways thanx 4 d reply...

                  Some Day I Will Prove MySelf :: GOLD

                  H 1 Reply Last reply
                  0
                  • G goldenrose9

                    nice joke.... Google. anyways thanx 4 d reply...

                    Some Day I Will Prove MySelf :: GOLD

                    H Offline
                    H Offline
                    Hans Dietrich
                    wrote on last edited by
                    #11

                    goldenrose9 wrote:

                    nice joke.... Google. anyways thanx 4 d reply

                    The only joke is that you consistently ask for answers you can find yourself, using google. If you expect people to take your questions seriously, then invest a little time to try to find the answer yourself, instead of expecting other people to do your work for you. BTW, use of SMS speak is not acceptable on these forums.

                    Best wishes, Hans


                    [Hans Dietrich Software]

                    G 1 Reply Last reply
                    0
                    • H Hans Dietrich

                      goldenrose9 wrote:

                      nice joke.... Google. anyways thanx 4 d reply

                      The only joke is that you consistently ask for answers you can find yourself, using google. If you expect people to take your questions seriously, then invest a little time to try to find the answer yourself, instead of expecting other people to do your work for you. BTW, use of SMS speak is not acceptable on these forums.

                      Best wishes, Hans


                      [Hans Dietrich Software]

                      G Offline
                      G Offline
                      goldenrose9
                      wrote on last edited by
                      #12

                      i understand what you want to tell. Its a request, don't mind it, please, i don't want to get lots of anwser. how much i had asked and how complex is it. If u see this question here, i had searched the code and tried to convert it. But i failed so asked here. if you feel that i ask most then i will never ask again. Why i commented on google. because everyone out on net know google very much. this answer is simply useless.

                      Some Day I Will Prove MySelf :: GOLD

                      L 1 Reply Last reply
                      0
                      • G goldenrose9

                        i understand what you want to tell. Its a request, don't mind it, please, i don't want to get lots of anwser. how much i had asked and how complex is it. If u see this question here, i had searched the code and tried to convert it. But i failed so asked here. if you feel that i ask most then i will never ask again. Why i commented on google. because everyone out on net know google very much. this answer is simply useless.

                        Some Day I Will Prove MySelf :: GOLD

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #13

                        Here's how it went:

                        • Hans suggested you could use the TransparentBlt function, and included a link to the MSDN documentation page to help you get started.
                        • You responded by asking for a sample, rather than trying to work it out for yourself.
                        • Hans suggested (quite rightly) that there were lots to be found if you use Google.
                        • You responded by saying you thought his answer was a joke, and thus not worth consideration.
                        • Hans explained that people are not going to help you unless you are prepared to at least try and do some of your own work.
                        • You responded by a childish show of petulance, just because people will not do what you are quite capable of doing for yourself.

                        I must get a clever new signature for 2011.

                        T 1 Reply Last reply
                        0
                        • L Lost User

                          Here's how it went:

                          • Hans suggested you could use the TransparentBlt function, and included a link to the MSDN documentation page to help you get started.
                          • You responded by asking for a sample, rather than trying to work it out for yourself.
                          • Hans suggested (quite rightly) that there were lots to be found if you use Google.
                          • You responded by saying you thought his answer was a joke, and thus not worth consideration.
                          • Hans explained that people are not going to help you unless you are prepared to at least try and do some of your own work.
                          • You responded by a childish show of petulance, just because people will not do what you are quite capable of doing for yourself.

                          I must get a clever new signature for 2011.

                          T Offline
                          T Offline
                          tagopi
                          wrote on last edited by
                          #14

                          Well said Richard.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups