Click here to Skip to main content
15,913,836 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionIs there anyway to make SEH works when stask is broken Pin
Tal Rasha's Guardianship7-Feb-09 16:49
Tal Rasha's Guardianship7-Feb-09 16:49 
AnswerRe: Is there anyway to make SEH works when stask is broken Pin
Stuart Dootson7-Feb-09 22:52
professionalStuart Dootson7-Feb-09 22:52 
GeneralRe: Is there anyway to make SEH works when stask is broken Pin
Tal Rasha's Guardianship22-Feb-09 17:15
Tal Rasha's Guardianship22-Feb-09 17:15 
AnswerRe: Is there anyway to make SEH works when stask is broken Pin
Stephen Hewitt8-Feb-09 4:45
Stephen Hewitt8-Feb-09 4:45 
GeneralRe: Is there anyway to make SEH works when stask is broken Pin
Tal Rasha's Guardianship22-Feb-09 16:50
Tal Rasha's Guardianship22-Feb-09 16:50 
AnswerRe: Is there anyway to make SEH works when stask is broken Pin
Rolf Kristensen8-Feb-09 10:23
Rolf Kristensen8-Feb-09 10:23 
GeneralRe: Is there anyway to make SEH works when stask is broken Pin
Tal Rasha's Guardianship22-Feb-09 16:28
Tal Rasha's Guardianship22-Feb-09 16:28 
QuestionHelp Repainting with GDI+ in C++ Pin
AntiBNI7-Feb-09 12:05
AntiBNI7-Feb-09 12:05 
I am trying to make Full screen (800 x 480) apps for vehicle PC's.

like this one:
http://i615.photobucket.com/albums/tt235/I_want_to_learn/SentaFS.jpg [i615.photobucket.com]

I'm trying to do apps like that with Fully Alpha Blended PNG's.

I managed to load a PNG as the Dialogs Background and one as a Button.

The button has 2 images:
1: The Normal State
2: the Down (Pressed) State

The problem i'm having is that every time i click the button, the "Down State" PNG gets drawn on top of the "Normal State" PNG and you can clearly see the Normal state Icon in the back of the button's Downstate Image and Viceversa

How can i clear or erase the the normal state image if i click my button and viceversa when i release my button.

If i put a solid background to the button i can fix the image overlapping problem but i get a big color full square, i need to redraw the button with the new image but still having the transparent background.


This is the code for my DialogBox:
// ODBII  Maker DatabaseDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ODBII  Maker Database.h"
#include "ODBII  Maker DatabaseDlg.h"
#include "SearchButton.h"
#include <fstream>
#include <gdiplus.h>
#include <gdiplusenums.h>

#pragma comment (lib,"gdiplus.lib")

using namespace std;

fstream database;

CString ItemText;
int mark;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CODBIIMakerDatabaseDlg dialog




CODBIIMakerDatabaseDlg::CODBIIMakerDatabaseDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CODBIIMakerDatabaseDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CODBIIMakerDatabaseDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_Maker);
	DDX_Control(pDX, IDC_FIND, Search);
	DDX_Control(pDX, IDC_CODE, m_Meaning);
	DDX_Control(pDX, IDC_Meaning, m_Code);
}

BEGIN_MESSAGE_MAP(CODBIIMakerDatabaseDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_FIND, &CODBIIMakerDatabaseDlg::OnBnClickedFind)
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()


// CODBIIMakerDatabaseDlg message handlers

BOOL CODBIIMakerDatabaseDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	Gdiplus::GdiplusStartupInput gdiplusstartupinput;
	Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusstartupinput,NULL);
	char Maker[MAX_PATH];
	m_Maker.InsertColumn(0,"");
	m_Maker.SetColumnWidth(0,180);

	database.open("Manufacturers//Manufacturer.txt",fstream::in);

	while (database.getline(Maker,sizeof(Maker)) != 0)
			{
				m_Maker.InsertItem(0,Maker);
		}

	database.clear();
	database.close();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CODBIIMakerDatabaseDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CODBIIMakerDatabaseDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	if (IsIconic())
	{

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<wparam>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CODBIIMakerDatabaseDlg::OnQueryDragIcon()
{
	return static_cast<hcursor>(m_hIcon);
}


void CODBIIMakerDatabaseDlg::OnBnClickedFind()
{
	//Search for the Code in the Database
	CString Search;
	CString Folder;
	char Temp[MAX_PATH];
	char Code[MAX_PATH];
	char Meaning[MAX_PATH];

	m_Meaning.SetWindowTextA("");

	Search = "[";
	m_Code.GetWindowTextA(Temp,sizeof(Temp));
	Search += Temp;
	Search += "]";

	if(m_Maker.GetSelectedCount() > 0)
		{
		//get the selected items number in the Listcontrol
		mark = m_Maker.GetSelectionMark();
		//get the text of the selected item in the listctrl
		ItemText = m_Maker.GetItemText(mark,NULL);
		//open the file for reading
		Folder = "Manufacturers\\";
		Folder += ItemText;
		Folder += ".txt";
		database.open(Folder,fstream::in);


			while (database.getline(Code,sizeof(Code)) != 0)
			{
		//if the Description line matches with the word searched
		//get the Codes Meaning and display it
				if(strcmp(Code,Search) == 0)
				{
					database.getline(Meaning,MAX_PATH);
					m_Meaning.SetWindowTextA(Meaning);
			}

		}
	}

	database.close();
	database.clear();
}
BOOL CODBIIMakerDatabaseDlg::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	Gdiplus::Image * BG;

	Gdiplus::Graphics grpx(*pDC);//GDI Graphics container
	Gdiplus::Rect rect(0,0,473,261);//GDI image pos and size

	BG = Gdiplus::Image::FromFile(L"Image\\BackGround.png",FALSE);

	grpx.DrawImage(BG,rect);


	return true;
}
</hcursor></wparam></gdiplusenums.h></gdiplus.h></fstream>


