Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting X,Y into LPARAM for WM_LBUTTONDOWN message

Status
Not open for further replies.

onrdbandit

Programmer
Mar 12, 2003
145
US
Howdy,

I need to send a control a mouse up and mouse down message, so that my custom cursors will refresh. I can do both, but I need the program to recieve the EXACT same message it would if I actually clicked the mouse i.e. the (X,Y) coordinates of the click. I don't know how to include these in the LPARAM parameter of the SendMessage function. Is there a method or specific technique by which this is done?

Thanks,
onrdbandit
 
I'm not so sure what you exactly want
But I hope this will help you
.....

POINT pt;

pt = MAKEPOINT(lp);
GetyourCoordinateFunction(...,&pt,...,
DoYourStuffFunction(...,pt.x,pt.y,...,

You can extract the x and y coordinates from LPARAM
variable such as lp by using the Macros:
LOWORD(lp) equals the x coordinate and
HIWORD(lp) equals the y coordinate.

succes
 
Actully, that is exactly opposite what I need.

I have the two coordinates, and I need to convert them into a single
Code:
Long int
to send AS an
Code:
LPARAM
. Anyone who can give any assistance in this area would be appreciated as I can only find one reference to it on the net, but is it a VB library...

Thanks 2 all,
onrdbandit
 
I think based on your previous thread that I understand what you're trying to do. I don't think that it will work though for your cursor refresh problem because when you send the mouse up message, you'll also be generating a mouseclick message and another MouseDown event and so on.

Or maybe I don't understand what you're trying to do.

At any rate, here's sample code that should send the message for a Left Mouse Button Up from a MouseDown event:
Code:
void __fastcall TForm1::Button1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  SendMessage(Button1->Handle,WM_LBUTTONUP,X,Y);
}

Hope this helps, maybe I'm off base on what you're asking though.

Good Luck.
 
Thanks for all the help, but I stumbled across the solution.

Code:
SendMessage(Handle, WM_LBUTTONDOWN, 0, MAKELPARAM(X,Y));
[code][/b]
The MAKELPARAM Marco is what I was after.  

Sending the message would cause another event, but I set a flag, and only process the event when that flag is not set.  If the flag is set, then I reset the flag and do nothing else.  Once the handler exits, the cursor is refreshed and displayed.


Thanks anyway for all the replies so quickly...

onrdbandit
 
/*
//If it concern only two coördinates, you have WPARAM and LPARAM to store those values.
//Of course you may need to send more than two value with your message into two param..
//In this case you can use other MACRO's as MAKELPARM, MAKEWPARAM,....
//
//This is an demo that show the two ways....
//I used CBUILDER 5
//You don't need res or def files with CBUILDER 5 for this code
//CBUILDER will generate them automaticly...
*/

//MyMain.h
#define APPNAME "Example WinMain"
#define WNDNAME "WExampleWinMain"

//Function prototype
void AppInit(HINSTANCE hInst,HINSTANCE hPrevInst, int nCmdShow);
void AppRun(void);
void WExampleRegister(HINSTANCE hInst,HINSTANCE hPrevInst);
LRESULT CALLBACK WExampleWndProc(HWND,UINT,WPARAM,LPARAM);
//

//MyMain.cpp
// click with the rbuttom in the window for the first demo
//click with the lbutton in the window for the second demo
#include <windows.h>
#include <windef.h>
#include <stdlib.h>

#include &quot;MyMain.h&quot; //windows declarations
HWND hWndMain; //Handle to main window
HINSTANCE hThisInst; //Handle to this program instance

//the start of a window program
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
LPSTR lpCmdLine, int nCmdShow){
AppInit(hInst,hPrevInst,nCmdShow);
AppRun();
return 0;
}

//AppInit -- Register and Create a window --
void AppInit(HINSTANCE hInst,HINSTANCE hPrevInst,int nCmdShow){
HWND hWnd; //Window identification handle

WExampleRegister(hInst,hPrevInst);

hWnd = CreateWindow(
WNDNAME, //The window's class name
APPNAME, //Caption for title bar
WS_OVERLAPPEDWINDOW, //The window's style
CW_USEDEFAULT, //starting x coordinate
CW_USEDEFAULT, //starting y coordinate
CW_USEDEFAULT, //starting width
CW_USEDEFAULT, //starting height
NULL, //Handle to parent window (none)
NULL, //Handle to menu
hInst, //Program istance handle
NULL); //Optional user parameter (none)

hWndMain = hWnd; //Save window handle in global var
hThisInst = hInst; //Save program instance handle

ShowWindow(hWnd,nCmdShow); //Make window visible
UpdateWindow(hWnd); //Update window contents
}

