Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Messages not reaching WndProc

Messages not reaching WndProc

Scheduled Pinned Locked Moved C#
csharpgraphicsjson
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kastro
    wrote on last edited by
    #1

    I am writing a class that overrides Control and utilizes the non-client area. I need to be able to have hotspots within the non-client area. However, because of what seems to me to be unusual behavior, I am not able to get it working. I override WndProc to intercept WM_NCMOUSEMOVE and WM_NCPAINT (as well as WM_NCCALCSIZE, WM_NCHITTEST, and WM_LBUTTONDOWN/UP) as follows: (Please don't flame me for posting VB.NET code. I use both interchangably as they are pretty much the same thing anyways. It just so happens that I wrote this in VB.NET. I posted here because I would guess that C# programmers know more about the Win32 API than VB.NET programmers, and my questions have nothing to do with VB.NET)

    Protected Overrides Sub WndProc(ByRef msg As Message)
        Select Case msg.Msg
            Case 131 'WM\_NCCALCSIZE
                ...
            Case 132 'WM\_NCHITTEST
                ...
            Case 133 'WM\_NCPAINT
                Dim dc As Integer
                dc = GetDCEx(msg.HWnd.ToInt32(), msg.WParam.ToInt32(), 65536 + 128 + 1)
                Dim hdc As IntPtr = New IntPtr(dc)
                Dim g As Graphics = Graphics.FromHdc(hdc)
                OnPaintNonClient(New PaintEventArgs(g, Rectangle.Round(g.ClipBounds)))
                ReleaseDC(msg.HWnd.ToInt32(), hdc.ToInt32())
            Case 160 'WM\_NCMOUSEMOVE
                Dim pt As PointL
                pt.x = msg.LParam.ToInt32() Mod 65536
                pt.y = msg.LParam.ToInt32() / 65536
                Dim ppt As IntPtr = Marshal.AllocHGlobal(8)
                Marshal.StructureToPtr(pt, ppt, False)
                ScreenToClient(msg.HWnd.ToInt32(), ppt.ToInt32())
                pt = Marshal.PtrToStructure(ppt, GetType(PointL))
                Dim args As MouseEventArgs = New MouseEventArgs(MouseButtons.None, 0, pt.x, pt.y, 0)
                OnNonClientMouseMove(args)
                Marshal.FreeHGlobal(ppt)
            Case 161 'WM\_NCLBUTTONDOWN
                ...
            Case 162 'WM\_NCLBUTTONUP
                ...
            Case Else
                MyBase.WndProc(msg)
        End Select
    End Sub
    
    Protected Overridable Sub OnNonClientMouseMove(ByVal args As MouseEventArgs)
        If ... Then 'Test hotspots
            ...
            PostMessage(Me.Handle, 133, 0, 0) 'WM\_NCPAINT
        End If
    End Sub
    
    Protected Overridable Sub OnPaintNonClient(ByVal args As PaintEventArgs)
        ...
    End Sub
    
    K 1 Reply Last reply
    0
    • K Kastro

      I am writing a class that overrides Control and utilizes the non-client area. I need to be able to have hotspots within the non-client area. However, because of what seems to me to be unusual behavior, I am not able to get it working. I override WndProc to intercept WM_NCMOUSEMOVE and WM_NCPAINT (as well as WM_NCCALCSIZE, WM_NCHITTEST, and WM_LBUTTONDOWN/UP) as follows: (Please don't flame me for posting VB.NET code. I use both interchangably as they are pretty much the same thing anyways. It just so happens that I wrote this in VB.NET. I posted here because I would guess that C# programmers know more about the Win32 API than VB.NET programmers, and my questions have nothing to do with VB.NET)

      Protected Overrides Sub WndProc(ByRef msg As Message)
          Select Case msg.Msg
              Case 131 'WM\_NCCALCSIZE
                  ...
              Case 132 'WM\_NCHITTEST
                  ...
              Case 133 'WM\_NCPAINT
                  Dim dc As Integer
                  dc = GetDCEx(msg.HWnd.ToInt32(), msg.WParam.ToInt32(), 65536 + 128 + 1)
                  Dim hdc As IntPtr = New IntPtr(dc)
                  Dim g As Graphics = Graphics.FromHdc(hdc)
                  OnPaintNonClient(New PaintEventArgs(g, Rectangle.Round(g.ClipBounds)))
                  ReleaseDC(msg.HWnd.ToInt32(), hdc.ToInt32())
              Case 160 'WM\_NCMOUSEMOVE
                  Dim pt As PointL
                  pt.x = msg.LParam.ToInt32() Mod 65536
                  pt.y = msg.LParam.ToInt32() / 65536
                  Dim ppt As IntPtr = Marshal.AllocHGlobal(8)
                  Marshal.StructureToPtr(pt, ppt, False)
                  ScreenToClient(msg.HWnd.ToInt32(), ppt.ToInt32())
                  pt = Marshal.PtrToStructure(ppt, GetType(PointL))
                  Dim args As MouseEventArgs = New MouseEventArgs(MouseButtons.None, 0, pt.x, pt.y, 0)
                  OnNonClientMouseMove(args)
                  Marshal.FreeHGlobal(ppt)
              Case 161 'WM\_NCLBUTTONDOWN
                  ...
              Case 162 'WM\_NCLBUTTONUP
                  ...
              Case Else
                  MyBase.WndProc(msg)
          End Select
      End Sub
      
      Protected Overridable Sub OnNonClientMouseMove(ByVal args As MouseEventArgs)
          If ... Then 'Test hotspots
              ...
              PostMessage(Me.Handle, 133, 0, 0) 'WM\_NCPAINT
          End If
      End Sub
      
      Protected Overridable Sub OnPaintNonClient(ByVal args As PaintEventArgs)
          ...
      End Sub
      
      K Offline
      K Offline
      Kastro
      wrote on last edited by
      #2

      I tried something else out that gave me strange results as well... Instead of using PostMessage, I switched to using SendMessage. The WM_NCPAINT message is now reaching WndProc, however, the strange thing is that the drawing that I do there does not show up. The drawing code works fine in response to WM_NCPAINT messages caused by resizes, min/maxes, etc... Any ideas?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups