Solved

Bitmaps in RichEdit CTRLS

Posted on 1999-01-08
2
153 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Handling string inputs in C/Linux 23 168
ADO Memory leak with DELPHI 2007 37 155
Find Visual Studio Tools 2 78
Problem with SqlConnection 5 117
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

758 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

18 Experts available now in Live!

Get 1:1 Help Now