• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

(Enabling) - SetWindowLong

Hi,

Can somebody show me how I could enable a command button
using the API function
SetWindowLong?

Thanks
0
BabyFace
Asked:
BabyFace
1 Solution
 
trilloCommented:
Wow!.... strange but elegant way for enabling/disabling a button.

The declarations are these:

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_DISABLED = &H8000000
Dim prev As Long


To enable the button use this code:
  Dim l As Long
  l = GetWindowLong(Command1.hwnd, GWL_STYLE)
  prev = SetWindowLong(Command1.hwnd, GWL_STYLE, l And Not WS_DISABLED)

To disable the button use this code:
  Dim l As Long
  l = GetWindowLong(Command1.hwnd, GWL_STYLE)
  prev = SetWindowLong(Command1.hwnd, GWL_STYLE, l Or WS_DISABLED)

Take special atention to the bitwise And Or and Not operators

Trillo
0
 
MirkwoodCommented:
Why not using EnableWindow?
0
 
BabyFaceAuthor Commented:
Thank you.

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now