Also is the width you supply wide enough?
Main Topics
Browse All TopicsI am trying to move a date-time control in a Visual C++ 2005 system. When I use MoveWindow it displays perfectly, but will not drop down the calendar.
This code
GetDlgItem(IDC_COMPDATETO)
does not display properly. The graphic at the right hand end of the control does not appear and the border is broken. If I click where the graphic should be, the calendar displays as it should. The graphic stays on the screen afterwards.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks Andy, but your suggestion had no effect.
It is a very busy form with many options: controls do overlap but those that do in this case are hidden.
I went through this exercise to remove confusion when modifying the form: I think it is time to place them using the IDE and tolerate the mess that will be caused. I tried MoveWindow first: the control was drawn correctly, but wouldn't drop down.
It is late Friday afternoon and I'll be closing down soon, so please excuse lack of response.
Seems like we have this question twise:
http://www.experts-e
I've answered there - try MoveWindow instead of SetWindowPos. I think MFC will do everything for you.
I don't think the problem is with SetWindowPos (or MoveWindow).
You talk about many controls on the form - just how many is that? (Don't answer - but have a quick count for yourself).
From your screen shot I count 10 - 5 with text, 1 check, 2 DateTimePickers and 2 rectangle (group box)
I seem to recall that windows can have problems when there are a lot of controls on a window (rather less than the documentation says you can have). I know it is not trivial but you may have to consider a significant reorganisation. Have you considered a propertysheet/page based organisation with tabs to group related controls together?
To Andy comment 25642068: I tried both SetWindowPos and MoveWindow on a similar control on a less busy form and it worked perfectly. The original form has 116 controls, the less busy one has 28
To pqnatyuk: the control displayed correctly, but the calendar did not drop down
To Dan: setting tab order to 1 made no discernible difference
I played with changing tab order and there were some changes: the control with the SWP_NOZORDER parameter sometimes displayed correctly and wouldn't drop down and sometimes dropped down but wouldn't display.
Thanks
I verified that a simple call to MoveWindow() works as expected.
CDateTimeCtrl* p= (CDateTimeCtrl*)GetDlgItem
p->MoveWindow(100,310, 100, 20, 1 );
The only way that I can get it to misbehave is if there is another control at the same position, especially if it overlaps the [v] drop-down button.
That other control might be a static control or a group box, or other control that you think is not important or that you can't easily see becasue it's the same color as the background.
If you can't get it to drop down, try this:
Tab to the control, then press Alt+<down arrow>. That should show th MonthCalCtrl even if clicks are prevented by some over-laying control.
One other possibility: Have you added an override for DTN_DROPDOWN ??
If so, show your code -- it's about the only way to mess things up.
>>To pqnatyuk: the control displayed correctly, but the calendar did not drop down
and DanRollins mentioned DTN_DROPDOWN.
I can be wrong....
The rectangle you pass to MovieWindow or SetWindowPos is big enough? Can we test a much bigger height?
I think you are moving the control, but, probably, the control calculates its size, and, maybe, you need to pass a rectangle big enough for the dropdown.
I'd try this way.
Overlapping controls - that was suggested early on by me.
SetWindowPos - that has a left, top and a width, height pair - not a rectangle.
> I tried both SetWindowPos and MoveWindow on a similar control on a less busy form and it worked perfectly.
The total number of controls (116) does seem rather small to cause problems but.
Can you reduce the total number of controls on the active form?
Could you rebuild it from scratch (in dialog editor) and add the controls you require and see if that cures it?
Can you put some controls onto another dialog and have that as a child dialog embedded in this one?
Can you redesign as a tabbed dailog (PropertySheet/PropertyPag
Thanks guys, some interesting points above.
Just fyi, the form is used for report selection parameters. There are now nearly 20 reports serviced by the form and controls are switched on and off and redefined as appropriate. When we needed to add another from/to date combo, it had to go where a pair of edit controls exist for another report. I thought it would be tidier to place the new controls in an unused area, and move them at run-time.
I'll put them in their place at design time and cope with the confusion.
I agree that a redesign would be a good idea.
I've placed the control using the IDE. I can confirm that moving it wasn't the problem, as I had to place it a few pixels away from where it really should have been, otherwise the calendar wouldn't drop.
Thanks to everyone who responded: I learned a few things even if the fundamental problem wasn't solved.
>>otherwise the calendar wouldn't drop.
Did you notice if it would drop down if you select it then use the keyboard command: Alt+<down arrow>
That symptom indicates that the problem is that a disabled or static control is overlaying part of the DatePicker.
There is no need to leave this question with any doubt in your mind. The control works exactly as it should. The problem lies with having too many overlapping controls. You can leave this (incorrectly) thinking there is a flaw in Windows, or you and use this as a lesson in proper U/I design. It's up to you.
Business Accounts
Answer for Membership
by: AndyAinscowPosted on 2009-10-22 at 23:11:16ID: 25641642
Areyou certain with the NULL as the first parameter in SetWindowPos?
d>
Also why do you pass NULL as the value for nFlags into the SetWindowPos function?
<dl><dt>From the help file
</dt><dt>nFlags</dt><d
Specifie s sizing and positioning options. This parameter can be a combination of the following:
</dd></dl>SWP_DRAWFRAME Draws a frame (defined when the window was created) around the window.
SWP_FRAMECHANGED Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.
SWP_HIDEWINDOW Hides the window.
SWP_NOACTIVATE Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or the nontopmost group (depending on the setting of the pWndInsertAfter parameter).
SWP_NOCOPYBITS Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
SWP_NOMOVE Retains current position (ignores the x and y parameters).
SWP_NOOWNERZOR DER Does not change the owner window's position in the Z-order.
SWP_NOREDRAW Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title and scroll bars), and any part of the parent window uncovered as a result of the moved window. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that must be redrawn.
SWP_NOREPOSITION Same as SWP_NOOWNERZORDER.
SWP_NOSENDCHANGING Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
SWP_NOSIZE Retains current size (ignores the cx and cy parameters).
SWP_NOZORDER Retains current ordering (ignores pWndInsertAfter).
SWP_SHOWW INDOW Displays the window.nFlags