• 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

    • ISTM from the article that the user was just out to get the developer for one reason or another. It may have had nothing to do with the software but the user just wanted to harm the developer in one way or another for some personal reason. They used the the project's Codeberg page to accomplish their goal.
    • ""Settings vs. Control Panel" - this has absolutely been fixed." - This is absolutely not fixed. Your personal experience may vary but still there is a clear division between two. "Error 0x80070643" - this issue never existed for Windows 11: https://learn.microsoft.com/en...(install-error-0x80070643). You can find similar cases for Windows 11; this is just example. Though with Windows 11, the issue is not so common like Windows 10. "UX inconsistencies" - This is terrible. And not just UX but UI as well. Windows 11 may work but it's not a good product. Hundreds thousands of engineering hours, billions of USD... This might be the only choice by force due to the jettisoning of Windows 10, however the end product for all those resources spent is simply not good. The real problem is lack of competition. Linux derivatives and MacOS unfortunately are not competitive.
    • Grab Motorola's Razr Ultra 2025 at 15% off and ditch your slab phone by Paul Hill Motorola is currently selling the Razr Ultra 2025 on Amazon at a discount of 15%, meaning you can pick it up now for $1,099.99 instead of the usual $1,299.99. This is a notable saving on a premium foldable smartphone, but it still remains a high-end purchase. Any Prime members out there can get free overnight delivery and if you have an old device to trade in, then you can get up to $725 in Amazon.com Gift Card credit that you can use towards your upgrade. One of the main perks of this device is that it’s universally unlocked, meaning you can use it on all major US carriers. It’s powered by the Snapdragon 8 Elite and comes with 16GB RAM and 512GB storage. With these specs, this device should be able to run any apps you throw at it. The Pantone Scarab color, a soft, velvety suede-like texture, is the result of a collaboration with the Italian brand Alcantara, known for its premium materials, giving the phone a very unique look. As a flip phone, you also get an intelligent and interactive external display that lets you access apps without opening your phone. Even with this external display, Motorola says you can expect over 36 hours of battery life and when you do need to recharge, you have fast charging. The main display on this device is 7 inches and features a Super HD resolution which is 2992 x 1224, the refresh rate is 165Hz. The external display has a resolution of 1272 x 1080. This phone could be a good pick for fashion-conscious users with its unique materials. It’s also a great device for anyone after a compact form factor or who is a fan of Motorola devices. The style, compact design, external display, fast performance, and improved camera system (50MP) are all positives on this device. There’s also IP48 rating for dust and water protection, adding durability. Motorola Razr Ultra 2025: $1,099.99 (Amazon US) / MSRP $1,299.99 This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
  • Recent Achievements

    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
    • One Month Later
      James_kobe earned a badge
      One Month Later
    • Week One Done
      James_kobe earned a badge
      Week One Done
    • Week One Done
      macomen earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      653
    2. 2
      ATLien_0
      253
    3. 3
      Xenon
      168
    4. 4
      neufuse
      147
    5. 5
      +FloatingFatMan
      125
  • Tell a friend

    Love Neowin? Tell a friend!