Solved

(Enabling) - SetWindowLong

Posted on 1998-11-27
3
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

735 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