Moving a window partially off the screen

This is a discussion on Moving a window partially off the screen within the Windows Programming forums, part of the Platform Specific Boards category; I have a simple window that I want to be able to move it partially off the screen. Here is ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    Moving a window partially off the screen

    I have a simple window that I want to be able to move it partially off the screen. Here is the problem: I am able to move this window successfully off the left of the screen, bottom of the screen, and the right of the screen. However, when I try moving it partially off the top of the screen, it won't stay. It will pop back down. I know it's possible to do because I have seen some other applications do this...

    Here is the code to my window. This is just the bare-boned window without title bar and you're able to move it by dragging on its client area

    Code:
    #include <windows.h>
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    /*  Make the class name into a global variable  */
    wchar_t szClassName[ ] = L"WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
    {
        HWND hwnd;               /* This is the handle for our window */
    	MSG messages;            /* Here messages to the application are saved */
    	ZeroMemory(&messages, sizeof(MSG));
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;				/* This function is called by windows */
        wincl.style = CS_DBLCLKS;							/* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);		/* Use default icon and mouse-pointer */
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;							/* No menu */
        wincl.cbClsExtra = 0;								/* No extra bytes after the window class */
        wincl.cbWndExtra = 0;								/* structure or the window instance */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;    /* Use Windows's default color as the background*/
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        /* The class is registered */
        /* WS_EX_TOPMOST - always on top | WS_EX_NOACTIVATE - Prevent mouse input from activating the window*/
        /* WS_POPUPWINDOW - no title bar | WS_SIZEBOX - resizable */
        hwnd = CreateWindowEx (WS_EX_TOPMOST | WS_EX_NOACTIVATE, szClassName, L"App", WS_POPUPWINDOW | WS_SIZEBOX,
    		CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hThisInstance, NULL);
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
    
    	while(messages.message != WM_QUIT)
    	{
    		// IF there is a Windows message then process it.
    		if(PeekMessage(&messages, 0, 0, 0, PM_REMOVE))
    		{
    			TranslateMessage(&messages);
    			DispatchMessage(&messages);
    		}
    		// ELSE, do other stuff.
    		else
            	{	
    				//SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
            	}
    	}
    
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    }
    
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_DESTROY:
            case WM_RBUTTONUP:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
    
    		case WM_MOVING:	/* fix for a bug in windows that prevents contents of the windows from being displayed */
    		case WM_SIZING:				
    			{
    				RECT *prc = (RECT *)lParam;
    				SetWindowPos(hwnd, NULL, prc->left, prc->top, prc->right - prc->left, prc->bottom - prc->top, 0);
    			}
    			break;
    
    		case WM_LBUTTONDOWN:
    			SendMessage(hwnd, WM_SYSCOMMAND, SC_MOVE | 0x0002, 0);
    			break;
    
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    I forget who originally posted this, but the below might work since it allows you to define how large an area a titlebar would be. Basically, you can't shove the window up further than the lower extreme of a titlebar since you have nothing to grab onto.

    Code:
            static RECT titleRect  = { 0, 0, 300, 90  };    
                        
            case WM_LBUTTONDOWN: 
                {
                POINT pt = { LOWORD(lParam), HIWORD(lParam) };
                if ( PtInRect(&titleRect, pt) )
                SendMessage(hwnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam) ;
                return 0 ;
                }
    Another option you could look into would be to set up the up/down arrow keys & move your window that way as well.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2
    This doesn't work (at least in 7). I notice in Windows 7, it doesn't matter how big the title bar is, you can't even move the title bar partially off the top of the screen. If any part of the title bar is obscured (even if it's 1 pixel), it will pop down.
    Last edited by quoc; 05-29-2010 at 02:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Replies: 4
    Last Post: 01-16-2006, 05:58 PM
  3. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 03:41 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21