Virtual Developer Workshop: Containerized Development with Docker
In the process of creating my own shell for Windows I found that having all of the individual elements snap to the edge of the screen very useful. To make this process much easier I put together a small class that provides drop in window snapping. It uses a MFC like class so modifying it to use MFC should be easy. NOTE: For dialog windows use the CSnapDlg instead.
- Snaps to the edge of the desktop
- Adjusts to screen resolution changes
How it Works
When the mouse is pressed in the non-client area of the window, the position is saved as an offset from the top left corner of the window. Then when the WM_MOVING message is sent it modifies the windows position based on the precalculated offset.
// register class CTestWnd twWnd; twWnd.RegisterClass("CSNAPWNDTEST",IDI_CSNAPWNDTEST,IDC_CSNAPWNDTEST); // Perform application initialization: twWnd.Init(NULL, "CSnapWnd Test", NULL, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, nCmdShow);