?
Solved

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

Posted on 2003-03-04
9
Medium Priority
?
358 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:lidorc
  • 4
  • 2
  • 2
8 Comments
 
LVL 12

Expert Comment

by:Salte
ID: 8063406
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
0
 
LVL 12

Expert Comment

by:Salte
ID: 8063409
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
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 800 total points
ID: 8066145
There is a style bit associated with the 'floating' feature -- CBRS_FLOATING I believe that it is a default for standard MFC programs.

If you remove that style bit before or after it is created, then the controlbar will not float.  See the MSDN documentation for GetBarStyle and SetBarStyle.  You might also check into EnableDocking just for fun.

-- Dan
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Salte
ID: 8066957
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
0
 
LVL 30

Expert Comment

by:Axter
ID: 9374675
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
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9374778
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
0
 
LVL 12

Expert Comment

by:Salte
ID: 9376659
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
0
 
LVL 30

Expert Comment

by:Axter
ID: 9377129
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.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question