and this is the code for my Button:

// SearchButton.cpp : implementation file
//

#include "stdafx.h"
#include "ODBII  Maker Database.h"
#include "ODBII  Maker DatabaseDlg.h"
#include "SearchButton.h"
#include <gdiplus.h>

#pragma comment (lib,"gdiplus.lib")


// SearchButton

IMPLEMENT_DYNAMIC(SearchButton, CButton)

SearchButton::SearchButton()
{
	Gdiplus::GdiplusStartupInput gdiplusstartupinput;
	Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusstartupinput,NULL);

	ButtonUp = Gdiplus::Image::FromFile(L"Image\\Button1.png",FALSE);
	ButtonDown = Gdiplus::Image::FromFile(L"Image\\Button2.png",FALSE);
}

SearchButton::~SearchButton()
{
	Gdiplus::GdiplusShutdown(gdiplusToken);
}


BEGIN_MESSAGE_MAP(SearchButton, CButton)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()



// SearchButton message handlers





void SearchButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;

dc.Attach(lpDrawItemStruct->hDC);

CRect rt;

rt = lpDrawItemStruct->rcItem;


Gdiplus::Graphics grpx(dc);

UINT State = lpDrawItemStruct->itemState;

Gdiplus::Rect rect(0,0,90,90);

if((State & ODS_SELECTED))
{
	grpx.DrawImage(ButtonUp,rect);
}
else
{
	grpx.DrawImage(ButtonDown,rect);
}
dc.Detach();

}

void SearchButton::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	Invalidate(1);
	CButton::OnLButtonDown(nFlags, point);
}

void SearchButton::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	Invalidate(1);
	CButton::OnLButtonUp(nFlags, point);
}
BOOL SearchButton::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	Gdiplus::Graphics grpx(*pDC);
	Gdiplus::Color trans(255,255,255,255);

	grpx.Clear(trans);

	return CButton::OnEraseBkgnd(pDC);
}

HBRUSH SearchButton::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
	// TODO:  Change any attributes of the DC here
	// TODO:  Return a non-NULL brush if the parent's handler should not be called
	return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
</gdiplus.h>


Thanks so much in advance ^_^.

God Bless.
AnswerRe: Help Repainting with GDI+ in C++ Pin
Stuart Dootson7-Feb-09 22:57
professionalStuart Dootson7-Feb-09 22:57 
GeneralRe: Help Repainting with GDI+ in C++ Pin
AntiBNI8-Feb-09 2:24
AntiBNI8-Feb-09 2:24 
QuestionMFC Combo Box Pin
VarwigDude7-Feb-09 8:22
VarwigDude7-Feb-09 8:22 
AnswerRe: MFC Combo Box Pin
Stuart Dootson7-Feb-09 23:00
professionalStuart Dootson7-Feb-09 23:00 
QuestionHow to convert jpg image to rgb Pin
simon alec smith7-Feb-09 5:49
simon alec smith7-Feb-09 5:49 
GeneralWord Capture Pin
Swapnil Shah7-Feb-09 0:18
Swapnil Shah7-Feb-09 0:18 
AnswerRe: Word Capture Pin
Rajesh R Subramanian7-Feb-09 5:30
professionalRajesh R Subramanian7-Feb-09 5:30 
QuestionRe: Word Capture Pin
Swapnil Shah7-Feb-09 8:10
Swapnil Shah7-Feb-09 8:10 
AnswerRe: Word Capture Pin
Rajesh R Subramanian7-Feb-09 19:25
professionalRajesh R Subramanian7-Feb-09 19:25 
GeneralRe: Word Capture Pin
Swapnil Shah8-Feb-09 4:44
Swapnil Shah8-Feb-09 4:44 
GeneralRe: Word Capture Pin
Rajesh R Subramanian10-Feb-09 3:49
professionalRajesh R Subramanian10-Feb-09 3:49 
GeneralRe: Word Capture Pin
onlyjaypatel9-Oct-09 1:32
onlyjaypatel9-Oct-09 1:32 
GeneralRe: Word Capture Pin
Rajesh R Subramanian9-Oct-09 19:14
professionalRajesh R Subramanian9-Oct-09 19:14 
QuestionMultilingual application using vc++.net in visual studio 2005 Pin
Purish Dwivedi6-Feb-09 18:27
Purish Dwivedi6-Feb-09 18:27 
AnswerRe: Multilingual application using vc++.net in visual studio 2005 Pin
Hamid_RT6-Feb-09 20:27
Hamid_RT6-Feb-09 20:27 
GeneralRe: Multilingual application using vc++.net in visual studio 2005 Pin
Purish Dwivedi6-Feb-09 21:32
Purish Dwivedi6-Feb-09 21:32 
GeneralRe: Multilingual application using vc++.net in visual studio 2005 Pin
Hamid_RT7-Feb-09 8:09
Hamid_RT7-Feb-09 8:09 

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.