Click here to Skip to main content
15,888,454 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CDhtmlDialog - IHtmlElementCollection Pin
Hamid_RT31-Aug-06 6:02
Hamid_RT31-Aug-06 6:02 
GeneralRe: CDhtmlDialog - IHtmlElementCollection Pin
Christopher Duncan31-Aug-06 6:10
Christopher Duncan31-Aug-06 6:10 
GeneralRe: CDhtmlDialog - IHtmlElementCollection Pin
Hamid_RT31-Aug-06 9:43
Hamid_RT31-Aug-06 9:43 
QuestionButton disappears after OnPaint() Pin
mfranco_neto29-Aug-06 16:08
mfranco_neto29-Aug-06 16:08 
AnswerRe: Button disappears after OnPaint() Pin
Nishad S29-Aug-06 18:39
Nishad S29-Aug-06 18:39 
GeneralRe: Button disappears after OnPaint() Pin
mfranco_neto30-Aug-06 12:04
mfranco_neto30-Aug-06 12:04 
GeneralRe: Button disappears after OnPaint() Pin
Nishad S30-Aug-06 17:33
Nishad S30-Aug-06 17:33 
GeneralRe: Button disappears after OnPaint() Pin
mfranco_neto31-Aug-06 2:53
mfranco_neto31-Aug-06 2:53 
Hello NS,

I am working on Erik Thompsom's toolbar tutorial (http://www.codeproject.com/atl/ietoolbartutorial.asp).
After making some modifications to Erik's code, I added a static control to the right of the button and managed to change bk color, text color and so on, which happens inside OnPaint()->BeginPaint(). However, after doing this the button doesn't get repainted. It is still there, since it is responding to mouse clicks. I tried many things, from clipping the (m_hWnd) toolbar's client rect so that it wouldn't overlap the button, to trying to paint only the static control (m_ReadWnd) which is a child window for the m_hWnd. I will show you three functions: OnCreate, OnSize and OnPaint.


<br />
LRESULT CMFToolbar::OnCreate(UINT uMsg,WPARAM wParam, LPARAM lParam, BOOL& bHandled)<br />
{<br />
	SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_MIXEDBUTTONS);<br />
<br />
	SendMessage(m_hWnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON),0);<br />
<br />
	SendMessage(m_hWnd, TB_SETMAXTEXTROWS, 1, 0L);<br />
<br />
	TCHAR* pCaption = _T("Cotação - Yahoo Finance");<br />
	int iIndex = ::SendMessage(m_hWnd, TB_ADDSTRING, 0, (LPARAM)pCaption);<br />
<br />
	HICON hMotley = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_MOTLEY));<br />
	m_hImageList = ImageList_Create(16,16,ILC_COLOR16,1,0);<br />
	int iImageIndex = ImageList_AddIcon(m_hImageList,hMotley);<br />
	DestroyIcon(hMotley);<br />
<br />
	::SendMessage(m_hWnd, TB_SETIMAGELIST, 0, (LPARAM)m_hImageList);<br />
<br />
	TBBUTTON Button;<br />
	ZeroMemory((void*)&Button, sizeof(TBBUTTON));<br />
	Button.idCommand = IDM_GETQUOTE;<br />
	Button.fsState = TBSTATE_ENABLED;<br />
	Button.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT;<br />
	Button.dwData = 0;<br />
	Button.iString = iIndex;<br />
	Button.iBitmap = 0;<br />
	::SendMessage(m_hWnd, TB_INSERTBUTTON, 0, (LPARAM)&Button);<br />
<br />
	<br />
	RECT rect = {0,0,0,0};<br />
	m_EditWnd.Create(m_hWnd, rect, NULL, WS_CHILD|WS_VISIBLE,WS_EX_CLIENTEDGE);<br />
	m_EditWnd.SetFont(static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)));<br />
<br />
	<br />
	RECT rect2 = {0,0,0,0};<br />
<br />
	m_ReadWnd.Create(m_hWnd, rect2, NULL,WS_CHILD|WS_VISIBLE|WS_EX_CLIENTEDGE);<br />
	m_ReadWnd.SetFont(static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)));<br />
	m_ReadWnd.SetWindowText("Text on STATIC OBJECT");<br />
