Click here to Skip to main content
16,011,120 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generaldifferent CView derived views on same document Pin
MVH31-Oct-02 1:28
MVH31-Oct-02 1:28 
GeneralCMultiDocTemplate? Pin
MVH31-Oct-02 1:37
MVH31-Oct-02 1:37 
GeneralRe: different CView derived views on same document Pin
Roger Allen1-Nov-02 6:27
Roger Allen1-Nov-02 6:27 
GeneralPrinter Status Pin
jerry0davis31-Oct-02 1:22
jerry0davis31-Oct-02 1:22 
GeneralBitmaps and static controls question Pin
Sens200231-Oct-02 1:18
Sens200231-Oct-02 1:18 
GeneralRe: Bitmaps and static controls question Pin
Ed Gadziemski31-Oct-02 3:36
professionalEd Gadziemski31-Oct-02 3:36 
GeneralYes type is set to bitmap... Pin
Sens200231-Oct-02 4:18
Sens200231-Oct-02 4:18 
GeneralDrawing Doubt Pin
RuiSantiago31-Oct-02 1:08
RuiSantiago31-Oct-02 1:08 
Hi,

I'm working on an application with many forms, i designed a layout for all the forms, but i wanted to build a class that had OnDraw(CDC* pDC) so i didn't have to override it from all my CFormView derived classes.

I created a CLayout Class with OnDraw(CDC* pDC) function and now i would like to call it from other classes so i could draw and paint the forms.

But, how can i get the pDC of this form?
And i also need the hWnd pointer in my CLayout::OnDraw Function

In my derived call i wrote:

HWND* hWnd=NULL;
hWnd=(HWND*)this->operator HWND();

CDC pDC=::GetDC(*hWnd);

CLayout ly(hWnd);
ly.OnDraw(&pDC);

...but GetDC function returns a HDC no CDC...

This is my OnDraw Function...

void CLayout::OnDraw(CDC* pDC)
{
//cria os objectos

CBrush brush(RGB_FUNDO);
CBrush* pTempBrush = NULL;
CBrush OrigBrush;
CString sFormName="New Machines";
CFont hFont;
CRect rc;

try
{
//cria a fonte para as letras de identificação do form

VERIFY(hFont.CreateFont(40, 15, 0, 0, FW_NORMAL,FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial Bold"));

//define a area total do ecran

GetClientRect(*hWnd,&rc);
ScreenToClient(*hWnd,&rc);

//seleciona o brush (cor) a usar

pTempBrush = (CBrush*)pDC->SelectObject(brush);

//guarda o brush original

OrigBrush.FromHandle((HBRUSH)pTempBrush);

//desenha o rectangulo a pintar com aquele brush

pDC->Rectangle(0, 0, rc.Width() , rc.Height());

//defino a cor do texto

pDC->SetTextColor(RGB_WHITE);

//elimino o bkgrn do texto

pDC->SetBkMode(TRANSPARENT);

//associa-lhe a fonte criada

pDC->SelectObject(hFont);
pDC->DrawText(sFormName, -1, CRect(15, 0, rc.Width(),80), DT_LEFT|DT_SINGLELINE|DT_VCENTER);

}
catch(CResourceException* e)
{
e->ReportError();
e->Delete();
}

pDC->SelectObject(&OrigBrush);
}

What am i doing wrong

Thank you for your time

rui




GeneralRe: Drawing Doubt Pin
dabs31-Oct-02 2:18
dabs31-Oct-02 2:18 
GeneralRe: Drawing Doubt Pin
RuiSantiago31-Oct-02 4:43
RuiSantiago31-Oct-02 4:43 
GeneralRe: Drawing Doubt Pin
dabs31-Oct-02 5:21
dabs31-Oct-02 5:21 
GeneralRe: Drawing Doubt Pin
RuiSantiago31-Oct-02 5:38
RuiSantiago31-Oct-02 5:38 
GeneralRe: Drawing Doubt Pin
dabs31-Oct-02 5:47
dabs31-Oct-02 5:47 
GeneralRe: Drawing Doubt Pin
RuiSantiago31-Oct-02 5:59
RuiSantiago31-Oct-02 5:59 
GeneralRe: Drawing Doubt Pin
dabs31-Oct-02 6:33
dabs31-Oct-02 6:33 
GeneralRe: Drawing Doubt Pin
RuiSantiago31-Oct-02 7:00
RuiSantiago31-Oct-02 7:00 
GeneralRe: Drawing Doubt Pin
dabs31-Oct-02 12:38
dabs31-Oct-02 12:38 
GeneralImplementing Custom Windows Control Pin
Maxime Labelle31-Oct-02 0:38
Maxime Labelle31-Oct-02 0:38 
GeneralSerial Comms Pin
Ruca31-Oct-02 0:05
Ruca31-Oct-02 0:05 
GeneralRe: Serial Comms Pin
Trollslayer31-Oct-02 1:46
mentorTrollslayer31-Oct-02 1:46 
GeneralRe: Serial Comms Pin
Gary R. Wheeler2-Nov-02 5:10
Gary R. Wheeler2-Nov-02 5:10 
QuestionGDI question, drawing fine dotted line (again)? Pin
Anonymous31-Oct-02 0:01
Anonymous31-Oct-02 0:01 
AnswerRe: GDI question, drawing fine dotted line (again)? Pin
dabs31-Oct-02 2:39
dabs31-Oct-02 2:39 
GeneralRe: GDI question, drawing fine dotted line (again)? Pin
Anonymous31-Oct-02 3:10
Anonymous31-Oct-02 3:10 
AnswerRe: GDI question, drawing fine dotted line (again)? Pin
Scott H. Settlemier31-Oct-02 6:01
Scott H. Settlemier31-Oct-02 6:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.