Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to prevent the user from moving a dialog dynamically

How to prevent the user from moving a dialog dynamically

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    caykahve
    wrote on last edited by
    #1

    Hello, I tried the below line to make my dialog start at a certain position, with certain size, and prevent the user from moving it afterwards. SetWindowPos(&this->wndTopMost,StartXPos,StartYPos,DlgWidth,DlgHeight,SWP_NOSENDCHANGING|SWP_NOZORDER|SWP_SHOWWINDOW); There is no problem with the start position and the size, but I can move it. Also there is some problem with CClientDC::LineTo() function. It sometimes draws after SetWindowPos is called, and sometimes not. I also want to write a function to enable moving again. Thanks in advance...

    I R 2 Replies Last reply
    0
    • C caykahve

      Hello, I tried the below line to make my dialog start at a certain position, with certain size, and prevent the user from moving it afterwards. SetWindowPos(&this->wndTopMost,StartXPos,StartYPos,DlgWidth,DlgHeight,SWP_NOSENDCHANGING|SWP_NOZORDER|SWP_SHOWWINDOW); There is no problem with the start position and the size, but I can move it. Also there is some problem with CClientDC::LineTo() function. It sometimes draws after SetWindowPos is called, and sometimes not. I also want to write a function to enable moving again. Thanks in advance...

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      I'm sure there is an article in the Dialogs section somewhere about this, but off the top of my head... Handle the WM_NCHITTEST message (OnNcHittest). If you want the normal behaviour, fall through to the standard behaviour. If you want the dialog locked, return HTCLIENT.

      ...
      ON_WM_NCHITEST()
      ...

      UINT CMyDialog::OnNcHitTest( CPoint point )
      {
      if (m_bLocked)
      return HTCLIENT;

      return CWnd::OnNcHitTest (point);
      

      }

      Tada! Iain.

      C 1 Reply Last reply
      0
      • C caykahve

        Hello, I tried the below line to make my dialog start at a certain position, with certain size, and prevent the user from moving it afterwards. SetWindowPos(&this->wndTopMost,StartXPos,StartYPos,DlgWidth,DlgHeight,SWP_NOSENDCHANGING|SWP_NOZORDER|SWP_SHOWWINDOW); There is no problem with the start position and the size, but I can move it. Also there is some problem with CClientDC::LineTo() function. It sometimes draws after SetWindowPos is called, and sometimes not. I also want to write a function to enable moving again. Thanks in advance...

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        Override WM_MOVING and WM_SIZING to control how the window can be moved (or resized) by the user. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        1 Reply Last reply
        0
        • I Iain Clarke Warrior Programmer

          I'm sure there is an article in the Dialogs section somewhere about this, but off the top of my head... Handle the WM_NCHITTEST message (OnNcHittest). If you want the normal behaviour, fall through to the standard behaviour. If you want the dialog locked, return HTCLIENT.

          ...
          ON_WM_NCHITEST()
          ...

          UINT CMyDialog::OnNcHitTest( CPoint point )
          {
          if (m_bLocked)
          return HTCLIENT;

          return CWnd::OnNcHitTest (point);
          

          }

          Tada! Iain.

          C Offline
          C Offline
          caykahve
          wrote on last edited by
          #4

          WM_NCHITTEST did the trick. :) thanks a lot! caykahve

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups