Solved

(Enabling) - SetWindowLong

Posted on 1998-11-27
3
318 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 42
change vba from autofit to 13.5 width? 4 29
Microsoft Access combo box help 2 44
Copy a row 12 61
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

815 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

11 Experts available now in Live!

Get 1:1 Help Now