Solved

(Enabling) - SetWindowLong

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

856 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