|
Hello,
I create a "Windows Form Application" project that names p2pport, in Microsoft visual .NET 2005.
I want to use the Message Map. I see it on MSDN. MFC uses it.
So I include the #include <afxwin.h>, and use MFC in a shared DLL.
This is my code.
BEGIN_MESSAGE_MAP(p2pport::Dlg,public System::Windows::Forms::Form)
ON_MESSAGE(WM_UI1, p2pport::Dlg::OnUI1, WPARAM wParam, LPARAM lParam)
ON_MESSAGE(WM_UI2, p2pport::Dlg::OnUI2, WPARAM wParam, LPARAM lParam)
ON_MESSAGE(MM_MIXM_LINE_CHANGE,p2pport::Dlg::onMixerCallBack)
ON_MESSAGE(MM_MIXM_CONTROL_CHANGE,p2pport::Dlg::onMixerCallBack)
END_MESSAGE_MAP()
p2pport is my project name, and Dlg is the name of my form file.
But I get a lots of errors.
error C2039: 'GetMessageMap' : is not a member of 'p2pport::Dlg'
error C2039: 'GetThisMessageMap' : is not a member of 'p2pport::Dlg'
error C2039: 'GetThisMessageMap' : is not a member of 'System::Int32'
error C2270: 'GetMessageMap' : modifiers not allowed on nonmember functions
error C2365: 'GetThisMessageMap' : redefinition; previous definition was 'formerly unknown identifier'
error C2440: 'static_cast' : cannot convert from 'void (__clrcall p2pport::Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
error C2440: 'static_cast' : cannot convert from 'void (__clrcall p2pport::Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
error C2440: 'static_cast' : cannot convert from 'void (__clrcall p2pport::Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
error C2440: 'static_cast' : cannot convert from 'void (__clrcall p2pport::Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
error C3861: 'GetThisMessageMap': identifier not found
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I google it, but nothing finds.
Can anybody help me to solve it?
Appreciate for ur reply. Thx.
-- modified at 5:03 Tuesday 6th November, 2007
|
|
|
|
|
Own created messages will be handled this way in >>MFC<<:
In header:
class MyView
{
...
LRESULT OnMyMessage(WPARAM w=0,LPARAM l=0);
...
};
in .cpp:
BEGIN_MESSAGEMAP(MyView,CFormView)
ON_MESSAGE(WM_MY_OWN_MESSAGE,OnMyMessage)
END_MESSAGE_MAP()
LRESULT MyView::OnMyMessage(WPARAM w,LPARAM l)
{
// Work
return TRUE;
}
I hope this helps you
|
|
|
|
|
Thx for your reply.
It helps me a lot.
But I still get some errors.
I create a header file that named CMyView and the content is following.
#ifndef CMYVIEW_H<br />
#define CMYVIEW_H<br />
#include <afxwin.h><br />
#include <afxext.h><br />
public class CMyView : public CFormView<br />
{<br />
LRESULT OnUI1(WPARAM wParam, LPARAM lParam);<br />
LRESULT OnUI2(WPARAM wParam, LPARAM lParam);<br />
LRESULT onMixerCallBack(WPARAM wParam, LPARAM lParam);<br />
<br />
};<br />
#endif
And my code is modified as below.
BEGIN_MESSAGE_MAP(CMyView,CFormView)<br />
ON_MESSAGE(WM_UI1, OnUI1)<br />
ON_MESSAGE(WM_UI2, OnUI2)<br />
ON_MESSAGE(MM_MIXM_LINE_CHANGE,onMixerCallBack)<br />
ON_MESSAGE(MM_MIXM_CONTROL_CHANGE,onMixerCallBack)<br />
END_MESSAGE_MAP()
And there's the error.
error C2509: 'GetMessageMap' : member function not declared in 'CMyView'
error C2509: 'GetThisMessageMap' : member function not declared in 'CMyView'
How could I solve this problem?
Appreciate for ur reply.
Thx.
|
|
|
|
|
I got it.
I lose DECLARE_MESSAGE_MAP()in the header file.
The correct code is as below.
#ifndef CMYVIEW_H<br />
#define CMYVIEW_H<br />
<br />
#include <afxwin.h><br />
#include <afxext.h><br />
<br />
public class CMyView : public CFormView<br />
{<br />
<br />
public:<br />
afx_msg LRESULT OnUI1(WPARAM wParam, LPARAM lParam);<br />
LRESULT OnUI2(WPARAM wParam, LPARAM lParam);<br />
LRESULT onMixerCallBack(WPARAM wParam, LPARAM lParam);<br />
protected:<br />
DECLARE_MESSAGE_MAP();<br />
<br />
};<br />
<br />
#endif
|
|
|
|
|
Outstanding
Great that it works for you
|
|
|
|
|
Hi All,
I have a notepad like application. I want to avoid from taking snapshots of my application using printscreen like facility. Is there any way?
|
|
|
|
|
I don't know the correct answer,
but i don't think so, because the PrintScreen-Key will be handled in each way in windows itselfs,
so you can't suppress this key in your app and windows never remarks it.
Because you can "steal" any picture in a browser which is protected via different methods over
the printscreen...
If the disabling of the PrintScreen-Key works, all browsers would use this method to protect
the pics into the browser
But propably there is a specific technique to do that, but i never heared about it.
Good luck
|
|
|
|
|
Im not sure about, but I think that hooking the message of "print screen" and doing nothing / something different while the application is active could work. But its pretty hard work.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Injecting a hook into windows? ouch
I never want to try this LOL, that's to hard for me
I even don't know in which DLL to hook in
But it's a solution, right
|
|
|
|
|
Neither do I, but it doesn't mean that is impossible
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hi,
Hope somebody can help me.
I want to access database in my program but I don't know how to make a connection. I'm using MySQL and VC++ 2003 MFC.
If you have an idea or a link related please let me know.
It would be a big help.
Thank you.
|
|
|
|
|
Did you see Database section on the codeproject ?
|
|
|
|
|
|
#include "mysql.h"
#include "winsock.h"
#pragma comment(lib,"libmySQL.lib")
MYSQL mysql;
mysql_init (&mysql);
if(!mysql_real_connect(&mysql,"localhost","root",NULL,"mydb",3306,NULL,0))
{
AfxMessageBox("database connection error");
return FALSE;
}
|
|
|
|
|
|
i created an application in Mfc Dialog and i want to increase the dialog size as per the screen size programatically so that the controls in the dialog does not change its positions.
Thanks in Advance
||SnAkeBed||
|
|
|
|
|
You can use of MoceWindow on the WM_SIZE .
|
|
|
|
|
Actually is MoveWindow :P (I know, typing error, but better to be sure the people gets the correct answer )
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
He needs to an if before using of it on the wm_size .
|
|
|
|
|
SnaKeBeD wrote: i created an application in Mfc Dialog and i want to increase the dialog size as per the screen size programatically so that the controls in the dialog does not change its positions.
SetWindowPos is another api, apart from MoveWindow as quoted by Mr. Hamid (nice one)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
My MFC program has many line of code that using relative path like
("./data/test.jpg")
I alway reset the current directory after using CFileDialog so that
the ralative path - code in my program alway work ,
by doing something like this.
<br />
char currentDir[MAX_PATH];<br />
GetCurrentDirectory(currentDir);<br />
---- browse for file ------<br />
SetCurrentDirectory(currentDir);<br />
I has recently intregrated WinHelp in my program.
The problem is when user using WinHelp print function and selected those virtual printer like (Microsoft document writer) and browse for save path ,
My application's
current directory also change and since WinHelp doesn't block my application
(It a modeless dialog or something) I cant use the reset current directory method above.
Since my time is very limit , The only solution I came up here is
-------1.save the current directory into some static variable immediately after launching program
-------2.before calling and file access function that may invole relative path,
call SetCurrentDirectory(); with the saved directory
Will this solution alway work ?
since converting any relative part to absolute part is not an option now (some data are store in database as relative path)
I have to apologize for my very poor english and thank for answer in advance.
Xanagan
|
|
|
|
|
To ensure that you are in your APP folder:
char FileName[MAX_PATH];
GetModuleFileName(NULL, FileName, MAX_PATH);
CString m_szPath = FileName;
m_szPath = m_szPath.Left(m_szPath.ReverseFind('\\'));
Afterwards you can this to open/create files in the folder or whatever you need.
m_szPath += "MyDll.dll";
HINSTANCE hInst = LoadLibrary (m_szPath);
or...
m_szPath += "AnyDataFile.ext";
CFile f (m_szPath, CFile::modeCreate | CFile::modeWrite);
And with this you don't have to worry about the CurrentDirectory modified by CFileDialog, actually I use both options, but for different things.
Hope it helps
EDIT: Ups, I missed your "since absolute path dont desired", your idea about saving the current directory in a variable and set it back after modifying will work perfectly. But watch out here you save it. You may overwrite it without pretending it.
-- modified at 3:11 Tuesday 6th November, 2007
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
This seem more safe than calling SetCurrentDirectory before every file operation.
but the amount of code I need to modified is too much (I have both those Hard-code and some that query relative path-string from file/database)
So I may have to go with my first solution
(calling SetCurrentDirectory(applicationPath) before any set of file operation / in the head of function where I am sure that the current directory will not change).
will my solution has any side effect in the long term ?
Thank for your answer
|
|
|
|
|
With this code you dont need to call it everywhere. You can call it just once in your OnInitialUpdate, OnInitDialog or wherever class/module you need it, save it in a member variable and just replace the old vars names with the new one.
I mean, with this code you can save the m_szAppPath and use it as basis for all the other places, m_szFileName = m_szAppPath + "WhateverYouWant.ext";
And you can make it automatically with search and replace. I have used it a lot in my project :P
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Yes it will work. Just assign the directory to a global variable and use SetDirectory after lines that may change the current directory the application is pointing to.
|
|
|
|