Question

Moving Date Time Picker Control

Asked by: BeaconSoftware

I 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)->SetWindowPos(NULL,DLGX(310),DLGY(208),DLGX(57),DLGY(12),NULL) ;
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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-22 at 16:48:16ID24836588
Tags

C++ MFC

Topics

Windows MFC Programming

,

Microsoft Visual C++.Net

Participating Experts
3
Points
250
Comments
25

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. GetWindowRect and MoveWindow
    How can I use GetWindowRect and MoveWindow together? In other words, if I use GetWindowRect to get a RECT value, and after changing the value, I want to set the window to the new value, how do I do this. I tried using MoveWindow, but this doesn't seem to work right with a c...
  2. Date Time Picker Problem
    Dear All, I am creating a dialog application using MFC , and in which i am using a "Date Time Picker control" I want to set the time in format hh:mm. --------- I have kept ID of control : IDC_TIME and using the following macro in Initdialog DateTime_SetFormat((HWND)...
  3. invalid pointer return from GetDlgItem
    Hi Experts, I've got a CPropertySheet-derived object that contains a CPropertyPage that contains a CListCtrl-derived class called CEditableListCtrl. When I GetDlgItem on that CEditableListCtrl's ID, I can see it's the first invalid pointer I get back. Note, the GetDlgItem ...
  4. calendar date picker
    Hi all, I am using c# code behind/ASP.NET. I need some code that will generate a "calendar date picker" ...eg i need a form with two text boxes with two calendar images next to them and when the calendar images are clicked a need a calendar to pop up and the user ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: AndyAinscowPosted on 2009-10-22 at 23:11:16ID: 25641642

Areyou certain with the NULL as the first parameter in SetWindowPos?

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><dd>

Specifies sizing and positioning options. This parameter can be a combination of the following:

  • 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_NOOWNERZORDER   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_SHOWWINDOW   Displays the window.nFlags  

     
</dd></dl>

 

by: AndyAinscowPosted on 2009-10-22 at 23:13:01ID: 25641650

Also is the width you supply wide enough?

 

by: BeaconSoftwarePosted on 2009-10-22 at 23:17:26ID: 25641670

I'm not certain of anything<g>

I have tried various variations for both first and last parameters. I have been playing with wider widths. See the code snippet and screenshot for two experiments.

Thanks

 

        GetDlgItem(IDC_COMPDATEFROM)->SetWindowPos(&wndTop,DLGX(230),DLGY(208),DLGX(63),DLGY(14),SWP_DRAWFRAME | SWP_SHOWWINDOW | SWP_NOCOPYBITS    ) ;
        GetDlgItem(IDC_COMPDATETO)->SetWindowPos(NULL,DLGX(310),DLGY(208),DLGX(58),DLGY(14),NULL) ;
                                              
1:
2:

Select allOpen in new window

 

by: AndyAinscowPosted on 2009-10-22 at 23:28:33ID: 25641705

Is there some other control that overlaps them?

Assume the check box displayed has the following ID for the following code

GetDlgItem(IDC_COMPDATEFROM)->SetWindowPos(GetDlgItem(IDC_CHECK1),DLGX(230),DLGY(208),DLGX(63),DLGY(14), SWP_SHOWWINDOW);

Does that help?

 

by: BeaconSoftwarePosted on 2009-10-22 at 23:39:58ID: 25641766

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.

 

by: AndyAinscowPosted on 2009-10-22 at 23:44:18ID: 25641785

OK.
By any chance is this date time picker a standard windows control or one you have based a new class on?

 

by: BeaconSoftwarePosted on 2009-10-22 at 23:50:34ID: 25641807

Standard Windows as far as I'm aware.

By the way, the control that I copied from for both controls was 57 x 12 so it looks to me as if the shadow (for want of a better description) is just about where the graphic should go.

Thanks

 

by: pgnatyukPosted on 2009-10-23 at 00:30:53ID: 25641989

Seems like we have this question twise:
http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_24836590.html

I've answered there - try MoveWindow instead of SetWindowPos. I think MFC will do everything for you.

 

by: AndyAinscowPosted on 2009-10-23 at 00:46:41ID: 25642033

@pgnatyuk
from question  When I use MoveWindow it displays perfectly, but will not drop down the calendar.

 

by: AndyAinscowPosted on 2009-10-23 at 00:55:14ID: 25642068

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?

 

by: pgnatyukPosted on 2009-10-23 at 01:10:31ID: 25642146

Please chek this:

GetDlgItem(IDC_COMPDATEFROM)->SetWindowPos(GetDlgItem(IDC_CHECK1),DLGX(230),DLGY(208),DLGX(63),DLGY(14), SWP_NOZORDER);

 

by: DanRollinsPosted on 2009-10-23 at 13:38:04ID: 25648332

One other tip:  Try changing the tab order.  Set the calendar controls with higher numbers than other controls (I suspect that you have static or edit controls that are interfering).

 

by: BeaconSoftwarePosted on 2009-10-24 at 15:26:34ID: 25654659

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

 

 

by: DanRollinsPosted on 2009-10-24 at 19:46:58ID: 25655315

I verified that a simple call to MoveWindow() works as expected.

CDateTimeCtrl* p= (CDateTimeCtrl*)GetDlgItem(IDC_DATETIMEPICKER1);
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.

 

by: DanRollinsPosted on 2009-10-24 at 19:50:42ID: 25655325

You can find which window is overlapping your control by using the Spy++ program (it's under the Tools menu).  

Start Spy++ and then press Ctrl+F.  Drag the "Finder Tool" all over your form.  You'll probably see things that you don't even realize are there!

 

by: DanRollinsPosted on 2009-10-24 at 19:52:52ID: 25655330

Sorry... one more point.  
Why are you moving this control?  Usually controls are put in position at design time and stay there forever.  Perhaps there is a method other than moving the control that will accomplish what you need tto do.

 

by: pgnatyukPosted on 2009-10-24 at 22:13:07ID: 25655611

>>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.

 

by: AndyAinscowPosted on 2009-10-25 at 00:38:38ID: 25655844

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/PropertyPages) ?

 

by: BeaconSoftwarePosted on 2009-10-25 at 14:10:35ID: 25658293

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.

 

by: DanRollinsPosted on 2009-10-25 at 17:46:57ID: 25659182

Wow.  I'd never go that route.  I'd probably use a propertysheet with different pages to handle the variations.

 

by: BeaconSoftwarePosted on 2009-10-27 at 14:25:54ID: 25677747

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.

 

by: BeaconSoftwarePosted on 2009-10-27 at 14:29:45ID: 31644820

My original question wasn't able to be answered but the answers make clear the problem is more Windows based than a programming error

 

by: DanRollinsPosted on 2009-10-27 at 15:22:21ID: 25678316

>>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.

 

by: AndyAinscowPosted on 2009-10-27 at 23:23:40ID: 25680367

>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.

As I said early on - that sounds rather like the control is partialy obscured by another.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...