• 0

Docking windows in Visual C++ .NET


Question

6 answers to this question

Recommended Posts

  • 0

1. In you .H file add in the following line

<pre>afx_msg void OnWindowPosChanging(WINDOWPOS* lpwndPos);</pre>

after the Generated message map functions part.

2. In your BEGIN_MESSAGE_MAP section in you .CPP file add the line

<pre>ON_WM_WINDOWPOSCHANGING()</pre>

3. Then do the following

<pre>

void CMyTestDlg:: OnWindowPosChanging(WINDOWPOS* lpwndPos)

{

	//Get Desktop Size

	CRect rectScreen;

	SystemParametersInfo(SPI_GETWORKAREA, 0, &rectScreen, 0);



	//Screen Offsets for Snap

	int m_nXOffset = 20;

	int m_nYOffset = 20;



	//Min & Max X Position

	if (lpwndPos->x < 0)

  lpwndPos->x = 0;

	else if (lpwndPos->x + lpwndPos->cx > rectScreen.right)

  lpwndPos->x = rectScreen.right - lpwndPos->cx;



	//Min & Max Y Position

	if (lpwndPos->y < 0)

  lpwndPos->y = 0;

	else if (lpwndPos->y + lpwndPos->cy > rectScreen.bottom)

  lpwndPos->y = rectScreen.bottom - lpwndPos->cy;



	int nGapX = 0;



	//X Snap

	if (abs(lpwndPos->x - rectScreen.left) <= m_nXOffset)

	{

  nGapX = lpwndPos->x - rectScreen.left;

  lpwndPos->cx+= nGapX;

  lpwndPos->x = rectScreen.left;

	}

	else if (abs(lpwndPos->x + lpwndPos->cx - rectScreen.right) <= m_nXOffset)

	{

  nGapX = rectScreen.right - (lpwndPos->x + lpwndPos->cx);

  lpwndPos->cx+= nGapX;

  lpwndPos->x = rectScreen.right - lpwndPos->cx;

	}



	//Y Snap

	if (abs(lpwndPos->y - rectScreen.top) <= m_nYOffset)

  lpwndPos->y = rectScreen.top;

	else if (abs(lpwndPos->y + lpwndPos->cy - rectScreen.bottom) <= m_nYOffset)

  lpwndPos->y = rectScreen.bottom - lpwndPos->cy;

}

</pre>

  • 0

Ok I copied the above code into a new project, and it worked OK. I have put a link to the zip file onto my site: Test Project.

One thing I did notice, was when the dialog gets too close to the left or right side of the screen, the dialog increases in size (this was needed for the client, but I forgot to remove it here).

The code should be as follows:

<pre>

	//X Snap

	if (abs(lpwndPos->x - rectScreen.left) <= m_nXOffset)

	{

//  nGapX = lpwndPos->x - rectScreen.left;

//  lpwndPos->cx+= nGapX;

  lpwndPos->x = rectScreen.left;

	}

	else if (abs(lpwndPos->x + lpwndPos->cx - rectScreen.right) <= m_nXOffset)

	{

//  nGapX = rectScreen.right - (lpwndPos->x + lpwndPos->cx);

//  lpwndPos->cx+= nGapX;

  lpwndPos->x = rectScreen.right - lpwndPos->cx;

	}

</pre>

If it still does not work, or if you have any other questions drop me an email, or PM.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Doing that has only worked for me with the Enterprise version.
    • I like Neowin a lot, but this "article" is shady and misleading. We need an "editorial" flag and this isn't "news" it's "my cousin's dog's best friend posted on twitter about their snapchat account from their dog's owner that a bad thing happened, so it's NEWS." Thanks
    • Burrrrn. Bought COD WWII last month when it was on sale for PC. Oh well. Excellent game tho, and the PC version plays/looks amazing (and has it's own PC achievements). ...wondering if this is a lesson on waiting on sales. ...also hoping Rise of the Tomb Raider has it's own PC Achievements
    • Google Chrome 137.0.7151.120 (offline installer) by Razvan Serea The web browser is arguably the most important piece of software on your computer. You spend much of your time online inside a browser: when you search, chat, email, shop, bank, read the news, and watch videos online, you often do all this using a browser. Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier. Use one box for everything--type in the address bar and get suggestions for both search and Web pages. Thumbnails of your top sites let you access your favorite pages instantly with lightning speed from any new tab. Desktop shortcuts allow you to launch your favorite Web apps straight from your desktop. Chrome has many useful features built in, including automatic full-page translation and access to thousands of apps, extensions, and themes from the Chrome Web Store. Google Chrome is one of the best solutions for Internet browsing giving you high level of security, speed and great features. Important to know! The offline installer links do not include the automatic update feature. Google Chrome 137.0.7151.120 changelog: [$7000][420697404] High CVE-2025-6191: Integer overflow in V8. Reported by Shaheen Fazim on 2025-05-27 [$4000][421471016] High CVE-2025-6192: Use after free in Profiler. Reported by Chaoyuan Peng (@ret2happy) on 2025-05-31 [425443272] Various fixes from internal audits, fuzzing and other initiatives Download web installer: Google Chrome Web 32-bit | Google Chrome 64-bit | Freeware Download: Google Chrome Offline Installer 64-bit | 128.0 MB Download: Google Chrome Offline Installer 32-bit | 115.0 MB Download page: Google Chrome Portable Download: Google Chrome MSI Installers for Windows (automatic update) View: Chrome Website | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      gatilogistic earned a badge
      One Month Later
    • One Year In
      Custom Greek Shirts earned a badge
      One Year In
    • One Month Later
      Custom Greek Shirts earned a badge
      One Month Later
    • Week One Done
      Custom Greek Shirts earned a badge
      Week One Done
    • Week One Done
      topantidetectbrowser earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      673
    2. 2
      ATLien_0
      281
    3. 3
      Michael Scrip
      222
    4. 4
      +FloatingFatMan
      190
    5. 5
      Steven P.
      146
  • Tell a friend

    Love Neowin? Tell a friend!