Home > Archive > Programming with dBASE > December 2005 > Centering Choose Printer form









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Centering Choose Printer form
Mike Nunn

2005-12-20, 8:23 pm

I've been noticing for some time that in some circumstances, the printer
options form appears not centre-screen.

I have now twigged what the common factor is.

In order to ensure all forms within the _app frame act as one when the app
is dropped to the task bar by another (Excel or other) window being opened,
I use the following code (picked up previously from this news group):

Form properties includes:

readModal = class::FORM_READMODA
L

/////
Then:

function form_readModal
this.showtaskbarbutton := false
If empty(this.hwndParent)
this.hwndParent := int(_app.framewin.hwnd)
Endif
return super::readModal()

What seems to be happening is that when a chooseprinter function call is
made from the form, the printer options form centres itself on the form, not
on the _app frame.

This is not life-threatenng, but is there any way to ensure the printer
options form centres within the _app frame in these circumstances?

Mike





Rick Miller

2005-12-20, 8:23 pm

Hello Mike,

"Mike Nunn" <mbnunnuk@yahoo.co.uk> wrote in
news:w3mEwIbBGHA.1296@news-server:

> This is not life-threatenng, but is there any way to ensure the
> printer options form centres within the _app frame in these
> circumstances?

----

Below is some quick code for a form
that can be called from Your form that
should put the ChoosePrinter dialog
fairly well centered on the frameWin.

IIRC
the hWndParent property should be assigned
before the showTaskBarButton.
when assigning in that order the chooseprinter
dialog is centered on the form.
since that did not help solve the problem,
a light went on for the form below which
can be called from an object on Your form
with Your form knowing whether the user
selected OK on the chooseprinter dialog.

Hope it helps,
Rick Miller

/*
Filename....: chooseprinter.wfm
----------------------------------------------
How to use:
Put code below into a method
linked to an object's event.
----------------------------------------------
set procedure to chooseprinter.wfm additive
Local oForm
oForm = new chooseprinterForm()
oForm.mdi := false
oForm.readModal()
if oForm.retvalue
// user selected OK in the dialog.
endif
oForm.release()
oForm := null
close procedure chooseprinter.wfm
----------------------------------------------
*/
** END HEADER -- do not remove this line
//
// Generated on 12/20/2005
//
parameter bModal
local f
f = new chooseprinterForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class chooseprinterForm of FORM
with (this)
onOpen = class::form_onOpen
readModal = class::FORM_READMODA
L
metric = 6 // Pixels
height = 10.0
left = 80.0
top = 0.0
width = 10.0
text = ""
endwith

this.PBPRINTER = new PUSHBUTTON(this)
with (this.PBPRINTER)
onClick = class::pbPrinter_onC
lick
height = 24.0
left = 2.0
top = 1.0
width = 60.0
text = "ChoosePrinter"
endwith


//------------------------------------------//
function form_onOpen
this.pbPrinter.onClick()
return

//------------------------------------------//
function form_readModal
this.top := -300
if not type(" RMM_GetSystemMetrics
") == "FP"
extern CINT RMM_GetSystemMetrics
(CINT) ;
user32 from "GetSystemMetrics"
endif
if not type("RMM_GetWindowRect") == "FP"
extern CLOGICAL RMM_GetWindowRect(CH
ANDLE, CPTR) ;
user32 from "GetWindowRect"
endif
this.hWndParent := int(_app.frameWin.hWnd)
this.showTaskBarButton := false
this.setPosition()
return FORM::readModal()

//------------------------------------------//
function pbPrinter_onClick
this.form.retvalue = ChoosePrinter()
this.form.close()
return

//------------------------------------------------------------//
// center this form on the frameWin.
function setPosition
Local sBuff, nBott, nRite, oRet
sBuff = replicate(chr(0), 8)
RMM_GetWindowRect(in
t(_app.frameWin.hWnd), sBuff)
nLeft = class::x_GetIntfromR
ect(sBuff, 0)
nTop = class::x_GetIntfromR
ect(sBuff, 4)
nRite = class::x_GetIntfromR
ect(sBuff, 8)
nBott = class::x_GetIntfromR
ect(sBuff, 12)
nWide = int(nRite - nLeft)
nHigh = int(nBott - nTop) - RMM_GetSystemMetrics
(4)
this.top := (nHigh - this.height) / 2 + nTop
this.left := (nWide - this.width) / 2 + nLeft
return

//------------------------------------------------------------//
// return an int value from a rect structure.
function x_GetIntfromRect(sRe
ct, nPos)
Local nRet
nRet = sRect.getbyte(nPos) + ;
BitLshift(sRect.getByte(nPos + 1), 8) + ;
BitLshift(sRect.getByte(nPos + 2), 16) + ;
BitLshift(sRect.getByte(nPos + 3), 24)
if BitSet(nRet, 31)
nRet := - BitNot(nRet)
endif
return int(nRet)

endclass

Mike Nunn

2005-12-21, 8:24 pm

Hi Rick

Wow, this is some code! Many thanks.

It'll take me a bit of time to get my mind round it.

I am wondering if I could also get round the problem by calling a .prg or an
off-screen .wfm which in turn calls the chooseprinter function.

A couple of things to work at anyway.

Mike


Rick Miller

2005-12-21, 8:24 pm

Hello Mike,

"Mike Nunn" <mbnunnuk@yahoo.co.uk> wrote in
news:j$POYbnBGHA.1664@news-server:

> Hi Rick
> It'll take me a bit of time to get my mind round it.

----

what makes it work is:
1) the chooseprinter form (very small visually)
centers itself on _app.frameWin
with the setPosition method.
2) the ChoosePrinter dialog is called in the onOpen
event of the chooseprinter form.
3) the ChoosePrinter dialog centers itself on
the form (chooseprinter) that called it
covering the form.
4) the chooseprinter form closes right after
the dialog closes.

> I am wondering if I could also get round the problem by calling a
> .prg or an off-screen .wfm which in turn calls the chooseprinter
> function.

----

sure, the oForm code could be put in a prg.
example:
function selectPrinter
set procedure to chooseprinter.wfm additive
Local bRet, oForm
oForm = new chooseprinterForm()
oForm.mdi := false
oForm.readModal()
bRet = iif(oForm.retvalue, true, false)
oForm.release()
oForm := null
close procedure chooseprinter.wfm
return iif(bRet, true, false)

You're welcome,
Rick Miller


Here is a little plug for the dBLPrint object at:
http://www.treturn.com/dbase/
It might do what You are looking for.

oRef = new dBLprint()
if oRef.choosePrinter()
oRef.setPrinter(_app.printer)
endif
oRef.release()
oRef := null

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com