//AppRun --The infamous 'message loop'
void AppRun(void){
MSG msg;

while(GetMessage(&msg,NULL,NULL,NULL)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
//WExampleRegister -- Register the MainWindow --
void WExampleRegister(HINSTANCE hInst,HINSTANCE hPrevInst){
WNDCLASS wc;
if (!hPrevInst){
wc.style =NULL;
wc.lpfnWndProc =WExampleWndProc;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hInstance =hInst;
wc.hIcon =0;
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground =(HBRUSH)(COLOR_WINDOW +1);
wc.lpszMenuName =NULL;
wc.lpszClassName =WNDNAME;
RegisterClass(&wc);
}
}

// -- WExampleWndProc -- Process window messages
LRESULT CALLBACK WExampleWndProc(HWND hWnd,UINT uMsg,WPARAM wp,LPARAM lp){
RECT rcWindow;
POINT pt1,pt2;
LONG lT=0,lB=0,lW=0,lH=0;
char str[255];
switch(uMsg) {
case WM_RBUTTONDOWN:
{
GetWindowRect(hWnd,&rcWindow);
GetCursorPos(&pt1);
//Store the new top and left
lT=pt1.x;
lB=pt1.y;
//Store the originate with and height
lW=rcWindow.right-rcWindow.left;
lH=rcWindow.bottom-rcWindow.top;
//Store the originate horizon. pos. and vert. pos.
pt2.x=rcWindow.top;
pt2.y=rcWindow.left;
MoveWindow(hWnd,lT,lB,lW,lH,1);
MessageBox(hWnd,&quot;The Windows was moved, klik OK to move it Back&quot;,&quot;INFO&quot;,MB_OK);
//Store the old xpos and ypos in WParam and LPARAM to put the window back
SendMessage(hWnd,WM_USER + 1,pt2.x,pt2.y);
}
break;
case WM_LBUTTONDOWN:
{
GetWindowRect(hWnd,&rcWindow);
GetCursorPos(&pt1);
lT=pt1.x;
lB=pt1.y;
lW=rcWindow.right-rcWindow.left;
lH=rcWindow.bottom-rcWindow.top;
pt2.x=rcWindow.top;
pt2.y=rcWindow.left;
MoveWindow(hWnd,lT,lB,lW,lH,1);
MessageBox(hWnd,&quot;The Windows was moved, klik OK to move it Back&quot;,&quot;INFO&quot;,MB_OK);
//Store the old xpos and ypos in WParam and LPARAM to put the window back
SendMessage(hWnd,WM_USER + 2,MAKEWPARAM(pt2.x,pt2.y),MAKELPARAM(lW,lH));
}
break;
case WM_USER + 1:
if (InSendMessage())
ReplyMessage(TRUE);
GetWindowRect(hWnd,&rcWindow);
lW=rcWindow.right-rcWindow.left;
lH=rcWindow.bottom-rcWindow.top;
MoveWindow(hWnd,lp,wp,lW,lH,1);
MessageBox(hWnd,&quot;Back x.coor in WPARAM, y.coor in LPARAM&quot;,&quot;INFO&quot;,MB_OK);
break;
case WM_USER + 2:
if (InSendMessage())
ReplyMessage(TRUE);
MoveWindow(hWnd,LOWORD(wp),HIWORD(wp),LOWORD(lp),HIWORD(lp),1);
MessageBox(hWnd,&quot;Back x.coor and y.coor in WPARAM, with and lenth in LPARAM&quot;,&quot;INFO&quot;,MB_OK);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0L;
default:
break;
}
return DefWindowProc(hWnd,uMsg,wp,lp);
}

//I will not return ;-)
//Alias HackServ with the stress on Serv
 
Luc,

Thanks for the post, but I already have what I need. A standard Mousedown event passes the (x,y) coordinates as the LPARAM, and a the mouse button (right, left, or middle) that was pressed as the WPARAM. Therefore I need the MAKELPARAM macro so that the message is handled correctly, but since all I aim to do is make the cursor refresh, I it is not necessary to send which button is pressed.

Thanks
onrdbandit
 
>A standard Mousedown event passes the (x,y) coordinates as the LPARAM, and the mouse button (right, left, or middle) that was pressed as the WPARAM.

You're correct onrdbandit, I (like Luc) was wrong in thinking that with only 2 coordinates you can pass them as WPARAM & LPARAM for the Mousedown event.

The MAKELPARAM (and MAKEWPARAM) macro shifts X & Y into the lparam:
Code:
(X & 0xffff) +((Y & 0xffff)<<16);

I was also incorrect in assuming that you would be sending a WM_LBUTTONUP message rather than a second WM_LBUTTONDOWN. With the WM_LBUTTONDOWN You shouldn't generate a click event.

Sorry about the misinfo. In the future I'll research & try code before posting it.

Glad You worked it out anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top