|
using namespace test
{
int a;
int b;
}
that's the problem.
it should be:
namespace test
{
int a;
int b;
};
and then, in your .cpp:
using namespace test; <--- fixed
|
|
|
|
|
Thanks Chris,
and this is the compiler output after your suggestion:
TEST.cpp
z:\0\0 mdi\test\bamesapce\test\testview.h(23) : error C2059: syntax error : 'namespace'
z:\0\0 mdi\test\bamesapce\test\testview.h(24) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
TESTDoc.cpp
TESTView.cpp
z:\0\0 mdi\test\bamesapce\test\testview.h(23) : error C2059: syntax error : 'namespace'
z:\0\0 mdi\test\bamesapce\test\testview.h(24) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
Z:\0\0 MDI\TEST\BAMESAPCE\TEST\TESTView.cpp(60) : error C2873: 'test' : symbol cannot be used in a using-declaration
Generating Code...
Error executing cl.exe.
TEST.exe - 5 error(s), 0 warning(s)
And here is what my ancient MSDN say about namespace:
namespace Declaration
C++ Specific —>
namespace [identifier] { namespace-body }
A namespace declaration identifies and assigns a name to a declarative region.
The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.
The declarative region of a namespace declaration is its namespace-body.
END C++ Specific
Notice - no semicolon.
And if it is a keyword it must not be in my VC6.0 Sp6 stuff.
I give up.
|
|
|
|
|
here is the complete source of a test program demonstrating the use of namespaces in VC6:
namespace foo
{
class testing
{
public:
testing()
{
i = 10;
}
int i;
};
};
using namespace foo;
int main(int argc, char* argv[])
{
testing t();
return 0;
}
|
|
|
|
|
Hi Chris - your line:
testing t(); doesn't actually create a new object. It's a prototype for a function that takes no parameters and returns a testing object.
It's a real bugger with C++ and bites loads of people. It's also the reason that the latest C++ standard introduced uniform initialisation (using braces where we've used parenthesis up to now).
|
|
|
|
|
ok. but that's not the point here.
|
|
|
|
|
Ah ha! Your problem is nesting a namespace within a class. You can't do that. This code gives the same error you got:
class A
{
namespace B
{
}
}; If you want something similar to a namespace nested within a class use another class:
class A
{
class B
{
};
}; It's probably got the effect you want.
|
|
|
|
|
Ash,
you are "the man"! ( Or a woman, I cannot tell from your name)
What has happended, as many times before,lazy me blindly copied ton of #define(s) wiht my new class and there was "use namespace std" in the mess.
I broke my code and had to go back a bit and without the additional defines the namespace stoped giving me syntax error.
One down, thanks to all of you guys persistence.
Appreciate that very much.
Now if I can find someone who knows capAVI and its use in OpenCV I'll be a happy camper.
Thanks Vaclav
|
|
|
|
|
Hi,
I am looking for the best approach to process KeyStroked <ENTER> <F7> <F8>
My code is MFC using Message using message mapping macros
I have a number of questions
1) what would the message be for a Keystrokes
2) is the message directed to the Dialog Box that contains the rich edit or is better to have the rich edit process to message
3) if I wrap the CDialog with a CWinThread
I can use the ::Run command to process the key strokes
<pre lang='cpp'> int CWinthread::Run()
{ ASSERT_VALID(this);
MSG m_msgCur;
for tracking the idle time state
if (!flags.is_connected)
return TRUE;
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
// acquire and dispatch messages until a WM_QUIT message is received.
for (;;)
{ phase1: // check to see if we can do idle work
while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{ // call OnIdle while in bIdle state
if (!OnIdle(lIdleCount++))
bIdle = FALSE; // assume "no idle" state
} // phase2: pump messages while available
do { // pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();
// reset "no idle" state after pumping "normal" message
if (IsIdleMessage(&m_msgCur)) {
bIdle = TRUE;
lIdleCount = 0;}
} while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}
ASSERT(FALSE); // not reachable
} </pre>
thanks for youe help
|
|
|
|
|
The messages for keystrokes are WM_KEYDOWN and WM_KEYUP .
These are directed to the parent dialog containing the control.
To have the message directed to the control in MFC, you have to create a class derived from CRichEditCtrl and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem[^] method.
|
|
|
|
|
Superman:
I respectfully disagree.
quote: "The messages for keystrokes are WM_KEYDOWN and WM_KEYUP
These are directed to the parent dialog containing the control."
Unless dialog does not contain any controls, dialog window never gets focus, hence WN_KEYDOWN and WM_KEYUP messages are not sent to a dialog.
quote: "and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem method."
It is possible to use SubclassDlgItem or SubclassWindow but it would be much easier to let the wizard do subclassing, by simply add variable of the CRichEditCtrl and later replace it with the derived class type.
ForNow:
Depending what is exactly you are trying to achieve, I think the best way to handle special keys is creating accelerators and add handlers to a CRichEditCtrl derived class.
JohnCz
|
|
|
|
|
how about using virtual ::PretranslateMessage
|
|
|
|
|
Hi...
I am working on image quality metrics and i have found that edge stability measure can be used to evaluate different edge detectors according to a paper "statistical evaluation of image quality measures". I am finding it difficult to implement this metric. So can anyone help me or suggest ideas to implement it.
Regards,
Mamatha E
|
|
|
|
|
Hello Friends
OnMouseMove ,After drawing some color stripes,I am using SetCursorPos(x,y) to Set MousePosition manually at end of stripe.
But As I move Only once after that mouse keeps on moving by itself until I dont release mouse lbutton up.
I am assuming that setCursorPos is calling MouseMove so it is going in Infinite Loop.
But,In actual I want to stop mouse pos at end of stripe while mouseMove.
Here is the Flow :
1.)LButtonDown
2.)MouseMove(drawing stripe then setCursorPos() calling) [want mouse cursor at end of stripe]
And again if Mousemove,strip should draw and cursor at end of Stripe.
3.)LbuttonUp[releasing the mouse]
Any Ideas??
Regards
Yogesh
modified 24-May-12 8:41am.
|
|
|
|
|
Just remember in a "global" variable that you have done the movement so that you can then ignore OnMouseOver the next time.
|
|
|
|
|
If you're drawing in MouseMove , why do you need to call SetCursorPos .
Please post some relevant code so that we can understand the problem better.
|
|
|
|
|
Hello
As I told that OnMouseMove I am drawin gsome color stripes on Ruler Scale .
Suppose scale is from 1 to 10 and If i am clicked on 2 and moved a little then it draws stripe of 5inch width.after that i want cursor should come at 7th Inch. So,for that i used SetCursorpos to move mouse manually after end of drawn stripe.
Any IDeas ?
Regards
Yogesh
|
|
|
|
|
The question is not clear to me, but let me answer with what I think the question is.
An OnMouseMove handler is called when the mouse is moved over a window.
When SetCursorPos is called, it does not normally call OnMouseMove .
But if the new cursor position as a result of calling SetCursorPos is over the window for which the OnMouseMove handler is created, then it will be invoked.
If that is the case, you will need to set a flag before calling SetCursorPos and then check this flag inside OnMouseMove to distinguish between manually moving the mouse and calling SetCursorPos .
Remember to reset this flag inside OnMouseMove .
|
|
|
|
|
Hello
you got it right.
I am facing the same scenario.
Let me try your way.
Thanks & Regards
Yogesh
|
|
|
|
|
Hello
As U suggested that I need to set a flag before calling setCursorPos to check on MouseMove. Suppose If this flag satisfies the condition on MouseMove that movement is through SeCursorPos then it will return from there and then how will i reset tht flag on MouseMove.
Here is sample Code for this:
void CMarkWnd::OnMouseMove(UINT nFlags, CPoint point)
{
if(GetCapture() != this) return;
SetCursorPos(x,y)
CWnd::OnMouseMove(nFlags, point);
}
Thanks
Yogesh
|
|
|
|
|
Please check the lines in bold.
That should do it.
void CMarkWnd::OnMouseMove(UINT nFlags, CPoint point)
{
if (mouseFlag)
{
mouseFlag = false;
return;
}
if(GetCapture() != this) return;
mouseFlag = true;
SetCursorPos(x,y)
CWnd::OnMouseMove(nFlags, point);
}
|
|
|
|
|
Hello.
I tried as u suggested but still Mouse is keep on Moving on my First move.
Thanks
Yogesh
|
|
|
|
|
Try to debug and find out what is happening.
|
|
|
|
|
I got it. Its Working now.
Thanks Sir ji.
Thanks David For your Info also.I will try your way too.
Regards
Yogesh
|
|
|
|
|
Hi,
Rather than using SetCursorPos you could use the SendInput function[^]. This would allow you to set some 'extra info' for marking simulated user input.
For example:
BOOL setcursorposition(long x, long y)
{
INPUT input = {0};
input.type = INPUT_MOUSE;
input.mi.dx = ((x - GetSystemMetrics(SM_XVIRTUALSCREEN)) * 65535) / (GetSystemMetrics(SM_CXVIRTUALSCREEN)-1);
input.mi.dy = ((y - GetSystemMetrics(SM_YVIRTUALSCREEN)) * 65535) / (GetSystemMetrics(SM_CYVIRTUALSCREEN)-1);
input.mi.dwFlags = MOUSEEVENTF_VIRTUALDESK | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
input.mi.dwExtraInfo = 0xC0DEDBAD;
return SendInput(1, &input, sizeof(input));
}
void YourClass::OnMouseMove(UINT nFlags, CPoint point)
{
if(0xC0DEDBAD != GetMessageExtraInfo())
{
}
YourBaseClass::OnMouseMove(nFlags, point);
}
Don't forget to convert client coordinates to screen before calling setcursorposition.
Best Wishes,
-David Delaune
|
|
|
|
|
This is definitely the best approach.
I wish I could rate your post.
JohnCz
|
|
|
|