instead of creating a new window, just save off the current window info, and
then set the current window to be the display window (WinGetDisplayWindow).
when you're done, restore the current window to what it was before.
sample code (for a progress meter) follows. (it will need a little tweaking
to compile, since i don't include the source for "Assert", for instance --
also, sorry about the single-space indents; the hard tabs got converted to
spaces):
===== header file =====
// progress ---------------------------------------------------------------
/*
1. call ProgressInit with the maximum value for the progress bar.
2. call ProgressUpdate whenever you want to update the progress bar,
passing a value between 0 and the maximum value you specified. it's a
no-op until 0.5 seconds have elapsed since the ProgressInit call.
3. call ProgressEnd to remove the progress bar. if the progress bar is
visible but the elapsed time since the ProgressInit call is less than
1.0 second, then it will pause for 1/3 of a second (to avoid confusing
the user with flicker from erasing the progress bar too quickly for
the user to have seen it).
*/
void ProgressInit(Word cMax);
Boolean ProgressUpdate(Word cProgress);
void ProgressEnd(void);
===== C source file =====
///////////////////////////////////////////////////////////////////////////
// Progress Bar
static DWord s_dwTicks;
static Boolean s_fProgress;
static Word s_cMax;
static RectangleType s_rcProgress;
static Int s_cxMax;
static WinHandle s_hwinProgress;
static WinHandle s_hwinSavedBits;
static WinHandle s_hwinActive;
static WinHandle s_hwinDraw;
enum {
CX_PROGRESS = 80,
CY_PROGRESS = 26,
};
void ProgressInit(Word cMax)
{
ASSERTGLOBALS;
s_fProgress = fFalse;
s_hwinProgress = 0;
s_hwinSavedBits = 0;
s_cMax = cMax;
#ifdef DEBUG
s_dwTicks = 0;
#else
s_dwTicks = TimGetTicks();
#endif
}
/*!-------------------------------------------------------------------------
::ProgressUpdate
returns fTrue if the user cancelled.
--------------------------------------------------------------------------
*/
Boolean ProgressUpdate(Word cProgress)
{
CharPtr psz;
VoidHand h;
Int cch;
FontID font;
Word err;
RectangleType rc;
if (!s_fProgress)
{
if (TimGetTicks() - s_dwTicks > SysTicksPerSecond() / 2)
{
s_fProgress = fTrue;
s_hwinDraw = WinGetDrawWindow();
s_hwinActive = WinGetActiveWindow();
s_rcProgress.topLeft.x = s_rcProgress.topLeft.y = 0;
WinGetDisplayExtent(&s_rcProgress.extent.x, &s_rcProgress.extent.y);
s_rcProgress.topLeft.x = (s_rcProgress.extent.x - CX_PROGRESS) / 2;
s_rcProgress.extent.x = CX_PROGRESS;
s_rcProgress.topLeft.y = (s_rcProgress.extent.y - CY_PROGRESS) / 2;
s_rcProgress.extent.y = CY_PROGRESS;
s_hwinProgress = WinCreateWindow(&s_rcProgress, dialogFrame, fTrue,
fFalse, &err);
if (s_hwinProgress)
{
// save the bits behind the window
WinSetDrawWindow(WinGetDisplayWindow());
WinGetWindowFrameRect(s_hwinProgress, &rc);
RctInsetRectangle(&rc, -1);
s_hwinSavedBits = WinSaveBits(&rc, &err);
WinSetDrawWindow(s_hwinProgress);
WinSetActiveWindow(s_hwinProgress);
WinEraseWindow();
WinDrawWindowFrame();
psz = LockStringRes(IDS_Working, &h);
cch = StrLen(psz);
font = FntSetFont(boldFont);
WinDrawChars(psz, cch, (s_rcProgress.extent.x - FntCharsWidth(psz, cch))
/ 2, 4);
FntSetFont(font);
UnlockStringRes(&h);
s_rcProgress.extent.x -= 12;
s_cxMax = s_rcProgress.extent.x;
s_rcProgress.topLeft.x = 6;
s_rcProgress.topLeft.y = 18;
s_rcProgress.extent.y = 4;
WinDrawRectangleFrame(simpleFrame, &s_rcProgress);
}
}
}
if (s_hwinProgress)
{
s_rcProgress.extent.x = ((cProgress) * s_cxMax) / s_cMax;
WinDrawRectangle(&s_rcProgress, 0);
}
return fFalse;
}
void ProgressEnd(void)
{
RectangleType rc;
if (s_fProgress)
{
s_fProgress = fFalse;
Assert(s_hwinProgress);
s_rcProgress.extent.x = s_cxMax;
WinDrawRectangle(&s_rcProgress, 0);
if (TimGetTicks() - s_dwTicks < SysTicksPerSecond())
SysTaskDelay(SysTicksPerSecond() / 3);
if (s_hwinSavedBits)
{
WinSetDrawWindow(WinGetDisplayWindow());
WinGetWindowFrameRect(s_hwinProgress, &rc);
RctInsetRectangle(&rc, -1);
WinRestoreBits(s_hwinSavedBits, rc.topLeft.x, rc.topLeft.y);
WinDeleteWindow(s_hwinProgress, fFalse);
}
WinSetDrawWindow(s_hwinDraw);
WinSetActiveWindow(s_hwinActive);
if (!s_hwinSavedBits)
FrmUpdateForm(FrmGetActiveFormID(), frmRedrawUpdateCode);
}
}
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 21, 1999 10:47 AM
Subject: Display-relative rather than window-relative
> I'm trying to make a temporary popup window appear in
> the center of the display. I discovered that the
> WinDraw... functions draw relative to the upper left
> corner of the active window (doh.. imagine that!). Then
> I discovered WinWindowToDisplayPt, that converts window-
> relative coordinates to display-relative. That works
> great, except that what I draw is clipped by the border
> of the display window (causes problems when the find
> dialog is open, or a category popup list is open). So, I
> tried temporarily changing the clipping window (using
> WinGetClip and WinSetClip) to match the rectangle I'm
> trying to draw, using the display relative coordinates I
> got back from WinWindowToDisplayPt. Apparently the
> clipping rectangle is intersected with the draw window's
> boundaries.
>
> Having met with failure trying to draw upon whatever
> window happens to be the draw window, I then tried a new
> approach: creating a new window, using WinCreateWindow,
> WinEnableWindow, WinSetDrawWindow, etc. However, nothing
> appears on the display.
>
> Does anybody have any sample code they wouldn't mind
> sharing? I've searched the knowledge base in vain.
> Thanks.
>
> --
> Roger Chaplin <[EMAIL PROTECTED]>
>