Link to home
Start Free TrialLog in
Avatar of lidorc
lidorc

asked on

How can I lock a control bar so it won't float

Hi there..

All the neccessary keywords: VC++ 6, MFC, Win2000, Standard MFC (exe) Application.

I have a regular control bar, how can I lock it in a way that the user will not be able to float it. I want it to be docked all the time. Another thing, if we're talking, I don't want the user to move the control bar either, but that's less important..

Hope you can help.

  lidorc
Avatar of Salte
Salte

Just override the functions that handles those actions.

All such actions are performed by user doing something with mouse or keyboard that causes an event to arrive to the application and the application will then call a function to handle that event. If you places your own handler there which essentially ignore the event the user won't be able to move it. Make sure you only block those that you really want to block, for example if you don't want the user to move the window you can just override the handler that moves the window. This handler will typically move the window using a low level Win32 function but it does so based on the input from user. If you override that function and simply doesn't call that Win32 function the window won't move.

Be aware that if you are not careful you might end up that suddenly none of the windows for that application can move any more. It is probably good to have a check something like:

int CMyControlBar::OnWindowMove(....)
{
   /* do nothing */
   return 0;
}

This code is safe, it is a function belonging to CMyControlBar and so only instances of that control bar will be unable to move any other windows can move.

If you instead intercept the message handling for all windows you should check that the window is the window for your control bar and not some other window.

Also note that the name 'OnWindowMove' is probably incorrect. I don't know what MFC calls that function to handle the window moving but I am also sure you can find it if you search the MFC help. There you will also find exactly what arguments and return type is and what that return type is supposed to mean. I would guess that one return value is used to mean that the window should not be moved and another might mean the window has already moved and possibly yet another might mean that Windows should move the windor after this function is done. Which values have which meaning is also explained in the MFC help.

Alf
Oh, just to make it clear:

The locking of the window so that it doesn't float is exactly like the move window situation. It is just another handler that you should intercept.

Alf
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
blah,

Dan got it right.

Yes, you can simply clear that bit to make the window 'not floatable'.

To avoid moving it I believe you might even have a bit for that too, if you don't you still have to override the OnWindowMove() handler.

I am not sure what the name of that event is called to tell the window to move itself but it is easy enough to find out: Just start a program and attempt to or move the window and see what messages you get in a spy program.

Check out the style bits, it's possible one of the style bits also indicate that the window is fixed and cannot move. Typically controls such as a button or edit box won't move around if you want them to, so they have somehow managed to block themselves from being moved. If this is because they usually don't have a title bar and you have to click the title bar etc to move it I don't know, but I doubt it, you could still move the control using keys but that is blocked as well. Chances are that they set a style bit to tell windows "I don't want move messages".

If you don't want the window to move you probably don't want it to be resized either so you should block that too.

Alf
lidorc,
No comment has been added lately (196 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to Salte http:#8063406

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

Axter
EE Cleanup Volunteer
I recommend a split on this.  Setting the style bit, as I suggested, is the normal way to prevent a toolbar from floating.   I suppose that Salte's idea to intercept the the move requests would also work, but it is unnecessary since MFC and the OS will do this for you.

-- Dan
I believe Dan should get the points for this one.

My solution was assuming old style MFC where you didn't have any style bit for floating controls.

However, the poster did write he has Win 2000 so I believe he does have support for style bit and then Dan's solution is better than mine.

Alf
Sounds good to me.
The EE Admin I talked to, said after you guys add your recommendation, that I didn't need to take any further action.  The EE Admin who takes the recommended action will review your recommendations before processing the question.