// main.cpp
#include "mainwindow.h"
#include "windows.h"
HHOOK g_hMouseHook;
LRESULT CALLBACK MouseProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if( nCode < 0 )
{
return CallNextHookEx( g_hMouseHook, nCode, wParam, lParam );
}
LPMOUSEHOOKSTRUCT mhs = (LPMOUSEHOOKSTRUCT) lParam;
if( wParam == WM_NCLBUTTONDOWN && mhs->wHitTestCode == HTCAPTION )
{
return true;
}
return CallNextHookEx( g_hMouseHook, nCode, wParam, lParam );
}
int main(int argc, char *argv[])
{
g_hMouseHook = SetWindowsHookEx( WH_MOUSE, MouseProc, GetModuleHandle( NULL ), GetCurrentThreadId() );
if (!g_hMouseHook)
{
qDebug() << GetLastError();
}
MainWindow w;
w.show();
return a.exec();
}
// main.cpp
#include "mainwindow.h"
#include "windows.h"
HHOOK g_hMouseHook;
LRESULT CALLBACK MouseProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if( nCode < 0 )
{
return CallNextHookEx( g_hMouseHook, nCode, wParam, lParam );
}
LPMOUSEHOOKSTRUCT mhs = (LPMOUSEHOOKSTRUCT) lParam;
if( wParam == WM_NCLBUTTONDOWN && mhs->wHitTestCode == HTCAPTION )
{
return true;
}
return CallNextHookEx( g_hMouseHook, nCode, wParam, lParam );
}
int main(int argc, char *argv[])
{
g_hMouseHook = SetWindowsHookEx( WH_MOUSE, MouseProc, GetModuleHandle( NULL ), GetCurrentThreadId() );
if (!g_hMouseHook)
{
qDebug() << GetLastError();
}
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
This piece of code will consume any Left Mouse Button Press event on the title bar (but not the buttons on the bar) preventing it from being moved by grabbing the bar.
Bookmarks