🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #15349

Re: How to disable a window in this way?

#15349
From: Damon Chandler (TeamB)
Date: Sun, 06 Jul 2003 19:34
121 lines
4506 bytes
Hi,
  If you want to flash the modal Form2 when the user clicks Form1, there are
two things that you need to do: (1) Determine when the user clicks Form1;
and (2) flash the title bar of Form2.  For the first step, you'll need to
handle the WM_SETCURSOR message, looking for a hit-test value [specified via
LOWORD(lParam)] of 0xFFFE (effective HTERROR), and a mouse-message value
[specified via HIWORD(lParam)] corresponding to a release of one of the
mouse buttons.  For the second step, as Bob mentioned, you can use the
FlashWindow() Win32 function [or the new FlashWindowEx() function if you
deploy only on systems greater than Win95/NT].  The FlashWindow() function
needs to be called in a non-blocking, interative fashion.  Here's a rough
example...

// in header...
class TForm1 : public TForm
{
__published:
  TButton *Button1;
  TTimer *Timer1;
  void __fastcall Button1Click(TObject *Sender);
  void __fastcall Timer1Timer(TObject *Sender);

public:
  __fastcall TForm1(TComponent* Owner) : 
    TForm(Owner), ModalForm_(NULL) {}

private:
  TForm* ModalForm_;
  MESSAGE void __fastcall WMSetCursor(TMessage& Msg);

public:
BEGIN_MESSAGE_MAP
  MESSAGE_HANDLER(WM_SETCURSOR, TMessage, WMSetCursor)
END_MESSAGE_MAP(TForm)
};


// in source...
void __fastcall TForm1::Button1Click(TObject* Sender)
{
  ModalForm_ = Form2;
  try
  {
    ModalForm_->ShowModal();
    // ...
  }
  __finally
  {
    ModalForm_ = NULL;
  }
}

void __fastcall TForm1::WMSetCursor(TMessage& Msg)
{
  TForm::Dispatch(&Msg);
  if (ModalForm_ != NULL &&
      ModalForm_->FormState.Contains(fsModal))
  {
    if (LOWORD(Msg.LParam) == 0xFFFE &&
        (HIWORD(Msg.LParam) == WM_LBUTTONUP ||
         HIWORD(Msg.LParam) == WM_MBUTTONUP ||
         HIWORD(Msg.LParam) == WM_RBUTTONUP))
    {
      Timer1->Enabled = true;
    }
  }
}

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  static unsigned char tic = 0;
  if (++tic < 9 && ModalForm_ != NULL)
  {
    try
    {
      FlashWindow(ModalForm_->Handle, true);
    }
    catch (...)
    {
      Timer1->Enabled = false;
      // reset, but be sure to debug the error condition 
      FlashWindow(ModalForm_->Handle, false);
      // reset, but be sure to debug the error condition 
      tic = 0; 
      throw;
    }
  }
  else
  {
    Timer1->Enabled = false;  
    FlashWindow(ModalForm_->Handle, false);
    tic = 0;
  }
}

Note that you'll need to add more robust error-handling because you don't
want to re-enable Timer1 in reponse to WM_SETCUROR if an exception is
(re)thrown within the OnTimer event handler.  Timer1 should be initially
disabled (e.g., at design time); and you'd set Timer1's Interval property to
adjust the pause between flashes (50ms seems about what Windows uses).

Good luck,
-- 
Damon (TeamB)
BCBCAQ - http://bcbcaq.bytamin-c.com


b wrote:
> 
> Yes, so how is possible to use FlashWindow ??
> 
> "JD" <nospam@nospam.com> ha scritto nel messaggio
> news:3f07c2aa$1@newsgroups.borland.com...
> >
> > "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
> > > I still do not understand what you are after.
> >
> > He wants to launch Form2 from Form1 using Form2->ShowModal();
> > Then, if the user tries to return to Form1 before Form2 is
> > closed, he wants to flash Form2 as a visual que to remind the
> > user to close Form2 first.
Technical Details
Message-ID: <3F0879B3.9E22CB74@cornell.edu>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3f06bf1c@newsgroups.borland.com> <3f075635$1@newsgroups.borland.com> <3f0766a4$1@newsgroups.borland.com> <3f07c2aa$1@newsgroups.borland.com> <3f07f776$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,994be8bc89f21914
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-07-06 12:37:40 PST
Message-ID: <3F0879B3.9E22CB74@cornell.edu>
Date: Sun, 06 Jul 2003 15:34:11 -0400
From: "Damon Chandler (TeamB)" <dmc27@cornell.edu>
X-Mailer: Mozilla 4.8 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How to disable a window in this way?
References: <3f06bf1c@newsgroups.borland.com> <3f075635$1@newsgroups.borland.com> <3f0766a4$1@newsgroups.borland.com> <3f07c2aa$1@newsgroups.borland.com> <3f07f776$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 24.92.234.87
X-Trace: newsgroups.borland.com 1057520038 24.92.234.87 (6 Jul 2003 12:33:58 -0700)
Lines: 121
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail