Results 1 to 15 of 15

Thread: subclassing

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    51

    Question 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

  2. #2
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    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

  3. #3
    Megatron
    Guest
    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.

  4. #4
    Megatron
    Guest
    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).

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    51
    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++?

  7. #7
    Fanatic Member Kings's Avatar
    Join Date
    Aug 2001
    Posts
    673
    yes, you can't make DLLs with VB
    K i n g s

  8. #8

  9. #9

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    51
    @Kings: An ActiveX-Dll isn't a Dll?
    @NotLKH: This time it's not 5 months but 3 days I'm making progresses

    What I want to do is this:
    On maximizing a window the window's height is automatically restricted by the taskbar. I want to create a region like the taskbar that forces Word not to use the whole desktop for maximizing but to leave a rectangle of 150 px width at the right edge of the screen.

    I've tried to put Word into a vb-window using the API's SetParent, but word crashed. A second experiment was to disable Word's maximize-button by removing the 'maximize'-entry of the word's system menu. This worked very fine, but you still could use the whole screen by changing the window's size or by moving the window around.

    I think the best way is to subclass the Word-window and to control the messages (WM_SIZE, WM_WINDOWPOSCHANGING...). But I don't want to use C++

    Any suggestions?
    Last edited by Quix; Dec 6th, 2001 at 04:44 AM.

  11. #11
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    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:
    1. Private Sub Command1_Click()
    2. 'a twip = 1/20 of a point
    3. Dim ConvertTwip As Long
    4. ConvertTwip = 20
    5. Dim scrwid As Long
    6. Dim scrhit As Long
    7. scrwid = Screen.Width \ (ConvertTwip)
    8. scrhit = Screen.Height \ (ConvertTwip)
    9.     Dim mWord As Word.Application
    10.     Set mWord = New Word.Application
    11.     mWord.Visible = True
    12.     mWord.WindowState = wdWindowStateNormal
    13.     DoEvents
    14.     mWord.Width = 4 * scrwid \ 5
    15.     mWord.Height = 3 * scrhit \ 5
    16.     mWord.Top = (scrhit - mWord.Height) \ 2
    17.     mWord.Left = (scrwid - mWord.Width) \ 2
    18.     DoEvents
    19.     Set mWord = Nothing
    20. 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

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    51

    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?

  13. #13

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    51
    Any ideas?

  14. #14
    Seth DK
    Guest
    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..

  15. #15
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    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:
    1. Option Explicit
    2.  
    3. Dim WithEvents vbLInk As EventVB.APIFunctions
    4. Dim WithEvents vbWnd As EventVB.ApiWindow
    5.  
    6. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    7.  
    8.  
    9. Private Sub Document_New()
    10.  
    11. End Sub
    12.  
    13. Private Sub Document_Open()
    14.  
    15. Call InitObjects
    16.  
    17. End Sub
    18.  
    19. Public Sub InitObjects()
    20.  
    21. Set vbLInk = New APIFunctions
    22.  
    23. Set vbWnd = New ApiWindow
    24. vbWnd.hwnd = FindWindow(vbNullString, Me.Application.Caption)
    25.  
    26. vbLInk.SubclassedWindows.Add vbWnd
    27.  
    28. End Sub
    29.  
    30. Private Sub vbWnd_Moving(ByVal MoveEdges As Long, MoveRectangle As EventVB._APIRect)
    31.  
    32. If MoveRectangle.Right > 800 Then
    33.     MoveRectangle.Right = 800
    34. End If
    35.  
    36. End Sub
    37.  
    38. Private Sub vbWnd_Sizing(ByVal SizeEdges As Long, DragRectangle As EventVB._APIRect)
    39.  
    40. If DragRectangle.Right > 800 Then
    41.     DragRectangle.Right = 800
    42. End If
    43.  
    44. End Sub

    That will keep Word in it's place ;-)

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width