The WM_NCHITTEST Message This is an internal message used by Windows for generating all the other...

Preview:

DESCRIPTION

Window Activation: WM_MOUSEACTIVATE  A window procedure gets a WM_MOUSEACTIVATE whenever its window is not activate and a mouse button is clicked over it.  If a program creates multiple windows, user could switch between them the mouse. In that event, the window being activated would receive this message.  Wparam:- will contain the handle of the window’s original granparent.  WM_ACTIVATE will tell you whatever any window is being activated or inactivated through whatever means.

Citation preview

The WM_NCHITTEST MessageThis is an internal message used by Windows for generating all the other mouse messages. Though it almost never needs to be used by programmer, it provides a fascinating insight into the windows mouse messages’ internal machniations.M_NCHITTEST originates in the USER.EXE module, which sends this message to the top most window overlying any mouse event. When you move the mouse, windows detects that movement, and determines the new mouse location.

The window receive the WM_NCHITTEST message with the mouse cursors’s screen co-ordinates as lparam. Wparam is not used.

wParam not used(0). Lparam:- mouse co-ordinates, relative to the top-left

corner of the screen. Loword contains the x co-ordinates, HIWORD contains the y- cordinates.

Window Activation: WM_MOUSEACTIVATE A window procedure gets a WM_MOUSEACTIVATE

whenever its window is not activate and a mouse button is clicked over it.

If a program creates multiple windows, user could switch between them the mouse. In that event, the window being activated would receive this message.

Wparam:- will contain the handle of the window’s original granparent.

WM_ACTIVATE will tell you whatever any window is being activated or inactivated through whatever means.

The mouse cursor• Many window applications including

window’s own applications such as the program manager, file manager, and task manager use a standard arrow-shaped cursor. This doesn’t necessarily have to be so.

• Program get their first opportunity to customize their mouse cursor.

• The register class function requires a pointer to a WNDCLASS structure, which contain a mouse cursor handle:-

typedef struct tagWNDCLASS { UINT style;WNDPROC lpfnWndProc;

int cbClsExtra;int cbWndExtra;

HINSTANCE hinstance; HICON hicon; HCURSOR hcursor;

Obtaining the cursor handles:-The easiest way to mouse cursor handle is by using the

LoadCursor() function:- LoadCursor( hinst, pszCursor);

changing mouse cursor

• The window API provides a simple function which can be used to change the mouse cursor:

• SetCursor(hcursor)

Code for changing the mouse cursor#include"resource.h"#include"afxwin.h"#include"windows.h"HWND hwndMainWindow;HINSTANCE hinstance;int nCurrentCursor;LPSTR lpszCursorId[]={ IDC_ARROW, IDC_IBEAM, IDC_WAIT, IDC_CROSS,

IDC_UPARROW, IDC_SIZE, IDC_ICON };#define CURSOR_COUNT(sizeof(lpszCursorId)/sizeof(LPSTR))LPSTR lpszCursorName[]={

"Arrow", "Ibeam", "Wait","Cross","Up Arrow","Size","Icon"}; HWND hwndButtons[CURSOR_COUNT]={0};

long WindowProc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp); int _stdcall WinMain(HINSTANCE h, HINSTANCE hp, char *r, int i) { MSG msg;

WNDCLASS wc; if(!hp)

{ wc.style=CS_HREDDRAW|CS_VREDDRAW|CS_DBLCLKS; wc.lpfnWndProc=WindowProc; wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hInstance=h;

wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wc.hCursor=NULL; wc.lpszClassName="my"; RegisterClass(&wc);

}

hwndMainWindow=CreateWindow("my","hello",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,NULL,NULL,h,NULL);

ShowWindow(hwndMainWindow,3); UpdateWindow(hwndMainWindow); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg);

DispatchMessage(&msg); }

return 0; }

long WindowProc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)

{int i, cxbuttonsize, cybuttonsize;RECT rect;POINT pt;switch(message){case WM_CREATE:

for(i=0;i<CURSOR_COUNT;i++){

hwndButtons[i]=CreateWindow("BUTTON",lpszCursorName[i],WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,0,0,h,0);

}return 0;

case WM_COMMAND:nCurrentCursor=wp;GetClientRect(hwnd,&rect);pt.x=rect.left;pt.y=rect.top;ClientToScreen(hwnd,&pt);SetCursorPos(pt.x+10,pt.y+10);return 0;

case WM_MOUSEMOVE:SetCursor(LoadCursor(NULL,lpszCursorId[nCurrentCursor]));

return 0;

case WM_PAINT:

SetCursor(LoadCursor(NULL,lpszCursorId[nCurrentCursor]));GetClientRect(hwnd,&rect);cxbuttonsize=rect.right;cybuttonsize=rect.bottom;for(i=0;i<CURSOR_COUNT;i++){

MoveWindow(hwndButtons[i],0,rect.bottom+i*cybuttonsize,cxbuttonsize,cybuttonsize,FALSE);SendMessage(hwndButtons[i],WM_PAINT,0,0);

}

case WM_DESTROY:PostQuitMessage(0);return 0;

}return DefWindowProc(hwnd,message,wp,lp);

}

Recommended