<br />
<br />
	return 0;<br />
}<br />
<br />
LRESULT CMFToolbar::OnSize(UINT uMsg,WPARAM wParam, LPARAM lParam, BOOL& bHandled)<br />
{<br />
<br />
	RECT wndRect, btnRect;<br />
<br />
	RECT fixedRect = {0,0,50,20};<br />
<br />
	GetClientRect(&wndRect);<br />
	::SendMessage(m_hWnd, TB_GETITEMRECT, 0, (LPARAM)&btnRect);<br />
<br />
	SendMessage(TB_SETINDENT,55);<br />
<br />
	m_EditWnd.MoveWindow(&fixedRect, FALSE);	<br />
<br />
	wndRect.left += btnRect.right + 300;<br />
<br />
	wndRect.right -= 100;<br />
<br />
	m_ReadWnd.MoveWindow(&wndRect, FALSE);<br />
	<br />
	return 0;<br />
}<br />
<br />
LRESULT CMFToolbar::OnPaint(UINT uMsg,WPARAM wParam, LPARAM lParam, BOOL& bHandled)<br />
{<br />
	<br />
	PAINTSTRUCT ps, ps2;<br />
	HDC hDC = NULL;<br />
	HDC hDC2= NULL;<br />
	RECT test_rect = {100,100,100,20};<br />
	RECT bk_rect = {100,100,100,20};<br />
	HRGN hRgn = NULL;<br />
	HRGN hRgn2 = NULL;<br />
	HBRUSH hBr = CreateSolidBrush(RGB(255,0,0));<br />
	HBRUSH hBr2 = CreateSolidBrush(RGB(0,0,255));<br />
<br />
	::GetClientRect(m_hWnd,&test_rect);<br />
	::GetClientRect(m_ReadWnd,&bk_rect);<br />
<br />
	hRgn2= CreateRectRgn(test_rect.right/2,test_rect.top+10,test_rect.right-900,test_rect.bottom-5);<br />
<br />
	hRgn = CreateRectRgn(bk_rect.left+200,bk_rect.top,bk_rect.right-100,bk_rect.bottom);<br />
<br />
	hDC2 =::BeginPaint(m_hWnd,&ps2);<br />
	hDC  =::BeginPaint(m_ReadWnd,&ps);<br />
<br />
	::SelectClipRgn(hDC2,hRgn2);<br />
	::SelectClipRgn(hDC,hRgn);<br />
	<br />
	::SetTextColor(hDC,RGB(255,255,255));<br />
	<br />
	::SetBkColor(hDC,RGB(255,0,0));<br />
	::FillRect(hDC2,&test_rect,hBr2);	<br />
	::FillRect(hDC,&bk_rect,hBr);<br />
<br />
	::TextOut( hDC, 0, 0, _T("Some Text"),9 );<br />
<br />
	::EndPaint(m_ReadWnd,&ps);<br />
	::EndPaint(m_hWnd,&ps2);<br />
<br />
<br />
<br />
	return 0;<br />
}<br />


If I do not treat the WM_PAINT message, the button appears. If I treat, it does not.

One other thing: you may notice that I have to BeginPaint(..) on both the parent window (m_hWnd) and the child window (m_ReadWnd), although I just want to paint the child. If I don't BeginPaint the parent, IE crashes...

Sorry for the long message. I can send you printscreen images of the toolbar so you can have a better idea if necessary.

Thank you NS

- Mfranco -
GeneralRe: Button disappears after OnPaint() Pin
Nishad S31-Aug-06 3:33
Nishad S31-Aug-06 3:33 
GeneralRe: Button disappears after OnPaint() Pin
mfranco_neto31-Aug-06 12:04
mfranco_neto31-Aug-06 12:04 
GeneralRe: Button disappears after OnPaint() Pin
Nishad S31-Aug-06 19:04
Nishad S31-Aug-06 19:04 
GeneralRe: Button disappears after OnPaint() Pin
mfranco_neto1-Sep-06 3:35
mfranco_neto1-Sep-06 3:35 
GeneralRe: Button disappears after OnPaint() Pin
mfranco_neto1-Sep-06 4:04
mfranco_neto1-Sep-06 4:04 
GeneralRe: Button disappears after OnPaint() Pin
Nishad S5-Sep-06 18:30
Nishad S5-Sep-06 18:30 
GeneralRe: Button disappears after OnPaint() Pin
mfranco_neto6-Sep-06 15:52
mfranco_neto6-Sep-06 15:52 
Questioncontrol list Pin
With_problem29-Aug-06 16:01
With_problem29-Aug-06 16:01 
AnswerRe: control list Pin
Naveen29-Aug-06 17:33
Naveen29-Aug-06 17:33 
QuestionStand alone function? Pin
Oliver12329-Aug-06 14:43
Oliver12329-Aug-06 14:43 
AnswerRe: Stand alone function? Pin
Chris Losinger29-Aug-06 16:34
professionalChris Losinger29-Aug-06 16:34 
AnswerRe: Stand alone function? Pin
Christopher Duncan30-Aug-06 1:48
Christopher Duncan30-Aug-06 1:48 
Questionusing CHttpConnection with "Proxy-Connection: Keep-Alive" Pin
darbien siamak29-Aug-06 14:38
darbien siamak29-Aug-06 14:38 
QuestionExcel automation function throws exception Pin
garyflet29-Aug-06 13:32
garyflet29-Aug-06 13:32 
AnswerRe: Excel automation function throws exception Pin
Stephen Hewitt29-Aug-06 13:47
Stephen Hewitt29-Aug-06 13:47 
QuestionRe: Excel automation function throws exception Pin
garyflet29-Aug-06 14:39
garyflet29-Aug-06 14:39 
QuestionSetting focus of another application from within an application Pin
si_6929-Aug-06 12:32
si_6929-Aug-06 12:32 

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.