CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2001
    Posts
    36

    Making the Form immovable

    Please help me to make a form immovable without using the movable property.

    Thanks


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Making the Form immovable

    Why without using the MoveAble property?

    You could intercept the WM_MOVE commands going to the form using a subclassing tool (see http://www.merrioncomputing.com/Download/index.htm for one called EventVB.dll) but this would be no different than that property.

    HTH,
    D

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Making the Form immovable

    I believe ithat if you delete the title bar from the form, then you cannot move the form without applying certian tricks. Try it.

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Making the Form immovable

    Another option:

    private Declare Function GetSystemMenu Lib "User" (byval hWnd%, byval bRevert%) as Integer
    private Declare Function DeleteMenu Lib "user" (byval hMenu%, byval iditem%, byval wflags%) as Integer

    private Const SC_SIZE = &HF000
    private Const SC_MOVE = &HF010
    private Const MF_BYCOMMAND = &H0

    Sub Form_Load()
    Dim hWnd%, hMenu%, Success%
    hWnd% = me.hWnd
    hMenu% = GetSystemMenu(hWnd%, 0)
    Success% = deletemenu(hMenu%, SC_SIZE, MF_BYCOMMAND)
    Success% = deletemenu(hMenu%, SC_MOVE, MF_BYCOMMAND)
    End Sub



    Deleting the corresponding item from the system menu prevents the action. This code prevents resizing too.


  5. #5
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Making the Form immovable

    Hi shree,
    It is an exellent solution. But I believe you have to use "user32" instead of "user"

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  6. #6
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Making the Form immovable

    Oh yes, this is an example from the MSDN, and I forgot to "upgrade"


  7. #7
    Join Date
    May 2001
    Posts
    36

    Re: Making the Form immovable

    Excellent but its not working in Windows CE

    Iam not finding the getSystemMenu api on windows API
    Please help me



  8. #8
    Join Date
    Jul 1999
    Posts
    84

    Re: Making the Form immovable

    Hello Shree,

    How will I know what values are to be passed for the second parameter of DeleteMenu.

    You have been giving &HF000 and &HF010. How will we know what value should be specified?

    Thanks
    Harini

  9. #9
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Making the Form immovable

    The common System menu items are Move, Size and Close, SC_CLOSE is defined as &hF060. If you want to access other items, then you can use MF_BYPOSITION and specify the position number, 0 for the first menu item. Here is the code that will remove Restore and Move from the system menu:


    Code:
    private Declare Function GetSystemMenu Lib "user32" (byval hWnd%, byval bRevert%) as Integer
    private Declare Function DeleteMenu Lib "user32" (byval hMenu%, byval iditem%, byval wflags%) as Integer
    
    private Const SC_SIZE = &HF000
    private Const SC_MOVE = &HF010
    private Const MF_BYCOMMAND = &H0
    private Const MF_BYPOSITION = &H400&
    
    Sub Form_Load()
        Dim hWnd%, hMenu%, Success%
        hWnd% = me.hWnd
        hMenu% = GetSystemMenu(hWnd%, 0)
        'Success% = DeleteMenu(hMenu%, SC_SIZE, MF_BYCOMMAND)
        'Success% = DeleteMenu(hMenu%, SC_MOVE, MF_BYCOMMAND)
        Success% = DeleteMenu(hMenu%, 0, MF_BYPOSITION)
        Success% = DeleteMenu(hMenu%, 0, MF_BYPOSITION)
    End Sub


    Note that I use 0 to remove the Move item too, because after Restore is removed, it is the first item in the menu.
    Last edited by Cimperiali; April 4th, 2003 at 01:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured