Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 11th, 2005, 11:06 AM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default DTM_SETSYSTEMTIME SendMessage

Anyone knows why a SendMessage/DTM_SETSYSTEMTIME fails across processes?[when the message is send from one process to the Date Time picker control in a different process, SendMessage returns 0 - indicating an error - and the picker remains unaffected]

Following is the code I had used to send

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long

Private Declare Function GetLastError Lib "kernel32" () As Long

Private Const DTM_GETSYSTEMTIME = &H1001
Private Const DTM_SETSYSTEMTIME = &H1002
Private Const DTM_SETFORMAT = &H1032


Private Const GDT_VALID = 0
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Sub Command1_Click()
Dim lngwhnd As Long
Dim lngwhnd_DTPick As Long
Dim lngErr As Long
Dim objSYS1 As SYSTEMTIME
Dim objSYS As SYSTEMTIME
Dim lngptr As Long

Dim str As String
objSYS.wYear = Year(Now) - 1
objSYS.wMonth = Month(Now) - 1
objSYS.wDay = Day(Now) - 1

lngwhnd = FindWindow(vbNullString, "DTPick")
lngwhnd_DTPick = FindWindowEx(lngwhnd, 0, "DTPicker20WndClass", vbNullString)

lngErr = SendMessage(lngwhnd_DTPick, DTM_GETSYSTEMTIME, GDT_VALID, objSYS)

lngErr = GetLastError

End Sub

I was able to set the date in the same process using the above code.

Also tried sending the LPARAM as pointer to the system date structure using the VarPtr function !! it didt work

 
Old November 18th, 2005, 04:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

FindWindowEx internally calls GetWinfowText to retrieve the name of the window if the control is in the same process, if however the control belongs to some other process GetWinfowText retreivs only the caption of the window if any otherwise it returns NULL in which case there's nothing to compare the window name with. So make sure that u are able to find the window name and thus getting the window handle correctly before trying to send the control any messages.


Regards
Ankur Verma





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to SendMessage to an IE Dialog? DriveU C# 0 January 9th, 2007 02:57 AM
Sendmessage in flexgrid areejan2000 Crystal Reports 0 November 12th, 2005 02:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.