Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi, Does anyone know how to freeze the active window using windows API? I tried this: Class named FreezeWindow: Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal ClassName As String, ByVal WindowName As String) As Long Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hWndLock As Long) As Long Public Sub Freeze(Window As Window) Dim hWnd As Long hWnd = FindWindow("XLMAIN", Application.Caption) End Sub Public Sub Unfreeze() LockWindowUpdate 0 End Sub Private Sub Class_Terminate() Unfreeze End Sub and in the macro: dim FreezeWnd as New FreezeWindow FreezeWnd.Freeze ActiveWindow FreezeWnd.Unfreeze I can't get it to work, don't know what's wrong (still learning VBA). Thanks in advance Mik -- Mikeyhen ----------------------------------------------------------------------- Mikeyhend's Profile: http://www.excelforum.com/member.php...fo&userid=3340 View this thread: http://www.excelforum.com/showthread.php?threadid=56442 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Your Freeze method does nothing of any value. All it does is find
the hWnd of XLMain, which you can get more simply with Application.Hwnd. Try the following to lock the window, Dim Res As Long Res = LockWindowUpdate(Application.Hwnd) and the following to unlock the window Dim Res As Long Res = LockWindowUpdate(0&) -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Mikeyhend" wrote in message ... Hi, Does anyone know how to freeze the active window using windows API? I tried this: Class named FreezeWindow: Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal ClassName As String, ByVal WindowName As String) As Long Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hWndLock As Long) As Long Public Sub Freeze(Window As Window) Dim hWnd As Long hWnd = FindWindow("XLMAIN", Application.Caption) End Sub Public Sub Unfreeze() LockWindowUpdate 0 End Sub Private Sub Class_Terminate() Unfreeze End Sub and in the macro: dim FreezeWnd as New FreezeWindow FreezeWnd.Freeze ActiveWindow FreezeWnd.Unfreeze I can't get it to work, don't know what's wrong (still learning VBA). Thanks in advance Mike -- Mikeyhend ------------------------------------------------------------------------ Mikeyhend's Profile: http://www.excelforum.com/member.php...o&userid=33400 View this thread: http://www.excelforum.com/showthread...hreadid=564429 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you want to freeze only one Excel window, rather than the
Application window, use code like Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hWndLock As Long) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Long Sub Test() FreezeWindow W:=ActiveWindow End Sub Sub FreezeWindow(W As Window) Dim WindowHWnd As Long Dim XLHwnd As Long Dim DeskHwnd As Long Dim Res As Long XLHwnd = Application.HWnd DeskHwnd = FindWindowEx(XLHwnd, 0&, "XLDESK", vbNullString) WindowHWnd = FindWindowEx(DeskHwnd, 0&, "EXCEL7", ActiveWindow.Caption) Res = LockWindowUpdate(WindowHWnd) End Sub Sub UnFreezeWindow() Dim Res As Long Res = LockWindowUpdate(0&) End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Mikeyhend" wrote in message ... Hi, Does anyone know how to freeze the active window using windows API? I tried this: Class named FreezeWindow: Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal ClassName As String, ByVal WindowName As String) As Long Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hWndLock As Long) As Long Public Sub Freeze(Window As Window) Dim hWnd As Long hWnd = FindWindow("XLMAIN", Application.Caption) End Sub Public Sub Unfreeze() LockWindowUpdate 0 End Sub Private Sub Class_Terminate() Unfreeze End Sub and in the macro: dim FreezeWnd as New FreezeWindow FreezeWnd.Freeze ActiveWindow FreezeWnd.Unfreeze I can't get it to work, don't know what's wrong (still learning VBA). Thanks in advance Mike -- Mikeyhend ------------------------------------------------------------------------ Mikeyhend's Profile: http://www.excelforum.com/member.php...o&userid=33400 View this thread: http://www.excelforum.com/showthread...hreadid=564429 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() WindowHWnd = FindWindowEx(DeskHwnd, 0&, "EXCEL7", ActiveWindow.Caption) should be WindowHWnd = FindWindowEx(DeskHwnd, 0&, "EXCEL7", W.Caption) -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Chip Pearson" wrote in message ... If you want to freeze only one Excel window, rather than the Application window, use code like Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hWndLock As Long) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Long Sub Test() FreezeWindow W:=ActiveWindow End Sub Sub FreezeWindow(W As Window) Dim WindowHWnd As Long Dim XLHwnd As Long Dim DeskHwnd As Long Dim Res As Long XLHwnd = Application.HWnd DeskHwnd = FindWindowEx(XLHwnd, 0&, "XLDESK", vbNullString) WindowHWnd = FindWindowEx(DeskHwnd, 0&, "EXCEL7", ActiveWindow.Caption) Res = LockWindowUpdate(WindowHWnd) End Sub Sub UnFreezeWindow() Dim Res As Long Res = LockWindowUpdate(0&) End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Mikeyhend" wrote in message ... Hi, Does anyone know how to freeze the active window using windows API? I tried this: Class named FreezeWindow: Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal ClassName As String, ByVal WindowName As String) As Long Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hWndLock As Long) As Long Public Sub Freeze(Window As Window) Dim hWnd As Long hWnd = FindWindow("XLMAIN", Application.Caption) End Sub Public Sub Unfreeze() LockWindowUpdate 0 End Sub Private Sub Class_Terminate() Unfreeze End Sub and in the macro: dim FreezeWnd as New FreezeWindow FreezeWnd.Freeze ActiveWindow FreezeWnd.Unfreeze I can't get it to work, don't know what's wrong (still learning VBA). Thanks in advance Mike -- Mikeyhend ------------------------------------------------------------------------ Mikeyhend's Profile: http://www.excelforum.com/member.php...o&userid=33400 View this thread: http://www.excelforum.com/showthread...hreadid=564429 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Why not use Application.ScreenUpdating?
- Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ "Mikeyhend" wrote in message ... Hi, Does anyone know how to freeze the active window using windows API? I tried this: Class named FreezeWindow: Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal ClassName As String, ByVal WindowName As String) As Long Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hWndLock As Long) As Long Public Sub Freeze(Window As Window) Dim hWnd As Long hWnd = FindWindow("XLMAIN", Application.Caption) End Sub Public Sub Unfreeze() LockWindowUpdate 0 End Sub Private Sub Class_Terminate() Unfreeze End Sub and in the macro: dim FreezeWnd as New FreezeWindow FreezeWnd.Freeze ActiveWindow FreezeWnd.Unfreeze I can't get it to work, don't know what's wrong (still learning VBA). Thanks in advance Mike -- Mikeyhend ------------------------------------------------------------------------ Mikeyhend's Profile: http://www.excelforum.com/member.php...o&userid=33400 View this thread: http://www.excelforum.com/showthread...hreadid=564429 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Chip, Thanks, the code works fine, but doesn't solve my problem. I was trying to put a combobox in a cell on doubleclick. In the example code I have, a line to create the combobox click event is written in the VBE after the combobox is put on the screen. I needed the code to hide the screen flickering when the VBE is switched on and back off, but when I put 'unfreezeWindow' line after the 'CreateEventProc' for the Combobox click event it raises an error. Is there a solution for this problem? Thanks Mike -- Mikeyhend ------------------------------------------------------------------------ Mikeyhend's Profile: http://www.excelforum.com/member.php...o&userid=33400 View this thread: http://www.excelforum.com/showthread...hreadid=564429 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You need to lock the VBA Editor's main window, not an Excel
Window object. Try code like the following: Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal ClassName As String, ByVal WindowName As String) As Long Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hWndLock As Long) As Long Sub TestIt() Dim VBCodeMod As Object Dim VBEHwnd As Long Application.VBE.MainWindow.Visible = False VBEHwnd = FindWindow("wndclass_desked_gsk", _ Application.VBE.MainWindow.Caption) If VBEHwnd Then LockWindowUpdate VBEHwnd End If Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("Sheet1").Code Module VBCodeMod.InsertLines _ VBCodeMod.CreateEventProc("Click", "CommandButton1") + 1, _ "Msgbox ""OK""" Application.VBE.MainWindow.Visible = False LockWindowUpdate (0&) End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Mikeyhend" wrote in message ... Chip, Thanks, the code works fine, but doesn't solve my problem. I was trying to put a combobox in a cell on doubleclick. In the example code I have, a line to create the combobox click event is written in the VBE after the combobox is put on the screen. I needed the code to hide the screen flickering when the VBE is switched on and back off, but when I put 'unfreezeWindow' line after the 'CreateEventProc' for the Combobox click event it raises an error. Is there a solution for this problem? Thanks Mike -- Mikeyhend ------------------------------------------------------------------------ Mikeyhend's Profile: http://www.excelforum.com/member.php...o&userid=33400 View this thread: http://www.excelforum.com/showthread...hreadid=564429 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Chip, Thanks, this one does the trick. Mike -- Mikeyhend ------------------------------------------------------------------------ Mikeyhend's Profile: http://www.excelforum.com/member.php...o&userid=33400 View this thread: http://www.excelforum.com/showthread...hreadid=564429 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I freeze/ unfreeze a window pane in Excel 2007? | Excel Discussion (Misc queries) | |||
view excel worksheet & freeze internet window synchronously | Excel Worksheet Functions | |||
Window Tool Bar - Freeze pane does not appear | Excel Discussion (Misc queries) | |||
Excel: find Window in which I can freeze panes | New Users to Excel | |||
Excel should allow me to freeze pane in a split window | Excel Worksheet Functions |