|
WM_MOUSEMOVE
WM_LBUTTONUP
WM_LBUTTONDOWN
Thank you masters!
|
|
|
|
|
Software2007 wrote: Do I need a timer to do this, or could this be done in other ways?
void CSam1Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
if( MK_LBUTTON == (MK_LBUTTON&nFlags))
{
}
CDialog::OnMouseMove(nFlags, point);
}
|
|
|
|
|
Its what I wanted - works fine - thanks.
sft
modified on Thursday, March 5, 2009 12:50 PM
|
|
|
|
|
the two Different Code create the same result i want to know the
different between the operator '*' and '&'
the code is below:
first:
<br />
#include<iostream><br />
<br />
using namespace std;<br />
<br />
int Add(int &P1,int &P2)<br />
{<br />
P1=5;<br />
P2=10;<br />
return P1+P2;<br />
}<br />
<br />
int main()<br />
{<br />
int P1=2,P2=3;<br />
<br />
cout<<"As Parameter Before The P1 is:"<<P1<<" P2 is:"<<P2<<endl;<br />
<br />
int Sum=Add(P1,P2);<br />
cout<<"P1 Parameter After The P1 is: "<<P1<<" P2 is:"<<P2<<endl;<br />
}<br />
Second:
<br />
#include<iostream><br />
<br />
using namespace std;<br />
<br />
int Add(int *P1,int *P2)<br />
{<br />
*P1=5;<br />
*P2=10;<br />
return *P1+*P2;<br />
}<br />
<br />
int main()<br />
{<br />
<br />
int *P1,*P2;<br />
<br />
int PA=2,PB=3;<br />
<br />
P1=&PA;<br />
<br />
P2=&PB;<br />
<br />
cout<<"As Parameter Before The P1 is:"<<*P1<<" P2 is:"<<*P2<<endl;<br />
<br />
int Sum=Add(P1,P2);<br />
cout<<"P1 Parameter After The P1 is: "<<*P1<<" P2 is:"<<*P2<<endl;<br />
}<br />
end the variable P1 and P2 's value are all change .
could you tell me the difference between them
thank you
|
|
|
|
|
The difference is in how you will access the variable in your function: if you pass the variables by reference (using &), you can access the variables directly. If you pass the pointer to the variables (using *), then in your function you will receive the pointer.
|
|
|
|
|
It is more neat sometimes to use &.
Take this simple example of a multiply function.
Using *
double multiply(double *x, double *y)
{
return *x * *y;
}
double d = multiply(&a, &b);
Using &
double multiply(double &x, double &y)
{
return x * y;
}
double d = multiply(a, b);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
* is backward compatible with C.
Edit: I was off by one character, I meant to indicate that C doesn't support references.
modified on Thursday, March 5, 2009 9:56 AM
|
|
|
|
|
You can use pointers in C too (thus using the '*' is valid in C).
|
|
|
|
|
Ah, I'm not awake yet, coffee just finished dripping.
I must have meant it the other way around. I only dabbled in C++ a little, and not recently.
|
|
|
|
|
I can't believe there're people who know C and not C++ still!
|
|
|
|
|
C++ is all hype; it's not necessary for most real work.
|
|
|
|
|
Is all the position the '*' use can replace by '&'?
|
|
|
|
|
in a declaration ie int *X means a a pointer to x named *;
You cannot define a reference with initializing it
so
int &X //doesn't work however
---
int Y;
int &x = Y; does
Y and X now refer to the same place in memory changing the value of one will change the value of the other. When you use a & in a function prototype we are saying I want my parameter to access memory at the location of the variable the caller specified; When you declare a pointer in the prototype you are going to explicitly pass in a pointer that pointer can however be reassigned but once reassinged the caller will no longer be able to read changes to what was passed in
I wrote a little example.
<br />
<br />
#include "stdafx.h"<br />
<br />
<br />
void NoSideEffect(int *T)<br />
{<br />
<br />
int G = 5;<br />
T = &G;<br />
<br />
<br />
}<br />
<br />
void SideEffect(int &T)<br />
{<br />
int G = 5;<br />
T = G;<br />
}<br />
<br />
void PointerSideEffect(int *T)<br />
{<br />
int G = 10;<br />
*T = G;<br />
}<br />
<br />
<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
char buffer[2];<br />
int X = 2;<br />
NoSideEffect(&X);<br />
printf("X is Now %d \n",X);<br />
SideEffect(X);<br />
printf("X is Now %d \n",X);<br />
PointerSideEffect(&X);<br />
printf("X is Now %d \n",X);<br />
gets(buffer);<br />
}<br />
<br />
this will print out
X is Now 2
X is Now 5
X is Now 10
a programmer traped in a thugs body
|
|
|
|
|
<br />
void NoSideEffect(int *T)<br />
{<br />
<br />
int G = 5;<br />
T = &G;<br />
<br />
<br />
}<br />
int X = 2;<br />
NoSideEffect(&X);<br />
printf("X is Now %d \n",X);<br />
X is Now 2
don't change why?could you explain more detail
|
|
|
|
|
This is because c++ accurately always passes by value When you pass a pointer you are passing the value of the pointer which is a memory address. when the compiler creates a stack frame the value of the memory address is put on the stack as a local variable when you change the value of that variable you point it to a new memory location and no longer maps to memory address of the variable in the caller. So any change will not affect the caller since you are changing the location associated with another variable in this case another local variable which is allso on the stack.
a programmer traped in a thugs body
|
|
|
|
|
using references is safer, you do not have to check for NULL pointers.
This signature was proudly tested on animals.
|
|
|
|
|
|
That's right. You cannot pass a null to a reference like you can for a pointer.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi All,
I m developing the sdi application.I want to handle the System menu move option.
If I press ALT+SPACE on my application and select move ..then I need the event handler..
can anybody pls help me out in this..
Thanks in Advance,
Ashok.
|
|
|
|
|
I believe this[^] is what you need.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I am attempting to control mouse events, like moving the mouse and pressing any mouse key ...
I am using the following code to set the mouse position as (0,0)
LPINPUT i;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));
But, I am getting an exception at the line
i[0].mi=mi;
Actually I want to control the mouse pointer through an external hardware, which will be connected at the serial port.
I will read the data from the serial port like mouse movement and any mouse key being pressed, then SET this mouse status to the system mouse ....this is my ultimate aim ...
So I wrote the above code to set the mouse position first, but its not working ...
Please someone help me here ...
Apurv
A man is but the product of his thoughts. What he thinks, he becomes.
.......Mahatma Gandhi
Be the change you want to see in the world.
.......Mahatma Gandhi
|
|
|
|
|
LPINPUT i;
LPINPUT means pointer to structure INPUT. Here i is of type LPINPUT. You have to allocate memory for this before you use this variable.
ie LPINPUT i = new INPUT;
akt
|
|
|
|
|
oh ... thanks ...
its not giving anymore errors ...
but the mouse position is not set ....
here is my updated code ...
LPINPUT i = new INPUT;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i[0].mi=mi;
i[0].type=INPUT_MOUSE;
SendInput(1,i,sizeof(i));
Apurv
A man is but the product of his thoughts. What he thinks, he becomes.
.......Mahatma Gandhi
Be the change you want to see in the world.
.......Mahatma Gandhi
|
|
|
|
|
Try this
INPUT i;
MOUSEINPUT mi;
mi.dx=0;
mi.dy=0;
mi.dwFlags=MOUSEEVENTF_MOVE;
mi.time=0;
mi.dwExtraInfo=GetMessageExtraInfo();
mi.mouseData=0;
i.mi=mi;
i.type=INPUT_MOUSE;
SendInput(1, &i, sizeof(i));
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
its working ... superman .... thank you very much ....
will this SendInput() function work outside the application window ?
I mean, while i interface it with my hardware, so that the key inputs are coming from the hardware, know suppose the mouse is over the start button, and i send the Left-button pressed event to the SendInput() function ... will this result the Start button being pressed ???
Apurv
A man is but the product of his thoughts. What he thinks, he becomes.
.......Mahatma Gandhi
Be the change you want to see in the world.
.......Mahatma Gandhi
|
|
|
|