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. Clear text from a device context.

Clear text from a device context.

Scheduled Pinned Locked Moved C / C++ / MFC
question
24 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.
  • M Offline
    M Offline
    Mr Simple
    wrote on last edited by
    #1

    Hi, I have written text to a device context using "dc.DrawText()" onto a transparent background. The text needs to move, but it leaves the old text on the DC, which just causes a long black smudge. As I mentioned, the background is transparent, so I cant just blit the background again. I have noticed that calling ShowWindow(SW_HIDE); then re-showing it clears the text, however I make the text move from within the OnPaint method, which obviously causes problems if I hide/show it constantly. Does anyone have any ideas as to how I can remove the text? Thanks. MS.

    C N 2 Replies Last reply
    0
    • M Mr Simple

      Hi, I have written text to a device context using "dc.DrawText()" onto a transparent background. The text needs to move, but it leaves the old text on the DC, which just causes a long black smudge. As I mentioned, the background is transparent, so I cant just blit the background again. I have noticed that calling ShowWindow(SW_HIDE); then re-showing it clears the text, however I make the text move from within the OnPaint method, which obviously causes problems if I hide/show it constantly. Does anyone have any ideas as to how I can remove the text? Thanks. MS.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Mr Simple wrote:

      however I make the text move from within the OnPaint method

      Is it a good idea? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      M 1 Reply Last reply
      0
      • C CPallini

        Mr Simple wrote:

        however I make the text move from within the OnPaint method

        Is it a good idea? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        M Offline
        M Offline
        Mr Simple
        wrote on last edited by
        #3

        Well, by 'move' i mean more 'repostitioned'. The location of the text is based upon a number of variables, the window itself is a large mishaped window. How do you think I should be drawing the text?

        C 1 Reply Last reply
        0
        • M Mr Simple

          Well, by 'move' i mean more 'repostitioned'. The location of the text is based upon a number of variables, the window itself is a large mishaped window. How do you think I should be drawing the text?

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          Well. I don't know exactly your needs. Anyway, I think the current text position has to be assigned outside the OnPaint method (for instance inside a timer) and then you have to invalidate both the latest text rectangle and the current text one and, finally, you have to call UpdateWindow to let OnPaint doing its job. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          M 1 Reply Last reply
          0
          • M Mr Simple

            Hi, I have written text to a device context using "dc.DrawText()" onto a transparent background. The text needs to move, but it leaves the old text on the DC, which just causes a long black smudge. As I mentioned, the background is transparent, so I cant just blit the background again. I have noticed that calling ShowWindow(SW_HIDE); then re-showing it clears the text, however I make the text move from within the OnPaint method, which obviously causes problems if I hide/show it constantly. Does anyone have any ideas as to how I can remove the text? Thanks. MS.

            N Offline
            N Offline
            Nelek
            wrote on last edited by
            #5

            Are you using Invalidate () before calling UpdateWindow () ?? It mades the drawing surface to be erased and then repainted, so the old text will be away, and just the new "repositioned" will be drawn.

            Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

            1 Reply Last reply
            0
            • C CPallini

              Well. I don't know exactly your needs. Anyway, I think the current text position has to be assigned outside the OnPaint method (for instance inside a timer) and then you have to invalidate both the latest text rectangle and the current text one and, finally, you have to call UpdateWindow to let OnPaint doing its job. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              M Offline
              M Offline
              Mr Simple
              wrote on last edited by
              #6

              How do you suggest I set the text from outside the paint method? Another reason I chose to use OnPaint is that I dont know how to do it without having the DC variable to use the .DrawText with! @Nelek, I have tried both Invalidate (entire), InvalidateRect (text in rectangles), and InvalidateRgn (dc region) all to no avail! Thank you for your time. MS

              C M 2 Replies Last reply
              0
              • M Mr Simple

                How do you suggest I set the text from outside the paint method? Another reason I chose to use OnPaint is that I dont know how to do it without having the DC variable to use the .DrawText with! @Nelek, I have tried both Invalidate (entire), InvalidateRect (text in rectangles), and InvalidateRgn (dc region) all to no avail! Thank you for your time. MS

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                Of course drawing should happen inside OnPaint method. Now suppose ('cause I don't know yet what are you trying to do...) you're doing a kind of animation of your text and, say rcCur is the current text rectangle. Inside the timer procedure you can: (1) Compute next position text rectangle rcNext. (2) Invalidate both rcCur, rcNext rectangles. (3) Set rcCur = rcNext. (4) call UpdateWindow. Point (4) makes OnPaint being called and your text position updated. Hope that helps. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                1 Reply Last reply
                0
                • M Mr Simple

                  How do you suggest I set the text from outside the paint method? Another reason I chose to use OnPaint is that I dont know how to do it without having the DC variable to use the .DrawText with! @Nelek, I have tried both Invalidate (entire), InvalidateRect (text in rectangles), and InvalidateRgn (dc region) all to no avail! Thank you for your time. MS

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  Also, keep in mind - you don't need to preserve a DC between WM_PAINT messages. The DC does not remember where you draw text - that's up to you to store. A DC is more like a canvas - when you paint on it, that's it. If you want to "move" something you've painted, you need to paint over the old item and repaint the item at it's new location. Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  M L 2 Replies Last reply
                  0
                  • M Mark Salsbery

                    Also, keep in mind - you don't need to preserve a DC between WM_PAINT messages. The DC does not remember where you draw text - that's up to you to store. A DC is more like a canvas - when you paint on it, that's it. If you want to "move" something you've painted, you need to paint over the old item and repaint the item at it's new location. Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    M Offline
                    M Offline
                    Mr Simple
                    wrote on last edited by
                    #9

                    Hi, I am not (knowingly/intentionally) preserving the DC. I am able to get this to work over sections of the DC are not transparent (the redrawn image covers the old text) but I am unable to draw over the transparent old text because I dont know what lies underneath. CPallini - I hope I am not coming across as stupid, but I still cannot get your suggestion to work. Please correct my thinking if it is wrong (see below); Thank you for your time. MS. // // A gloabal rectangle. CRect rTextMain; // // In my timer; CRect rMoveTo; InvalidateRect(&rTextMain); // Your steps said to do this after, I tried both. InvalidateRect(&rMoveTo); rMoveTo.top = val1; rMoveTo.left....... rTextMain = rMoveTo; UpdateWindow(); // // In OnPaint; CFont newFont; newFont.CreateFont(15, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, _T("MS Sans Serif")); CFont *oldFont = dc.SelectObject(&newFont); CString sWords = "test"; dc.DrawText(sWords, &rTextMain, DT_TOP | DT_LEFT)

                    M 1 Reply Last reply
                    0
                    • M Mr Simple

                      Hi, I am not (knowingly/intentionally) preserving the DC. I am able to get this to work over sections of the DC are not transparent (the redrawn image covers the old text) but I am unable to draw over the transparent old text because I dont know what lies underneath. CPallini - I hope I am not coming across as stupid, but I still cannot get your suggestion to work. Please correct my thinking if it is wrong (see below); Thank you for your time. MS. // // A gloabal rectangle. CRect rTextMain; // // In my timer; CRect rMoveTo; InvalidateRect(&rTextMain); // Your steps said to do this after, I tried both. InvalidateRect(&rMoveTo); rMoveTo.top = val1; rMoveTo.left....... rTextMain = rMoveTo; UpdateWindow(); // // In OnPaint; CFont newFont; newFont.CreateFont(15, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, _T("MS Sans Serif")); CFont *oldFont = dc.SelectObject(&newFont); CString sWords = "test"; dc.DrawText(sWords, &rTextMain, DT_TOP | DT_LEFT)

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      You've used rMoveTo before it's initialized. You shouldn't need the second (rMoveTo) rect. This should be enough:

                      //
                      // A gloabal rectangle.
                      CRect rTextMain;

                      //
                      // In my timer;
                      InvalidateRect(&rTextMain); // Your steps said to do this after, I tried both.

                      rTextMain.top = val1; rTextMain.left.......

                      UpdateWindow();

                      //
                      // In OnPaint;
                      CFont newFont;
                      newFont.CreateFont(15, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, _T("MS Sans Serif"));
                      CFont *oldFont = dc.SelectObject(&newFont);

                      CString sWords = "test";
                      dc.DrawText(sWords, &rTextMain, DT_TOP | DT_LEFT)

                      The WM_ERASEBKGND should take care of the invalidated rect. Then the WM_PAINT handler should draw the text at the new location. I don't see anything related to transparency or images. Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      M 1 Reply Last reply
                      0
                      • M Mark Salsbery

                        Also, keep in mind - you don't need to preserve a DC between WM_PAINT messages. The DC does not remember where you draw text - that's up to you to store. A DC is more like a canvas - when you paint on it, that's it. If you want to "move" something you've painted, you need to paint over the old item and repaint the item at it's new location. Mark

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        L Offline
                        L Offline
                        led mike
                        wrote on last edited by
                        #11

                        Mark Salsbery wrote:

                        you don't need to preserve a DC between WM_PAINT messages.

                        ummm.... don't you mean you should not?

                        M 1 Reply Last reply
                        0
                        • L led mike

                          Mark Salsbery wrote:

                          you don't need to preserve a DC between WM_PAINT messages.

                          ummm.... don't you mean you should not?

                          M Offline
                          M Offline
                          Mark Salsbery
                          wrote on last edited by
                          #12

                          led mike wrote:

                          don't you mean you should not?

                          For the sake of this thread - yes. Discussing owned DCs is beyond the scope of the problem/OP/thread, IMO :) Mark

                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                          1 Reply Last reply
                          0
                          • M Mark Salsbery

                            You've used rMoveTo before it's initialized. You shouldn't need the second (rMoveTo) rect. This should be enough:

                            //
                            // A gloabal rectangle.
                            CRect rTextMain;

                            //
                            // In my timer;
                            InvalidateRect(&rTextMain); // Your steps said to do this after, I tried both.

                            rTextMain.top = val1; rTextMain.left.......

                            UpdateWindow();

                            //
                            // In OnPaint;
                            CFont newFont;
                            newFont.CreateFont(15, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, _T("MS Sans Serif"));
                            CFont *oldFont = dc.SelectObject(&newFont);

                            CString sWords = "test";
                            dc.DrawText(sWords, &rTextMain, DT_TOP | DT_LEFT)

                            The WM_ERASEBKGND should take care of the invalidated rect. Then the WM_PAINT handler should draw the text at the new location. I don't see anything related to transparency or images. Mark

                            Mark Salsbery Microsoft MVP - Visual C++ :java:

                            M Offline
                            M Offline
                            Mr Simple
                            wrote on last edited by
                            #13

                            Hi, Unfortunately I could not get this to work either. Do you have any other ideas? This is being run on Win CE by the way. I didn't put the transparency stuff in the last post, but it comes just before the text is printed. A global region is made in the constructor with bits missing (missing bits are therefore transparent). The images are loaded into a CBitmap array. In OnPaint; To display the BMP; Create CDC from DC CDC select object (global/main region) CDC select object (bitmap) TransparentBlt to DC; TransparentBlt(dc.GetSafeHdc(), 0, 0, floatingBMP.bmWidth, floatingBMP.bmHeight, myCDC->GetSafeHdc(), 0, 0, floatingBMP.bmWidth, floatingBMP.bmHeight, 0x00ff00);// Transparency = lime green, altho this doesnt matter as the region has already been created to take this into account; After this is the DrawText code which has already been show. Any ideas? Thanks MS.

                            M 1 Reply Last reply
                            0
                            • M Mr Simple

                              Hi, Unfortunately I could not get this to work either. Do you have any other ideas? This is being run on Win CE by the way. I didn't put the transparency stuff in the last post, but it comes just before the text is printed. A global region is made in the constructor with bits missing (missing bits are therefore transparent). The images are loaded into a CBitmap array. In OnPaint; To display the BMP; Create CDC from DC CDC select object (global/main region) CDC select object (bitmap) TransparentBlt to DC; TransparentBlt(dc.GetSafeHdc(), 0, 0, floatingBMP.bmWidth, floatingBMP.bmHeight, myCDC->GetSafeHdc(), 0, 0, floatingBMP.bmWidth, floatingBMP.bmHeight, 0x00ff00);// Transparency = lime green, altho this doesnt matter as the region has already been created to take this into account; After this is the DrawText code which has already been show. Any ideas? Thanks MS.

                              M Offline
                              M Offline
                              Mark Salsbery
                              wrote on last edited by
                              #14

                              Without knowing what's not working...

                              Mr Simple wrote:

                              Create CDC from DC

                              How are you doing this? It should be a memory DC created with CDC::CreateCompatibleDC().

                              Mr Simple wrote:

                              CDC select object (global/main region)

                              What's the purpose of the region - for clipping? Why select it into the source DC? That looks suspicious...I would try commenting the region stuff out and see what happens. Are you handling WM_ERASEBKGND? If so, what are you doing there? What do you want to see and what is happening that is wrong? Mark

                              Mark Salsbery Microsoft MVP - Visual C++ :java:

                              M 1 Reply Last reply
                              0
                              • M Mark Salsbery

                                Without knowing what's not working...

                                Mr Simple wrote:

                                Create CDC from DC

                                How are you doing this? It should be a memory DC created with CDC::CreateCompatibleDC().

                                Mr Simple wrote:

                                CDC select object (global/main region)

                                What's the purpose of the region - for clipping? Why select it into the source DC? That looks suspicious...I would try commenting the region stuff out and see what happens. Are you handling WM_ERASEBKGND? If so, what are you doing there? What do you want to see and what is happening that is wrong? Mark

                                Mark Salsbery Microsoft MVP - Visual C++ :java:

                                M Offline
                                M Offline
                                Mr Simple
                                wrote on last edited by
                                #15

                                Hi, I am using CreateCompatibleDC; CPaintDC dc(this); // device context for painting CDC *floatCDC = new CDC; floatCDC->CreateCompatibleDC(&dc); I have removed the region code, and can report having it there made no difference to my application. I had read about it in a 'funky shaped window' article and assumed I needed it, obviously I was wrong :-) I am not handling WM_ERASEBKGND. What I want to see is text moving on a transparent background. I have manged this to a degree, however when the text is moved, the old text remains underneath the new text. I think part of the problem is that I am drawing over the old text with a transparent image, so the old text is still visible. Any other ideas? Thank you for your time! MS

                                M 1 Reply Last reply
                                0
                                • M Mr Simple

                                  Hi, I am using CreateCompatibleDC; CPaintDC dc(this); // device context for painting CDC *floatCDC = new CDC; floatCDC->CreateCompatibleDC(&dc); I have removed the region code, and can report having it there made no difference to my application. I had read about it in a 'funky shaped window' article and assumed I needed it, obviously I was wrong :-) I am not handling WM_ERASEBKGND. What I want to see is text moving on a transparent background. I have manged this to a degree, however when the text is moved, the old text remains underneath the new text. I think part of the problem is that I am drawing over the old text with a transparent image, so the old text is still visible. Any other ideas? Thank you for your time! MS

                                  M Offline
                                  M Offline
                                  Mark Salsbery
                                  wrote on last edited by
                                  #16

                                  Here's a working example, moving text with a timer across a bitmap background. This is implemented on a simple dialog with just an ok button.  The same code would work in a CWnd-derived class - In that case, WM_CREATE/OnCreate would be used instead of OnInitDialog()...

                                  #pragma once

                                  #include <atlimage.h>

                                  // CMovingTextDialog dialog

                                  class CMovingTextDialog : public CDialog
                                  {
                                      DECLARE_DYNAMIC(CMovingTextDialog)

                                  public:
                                      CMovingTextDialog(CWnd* pParent = NULL);   // standard constructor
                                      virtual ~CMovingTextDialog();

                                  // Dialog Data
                                      enum { IDD = IDD_DIALOG2 }; //<-- Use the correct dialog resource ID here!

                                  protected:
                                      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

                                  DECLARE_MESSAGE_MAP()
                                  public:
                                      virtual BOOL OnInitDialog();
                                  protected:
                                      virtual void OnOK();
                                  public:
                                      CImage BkImage;
                                      UINT_PTR MoveTimer;
                                      CString TextStr;
                                      CSize TextSize;
                                      CRect TextRect;

                                  afx_msg void OnPaint();
                                      afx_msg BOOL OnEraseBkgnd(CDC* pDC);
                                      afx_msg void OnTimer(UINT_PTR nIDEvent);

                                  };

                                  // MovingTextDialog.cpp : implementation file
                                  //

                                  #include "stdafx.h"
                                  #include "MFCTester.h"
                                  #include "MovingTextDialog.h"

                                  // CMovingTextDialog dialog

                                  IMPLEMENT_DYNAMIC(CMovingTextDialog, CDialog)

                                  CMovingTextDialog::CMovingTextDialog(CWnd* pParent /*=NULL*/)
                                      : CDialog(CMovingTextDialog::IDD, pParent)
                                  {
                                      BkImage.Load(_T("e:\\test.bmp")); //<-- load your own bmp/jpg/tiff here!
                                      MoveTimer = 0;
                                      TextStr = _T("Moving Text");
                                      TextSize.cx = TextSize.cy = 0;
                                      TextRect.SetRect(0,0,0,0);
                                  }

                                  CMovingTextDialog::~CMovingTextDialog()
                                  {
                                  }

                                  void CMovingTextDialog::DoDataExchange(CDataExchange* pDX)
                                  {
                                      CDialog::DoDataExchange(pDX);
                                  }

                                  BEGIN_MESSAGE_MAP(CMovingTextDialog, CDialog)
                                      ON_WM_PAINT()
                                      ON_WM_ERASEBKGND()
                                      ON_WM_TIMER()
                                  END_MESSAGE_MAP()

                                  // CMovingTextDialog message handlers

                                  BOOL CMovingTextDialog::OnInitDialog()
                                  {
                                      CDialog::OnInitDialog();

                                  MoveTimer = ::SetTimer(*this, (UINT_PTR)12345, 10, NULL);

                                  return TRUE;&n

                                  M 1 Reply Last reply
                                  0
                                  • M Mark Salsbery

                                    Here's a working example, moving text with a timer across a bitmap background. This is implemented on a simple dialog with just an ok button.  The same code would work in a CWnd-derived class - In that case, WM_CREATE/OnCreate would be used instead of OnInitDialog()...

                                    #pragma once

                                    #include <atlimage.h>

                                    // CMovingTextDialog dialog

                                    class CMovingTextDialog : public CDialog
                                    {
                                        DECLARE_DYNAMIC(CMovingTextDialog)

                                    public:
                                        CMovingTextDialog(CWnd* pParent = NULL);   // standard constructor
                                        virtual ~CMovingTextDialog();

                                    // Dialog Data
                                        enum { IDD = IDD_DIALOG2 }; //<-- Use the correct dialog resource ID here!

                                    protected:
                                        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

                                    DECLARE_MESSAGE_MAP()
                                    public:
                                        virtual BOOL OnInitDialog();
                                    protected:
                                        virtual void OnOK();
                                    public:
                                        CImage BkImage;
                                        UINT_PTR MoveTimer;
                                        CString TextStr;
                                        CSize TextSize;
                                        CRect TextRect;

                                    afx_msg void OnPaint();
                                        afx_msg BOOL OnEraseBkgnd(CDC* pDC);
                                        afx_msg void OnTimer(UINT_PTR nIDEvent);

                                    };

                                    // MovingTextDialog.cpp : implementation file
                                    //

                                    #include "stdafx.h"
                                    #include "MFCTester.h"
                                    #include "MovingTextDialog.h"

                                    // CMovingTextDialog dialog

                                    IMPLEMENT_DYNAMIC(CMovingTextDialog, CDialog)

                                    CMovingTextDialog::CMovingTextDialog(CWnd* pParent /*=NULL*/)
                                        : CDialog(CMovingTextDialog::IDD, pParent)
                                    {
                                        BkImage.Load(_T("e:\\test.bmp")); //<-- load your own bmp/jpg/tiff here!
                                        MoveTimer = 0;
                                        TextStr = _T("Moving Text");
                                        TextSize.cx = TextSize.cy = 0;
                                        TextRect.SetRect(0,0,0,0);
                                    }

                                    CMovingTextDialog::~CMovingTextDialog()
                                    {
                                    }

                                    void CMovingTextDialog::DoDataExchange(CDataExchange* pDX)
                                    {
                                        CDialog::DoDataExchange(pDX);
                                    }

                                    BEGIN_MESSAGE_MAP(CMovingTextDialog, CDialog)
                                        ON_WM_PAINT()
                                        ON_WM_ERASEBKGND()
                                        ON_WM_TIMER()
                                    END_MESSAGE_MAP()

                                    // CMovingTextDialog message handlers

                                    BOOL CMovingTextDialog::OnInitDialog()
                                    {
                                        CDialog::OnInitDialog();

                                    MoveTimer = ::SetTimer(*this, (UINT_PTR)12345, 10, NULL);

                                    return TRUE;&n

                                    M Offline
                                    M Offline
                                    Mr Simple
                                    wrote on last edited by
                                    #17

                                    Hello, The only major difference is that I am not using CImage, as I need to be able to TransparentBlt which I have been told there are problems with on WinCE. I converted your code closer to my existing (using CBitmap, transparency, removing erase bkground) and it worked great. Then I made my existing code practically idential, and it still didn't work :-( The only thing I can find different is the way I create the window. I have a method in the class called "CreateFloaterWnd" (parent as parameter) which loads the bitmap, gets it's size, then calls CWnd::CreateEx, positioning itself relative to the parent's X/Y location. I will try to convert it to use a dialog and see what happens. I still dont understand how this could be the problem though. Thank you very much for your effort!! MS.

                                    M 1 Reply Last reply
                                    0
                                    • M Mr Simple

                                      Hello, The only major difference is that I am not using CImage, as I need to be able to TransparentBlt which I have been told there are problems with on WinCE. I converted your code closer to my existing (using CBitmap, transparency, removing erase bkground) and it worked great. Then I made my existing code practically idential, and it still didn't work :-( The only thing I can find different is the way I create the window. I have a method in the class called "CreateFloaterWnd" (parent as parameter) which loads the bitmap, gets it's size, then calls CWnd::CreateEx, positioning itself relative to the parent's X/Y location. I will try to convert it to use a dialog and see what happens. I still dont understand how this could be the problem though. Thank you very much for your effort!! MS.

                                      M Offline
                                      M Offline
                                      Mark Salsbery
                                      wrote on last edited by
                                      #18

                                      Hmmm I don't know about WinCE unfortunately. CImage wraps a little GDI+ for loading and saving, and also wraps a HBITMAP/DIBSection, which works with TransparentBlt() just fine (in fact, the class has a TransparentBlt() method). Again, I'm not sure about WinCE compatibility though. If you have a little project that doesn't work that I can test on regular Windows I'll check it out. Good luck :) Mark

                                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                                      M 1 Reply Last reply
                                      0
                                      • M Mark Salsbery

                                        Hmmm I don't know about WinCE unfortunately. CImage wraps a little GDI+ for loading and saving, and also wraps a HBITMAP/DIBSection, which works with TransparentBlt() just fine (in fact, the class has a TransparentBlt() method). Again, I'm not sure about WinCE compatibility though. If you have a little project that doesn't work that I can test on regular Windows I'll check it out. Good luck :) Mark

                                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                                        M Offline
                                        M Offline
                                        Mr Simple
                                        wrote on last edited by
                                        #19

                                        Hi, Everything in normal windows can be done in CE, sometimes you just need to go about it a bit differently. I have cut out everything from my project and managed to write a non-working class if you are interested. I wont have access to CE again until monday so wont be able to test the dialog thing yet. Below is the code, it is very simple as you can probably see. Just call the .CreateTransparent(this); and you should get a nice streak down the form. Once again, thanks for your help! MS. The .H; class CNotWorking : public CWnd { public: CNotWorking(void); ~CNotWorking(void); void CreateTransparent(CWnd *pParent); DECLARE_MESSAGE_MAP() afx_msg void OnPaint(); afx_msg void OnTimer(UINT nIDEvent); private: CRect rTextRect; UINT tTicker; }; ////////// And the .CPP; BEGIN_MESSAGE_MAP(CNotWorking, CWnd) ON_WM_PAINT() ON_WM_TIMER() END_MESSAGE_MAP() CNotWorking::CNotWorking(void) { rTextRect.SetRect(0, 0, 40, 20); tTicker = 0; } CNotWorking::~CNotWorking(void) { } void CNotWorking::CreateTransparent(CWnd *pParent) { // Create & flag as existing. CWnd::CreateEx(NULL, NULL, _T("Transparent"), WS_CHILD, 20, 20, 500, 500, pParent->GetSafeHwnd(), NULL); tTicker = ::SetTimer(*this, (UINT_PTR)12345, 20, NULL); ShowWindow(SW_SHOW); } void CNotWorking::OnPaint() { CPaintDC dc(this); // device context for painting dc.SetBkMode(TRANSPARENT); CString textStr = "test"; dc.DrawText(textStr, &rTextRect, DT_LEFT | DT_TOP); } void CNotWorking::OnTimer(UINT nIDEvent) { InvalidateRect(rTextRect); rTextRect.OffsetRect(0, 2); UpdateWindow(); CWnd::OnTimer(nIDEvent); }

                                        M 1 Reply Last reply
                                        0
                                        • M Mr Simple

                                          Hi, Everything in normal windows can be done in CE, sometimes you just need to go about it a bit differently. I have cut out everything from my project and managed to write a non-working class if you are interested. I wont have access to CE again until monday so wont be able to test the dialog thing yet. Below is the code, it is very simple as you can probably see. Just call the .CreateTransparent(this); and you should get a nice streak down the form. Once again, thanks for your help! MS. The .H; class CNotWorking : public CWnd { public: CNotWorking(void); ~CNotWorking(void); void CreateTransparent(CWnd *pParent); DECLARE_MESSAGE_MAP() afx_msg void OnPaint(); afx_msg void OnTimer(UINT nIDEvent); private: CRect rTextRect; UINT tTicker; }; ////////// And the .CPP; BEGIN_MESSAGE_MAP(CNotWorking, CWnd) ON_WM_PAINT() ON_WM_TIMER() END_MESSAGE_MAP() CNotWorking::CNotWorking(void) { rTextRect.SetRect(0, 0, 40, 20); tTicker = 0; } CNotWorking::~CNotWorking(void) { } void CNotWorking::CreateTransparent(CWnd *pParent) { // Create & flag as existing. CWnd::CreateEx(NULL, NULL, _T("Transparent"), WS_CHILD, 20, 20, 500, 500, pParent->GetSafeHwnd(), NULL); tTicker = ::SetTimer(*this, (UINT_PTR)12345, 20, NULL); ShowWindow(SW_SHOW); } void CNotWorking::OnPaint() { CPaintDC dc(this); // device context for painting dc.SetBkMode(TRANSPARENT); CString textStr = "test"; dc.DrawText(textStr, &rTextRect, DT_LEFT | DT_TOP); } void CNotWorking::OnTimer(UINT nIDEvent) { InvalidateRect(rTextRect); rTextRect.OffsetRect(0, 2); UpdateWindow(); CWnd::OnTimer(nIDEvent); }

                                          M Offline
                                          M Offline
                                          Mark Salsbery
                                          wrote on last edited by
                                          #20

                                          Your code works for me. In OnTimer(), I had to change InvalidateRect(rTextRect); to InvalidateRect(&rTextRect); Mark

                                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                                          M 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