如何向运行外部应用程序的SysMonthCal32发送日期? [英] How to send a date to SysMonthCal32 of running external application?
本文介绍了如何向运行外部应用程序的SysMonthCal32发送日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在试图弄清楚如何向外部应用程序的SysMonthCal32发送/设置日期。我有正确的窗口,可以设置当前的文本框,复选框和按钮,但不知怎的,我无法让它为MonthCalendar工作。
我的代码:
I'm trying to figure out how to send/set a date to SysMonthCal32 of a external application. I have the correct windowhandle and can set present textboxes, checkboxes and buttons, but somehow I can't get it to work for the MonthCalendar.
My code:
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
'MonthCalendar
Public Const MCM_SETCURSEL = &H1002
Dim hWnd As IntPtr
Dim sClassName As StringBuilder
Dim length As Integer
Dim sb As New System.Text.StringBuilder
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ChildHandle As IntPtr
Dim ChildHandle2 As IntPtr
Dim ChildHandle3 As IntPtr
Dim ButtonHandle As IntPtr
Dim MainWindowHandle As IntPtr
MainWindowHandle = FindWindow(Nothing, TextBox3.Text)
hWnd = Nothing
hWnd = FindWindowEx(MainWindowHandle, 0&, vbNullString, vbNullString)
hWnd = FindWindowEx(MainWindowHandle, hWnd, vbNullString, vbNullString)
hWnd = FindWindowEx(MainWindowHandle, hWnd, vbNullString, vbNullString)
ChildHandle = FindWindowEx(hWnd, 0&, vbNullString, vbNullString)
ChildHandle = FindWindowEx(hWnd, ChildHandle, vbNullString, vbNullString)
ChildHandle2 = FindWindowEx(ChildHandle, IntPtr.Zero, "WindowsForms10.Window.8.app.0.33c0d9d", "Date frame to search")
ChildHandle3 = FindWindowEx(ChildHandle2, 0&, vbNullString, vbNullString)
ButtonHandle = FindWindowEx(ChildHandle2, ChildHandle3, vbNullString, vbNullString)
'### TO CHECK FOR CORRECT WINDOW/HANDLE ###
sClassName = New StringBuilder("", 256)
Call GetClassName(ButtonHandle, sClassName, 256)
TextBox1.Text = sClassName.ToString
length = GetWindowTextLength(ButtonHandle)
sb = New System.Text.StringBuilder("", length)
GetWindowText(ButtonHandle, sb, sb.Capacity + 1)
TextBox2.Text = sb.ToString
'###
Dim seldate As Date = Format(CDate("24-08-2013"), "dd-MM-yyyy")
Dim setdate As SYSTEMTIME
With setdate
.wYear = Year(seldate)
.wMonth = Month(seldate)
.wDayOfWeek = Weekday(seldate, vbSunday) - 1
.wDay = seldate.Day
.wHour = Hour(seldate)
.wMinute = Minute(seldate)
.wSecond = Second(seldate)
.wMilliseconds = 0
End With
If ButtonHandle <> 0 Then
SendMessageDate(ButtonHandle, MCM_SETCURSEL, 0&, setdate)
End If
End Sub
'SENDMESSAGEDATE
Private Declare Function SendMessageDate Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As SYSTEMTIME) As Long
Public Structure SYSTEMTIME
Dim wYear As Integer
Dim wMonth As Integer
Dim wDayOfWeek As Integer
Dim wDay As Integer
Dim wHour As Integer
Dim wMinute As Integer
Dim wSecond As Integer
Dim wMilliseconds As Integer
End Structure
End Class
错误我是得到的是SendMessageDate:
检测到PInvokeStackImbalance!
有没有人有任何想法?在此先感谢!
The error I'm getting is on the SendMessageDate:
PInvokeStackImbalance was detected!
Does anyone have any ideas? Thanks in advance!
推荐答案
好吧,我怀疑任何人都能够帮助处理SysMonthCal32的事情,无论是什么。
但是,堆栈不平衡来自你的Declare。你正在使用VB6的Decalre语句,而不是VB.NET。 VB6中的Long是一个32位有符号整数,在VB.NET中它是一个64位有符号整数。
VB.NET中的Declare语句是:
Well, I doubt anyone is going to be able to help with the SysMonthCal32 thing, whatever that is.
But, the stack imbalance is coming from your Declare. You're using a Decalre statement for VB6, not VB.NET. A Long in VB6 was a 32-bit signed integer, where in VB.NET it's a 64-bit signed integer.
The Declare statement in VB.NET is:
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
这篇关于如何向运行外部应用程序的SysMonthCal32发送日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文