Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Tazo on February 03, 2007, 09:14 AM

Title: More SendMessage issues.
Post by: Tazo on February 03, 2007, 09:14 AM
Once again I'm trying to simulate a mouse click to an inactice window... here's what I have so far:


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


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.
Title: Re: More SendMessage issues.
Post by: Grok on February 03, 2007, 04:29 PM
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.

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:


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


Fix up your code so you are properly alerted to errors and try again.
Title: Re: More SendMessage issues.
Post by: Tazo on February 03, 2007, 05:51 PM
Quote from: Grok on February 03, 2007, 04:29 PM
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.

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:


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


Fix up your code so you are properly alerted to errors and try again.
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.
Title: Re: More SendMessage issues.
Post by: topaz on February 03, 2007, 06:36 PM
Isn't VB6 supposed to report errors when you refer to nonexistent variables?
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 03, 2007, 06:39 PM
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.
Title: Re: More SendMessage issues.
Post by: topaz on February 03, 2007, 07:16 PM
That's only the editor. It should be raising errors when you refer to absent variables during runtime
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 03, 2007, 07:18 PM
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.
Title: Re: More SendMessage issues.
Post by: topaz on February 03, 2007, 07:28 PM
VB6 isn't dynamically typed. Please, delete your account again
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 03, 2007, 07:30 PM
Please learn a bit more about languages before you insult them. I'll delete my account again when I want it deleted again, ty.
Title: Re: More SendMessage issues.
Post by: topaz on February 03, 2007, 07:38 PM
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
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 03, 2007, 08:05 PM
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.
Title: Re: More SendMessage issues.
Post by: topaz on February 03, 2007, 08:22 PM
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)


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)
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 04, 2007, 03:36 PM
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.
Title: Re: More SendMessage issues.
Post by: l2k-Shadow on February 04, 2007, 04:28 PM
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.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 04, 2007, 04:32 PM
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.
Title: Re: More SendMessage issues.
Post by: Warrior on February 04, 2007, 05:02 PM
I forgot when this became a "argue about a stupid feature in VB6" thread.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 04, 2007, 05:07 PM
Quote from: topaz on February 03, 2007, 06:36 PM
Isn't VB6 supposed to report errors when you refer to nonexistent variables?

Right there.
Title: Re: More SendMessage issues.
Post by: Warrior on February 04, 2007, 05:08 PM
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.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 04, 2007, 05:12 PM
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).
Title: Re: More SendMessage issues.
Post by: Explicit on February 04, 2007, 05:49 PM
Quote from: Ripple on February 04, 2007, 04:32 PM
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.

You could just as easily read something that follows the naming conventions used today...
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 04, 2007, 05:52 PM
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.
Title: Re: More SendMessage issues.
Post by: Warrior on February 04, 2007, 06:00 PM
Quote from: [RealityRipple] on February 04, 2007, 05:12 PM
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).

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?
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 04, 2007, 06:03 PM
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.
Title: Re: More SendMessage issues.
Post by: Explicit on February 04, 2007, 06:16 PM
Quote from: [RealityRipple] on February 04, 2007, 05:52 PM
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.

Most people don't care?  See, that might be the case with Battle.net-related programmers, but beyond that, it's different.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 04, 2007, 06:19 PM
Most people as in people that don't do programming as a profession, but as a hobby. Say about 70% of VB6 users.
Title: Re: More SendMessage issues.
Post by: topaz on February 05, 2007, 01:38 AM
Quote from: [RealityRipple] on February 04, 2007, 06:03 PM
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.

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
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 05, 2007, 01:44 AM
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.
Title: Re: More SendMessage issues.
Post by: Tazo on February 05, 2007, 06:05 AM
so about the topic.
Title: Re: More SendMessage issues.
Post by: Warrior on February 05, 2007, 05:29 PM
Lolol @ VB6 certification.
Title: Re: More SendMessage issues.
Post by: Mystical on February 06, 2007, 12:43 AM
Quote from: Warrior on February 05, 2007, 05:29 PM
Lolol @ VB6 certification.

he paid 9$ for a online test that multiple choice from a retarded site! =)
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 06, 2007, 01:47 AM
$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 (http://www.expertrating.com/index.asp?affid=388). If you don't want to believe they're a true form of certification, then whatever.
Title: Re: More SendMessage issues.
Post by: FrOzeN on February 06, 2007, 04:31 AM
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).
Title: Re: More SendMessage issues.
Post by: Tazo on February 06, 2007, 08:57 AM
okk since vb is so crappy, let's assume im doing this in c++. now what is the problem?
Title: Re: More SendMessage issues.
Post by: topaz on February 06, 2007, 10:28 AM
The use of $ probably derived from Perl
Title: Re: More SendMessage issues.
Post by: Grok on February 06, 2007, 01:01 PM
Quote from: topaz on February 03, 2007, 07:38 PM
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 from: topaz on February 05, 2007, 01:38 AM
Quote from: [RealityRipple] on February 04, 2007, 06:03 PM
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.

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

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.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 06, 2007, 01:09 PM
Quote from: topaz on February 06, 2007, 10:28 AM
The use of $ probably derived from Perl
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.
Title: Re: More SendMessage issues.
Post by: Mystical on February 08, 2007, 02:56 PM
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
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 08, 2007, 04:34 PM
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.
Title: Re: More SendMessage issues.
Post by: LCSBSSRHXXX on February 08, 2007, 09:22 PM
Quote from: [RealityRipple] on February 04, 2007, 03:36 PM
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.
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.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 08, 2007, 09:39 PM
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.
Title: Re: More SendMessage issues.
Post by: Mystical on February 09, 2007, 02:56 PM
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! =)
Title: Re: More SendMessage issues.
Post by: Warrior on February 09, 2007, 05:36 PM
Quote from: [RealityRipple] on February 08, 2007, 09:39 PM
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.

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.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 09, 2007, 05:52 PM
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..
Title: Re: More SendMessage issues.
Post by: Warrior on February 09, 2007, 06:00 PM
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.

Title: Re: More SendMessage issues.
Post by: Barabajagal on February 09, 2007, 06:20 PM
...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).
Title: Re: More SendMessage issues.
Post by: Warrior on February 09, 2007, 07:58 PM
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.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 09, 2007, 08:01 PM
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.
Title: Re: More SendMessage issues.
Post by: Warrior on February 10, 2007, 11:17 AM
I give up.
Title: Re: More SendMessage issues.
Post by: Explicit on February 10, 2007, 12:57 PM
Quote from: [RealityRipple] on February 04, 2007, 06:19 PM
Most people as in people that don't do programming as a profession, but as a hobby. Say about 70% of VB6 users.

Don't make up statistics...

Quote from: [RealityRipple] on February 09, 2007, 08:01 PM
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.

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.
Title: Re: More SendMessage issues.
Post by: Barabajagal on February 10, 2007, 03:19 PM
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.
Title: Re: More SendMessage issues.
Post by: Explicit on February 23, 2007, 03:58 PM
Quote from: [RealityRipple] on February 10, 2007, 03:19 PM
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.

Fair enough.  :)