M
Nur mal schnell zusammenkopiert, stammt von einem Dialog, kann aber auch auf normale Fenster angewendet werden, Unterschied siehe Kommentar:
case WM_NCHITTEST:
//xPos = LOWORD( lParam ); //Horizontal position of cursor.
//yPos = HIWORD( lParam ); //Vertical position of cursor.
//The simplest way to drag a window by its client area (or drag a window if it has no title bar),
//is to handle the WM_NCHITTEST message that is sent to every window when a mouse event occurs.
//By returning a value of HTCAPTION from the WM_NCHITTEST message handler, you can fool windows into
//thinking that the mouse is over a caption bar, and the window can be dragged around with the mouse.
//It is best to only allow dragging by the client area of a window - otherwise, the window borders would become unusable.
//To achieve this, call the default window procedure, and check if its return value is HTCLIENT -
//if it is, then return HTCAPTION instead. Otherwise, just let the default behaviour take place.
//Windows Vista: When creating custom frames that include the standard caption buttons, this message should first be passed to the DwmDefWindowProc() function.
// This enables the Desktop Window Manager (DWM) to provide hit-testing for the captions buttons.
// If DwmDefWindowProc() does not handle the message, further processing of WM_NCHITTEST may be needed.
lresult = DefWindowProc( hwnd_dialog, WM_NCHITTEST, wParam, lParam );
if ( lresult == HTCLIENT ) //indicating the position of the cursor hot spot in a client area.
{
lresult = HTCAPTION; //indicating the position of the cursor hot spot in a title bar.
//Hiermit wird Windows vorgegaukelt, daß sich der Mauscursor in der Titelleiste befindet.
}
SetWindowLong( hwnd_dialog, DWL_MSGRESULT, lresult );
//Der tatsächliche Rückgabewert bei Dialogen.
//Bei Fenstern kann man den Wert via return zurückgeben - bei Dialogen muss man mit SetWindowLong() arbeiten.
return( TRUE ); //Nachricht wurde bearbeitet -> TRUE.
break; //Zwar wg. return überflüssig, ist bei mir aber disziplinarische Gewohnheit
Aber was in meinen Augen vermutlich gravierender ist:
Bei Deinen Switch-case Konstrukten fehlen die obligatorischen breaks bei jedem case-Zweig!
HTH,
Martin