Solved

Bitmaps in RichEdit CTRLS

Posted on 1999-01-08
2
154 Views
Last Modified: 2010-04-02
How can I mix pictures with text in a RichText Control in Visual C++ using MFC? I tried using the PasteSpecial Method but it didn't work.
0
Comment
Question by:neamtu
2 Comments
 

Author Comment

by:neamtu
ID: 1181742
If you know the answer please include a small example...
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1181743
Ok, here is some code... try it out and see how it works...
===========UNIT1.H==============
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:      // IDE-managed Components
    TRichEdit *RichEdit1;void __fastcall FormCreate(TObject *Sender);void __fastcall MyWndProc(TMessage &Message);
    void __fastcall FormDestroy(TObject *Sender);
private:      // User declarations
public:            // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
=============UNIT1.CPP===================
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;

TWndMethod OldWndProc;
Graphics::TBitmap *bmp;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MyWndProc(TMessage &Message)
{
    OldWndProc(Message);
    if (Message.Msg == WM_PAINT) {
        TCanvas *MyCanvas = new TCanvas;
        MyCanvas->Handle = GetDC(RichEdit1->Handle);
        BitBlt(MyCanvas->Handle, 0, 0, bmp->Width, bmp->Height, bmp->Canvas->Handle, 0, 0, SRCCOPY);
        ReleaseDC(RichEdit1->Handle, MyCanvas->Handle);
        delete MyCanvas;
    }
}



void __fastcall TForm1::FormCreate(TObject *Sender)
{
    OldWndProc = RichEdit1->WindowProc;
    RichEdit1->WindowProc = MyWndProc;
    bmp = new Graphics::TBitmap;
 //You MUST have a file on the desktop in order for it to work
    bmp->LoadFromFile("C:\\windows\\desktop\\test.bmp");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
    delete bmp;
}
//---------------------------------------------------------------------------
===================

Hope this helps...

-Viktor
--Ivanov
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now