Results 1 to 6 of 6

Thread: [RESOLVED] How do I BitBlt onto an MDI client area when the client rect is adjusted?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Resolved [RESOLVED] How do I BitBlt onto an MDI client area when the client rect is adjusted?

    I am drawing a tabstrip onto an MDI client area, and subclassing to catch the WM_NCCALCSIZE message and altering the client area to give myself some room at the top to draw the tab strip. However, when it comes to actually drawing the tabstrip, I am stuck... I am trying to BitBlt from a picturebox on to the "off-limits" area I have just created, but no success (Nothing gets drawn). However drawing on to the rest of the client area works perfectly.

    Maybe some code would help, this is the WndProc code which shows the client area size adjustment (which works) and the BitBlt (which doesn't)
    VB Code:
    1. Private Function WndProc( _
    2.     ByVal hWnd As Long, _
    3.     ByVal uMsg As Long, _
    4.     ByVal wParam As Long, _
    5.     ByVal lParam As Long _
    6. ) As Long
    7.  
    8. Dim udtNCCalcSize   As NCCALCSIZE_PARAMS
    9. Dim udtWndPos       As WINDOWPOS
    10. Dim udtWndRect      As RECT
    11. Dim udtPicBoxRect   As RECT
    12. Dim lhDC            As Long
    13.  
    14.     Select Case uMsg
    15.         Case WM_NCCALCSIZE
    16.  
    17.             ' Adjust the client area size calculation to allow for our tabstrip
    18.  
    19.             If (wParam <> 0) Then
    20.                 RtlMoveMemory udtNCCalcSize, _
    21.                               ByVal lParam, _
    22.                               Len(udtNCCalcSize)
    23.  
    24.                 RtlMoveMemory udtWndPos, _
    25.                               ByVal udtNCCalcSize.lppos, _
    26.                               Len(udtWndPos)
    27.  
    28.                 With udtNCCalcSize.rgrc(0)
    29.                     .Left = udtWndPos.x + 2
    30.                     .Top = udtWndPos.y + MAGICNUMBER
    31.                     .Right = (udtWndPos.x + udtWndPos.cX) - 2
    32.                     .Bottom = (udtWndPos.y + udtWndPos.cY) - 2
    33.                 End With
    34.  
    35.                 LSet udtNCCalcSize.rgrc(1) = udtNCCalcSize.rgrc(0)
    36.  
    37.                 RtlMoveMemory ByVal lParam, _
    38.                               udtNCCalcSize, _
    39.                               Len(udtNCCalcSize)
    40.  
    41.                 WndProc = WVR_VALIDRECTS
    42.  
    43.               Else
    44.                 WndProc = CallWindowProc(mlpfnOldWindowProc, _
    45.                                          hWnd, _
    46.                                          uMsg, _
    47.                                          wParam, _
    48.                                          lParam)
    49.             End If
    50.  
    51.         Case WM_PAINT, WM_NCPAINT
    52.             GetWindowRect hWnd, udtWndRect
    53.             GetWindowRect mobjDrawPicBox.hWnd, udtPicBoxRect
    54.  
    55.             DrawGradient GradientColorEnd, _
    56.                          GradientColorStart, _
    57.                          GRADIENT_DRAW_VERTICAL, _
    58.                          MAGICNUMBER, _
    59.                          udtWndRect.Right - udtWndRect.Left
    60.  
    61.             lhDC = GetDC(hWnd)
    62.  
    63.             BitBlt lhDC, 0, _
    64.                          (-MAGICNUMBER), _
    65.                          udtWndRect.Right - udtWndRect.Left, _
    66.                          MAGICNUMBER, _
    67.                    mobjDrawPicBox.hDC, _
    68.                          0, _
    69.                          0, _
    70.                          vbSrcCopy
    71.  
    72.             ReleaseDC hWnd, lhDC
    73.  
    74.             WndProc = CallWindowProc(mlpfnOldWindowProc, _
    75.                                      hWnd, _
    76.                                      uMsg, _
    77.                                      wParam, _
    78.                                      lParam)
    79.  
    80.         Case Else
    81.             WndProc = CallWindowProc(mlpfnOldWindowProc, _
    82.                                      hWnd, _
    83.                                      uMsg, _
    84.                                      wParam, _
    85.                                      lParam)
    86.     End Select
    87. End Function

    MAGICNUMBER = 23.
    Bear in mind that BitBlt'ing to a y value > 0 works, but I need it to be absolute 0, i.e. adjusted top of client area minus adjustment offset. Above this point nothing is drawn, it just picks up bits from the rest of the screen when I resize the window (not refreshing effect).

    Any ideas?

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How do I BitBlt onto an MDI client area when the client rect is adjusted?

    You have to make sure the standard non-client drawing is done before you try to paint your own tabs otherwise they might get overpainted when the standard painting is done. So the first thing you should do when you get the WM_NCPAINT message is to call the old WndProc procedure.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How do I BitBlt onto an MDI client area when the client rect is adjusted?

    Thanks for the reply, I tried it, however it made no difference... the drawing still does not work properly.

    Is it possible I am drawing to the wrong DC? I have tried both the MDIClient area and the MDI form itself, but neither worked; maybe I have somehow lost my drawing area in that space?

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How do I BitBlt onto an MDI client area when the client rect is adjusted?

    You're trying to draw on the non-client area that is above the resized MDI client area right? In that case, first of all I don't think you should use the same code for both WM_PAINT and WM_NCPAINT, I don't even think you need to catch the WM_PAINT message, at least not to draw on the non-client area. Secondly you use GetDC to get a device context, that's fine except that DC will only be for the client area and you will not be able to draw anything in the non-client area. You should use GetWindowDC instead.

  5. #5

    Thread Starter
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How do I BitBlt onto an MDI client area when the client rect is adjusted?

    I was about to reply that I had been trying GetWindowDC and GetDCEx also until it occured to me that of course the coordinates are different... it works now Thanks so much

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] How do I BitBlt onto an MDI client area when the client rect is adjusted?

    You're welcome.

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