C++ and STL
  Common Issues
  Destructor
  regex
  string
 MFC
  CButton
  CDialog
  CEdit
  CInternetSession
  CWinThread
  CWnd
 MS VS FAQ
  Compiling, building
  Debugging
  Editor
  Settings
 Win32, API
  Console
  File System
  Graphics
  Internet functions
  Kernel objects
  Security
  Sound
  Thread, process
  Window
 Windows NT/2K*
  Logon, logoff...
  Networking
  Service Packs
 | About
  About
  Links & Freeware

Powered by
CoderTown



How to move dialog window by dragging at any point?

Here we need a handle for WM_NCHITTEST message. Every time you drag mouse over the window the system post this message to find out where the cursor is. We simply cheat the system and make thinking it is over the caption of the window (even if there is no any) and in mainWndProc return HTCAPTION.


LRESULT CALLBACK mainDlgProc(HWND hWnd,UINT uMessage,WPARAM wParam,LPARAM lParam)
{
  switch(uMessage) {
    case WM_DESTROY:
      PostQuitMessage(0);
      break;

    case WM_NCHITTEST:
      return HTCAPTION;

    case WM_CLOSE:
      PostMessage(hWnd, WM_COMMAND, IDCANCEL,0);
      break;

    case WM_DESTROY:
      PostQuitMessage(0);
      break;

   /* Some more */

    default:
      return DefWindowProc(hWnd, uMessage, wParam, lParam);
  }
  return 0;
}

Sample Win32 project for MSVC and executable are available.

Created: 2003-05-14
Updated: 2003-05-14

Google
 
Web visualcpp.net
msdn.microsoft.com codeguru.com