need help Opencv with MFC (Solved)
-
hi, i am developing code using Opencv and MFC in vs 2008. i am getting error:
error C2660: 'SetDlgItemTextW' : function does not take 2 arguments
the complete code is:
//headers files included
#ifdef _DEBUG
#define new DEBUG_NEW
#endifvoid mouseEvent( int evt, int x, int y, int flags, void* param );
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
.......
.......
protected:
.......
}:
........
........
........BEGIN_MESSAGE_MAP(Copencv01Dlg, CDialog)
.......
.......
END_MESSAGE_MAP()// Copencv01Dlg message handlers
BOOL Copencv01Dlg::OnInitDialog()
{
CDialog::OnInitDialog();........ ........ MoveWindow(0, 0, 500, 500, 1); AfxBeginThread(MyThreadProc, this); return TRUE;
}
UINT Copencv01Dlg::MyThreadProc(LPVOID pParam)
{
Copencv01Dlg * me = (Copencv01Dlg *)pParam;
me->MyThreadProc();
return TRUE;
}void Copencv01Dlg::MyThreadProc()
{cvNamedWindow("MyWindow"); //assigning the callback function for mouse events cvSetMouseCallback("MyWindow", mouseEvent, 0); IplImage\* img = cvLoadImage("box.png"); cvShowImage("MyWindow", img); cvWaitKey(0); cvDestroyWindow("MyWindow"); cvReleaseImage(&img);
}
void Copencv01Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
........
........
}void Copencv01Dlg::OnPaint()
{
.........
.........
}HCURSOR Copencv01Dlg::OnQueryDragIcon()
{
return static_cast(m_hIcon);
}
void mouseEvent(int evt, int x, int y, int flags, void* param)
{
if(evt==CV_EVENT_LBUTTONDOWN){
CString cx, cy;
cx.Format(_T("%d"), x);
cy.Format(_T("%d"), y);
SetDlgItemTextW(IDC_Blue, cx); //error generating line
SetDlgItemTextW(IDC_Green, cy); //error generating line
}
}can anyone help me with this errors? Regards Jawad
-
hi, i am developing code using Opencv and MFC in vs 2008. i am getting error:
error C2660: 'SetDlgItemTextW' : function does not take 2 arguments
the complete code is:
//headers files included
#ifdef _DEBUG
#define new DEBUG_NEW
#endifvoid mouseEvent( int evt, int x, int y, int flags, void* param );
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
.......
.......
protected:
.......
}:
........
........
........BEGIN_MESSAGE_MAP(Copencv01Dlg, CDialog)
.......
.......
END_MESSAGE_MAP()// Copencv01Dlg message handlers
BOOL Copencv01Dlg::OnInitDialog()
{
CDialog::OnInitDialog();........ ........ MoveWindow(0, 0, 500, 500, 1); AfxBeginThread(MyThreadProc, this); return TRUE;
}
UINT Copencv01Dlg::MyThreadProc(LPVOID pParam)
{
Copencv01Dlg * me = (Copencv01Dlg *)pParam;
me->MyThreadProc();
return TRUE;
}void Copencv01Dlg::MyThreadProc()
{cvNamedWindow("MyWindow"); //assigning the callback function for mouse events cvSetMouseCallback("MyWindow", mouseEvent, 0); IplImage\* img = cvLoadImage("box.png"); cvShowImage("MyWindow", img); cvWaitKey(0); cvDestroyWindow("MyWindow"); cvReleaseImage(&img);
}
void Copencv01Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
........
........
}void Copencv01Dlg::OnPaint()
{
.........
.........
}HCURSOR Copencv01Dlg::OnQueryDragIcon()
{
return static_cast(m_hIcon);
}
void mouseEvent(int evt, int x, int y, int flags, void* param)
{
if(evt==CV_EVENT_LBUTTONDOWN){
CString cx, cy;
cx.Format(_T("%d"), x);
cy.Format(_T("%d"), y);
SetDlgItemTextW(IDC_Blue, cx); //error generating line
SetDlgItemTextW(IDC_Green, cy); //error generating line
}
}can anyone help me with this errors? Regards Jawad
-
hi, i am developing code using Opencv and MFC in vs 2008. i am getting error:
error C2660: 'SetDlgItemTextW' : function does not take 2 arguments
the complete code is:
//headers files included
#ifdef _DEBUG
#define new DEBUG_NEW
#endifvoid mouseEvent( int evt, int x, int y, int flags, void* param );
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
.......
.......
protected:
.......
}:
........
........
........BEGIN_MESSAGE_MAP(Copencv01Dlg, CDialog)
.......
.......
END_MESSAGE_MAP()// Copencv01Dlg message handlers
BOOL Copencv01Dlg::OnInitDialog()
{
CDialog::OnInitDialog();........ ........ MoveWindow(0, 0, 500, 500, 1); AfxBeginThread(MyThreadProc, this); return TRUE;
}
UINT Copencv01Dlg::MyThreadProc(LPVOID pParam)
{
Copencv01Dlg * me = (Copencv01Dlg *)pParam;
me->MyThreadProc();
return TRUE;
}void Copencv01Dlg::MyThreadProc()
{cvNamedWindow("MyWindow"); //assigning the callback function for mouse events cvSetMouseCallback("MyWindow", mouseEvent, 0); IplImage\* img = cvLoadImage("box.png"); cvShowImage("MyWindow", img); cvWaitKey(0); cvDestroyWindow("MyWindow"); cvReleaseImage(&img);
}
void Copencv01Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
........
........
}void Copencv01Dlg::OnPaint()
{
.........
.........
}HCURSOR Copencv01Dlg::OnQueryDragIcon()
{
return static_cast(m_hIcon);
}
void mouseEvent(int evt, int x, int y, int flags, void* param)
{
if(evt==CV_EVENT_LBUTTONDOWN){
CString cx, cy;
cx.Format(_T("%d"), x);
cy.Format(_T("%d"), y);
SetDlgItemTextW(IDC_Blue, cx); //error generating line
SetDlgItemTextW(IDC_Green, cy); //error generating line
}
}can anyone help me with this errors? Regards Jawad
There are multiple versions of
SetDlgItemText()
: The Windows API version that requires three parameters (first is the handle of the dialog window) and the MFC versions. Because yourmouseEvent()
function is not a member of any class, the first version is used. The error will disappear when correcting your function to:void Copencv01Dlg::mouseEvent(int evt, int x, int y, int flags, void* param)
-
You didn't pass the handle of the dialog window as first argument to the function (see SetDlgItem[^]).
Veni, vidi, vici.
i'm new in programming, specially in MFC. my understanding of handle is weak. so can you please help me in this regard. means how to pass the handle of dialog window to SetDlgItemText()? any example please. Regards Jawad
-
i'm new in programming, specially in MFC. my understanding of handle is weak. so can you please help me in this regard. means how to pass the handle of dialog window to SetDlgItemText()? any example please. Regards Jawad
I already explained this to you in this answer[^]. If you do not understand how to use the Win32 API then you should go to MSDN[^] and spend some time studying the basics. Alternatively get a copy of a book on Windows Programming (Charles Petzold[^] has written some of the best). Trying to learn Windows programming by trial and error, and posting questions in this forum is likely to take you a long time.
-
I already explained this to you in this answer[^]. If you do not understand how to use the Win32 API then you should go to MSDN[^] and spend some time studying the basics. Alternatively get a copy of a book on Windows Programming (Charles Petzold[^] has written some of the best). Trying to learn Windows programming by trial and error, and posting questions in this forum is likely to take you a long time.
thanks you Richard MacCutchan for your replies. that was really helpful.