|
-
December 19th, 2002, 02:20 PM
#1
close application using PostMessage
Hi, All
I am trying to use the following VB .Net code (originated from VB code) to close applicaiton. The applicaiton is not closing.
Please let me know what is the problem.
Thanks /dan
'*************************************************
Module Module1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_CLOSE = &H10
Sub Main()
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "Calculator")
If winHwnd <> 0 Then
PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
MsgBox(winHwnd)
Else
MsgBox("The Calculator is not open.")
End If
End Sub
End Module
-
December 19th, 2002, 03:36 PM
#2
First think I notice is that all your "As Long"s need to be changed to "As Integer"...
-
December 19th, 2002, 03:54 PM
#3
Actually The First thing I notices was that DSJ is wrong.
VB Long = C++ int = 32 bits
VB Int = C++ short = 16 bits.
I am assuming that the MsgBox which simply displays a number is appearing....
Is the calculator program the same one as was used with the VB6 code? Could there be any reason why the calculator acan NOT close?
Finally, do the first thing that should be done and check the return code from PostMessage (use GetLast Error as needed).
It is poor practice to not check the return value of every API call. Check 999 out of 1000 and that will be the one that fails!
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 20th, 2002, 09:37 AM
#4
I beg to differ... unless Mircosoft sent me a bad help file. Mine plainly states in the "Integer Data Type Changes" section:
VB 6 Integer = 16 bits
VB 6 Long = 32 bits
.Net Short = 16 bits
.Net Integer = 32 bits
.Net Long = 64 bits
The declarations given are correct for VB6 but NOT .NET!!!
-
December 20th, 2002, 10:21 AM
#5
aargh, a thousand lashes!!!!!
I did not notice that this was the .NET forum!!!!!!
My post applied to the differences between Vc6 and vB6.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 20th, 2002, 04:12 PM
#6
DSJ,
Thanks, and it's working now./dan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|