"What's This" button

B

brett

....as also posted in the "Forms" Group.

I am using forms with no borders so the standard "What's This" button
is not an option for me. Apparently this code should make the cursor
behave the same way as clicking the "What's This" button. It is close
but not quite right. Can anyone expand on it please?
It is attached to a button on a form.

Private Declare Function PostMessage Lib "user32" Alias
"PostMessageA"
_
(ByVal hWnd As Integer, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) _
As Integer

Private Declare Function GetActiveWindow Lib "user32" () As Integer

Private Const WM_SYSCOMMAND = &H112
Private Const SC_CONTEXTHELP = &HF180

Public Sub WhatsThisMode()
If Not PostMessage(GetActiveWindow(), WM_SYSCOMMAND,
SC_CONTEXTHELP, 0) Then
MsgBox "This is not good!" 'Put actual error message here
End If
End Sub


Regards Brett
 
J

Jon Lewis

VB and VBA differ slightly so if you use If Not, this is the equivalent (in
VBA) of using If Postmessage(.......) <> -1
i.e. if the return value of Postmessage is different to -1 then you are
assuming you have an error.

PostMessage returns 0 if it is unsuccessful and non-zero if successful (1 in
a quick test I did)
So your WhatsThisMode sub is indicating an error when there isn't one.

Better to use:

Public Sub WhatsThisMode()
If PostMessage(GetActiveWindow(), WM_SYSCOMMAND, SC_CONTEXTHELP, 0) = 0 Then
MsgBox "Error"
End If
End Sub

Is this what you mean by 'It is close but not quite right.'?

HTH
 
B

brett

VB and VBA differ slightly so if you use If Not, this is the equivalent (in
VBA) of using If Postmessage(.......) <> -1
i.e. if the return value of Postmessage is different to -1 then you are
assuming you have an error.

PostMessage returns 0 if it is unsuccessful and non-zero if successful (1in
a quick test I did)
So your WhatsThisMode sub is indicating an error when there isn't one.

Better to use:

Public Sub WhatsThisMode()
If PostMessage(GetActiveWindow(), WM_SYSCOMMAND, SC_CONTEXTHELP, 0) = 0Then
    MsgBox "Error"
End If
End Sub

Is this what you mean by 'It is close but not quite right.'?

HTH












- Show quoted text -

No... Unfortunately the "not quite right" is that it doesn't produce
the expected cursor with a question mark like the actual "What's This"
button does.

Changed the code as suggested... it always comes back valued as 1.
Probably a correct response for the value but not in the action.

This is driving me nuts.

Brett.
 
J

Jon Lewis

I was going to add to my last response that 'It is close but not quite
right.' is not very helpful when requesting help from a newsgroup :)

Are your Forms popup? As far as I can tell they need to be for this to work
using GetActiveWindow. If they can't be popup then supplying the
hWnd parameter for PostMessage directly seems to work as long as you have
the correct declaration (Longs rather than Integers).e.g.:

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_SYSCOMMAND = &H112
Private Const SC_CONTEXTHELP = &HF180

Public Sub WhatsThisMode(lngH As Long)
If PostMessage(lngH, WM_SYSCOMMAND, SC_CONTEXTHELP, 0) = 0 Then
MsgBox "Error"
End If
End Sub

In a Form with a command button cmdWT:
Private Sub cmdWT_Click()
WhatsThisMode Me.hWnd
End Sub

Does this help?


VB and VBA differ slightly so if you use If Not, this is the equivalent
(in
VBA) of using If Postmessage(.......) <> -1
i.e. if the return value of Postmessage is different to -1 then you are
assuming you have an error.

PostMessage returns 0 if it is unsuccessful and non-zero if successful (1
in
a quick test I did)
So your WhatsThisMode sub is indicating an error when there isn't one.

Better to use:

Public Sub WhatsThisMode()
If PostMessage(GetActiveWindow(), WM_SYSCOMMAND, SC_CONTEXTHELP, 0) = 0
Then
MsgBox "Error"
End If
End Sub

Is this what you mean by 'It is close but not quite right.'?

HTH












- Show quoted text -

No... Unfortunately the "not quite right" is that it doesn't produce
the expected cursor with a question mark like the actual "What's This"
button does.

Changed the code as suggested... it always comes back valued as 1.
Probably a correct response for the value but not in the action.

This is driving me nuts.

Brett.
 
B

brett

Your blood is worth bottling Jon. This works beautifully.

Regards Brett

Hi again Jon,

I notice that whilst the help file content is correct, the window used
for the "what's this" is different to the standard help window (no
left frame). Any thoughts on how to set the API to use the window
format I have specified in the HTML Help generator or how to set the
size?

As an aside, how did you stop your email from showing up here? The
thing warns me about disclosing mine but doesn't show an easy way to
fix it.

Regards Brett.
 
J

Jon Lewis

It may help to appreciate that you are relying on your Form's Window's built
in 'procedure' to handle the message you give it when deliver a click in
'WhatsThis' mode. If you want to customise the behaviour, you have to
intercept the message sent to the Form (or Window) and use your own
WindowsProcedure to handle it, a process known as subclassing. This is not
easy, and I doubt whether it would be worth the effort for you.

You could, instead of running your WhatsThisMode code form your command
button, look at the SetCursor API and just change the cursor to a 'What's
This' type. (Google for examples) It would then be easy to control what
happens next maybe using the WinHelp api.

I've not used the WinHelp api before but there does seem to be provision for
specifying a pre-defined display window for the help topic

http://allapi.mentalis.org/apilist/apilist.php
is a great source for api help btw

Good luck





Your blood is worth bottling Jon. This works beautifully.

Regards Brett

Hi again Jon,

I notice that whilst the help file content is correct, the window used
for the "what's this" is different to the standard help window (no
left frame). Any thoughts on how to set the API to use the window
format I have specified in the HTML Help generator or how to set the
size?

As an aside, how did you stop your email from showing up here? The
thing warns me about disclosing mine but doesn't show an easy way to
fix it.

Regards Brett.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top