🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages Started by Saravanan Wed, 05 Apr 2006 06:19
MDI Child with no caption and flat border
#4029
Author: Saravanan
Date: Wed, 05 Apr 2006 06:19
76 lines
3022 bytes
Hi,

   I want a flat border MDI child window without any caption.  I have tried
various combinations listed below

Tryout 1 :
=======

I changed the child form border style to bsNone and

void __fastcall TMDIChild::FormShow(TObject *Sender)
{
  SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) &
~WS_CAPTION ) ;
  SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
SWP_FRAMECHANGED);
}

void __fastcall TMDIChild::OnNCHitTest(TWMNCHitTest& Message)
{
  DefaultHandler(&Message);

  if ( Message.YPos - 3 < Top )
    Message.Result = HTTOP ;
  else if ( Message.YPos + 3 > Height + Top ) {
    Message.Result = HTBOTTOM ;
  }

  if ( Message.XPos - 3 < Left ) {
     Message.Result = HTLEFT ;
  }

  else if ( Message.XPos + 3 > Width + Left ) {
     Message.Result = HTRIGHT ;
  }

  if ( Message.YPos - 3 < Top && Message.XPos - 3 < Left )
      Message.Result = HTTOPLEFT ;

  if ( Message.YPos + 3 > Height + Top && Message.XPos - 3 < Left )
      Message.Result = HTBOTTOMLEFT ;

  if ( Message.YPos - 3 < Top && Message.XPos + 3 > Width + Left )
      Message.Result = HTTOPRIGHT ;

  if ( Message.YPos + 3 > Height + Top && Message.XPos + 3 > Width + Left )
      Message.Result = HTBOTTOMRIGHT ;
}

childform.h

  void __fastcall OnNCHitTest(TWMNCHitTest& Message) ;
  BEGIN_MESSAGE_MAP
    VCL_MESSAGE_HANDLER(WM_NCHITTEST, TWMNCHitTest, OnNCHitTest)
  END_MESSAGE_MAP(TForm)

I can able to resize the form using the HitTest and cursor appears properly
(Meaning resize cursor is displayed when mouse is moved over the border)

Problem : Border is not flat it is shows as 3d border


Tryout 2 :
=======

I changed the child form border style to bsSingle.

Now the Border Style is flat.  Still i can able to resize the form using the
HitTest but cursor not appearing properly. (Meaning resize cursor is not
displayed when mouse is moved over the border)

Note : One more observation, when the FormStyle is fsNormal, Tryout1 works
well.  But i want the formStyle as fsMDIChild

Regards,
Saravanan A
Re: MDI Child with no caption and flat border
#3948
Author: JD
Date: Thu, 06 Apr 2006 17:47
53 lines
2626 bytes
"Saravanan" <asaravanan@ften.com> wrote:
>

<snip>

>  SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) & ~WS_CAPTION ) ;

You should be overriding the CreateParams method for this
and if you intercept WM_NCPAINT, you can draw a flat border
so you don't have to mimic default behavior with resizing.
For example:

    protected:
        virtual void __fastcall CreateParams( TCreateParams &Params );
    private:    // User declarations
        MESSAGE void __fastcall WMNCPaint( TMessage &Message );
    public:    // User declarations
        BEGIN_MESSAGE_MAP
            VCL_MESSAGE_HANDLER( WM_NCPAINT, TMessage, WMNCPaint )
        END_MESSAGE_MAP( TForm )


#include <memory>
//-------------------------------------------------------------
void __fastcall TForm2::CreateParams( TCreateParams &Params )
{
    TForm::CreateParams( Params );
    Params.Style = Params.Style & ~WS_CAPTION;
}
//-------------------------------------------------------------
MESSAGE void __fastcall TForm2::WMNCPaint(TMessage &Message)
{
    TForm::Dispatch( &Message );
    std::auto_ptr<TCanvas> pCanvas ( new TCanvas );
    pCanvas->Handle = ::GetWindowDC( Handle );
    TRect R;
    ::GetWindowRect( Handle, &R );
    int width = R.Right - R.Left,
        height = R.Bottom - R.Top,
        Limit = ::GetSystemMetrics( SM_CXDLGFRAME );
    for( int x = 0; x < Limit; ++x )
      {
          pCanvas->Pen->Color = pCanvas->Pixels[ width - 1 - x ][ height - 1 - x ];
          pCanvas->MoveTo( x, height - 2 - x );
          pCanvas->LineTo( x, x );
          pCanvas->LineTo( width - x, x );
      }
    ::ReleaseDC( Handle, pCanvas->Handle );
}
//-------------------------------------------------------------

~ JD
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads