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

C / C++ / MFC

 
AnswerRe: How to configure GTK+ in CodeBlocks? Pin
Richard MacCutchan2-Jul-12 6:41
mveRichard MacCutchan2-Jul-12 6:41 
General[solved] CDialog Goes Blank When Press ENTER Pin
AmbiguousName2-Jul-12 0:32
AmbiguousName2-Jul-12 0:32 
QuestionRe: CDialog Goes Blank When Press ENTER Pin
Code-o-mat2-Jul-12 1:03
Code-o-mat2-Jul-12 1:03 
AnswerRe: CDialog Goes Blank When Press ENTER Pin
AmbiguousName2-Jul-12 1:18
AmbiguousName2-Jul-12 1:18 
GeneralRe: CDialog Goes Blank When Press ENTER Pin
Code-o-mat2-Jul-12 1:34
Code-o-mat2-Jul-12 1:34 
GeneralBios Bootable software Pin
Brandon-X120001-Jul-12 21:28
Brandon-X120001-Jul-12 21:28 
GeneralRe: Bios Bootable software Pin
Richard MacCutchan1-Jul-12 22:22
mveRichard MacCutchan1-Jul-12 22:22 
Questionneed help: image coordinates(x,y) in opencv with mfc Pin Pin
jawadali4771-Jul-12 19:40
jawadali4771-Jul-12 19:40 
hi,
below is the complete code that i have developed using opencv with MFC in vs2008. it builds fine and after debugging it shows two different windows, one containing image and other containing static boxes. the purpose of this code is to display image coordinates (x,y) in static boxes but when i double click on the image window (which is my mouse event), values of (x,y) coordinates are not displayed in the static boxes (static boxes are in the separate window). please pardon my mistakes.

#include "stdafx.h"
#include "opencv01.h"
#include "opencv01Dlg.h"
#include "highgui.h"
#include "afxwin.h"
#include "cv.h"
#include "math.h"
#include<stdlib.h>
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
void on_mouse( int evt, int x, int y, int flags, void* param );    //defining mouse event
HWND hwnd;   //defining handle
 
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
 
	enum { IDD = IDD_ABOUTBOX };
 
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 
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()
 
Copencv01Dlg::Copencv01Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(Copencv01Dlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
 
void Copencv01Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}
 
BEGIN_MESSAGE_MAP(Copencv01Dlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
 

// Copencv01Dlg message handlers
 
BOOL Copencv01Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
 
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
 
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
 
	
	AfxBeginThread(MyThreadProc, this); //calling thread
 
	return TRUE;  // return TRUE  unless you set the focus to a control
}
 

UINT Copencv01Dlg::MyThreadProc(LPVOID pParam)
    {
     Copencv01Dlg * me = (Copencv01Dlg *)pParam;
     me->MyThreadProc();
     return TRUE;
    }
 

void Copencv01Dlg::MyThreadProc()
{ 
	//image initialization
	
	IplImage* img = cvLoadImage("box.png", CV_WINDOW_AUTOSIZE);
		cvNamedWindow("map", 0);
		cvShowImage("map", img);
 
                cvSetMouseCallback("map", on_mouse, NULL);     //calling mouse function
 
                cvWaitKey(0);
                cvReleaseImage(&img);
		cvDestroyWindow("map");
	
}
 

void Copencv01Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}
void Copencv01Dlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting
 
		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();
	}
}
 
HCURSOR Copencv01Dlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}
 
void on_mouse( int evt, int x, int y, int flags, void* param )
{
	CString xaxis, yaxis;
 
		if (evt == CV_EVENT_LBUTTONDBLCLK)
	{
		
			xaxis.Format(_T("%d"), x);
			yaxis.Format(_T("%d"), y);
			SetDlgItemText(hwnd, IDC_Blue, xaxis);
			SetDlgItemText(hwnd, IDC_Green, yaxis);
	}
 
}




Jawad
AnswerRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
Richard MacCutchan1-Jul-12 22:20
mveRichard MacCutchan1-Jul-12 22:20 
GeneralRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
jawadali4772-Jul-12 0:19
jawadali4772-Jul-12 0:19 
GeneralRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
Richard MacCutchan2-Jul-12 0:31
mveRichard MacCutchan2-Jul-12 0:31 
GeneralRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
jawadali4772-Jul-12 1:38
jawadali4772-Jul-12 1:38 
GeneralRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
Richard MacCutchan2-Jul-12 6:40
mveRichard MacCutchan2-Jul-12 6:40 
GeneralRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
jawadali4772-Jul-12 17:53
jawadali4772-Jul-12 17:53 
GeneralRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
Richard MacCutchan2-Jul-12 21:17
mveRichard MacCutchan2-Jul-12 21:17 
GeneralRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
jawadali4775-Jul-12 0:49
jawadali4775-Jul-12 0:49 
GeneralRe: need help: image coordinates(x,y) in opencv with mfc Pin Pin
Richard MacCutchan5-Jul-12 2:28
mveRichard MacCutchan5-Jul-12 2:28 
QuestionGet Current View in SDI Pin
D.Manivelan1-Jul-12 18:40
D.Manivelan1-Jul-12 18:40 
AnswerRe: Get Current View in SDI Pin
Richard MacCutchan1-Jul-12 22:14
mveRichard MacCutchan1-Jul-12 22:14 
GeneralRe: Get Current View in SDI Pin
krmed2-Jul-12 0:48
krmed2-Jul-12 0:48 
GeneralRe: Get Current View in SDI Pin
Richard MacCutchan2-Jul-12 0:53
mveRichard MacCutchan2-Jul-12 0:53 
QuestionCalling a member class implicitly Pin
ForNow1-Jul-12 3:36
ForNow1-Jul-12 3:36 
GeneralRe: Calling a member class implicitly Pin
Richard MacCutchan1-Jul-12 6:16
mveRichard MacCutchan1-Jul-12 6:16 
GeneralRe: Calling a member class implicitly Pin
ForNow1-Jul-12 6:30
ForNow1-Jul-12 6:30 
GeneralRe: Calling a member class implicitly Pin
Richard MacCutchan1-Jul-12 6:43
mveRichard MacCutchan1-Jul-12 6:43 

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.