Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Date/Time 2

Status
Not open for further replies.

1962dez

Programmer
Nov 20, 2008
4
CV
Good morning,
I can call the date/time control with the following command but sometimes it doesn't open directly and appears in the toolbar. I need control to come forward.
Thanks in advance.

! /n control date/time
* Declara funções de API
cTituloJanela = 'Data e hora'
Declare Integer BringWindowToTop In Win32API Integer HWnd
lnWinHandle = FindWindowLike(cTituloJanela)
If !Empty(lnWinHandle)
BringWindowToTop(lnWinHandle) && Trazer a janela para frente
endif
CLEAR DLLS GringWindowToTop
 
What is FindWindowLike()? That is not a VFP function or a standard API call, as far as I know. I think the function you want is FindWindow().

Also, try using SetForegroundWindow() rather than BringWindowToTop().

With that in mind, try the following code:

Code:
! /n control date/time
cTituloJanela = 'Data e hora'

* Declara funções de API
DECLARE INTEGER FindWindow IN user32;
 STRING lpClassName,;
 STRING lpWindowName 
DECLARE INTEGER SetForegroundWindow IN user32 INTEGER hwnd 

lnWinHandle = FindWindow(NULL,cTituloJanela)

If !Empty(lnWinHandle)
 SetForegroundWindow(lnWinHandle)
ENDIF

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you very much,
It works but I can't get it to stay on top. It always goes to the toolbar and I have to click on it to appear.
 
Yes, I'm seeing the same thing. It is launching the applet OK, but FindWindow() is returning 0 rather than the actual window handle.

I'm not sure why this is happening. The same code works OK with other applets, such as Character Map and Calculator.

What is your ultimate goal? Do you simply want to display a clock? Or give the user the ability to change heto clock or the time zone? It's possible that there is some other way of achieving that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
For me, both ! /n control date/time and ! /n control timedate.cpl work the same, both reliably start the Date/Time system window.

Yes, it's getting into the Taskbar (I think you mean taskbar, not toolbar, 1962dez). That's not unusual even for a normal application, there's nothing to bother with that.

If SetForegroundWindow(lnWinHandle) doesn't work, the question is, is it even run? I mean, try this:

Code:
If !Empty(lnWinHandle)
 SetForegroundWindow(lnWinHandle)
Else
 MessageBox('Window "'+cTituloJanela+'" not found.')
Endif

If you often get the message Window "Data e hora" not found you should wait. Also notice in English Windows you won't find that window, the title is localized with the Windows language used, so it will differ by countries and your version only works for Spain (I assume) or is it Portugal, Brazil? Anyway, not internationally. That's a problem for working with FindWindow.

Googling screenshots I see that the actual Spanish title is "Data e Hora" with a big H. That doesn't matter, though, FindWindow finds windows case insensitive, i.e. it also finds "date and time", not only "Date and Time", it would also find "data e hora", so it is - furtately for you - not important whether the case of the title matches.

The other reason a window is not found is that it takes a bit longer to start on your system. ! /N does not wait for the command to execute, VFP continues right away and the FindWindow call could be done before the control.exe actually started the Date and Time window, then you don't just have a localization problem and would just need to wait before issuing FindWindow, which could be done with WAIT WINDOW '' TIMEOUT 0.5 or Windows API Sleep.

Chriss
 
According to a clean variatio of running control.exe is with canonical names of the Control Panel items

MS said:
control.exe /name canonicalName

And the canonical name for Date and Time is Microsoft.DateAndTime.

See
So another way is:
Code:
! /N control /name Microsoft.DateAndTime

This section for Canonical Names also tells this:
MS said:
Module name: @%SystemRoot%\System32\timedate.cpl,-51

So Mike's recommendation is also true, you can run timedate.cpl, perhaps better exactly as given:
Code:
! /N control timedate.cpl,-51

None of these variations will run the window faster or slower, I think. So the problem I guess is timing, i.e. waiting for the window to actually be started. The canonical names unfortunately won't help you with FindWindow, though, so if it is a problem of localization you only can halfways solve that in the start command, but not for FindWindow.

Chriss
 
Good afternoon,
I have the following scenario.
I need to send electronic invoices to a certain website, which has the time synchronized to (0.europe.pool.ntp.org). At the beginning of the day, I would like to force the machine window to synchronize with the address once, from my application VFP9 SP2.
I made some attempts with the following command but without success. Every help is welcome.
Thank you in advance.

Code:
DECLARE INTEGER ShellExecute IN shell32.DLL ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin
*ShellExecute(0,"runas","cmd.exe","w32tm /config /update /manualpeerlist:0.europe.pool.ntp.org","",0) && sometimes Admin rights are needed!
*ShellExecute(0,"runas","cmd.exe","net start w32time","",0) && sometimes Admin rights are needed!
*ShellExecute(0,"runas","cmd.exe","w32tm /resync","",0) && sometimes Admin rights are needed!
endfunc
 
Once you set up a time server (Windows usually is set to time.windows.com) in system configuration the clock synchrnoizes several times a day automatically.

No matter what time server you pick, the system clock time is always UTC and the time displayed by Windows is shifted to local time by the configured timezone of the system. So, no matter if you use a special eruopean time server or not, the effect doesn't differ from time.windows.com

Windows allows you to adjust for DST or not, if it comes to local time, so that's a reason systems can be an hour off the actual local time. I think - not sure - MS also did mistakes in DST bias, but I won't expect anything special from that override of the time server, unless that time server does something special and perhaps specifically intentionally wrong in comparison with the rest of the world, but why would it?

Anyway, all that said, runas itself does not run something as admin, you have to specify the user as parameter to it or a trustlevel. See
Chriss
 
I wonder whether you really need this, but after digging a bit, even with a /user parameter picking a local or domain admin account user, you start the process with that user profile but not yet elevated.

Here is an example of a thread providing several other solutions, some require powershell, others third party tools like nircmdc
Edit: I forgot to add the link, here it is:
Chriss
 
1962dez,

A different question, a different thread, please.

But, in anticipation of your new thread, when you say that the website is "time synchronized to (something)", do you mean it's in a different time zone?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top