|
-
October 5th, 2007, 03:07 PM
#1
Mouse Power -
Sup guys,
This time I would like to know how to work with SetCapture and ReleaseCapture and would like a complete example.
Thanks.
-
October 5th, 2007, 07:08 PM
#2
Re: Mouse Power -
 Originally Posted by .pcbrainbuster
This time I would like to know how to work with SetCapture and ReleaseCapture and would like a complete example.
Code:
SetCapture(yourHwnd);
// do your stuff
ReleaseCapture();
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
October 6th, 2007, 07:48 AM
#3
Re: Mouse Power -
Thanks for your post, but it seems that I wasn't clear enough. What I wanted was HOW to work with it.
-
October 6th, 2007, 11:21 AM
#4
Re: Mouse Power -
What do you mean "How to work with it"?
Just call SetCapture at the moment you want to start the capture and call ReleaseCapture to release it.
-
October 6th, 2007, 01:46 PM
#5
Re: Mouse Power -
It took me long but know I know how to use it and it seems that this is the wrong method I'm using -
Code:
#include <windows>
const char *ClsName = "BasicApp";
const char *WndName = "A Simple Window";
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
HINSTANCE hInstance;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;
// Create the application window
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProc;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClsName;
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// Register the application
RegisterClassEx(&WndClsEx);
// Create the window object
hWnd = CreateWindowEx(NULL,
ClsName,
WndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
// Find out if the window was created
if( !hWnd ) // If the window was not created,
return 0; // stop the application
// Display the window to the user
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
SetCapture(hWnd);
// Decode and treat the messages
// as long as the application is running
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
static POINT Area;
static int Draw = 0;
static RECT Point;
switch (Msg) {
case WM_DESTROY :
PostQuitMessage(WM_QUIT);
ReleaseCapture();
break;
case WM_LBUTTONUP :
Draw = 0;
break;
case WM_LBUTTONDOWN :
Draw = 1;
break;
case WM_CAPTURECHANGED :
SetCapture(hWnd);
break;
case WM_MOUSEMOVE :
HDC DC = GetDC(hWnd);
if (Draw == 1) {
GetCursorPos(&Area);
ScreenToClient(hWnd, &Area);
LineTo(DC, Area.x+1, Area.y+1);
GetClientRect(hWnd, &Point);
MoveToEx(DC, Point.right, Point.top, NULL);
LineTo(DC, Area.x+1, Area.y+1);
MoveToEx(DC, Point.left, Point.bottom, NULL);
LineTo(DC, Area.x+1, Area.y+1);
MoveToEx(DC, Point.right, Point.bottom, NULL);
LineTo(DC, Area.x+1, Area.y+1);
}
ReleaseDC(hWnd, DC);
break;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
This code has so many problems and it is all because of the method used to capture the mouse, you even have to click in the program to start the capture and then go outside for it to still be drawing. One problem is that when the desktop as the mouse in it's power my program hangs. What I want this TEST program to do is to be able to start drawing even when the mouse is held down while its outside my window. How do you do this?
Thanks.
-
October 7th, 2007, 02:40 AM
#6
Re: Mouse Power -
According to MSDN:
 Originally Posted by MSDN
SetCapture captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down.
So what you want is not possible with SetCapture.
But if you implement what you want, meaning start drawing even when clicking outside your window, how can the user switch to a different application? You should not do this.
-
October 7th, 2007, 02:33 PM
#7
Re: Mouse Power -
This is a test you know, meaning that I simply when to test the mouse capture and that's simply it... When I know how to do it I will be changing the code to also draw on the screen and not just the application, but that will also be a test the main goal in the future would be to use it in combination with WindowFromPoint and many others.
question -
1) In my country/area when you sign-up for a new school they ask whether many things including what you would/could do for the school in return, is the ability to program good or not? I mean FOR the school.
Thanks.
Last edited by .pcbrainbuster; October 7th, 2007 at 02:37 PM.
-
October 8th, 2007, 07:52 AM
#8
Re: Mouse Power -
If you want to capture mouse events outside of your window, you need to use windows hook. Try to browse the articles at www.codeguru.com. There are some explaining mouse hooks.
-
October 8th, 2007, 01:13 PM
#9
Re: Mouse Power -
Aww, but I do not know how to work with DLLs. Can you please direct me to a tutorial?
Thanks.
-
October 9th, 2007, 12:47 PM
#10
Re: Mouse Power -
Please Look at the "cute"(ekhh) face( ).
-
October 9th, 2007, 01:33 PM
#11
Re: Mouse Power -
Have you tried googling 'dll tutorial'?
-
October 11th, 2007, 10:39 AM
#12
Re: Mouse Power -
Besides google, did you search the articles at codeguru.com? There is probably example code which you can learn from.
-
October 11th, 2007, 12:54 PM
#13
Re: Mouse Power -
Hey. I always though the way to 'draw' over the desktop was to create a transparent window to cover the desktop. The only problem is that the user will not be able to interact with anything under your transparent window anymore. But I guess that is your intention, since you only want to draw stuff into your DC, and not do much else with your app. except highlight things? Is this a CBT application?
try : Browse this ancient thread http://www.codeguru.com/forum/showthread.php?t=433664
Last edited by Conrad Braam; October 11th, 2007 at 01:23 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|