PC Review


Reply
Thread Tools Rate Thread

API Screen Locking

 
 
Paul W Smith
Guest
Posts: n/a
 
      16th Mar 2010
I have seen code in the past which uses an windows API to lock the screen

I found the code below which apparently does this.

However it does not work or more accurately the LockWindowUpdate
ThisApplication.MainFrameHWND line gives a "Object does not support this
property or method" error.

How do I correct this?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paste the following declaration at the top of your module:

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As
Long) As Long

And then use these lines of code in your macro to lock and unlock screen
updates:

' Locks window updates
LockWindowUpdate ThisApplication.MainFrameHWND

' Unlocks window updates
LockWindowUpdate 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      16th Mar 2010
simply
pplication.hWnd in xl2002 or later,

in earlier and/or all versions

Private Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

sub test()
dim nHwnd as long
nHwnd = FindWindow("XLMAIN", Application.Caption)
end sub

In passing, unless you really know what you are doing and have cast iron
error handling I strongly recommend you don't use LockWindowUpdate,
particularly if distributing.

Regards,
Peter T

"Paul W Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have seen code in the past which uses an windows API to lock the screen
>
> I found the code below which apparently does this.
>
> However it does not work or more accurately the LockWindowUpdate
> ThisApplication.MainFrameHWND line gives a "Object does not support this
> property or method" error.
>
> How do I correct this?
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Paste the following declaration at the top of your module:
>
> Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As
> Long) As Long
>
> And then use these lines of code in your macro to lock and unlock screen
> updates:
>
> ' Locks window updates
> LockWindowUpdate ThisApplication.MainFrameHWND
>
> ' Unlocks window updates
> LockWindowUpdate 0
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>



 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      16th Mar 2010
>nHwnd = FindWindow("XLMAIN", Application.Caption)

Since XL 2000, the Application object exposes the HWnd of the XLMAIN
window, so FindWindow is not necessary.

Dim L As Long
L = Application.HWnd

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com




On Tue, 16 Mar 2010 12:08:19 -0000, "Peter T" <peter_t@discussions>
wrote:

>simply
>pplication.hWnd in xl2002 or later,
>
> in earlier and/or all versions
>
>Private Declare Function FindWindow Lib "user32.dll" _
> Alias "FindWindowA" ( _
> ByVal lpClassName As String, _
> ByVal lpWindowName As String) As Long
>
>sub test()
>dim nHwnd as long
>nHwnd = FindWindow("XLMAIN", Application.Caption)
>end sub
>
>In passing, unless you really know what you are doing and have cast iron
>error handling I strongly recommend you don't use LockWindowUpdate,
>particularly if distributing.
>
>Regards,
>Peter T
>
>"Paul W Smith" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>>I have seen code in the past which uses an windows API to lock the screen
>>
>> I found the code below which apparently does this.
>>
>> However it does not work or more accurately the LockWindowUpdate
>> ThisApplication.MainFrameHWND line gives a "Object does not support this
>> property or method" error.
>>
>> How do I correct this?
>>
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Paste the following declaration at the top of your module:
>>
>> Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As
>> Long) As Long
>>
>> And then use these lines of code in your macro to lock and unlock screen
>> updates:
>>
>> ' Locks window updates
>> LockWindowUpdate ThisApplication.MainFrameHWND
>>
>> ' Unlocks window updates
>> LockWindowUpdate 0
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>

>

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      16th Mar 2010
I believe Excel's HWnd property first became directly exposed in XL2002, and
in both XL97 & 2000 need to use FindWindow.

Regards,
Peter T

"Chip Pearson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> >nHwnd = FindWindow("XLMAIN", Application.Caption)

>
> Since XL 2000, the Application object exposes the HWnd of the XLMAIN
> window, so FindWindow is not necessary.
>
> Dim L As Long
> L = Application.HWnd
>
> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional,
> Excel, 1998 - 2010
> Pearson Software Consulting, LLC
> www.cpearson.com
>
>
>
>
> On Tue, 16 Mar 2010 12:08:19 -0000, "Peter T" <peter_t@discussions>
> wrote:
>
>>simply
>>pplication.hWnd in xl2002 or later,
>>
>> in earlier and/or all versions
>>
>>Private Declare Function FindWindow Lib "user32.dll" _
>> Alias "FindWindowA" ( _
>> ByVal lpClassName As String, _
>> ByVal lpWindowName As String) As Long
>>
>>sub test()
>>dim nHwnd as long
>>nHwnd = FindWindow("XLMAIN", Application.Caption)
>>end sub
>>
>>In passing, unless you really know what you are doing and have cast iron
>>error handling I strongly recommend you don't use LockWindowUpdate,
>>particularly if distributing.
>>
>>Regards,
>>Peter T
>>
>>"Paul W Smith" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>>I have seen code in the past which uses an windows API to lock the screen
>>>
>>> I found the code below which apparently does this.
>>>
>>> However it does not work or more accurately the LockWindowUpdate
>>> ThisApplication.MainFrameHWND line gives a "Object does not support this
>>> property or method" error.
>>>
>>> How do I correct this?
>>>
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> Paste the following declaration at the top of your module:
>>>
>>> Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock
>>> As
>>> Long) As Long
>>>
>>> And then use these lines of code in your macro to lock and unlock screen
>>> updates:
>>>
>>> ' Locks window updates
>>> LockWindowUpdate ThisApplication.MainFrameHWND
>>>
>>> ' Unlocks window updates
>>> LockWindowUpdate 0
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>

>>

> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional,
> Excel, 1998 - 2010
> Pearson Software Consulting, LLC
> www.cpearson.com



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locking up at Log in Screen klafert Windows XP General 4 21st Apr 2010 08:25 PM
Activation nag screen locking me out at Log-in screen on XP Pro TwiZted Biker Windows XP General 4 21st May 2008 12:12 AM
screen locking after 24 hrs wyadvd Windows XP Hardware 2 2nd Jun 2006 07:35 AM
Locking Screen Daniel Diehl Microsoft C# .NET 2 24th Dec 2003 04:24 AM
screen locking Lisa Windows XP General 1 9th Sep 2003 09:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:54 PM.