Solved

Bitmaps in RichEdit CTRLS

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SetCurrentDirectory path limit 7 121
Should CArray be used for a list of pointers in C++? 19 102
Why isn't object file created? 6 59
c++, dynamic object by json 1 42
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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