Results 1 to 7 of 7

Thread: CallWindowProc Issue

  1. #1

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    CallWindowProc Issue

    I am in the middle of reading Steve Romans "Win32 API Programming with Visual Basic 6" and i am on to chapter 18 "Windows Subclassing", at the moment i am reading up on the CalWindowProc. I have come with this so far and it does not seem to be working, it is supposed to be a classic example of restricting the size of the form.

    VB Code:
    1. ' Module Code
    2. Option Explicit
    3.  
    4. Declare Function CallWindowProc _
    5.     Lib "user32" _
    6.     Alias "CallWindowProcA" ( _
    7.         ByVal lpPrevWndFunc As Long, _
    8.         ByVal hwnd As Long, _
    9.         ByVal Msg As Long, _
    10.         ByVal wParam As Long, _
    11.         ByVal lParam As Long) _
    12.         As Long
    13.        
    14. ' Allows us to set the window style
    15. ' Returns the Procedure address which will
    16. ' be stored in 'OldWindowProc'
    17. Declare Function SetWindowLong _
    18.     Lib "user32" _
    19.     Alias "SetWindowLongA" ( _
    20.         ByVal hwnd As Long, _
    21.         ByVal nIndex As Long, _
    22.         ByVal dwNewLong As Long) _
    23.         As Long
    24.  
    25. ' Returns the cordinates for the
    26. ' mouse
    27. Public Type POINTAPI
    28.         X               As Long
    29.         Y               As Long
    30. End Type
    31.  
    32. ' Holds the sizing information for
    33. ' the form
    34. Private Type MINMAXINFO
    35.     ptReserved          As POINTAPI
    36.     ptMaxSize           As POINTAPI
    37.     ptMaxPosition       As POINTAPI
    38.     ptMinTrackSize      As POINTAPI
    39.     ptMaxTrackSize      As POINTAPI
    40. End Type
    41.  
    42. Const GWL_WNDPROC = (-4)            ' Sets a new procdure address
    43. Const WM_GETMINMAXINFO = &H24       ' Gets the window size information
    44.  
    45. Public OldWindowProc       As Long  ' Holds thw Old Window Address
    46.  
    47. Public Function NewWindowProc(hwnd As Long, Msg As Long, wParam As Long, lParam As MINMAXINFO) As Long
    48.    
    49.     Dim Point       As POINTAPI
    50.    
    51.     ' Check for any messages
    52.     Select Case Msg
    53.        
    54.         ' If the message is a sizeing message
    55.         Case WM_GETMINMAXINFO
    56.            
    57.             ' Limit the form size to the cursor co-ordinates
    58.             With lParam
    59.                 .ptMaxTrackSize.X = Point.X
    60.                 .ptMaxTrackSize.Y = Point.Y
    61.                 .ptMinTrackSize.X = Point.X
    62.                 .ptMinTrackSize.Y = Point.Y
    63.             End With
    64.            
    65.             NewWindowProc = 0
    66.                
    67.         Case Else
    68.            
    69.             ' Call the new Window Procedure
    70.             NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
    71.                
    72.     End Select
    73. End Function
    74.  
    75. ' Form Code
    76.  
    77. Option Explicit
    78.  
    79. Private Sub Form_Load()
    80.     OldWindowProc = SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
    81. End Sub
    82.  
    83.  
    84. Private Sub Form_Unload(Cancel As Integer)
    85.     OldWindowProc = SetWindowLong(Form1.hwnd, GWL_WNDPROC, OldWindowProc)
    86. End Sub

    However, when i run the code it does not seem to work, i have tried other methods such as setting the form size to a specific height and width but it still does not seem to work. From what i have made out so far it it looks as though my application can not process the message and i am quite confident that this is the issue. Can you guys give me any hints as to where the problem lies and how i might be able to fix it?

    Regards,

    Jenova

  2. #2
    Hyperactive Member
    Join Date
    Aug 2006
    Posts
    367

    Re: CallWindowProc Issue

    your lparam isn't of proper type I believe. it expects a long, but you give it MAXMININFO which totals 8 longs see if it works if you declare SetWindowLong with MINMAXINFO for lparam..

  3. #3

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: CallWindowProc Issue

    I did that before but it did not seem to work.

    Regards,

    Jenova

  4. #4
    Hyperactive Member
    Join Date
    Aug 2006
    Posts
    367

    Re: CallWindowProc Issue

    You should put types and constants above function declarations.. I doubt it sees your types..

  5. #5

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: CallWindowProc Issue

    I don't think that would cause the issue

  6. #6

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: CallWindowProc Issue

    Can anyone point in the right direction at all?

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: CallWindowProc Issue

    the lParam needs to be a Long.

    you then use the CopyMemory API to get the MINMAXINFO structure that you can work with - then copy it back when you're done.

    Check the example in the API FAQs

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