Valhalla Legends Forums Archive | Visual Basic Programming | Re: More SendMessage issues.

AuthorMessageTime
laurion
Once again I'm trying to simulate a mouse click to an inactice window... here's what I have so far:

[code]
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
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 PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_PARENTNOTIFY = &H210
Private Const WM_MOUSEACTIVATE = &H21
Private Const HTCLIENT = 1


Private hWndParent As Long
Private hWndChild As Long


Private Sub cmdClickSub_Click()

    Dim lngResult As Long

    lngResult = SendMessage(hWndParent, WM_PARENTNOTIFY, WM_LBUTTONDOWN, MAKELPARAM(466, 301))
       
        Debug.Print "Result: " & lResult
   
    'lngResult = SendMessage(hWndParent, WM_PARENTNOTIFY, WM_LBUTTONUP, MAKELPARAM(466, 301))
    'in Winspector it doesn't show a WM_LBUTTONUP being sent after the WM_LBUTTONDOWN so i'll
    'hold off on that

    lngResult = SendMessage(hWndChild, WM_MOUSEACTIVATE, hWndParent, MAKELPARAM(HTCLIENT, 513))

        Debug.Print "Result: " & lResult

End Sub

Private Sub Form_Load()

    hWndParent = FindWindow("IEFrame", "Fiji - Windows Internet Explorer")
   
    Debug.Print "Parent:    0x" & Hex(hWndParent)

    hWndChild = FindWindowEx(hWndParent, 0&, "TabWindowClass", vbNullString)

    Debug.Print "Child:    0x" & Hex(hWndChild)
   
End Sub

'pulled off the internet, not my code
Public Function MAKELPARAM(wLow As Long, wHigh As Long) As Long
    MAKELPARAM = MAKELONG(wLow, wHigh)
End Function
Public Function MAKELONG(wLow As Long, wHigh As Long) As Long
    MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHigh))
End Function
Function LOWORD(ByVal dw As Long) As Integer
    If dw And &H8000& Then
        LOWORD = dw Or &HFFFF0000
    Else
        LOWORD = dw And &HFFFF&
    End If
End Function
[/code]

SendMessage isn't returning anything in the cmdClickSub_click event.
The hWnds match what I see in Winspector.
Can someone point me in the right direction? thanks.
February 3, 2007, 3:14 PM
Grok
What do you mean by "isn't returning anything"?
Your Debug.Print is displaying the contents of lngResult, which will definitely have a value, even if that is 0.
So, is it returning 0?

[quote]
Return Value
If an application processes this message, it should return zero.
[/quote]

With some after thought, I think you could use some error handling.  It will help you determine what's going on.  My general VB6 error handling is this:

[code]
Private Sub cmdClickSub_Click()
   
    On Error Goto cmdClickSub_ClickErr
    'do stuff that might possibly generate an error (pretty much anything)
    'your code goes here
   
cmdClickSub_ClickExit:
    Exit Sub
   
cmdClickSub_ClickErr:
    Select Case Err.Number
    Case 5                  'some handled case or cases
        'followed by the code to handle that case, such as:
        Resume Next
    Case Else
        Debug.Print "ERROR: " & Err.Number & "->" & Err.Description
    End Select
    Resume
   
End Sub
[/code]

