Solved

Bitmaps in RichEdit CTRLS

Posted on 1999-01-08
2
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

733 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