A little positioning issue -
In the following code the program should simply make a cross over any window clicked, although it does that there is a slight problem; the lines start at the correct corners of the client area but end at the wrong and also the beggining positions are also wrong when the window is not maximised.
#include <windows>
const char *ClsName = "BasicApp";
const char *WndName = "Pro Painter Deluxe - Matahir Shah";
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);
// 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)
{
switch (Msg)
{
case WM_LBUTTONDOWN :
POINT AreaClicked;
HWND WindowHandle;
HDC DC;
RECT WindowPosition;
GetCursorPos(&AreaClicked);
ScreenToClient(hWnd, &AreaClicked);
WindowHandle = WindowFromPoint(AreaClicked);
GetWindowRect(WindowHandle, &WindowPosition);
DC = GetDC(WindowHandle);
LineTo(DC, WindowPosition.right, WindowPosition.bottom);
MoveToEx(DC, WindowPosition.right, WindowPosition.top, NULL);
LineTo(DC, WindowPosition.left, WindowPosition.bottom);
ReleaseDC(WindowHandle, DC);
break;
case WM_DESTROY :
InvalidateRect(NULL, NULL, NULL);
PostQuitMessage(0);
break;
}
I know there are many problems in the code but it is because I still don't know how to work with total mouse control, if you know please reply to the thread known as "Mouse Power".
Thanks.

