Solved

(Enabling) - SetWindowLong

Posted on 1998-11-27
3
313 Views
Last Modified: 2006-11-17
Hi,

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

Thanks
0
Comment
Question by:BabyFace
3 Comments
 
LVL 2

Accepted Solution

by:
trillo earned 20 total points
ID: 1447175
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1447176
Why not using EnableWindow?
0
 
LVL 1

Author Comment

by:BabyFace
ID: 1447177
Thank you.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now