|
-
Jul 21st, 2001, 09:22 AM
#1
Thread Starter
Member
subclassing
Hi,
two questions concerning window-subclassing:
1. How can I subclass a window outside vb (e.g. Winword)?
2. Is it possible to subclass not only single windows using their
handle, but every window of a class?
thx, Quix
-
Jul 21st, 2001, 09:27 AM
#2
Hmm,
Are you sure you want to subclass Word when you could do
everything you want in word with the Microsoft Word Int.Int Object Library?
-Lou
-
Jul 21st, 2001, 09:30 AM
#3
To subclass a window outside your thread, you need to create a standard DLL and add your procedure to the DLL instead of your App.
Subclassing a window of every class requires you to use SetClassLong instead of SetWindowLong.
-
Jul 21st, 2001, 09:38 AM
#4
I forgot to mention, SetClassLong will only affect the classes that are going to be created after the function is called (it will not affect the existing classes).
-
Jul 21st, 2001, 03:56 PM
#5
Also, bare in mind that in VB you cannot subclass something that doesnt belong to your thread. So in order for you to subclass other applications, you'll have to use C/C++ as well as other languages to achieve it.
-
Dec 3rd, 2001, 04:52 AM
#6
Thread Starter
Member
Ok, I'm back to my thread. Thanks for your replies. I've made some tests, but I didn't succeed in subclassing a Word-window using SetWindowLong in an ActiveX-Dll.
@megatron: What do you mean "create a standard DLL"? There is no Standard-DLL in VB. An ActiveX-Dll wouldn't work. Where do I have to put the hook-function? In the class-module? And what about Serge's comment "...in VB you cannot subclass something that doesnt belong to your thread."?
Will I really have to use C++?
-
Dec 3rd, 2001, 05:27 AM
#7
Fanatic Member
yes, you can't make DLLs with VB
-
Dec 3rd, 2001, 05:34 AM
#8
What is your goal? What do you want to subclass in word from VB?
-Lou
-
Dec 3rd, 2001, 05:36 AM
#9
And this better not be another 5 month wait-for!
-
Dec 6th, 2001, 04:40 AM
#10
Thread Starter
Member
-
Dec 6th, 2001, 04:11 PM
#11
You can control Word without sub-classing.
Start a new project, add a reference to MS Word Object Library, {See attached image}
Add a Command1 button, and paste the Following code:
VB Code:
Private Sub Command1_Click()
'a twip = 1/20 of a point
Dim ConvertTwip As Long
ConvertTwip = 20
Dim scrwid As Long
Dim scrhit As Long
scrwid = Screen.Width \ (ConvertTwip)
scrhit = Screen.Height \ (ConvertTwip)
Dim mWord As Word.Application
Set mWord = New Word.Application
mWord.Visible = True
mWord.WindowState = wdWindowStateNormal
DoEvents
mWord.Width = 4 * scrwid \ 5
mWord.Height = 3 * scrhit \ 5
mWord.Top = (scrhit - mWord.Height) \ 2
mWord.Left = (scrwid - mWord.Width) \ 2
DoEvents
Set mWord = Nothing
End Sub
This code illustrates how to control the width, height and positioning of Word.
Really, it should be checking for a previous instance of word, and it should GetObject if it exists, or if not, do a CreateObject, But I figure you can find some sample code for that.
But, this should get you started down the path to success!
-Lou
-
Dec 7th, 2001, 07:21 AM
#12
Thread Starter
Member
Hmmm
Thanks for your reply Lou, but this is not at all wat I want to do. I know about VBA and the possibility to control the height and width of the Word-window. But I want to restrict the region where the Word-window can be displayed. Using 'Application.Width = [any value]' would only set the width to the defined value. But the Word-window still can be moved around and resized. What I want is to set a maximum value for the right edge of the Word-window, that neither is exceeded on resizing nor on moving the window around.
Perhaps I should use a timer to control the window's size and position every 200 msec, but this isn't the best way to do it .
Any ideas?
-
Dec 11th, 2001, 11:54 AM
#13
Thread Starter
Member
-
Jun 1st, 2002, 07:35 AM
#14
Perhaps still might give you some ideas?
http://www.planetsourcecode.com/vb/s...14755&lngWId=1
Haven't tried the code myself, just noticed it was there..
-
Jun 1st, 2002, 08:06 AM
#15
Frenzied Member
You can subclass MS Word from withing word by using the EventVB.dll and putting the following code in the VBA ThisDocument code and saving it as Normal.dot:
VB Code:
Option Explicit
Dim WithEvents vbLInk As EventVB.APIFunctions
Dim WithEvents vbWnd As EventVB.ApiWindow
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Document_New()
End Sub
Private Sub Document_Open()
Call InitObjects
End Sub
Public Sub InitObjects()
Set vbLInk = New APIFunctions
Set vbWnd = New ApiWindow
vbWnd.hwnd = FindWindow(vbNullString, Me.Application.Caption)
vbLInk.SubclassedWindows.Add vbWnd
End Sub
Private Sub vbWnd_Moving(ByVal MoveEdges As Long, MoveRectangle As EventVB._APIRect)
If MoveRectangle.Right > 800 Then
MoveRectangle.Right = 800
End If
End Sub
Private Sub vbWnd_Sizing(ByVal SizeEdges As Long, DragRectangle As EventVB._APIRect)
If DragRectangle.Right > 800 Then
DragRectangle.Right = 800
End If
End Sub
That will keep Word in it's place ;-)
HTH,
Duncan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|