Fix up your code so you are properly alerted to errors and try again.
February 3, 2007, 10:29 PM
laurion
[quote author=Grok link=topic=16234.msg163827#msg163827 date=1170541765]
What do you mean by "isn't returning anything"?
Your Debug.Print is displaying the contents of lngResult, which will definitely have a value, even if that is 0.
So, is it returning 0?

[quote]
Return Value
If an application processes this message, it should return zero.
[/quote]

With some after thought, I think you could use some error handling.  It will help you determine what's going on.  My general VB6 error handling is this:

[code]
Private Sub cmdClickSub_Click()
   
    On Error Goto cmdClickSub_ClickErr
    'do stuff that might possibly generate an error (pretty much anything)
    'your code goes here
   
cmdClickSub_ClickExit:
    Exit Sub
   
cmdClickSub_ClickErr:
    Select Case Err.Number
    Case 5                  'some handled case or cases
        'followed by the code to handle that case, such as:
        Resume Next
    Case Else
        Debug.Print "ERROR: " & Err.Number & "->" & Err.Description
    End Select
    Resume
   
End Sub
[/code]

Fix up your code so you are properly alerted to errors and try again.
[/quote]
Oh wow. I had it printing "lResult" to the debug and it should've been "lngResult".

Well, anyways, I'm getting these results: 0 for the first one, 1 for the second.

A return of 1 would be MA_ACTIVATE = Activates the window, and does not discard the mouse message.

I'm not seeing the button being clicked. Even when the IE window is active it isn't clicking.

Hm. I want it sent while the window isn't active, though.
February 3, 2007, 11:51 PM
Topaz
Isn't VB6 supposed to report errors when you refer to nonexistent variables?
February 4, 2007, 12:36 AM
Barabajagal
Only if Option Explicit is at the top of each Module (form, class, or otherwise). You can enable automatic adding of Option Explicit by going to the Options window in vb6, and checking the "Require Variable Declaration" checkbox.
February 4, 2007, 12:39 AM
Topaz
That's only the editor. It should be raising errors when you refer to absent variables during runtime
February 4, 2007, 1:16 AM
Barabajagal
You don't give VB as a language enough credit. Without Option Explicit, the compiled EXE counts all variables as defined when used. It's an amazing feature, so long as you have flawless typing skills.
February 4, 2007, 1:18 AM
Topaz
VB6 isn't dynamically typed. Please, delete your account again
February 4, 2007, 1:28 AM
Barabajagal
Please learn a bit more about languages before you insult them. I'll delete my account again when I want it deleted again, ty.
February 4, 2007, 1:30 AM
Topaz
You think it's ok for a language to allow the coder to call variables that don't exist? srsly?


You're just as dumb as I thought you were when you put "I Am Not What I Am - Iago from Shakesphere". lol @ phonetically spelling your words like a third grader
February 4, 2007, 1:38 AM
Barabajagal
I don't remember misspelling Shakespeare's name so terribly, but if I did, I apologize to Will and his family. It's perfectly fine to use variables that haven't been declared if the language supports it, since the COMPILER adds the declarations in automatically. Except that nowadays, it'd probably be defined as Variant, which isn't so good. but when it was originally written, there was one variable type: Variable. The difference was strings had $ at the end and numbers didn't.
February 4, 2007, 2:05 AM
Topaz
You are a liar.

http://72.14.253.104/search?q=cache:N4D3n2x0FDUJ:www.bnetweb.net/showthread.php%3Fp%3D674+Shakesphere+RealityRipple

[quote]
"I am not what I am" - iago(Shakesphere)[/quote]


There is no point declaring variables that don't exist if they never end up being used (other in the context where they're misspelled)
February 4, 2007, 2:22 AM
Barabajagal
Yes, because I don't remember something, and state that I don't remember it, I must be a liar. How wonderful your logic is. Of course there's no point declaring variables that don't exist. Removal of Option Explicit lets you save time by NOT declaring variables and using them anyway. When converted to assembly and compiled to an EXE, the converter adds the declarations automatically.
February 4, 2007, 9:36 PM
l2k-Shadow
However, having compiler automatically declare variables can lead to it declaring the variable to something that it shouldn't be, hence your program will then act like shit. Very bad coding practice.
February 4, 2007, 10:28 PM
Barabajagal
Yes, it is laziness, but if you follow old coding practices, like naming conventions that include a variable representation symbol like $, %, &, etc... it can make things much better, and actually allows for BETTER readability, because all the variables will be labeled by their type.
February 4, 2007, 10:32 PM
Quarantine
I forgot when this became a "argue about a stupid feature in VB6" thread.
February 4, 2007, 11:02 PM
Barabajagal
[quote author=topaz link=topic=16234.msg163852#msg163852 date=1170549394]
Isn't VB6 supposed to report errors when you refer to nonexistent variables?
[/quote]

Right there.
February 4, 2007, 11:07 PM
Quarantine
It's a bad design feature in VB6. It enforces shitty programming standards. Anyone who doesn't use Option Explicit should be shot.

What kind of retarded language lets you turn this stuff off anyhow? smh.
February 4, 2007, 11:08 PM
Barabajagal
It's not a bad design feature, it's remnants of the original BASIC language series. The feature is that you can turn it off, which is great. I agree, nowadays it should always be off, especially because of scopes, shared variable names with separate values, and the multitude of types (and yes, i realize there's more var types in other languages).
February 4, 2007, 11:12 PM
Explicit[nK]
[quote author=Ripple link=topic=16234.msg163978#msg163978 date=1170628321]
Yes, it is laziness, but if you follow old coding practices, like naming conventions that include a variable representation symbol like $, %, &, etc... it can make things much better, and actually allows for BETTER readability, because all the variables will be labeled by their type.
[/quote]

You could just as easily read something that follows the naming conventions used today...
February 4, 2007, 11:49 PM
Barabajagal
Yes, but most people don't. This would force you to do so, somewhat... except that most people don't care much about correct variable declaration anyway... In the end, it's no longer a useful feature, and so the option to disable it exists.
February 4, 2007, 11:52 PM
Quarantine
[quote author=[RealityRipple] link=topic=16234.msg163988#msg163988 date=1170630727]
It's not a bad design feature, it's remnants of the original BASIC language series. The feature is that you can turn it off, which is great. I agree, nowadays it should always be off, especially because of scopes, shared variable names with separate values, and the multitude of types (and yes, i realize there's more var types in other languages).
[/quote]

Then how is it not bad? You say it should be off today which means it's useless. Useless = Bad. This feature is bad. You done yet?
February 5, 2007, 12:00 AM
Barabajagal
it is not a "bad feature", it's a "remnant". I'm not saying it's not useless nowadays, that statement just says it wasn't written as a new feature.
February 5, 2007, 12:03 AM
Explicit[nK]
[quote author=[RealityRipple] link=topic=16234.msg163990#msg163990 date=1170633169]
Yes, but most people don't. This would force you to do so, somewhat... except that most people don't care much about correct variable declaration anyway... In the end, it's no longer a useful feature, and so the option to disable it exists.
[/quote]

Most people don't care?  See, that might be the case with Battle.net-related programmers, but beyond that, it's different.
February 5, 2007, 12:16 AM
Barabajagal
Most people as in people that don't do programming as a profession, but as a hobby. Say about 70% of VB6 users.
February 5, 2007, 12:19 AM
Topaz
[quote author=[RealityRipple] link=topic=16234.msg163992#msg163992 date=1170633828]
it is not a "bad feature", it's a "remnant". I'm not saying it's not useless nowadays, that statement just says it wasn't written as a new feature.
[/quote]

lol @ calling it a remnant. Perhaps there's a reason why it's a remnant instead of present in other languages? Give up. It's worthless and there's no reason for it to be there; I don't if you paid $20 for a piece of paper that says you're a Certified VB6 Interface Coding Professional. You admitted to it's worthlessness, and still you maintain the defense that it's still useful. Give up, you're a loser
February 5, 2007, 7:38 AM
Barabajagal
Ok, your grammar is lacking a bit there... So I'll try to answer what I think you asked. Yes, I paid $25 for Visual Basic 6 certification. Yes, it's pretty much a worthless feature nowadays (PRETTY MUCH doesn't mean totally useless). It's still there because there are uses for it. The fact is, it's there in (i think) all BASIC languages in some form. It's a handy time saver if you use it right.
February 5, 2007, 7:44 AM
laurion
so about the topic.
February 5, 2007, 12:05 PM
Quarantine
Lolol @ VB6 certification.
February 5, 2007, 11:29 PM
MyStiCaL
[quote author=Warrior link=topic=16234.msg164076#msg164076 date=1170718165]
Lolol @ VB6 certification.
[/quote]

he paid 9$ for a online test that multiple choice from a retarded site! =)
February 6, 2007, 6:43 AM
Barabajagal
$25 for certification from an ISO compliant certification system. They're fully accredited, used by many companies as a certification method. If you want to take a look, go to ExpertRating.com. If you don't want to believe they're a true form of certification, then whatever.
February 6, 2007, 7:47 AM
FrOzeN
You paid $25 for a certificate showing you know how to program in a deprecated language? What a total waste of money.

Essentially, VB6 is a language written in almost pseudo code allowing for RAD compared to what was previously available. I assume the reasoning behind allowing "Option Explicit" to be toggled on/off is that they wanted people to just type in code for what they wanted the program to do, and get it working with as little effort as possible. Though, it had it's huge fallback that all undeclared variables become Variants which requires VB6 to give them extra handling whilst being parsed around, and often lead to giving incorrect output. Not using Option Explicit for compiling a program of any importance is very stupid.

The idea behind dollar sign ($) and others to be used to declare variable types was probably to add a short-hand way of typing. However, it too is generally not used as the signs are also used when forcing certain built-in VB6 functions to return a value as a certain varible type (such as Mid$() returning a String, opposed to Mid() returning a Variant).
February 6, 2007, 10:31 AM
laurion
okk since vb is so crappy, let's assume im doing this in c++. now what is the problem?
February 6, 2007, 2:57 PM
Topaz
The use of $ probably derived from Perl
February 6, 2007, 4:28 PM
Grok
[quote author=topaz link=topic=16234.msg163895#msg163895 date=1170553134]
You think it's ok for a language to allow the coder to call variables that don't exist? srsly?


You're just as dumb as I thought you were when you put "I Am Not What I Am - iago from Shakesphere". lol @ phonetically spelling your words like a third grader
[/quote]

[quote author=topaz link=topic=16234.msg164030#msg164030 date=1170661113]
[quote author=[RealityRipple] link=topic=16234.msg163992#msg163992 date=1170633828]
it is not a "bad feature", it's a "remnant". I'm not saying it's not useless nowadays, that statement just says it wasn't written as a new feature.
[/quote]

lol @ calling it a remnant. Perhaps there's a reason why it's a remnant instead of present in other languages? Give up. It's worthless and there's no reason for it to be there; I don't if you paid $20 for a piece of paper that says you're a Certified VB6 Interface Coding Professional. You admitted to it's worthlessness, and still you maintain the defense that it's still useful. Give up, you're a loser
[/quote]

Damn topaz, you've been busy getting in people's faces.  These two each add 15 days to your ban, bringing it to 45 days.

Go take a chill pill and learn to be part of a community.  You're smart, you should want to be helpful and not such a negative person.  If that's not your choice, well, good luck in whatever you do, but take it elsewhere.
February 6, 2007, 7:01 PM
Barabajagal
[quote author=topaz link=topic=16234.msg164144#msg164144 date=1170779305]
The use of $ probably derived from Perl
[/quote]
The BASIC language series has been around much longer than Perl. Perl's been around since 87, whereas BASIC was designed in 63. It's always used $ as a string definition.
February 6, 2007, 7:09 PM
MyStiCaL
oh boy, to see what a computer looked like in 63 haha.. what would you even program in 63? a calculater? take your desktop comp around with u to cacluate things? =)

gezz if grok finds all of topaz's other post BOOM, he/shes gunna be banned for the rest of the year ahha
February 8, 2007, 8:56 PM
Barabajagal
Back then, PCs didn't exist. there were Mainframes, terminals, and timesharing. Computers had useful purposes, like bank databases, complex math calculations, and other more practical uses. BASIC was designed originally as a way for students to be introduced into the Programming world. Eventually, they realized if they kept the same Syntax, and improved the features, they could make programming a lot easier.
February 8, 2007, 10:34 PM
LCSBSSRHXXX
[quote author=[RealityRipple] link=topic=16234.msg163966#msg163966 date=1170624999]
Yes, because I don't remember something, and state that I don't remember it, I must be a liar. How wonderful your logic is. Of course there's no point declaring variables that don't exist. Removal of Option Explicit lets you save time by NOT declaring variables and using them anyway. When converted to assembly and compiled to an EXE, the converter adds the declarations automatically.
[/quote]Not using Option Explicit is a bad choice, when Option Explicit isn't being used I'm pretty sure it treats all undeclared variables as Variants and a value declared as a Variant is more memory intensive and not friendly.  Also not declaring variables can lead to problems when trying to read over code to find a problem in the application.  If I'm incorrect about what I just said please let me know, I have not programmed in a long time, but I'm pretty sure that what I said is true.

Lazy is not an excuse, variables should always be declared.
February 9, 2007, 3:22 AM
Barabajagal
As long as you add the correct symbol to the end of the variable name, it should be defined as the correct type. It wouldn't surprise me if Microsoft dropped that standard, though :-\ . Yes, Option Explicit is good. Yes, you should always declare your variables. But it's still an option, and if you use it right, it makes things easier (as long as you don't screw up the spelling), which is what the BASIC series goal is.
February 9, 2007, 3:39 AM
MyStiCaL
well as far as i know option explicit i've used as a tool to let me know what i've had undeclared. If you don't use it, and you have undeclared variables, then they are automaticly variants. it shouldn't really matter if you have it in your class, form, module if everthing in it is declared? I think it's a good programming habit to be the first thing you have in your classes. to my knowlegde of compiling, you can't compile if you have Option Explicit in a module with variables undeclared. thus acts like vb helper =) and maybe i jsust read your messages wrong, to much typing, and you just wasted a good minuate or 2 reading what i just wrote, thanks! =)
February 9, 2007, 8:56 PM
Quarantine
[quote author=[RealityRipple] link=topic=16234.msg164359#msg164359 date=1170992396]
As long as you add the correct symbol to the end of the variable name, it should be defined as the correct type. It wouldn't surprise me if Microsoft dropped that standard, though :-\ . Yes, Option Explicit is good. Yes, you should always declare your variables. But it's still an option, and if you use it right, it makes things easier (as long as you don't screw up the spelling), which is what the BASIC series goal is.
[/quote]

If I crash my car it makes it easier for me to get hurt. Is that a good thing? No.

Not using Option Explicit makes something easier..it makes it easier to have bugs in your code. No one is a perfect programmers, programmers are humans.
February 9, 2007, 11:36 PM
Barabajagal
Actually, it's more of seatbelt. It makes getting in and out of your car harder (if you're not used to it), and when you screw up, it's there to save you.... wow, i like that metaphor..
February 9, 2007, 11:52 PM
Quarantine
You missed the entire point. Don't you get it? Nothing that makes the compiler assume anything about something as crucial as variables can be good. Just because something is easy doesn't make it good. If it's bad in the first place, it defeats the purpose of it being easy.

February 10, 2007, 12:00 AM
Barabajagal
...actually, I don't think you're reading my postings correctly. I'm completely against not declaring variables in today's languages, and my seatbelt = option explicit example seems like a perfect metaphor (except that it's not illegal not to use it).
February 10, 2007, 12:20 AM
Quarantine
Something like that shouldn't be an option. Let's also consider the fact that it's off by default. Sounds like a language which promotes bad habbits.
February 10, 2007, 1:58 AM
Barabajagal
Seeing as previous versions of BASIC didn't even have the option, it would make historical sense for it to be off by default, because that's the native style of the language. The point is, that's the way it is, and yes you should probably use it, and you shouldn't enforce your opinions on others, even if they make complete sense.
February 10, 2007, 2:01 AM
Quarantine
I give up.
February 10, 2007, 5:17 PM
Explicit[nK]
[quote author=[RealityRipple] link=topic=16234.msg163994#msg163994 date=1170634792]
Most people as in people that don't do programming as a profession, but as a hobby. Say about 70% of VB6 users.
[/quote]

Don't make up statistics...

[quote author=[RealityRipple] link=topic=16234.msg164450#msg164450 date=1171072872]
Seeing as previous versions of BASIC didn't even have the option, it would make historical sense for it to be off by default, because that's the native style of the language. The point is, that's the way it is, and yes you should probably use it, and you shouldn't enforce your opinions on others, even if they make complete sense.
[/quote]

He's not pressing his opinion on the matter onto others, he's just explaining why it's illogical to have 'Option Explicit' off by default.  I won't bother listing the reasons why seeing as how they've been covered in previous posts, but what I wanted to point out was that you'd make some kind of assertion about a coding practice in here, and then (seemingly) would switch your stance on it, resulting in some history lesson that (from what I can see) doesn't really help your point(s) at all.
February 10, 2007, 6:57 PM
Barabajagal
I wasn't making up statistics, I was making a guess. BASIC was designed as an educational language.

The choice to use Option Explicit or not is an opinion. I don't agree with it, but I support it's right, nonetheless.
February 10, 2007, 9:19 PM
Explicit[nK]
[quote author=[RealityRipple] link=topic=16234.msg164492#msg164492 date=1171142374]
I wasn't making up statistics, I was making a guess. BASIC was designed as an educational language.

The choice to use Option Explicit or not is an opinion. I don't agree with it, but I support it's right, nonetheless.
[/quote]

Fair enough.  :)
February 23, 2007, 9:58 PM

Search