Solved

Bitmaps in RichEdit CTRLS

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

707 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