June 18, 2024, 10:08:23 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Positioning System Dialogs

Started by ckoehn, December 31, 2020, 01:23:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ckoehn

December 31, 2020, 01:23:35 PM Last Edit: December 31, 2020, 04:17:46 PM by ckoehn
I was making a program that used the print routines posted on this forum awhile back and when I called SelectPrinter() it placed the Printer Dialog in the upper left hand corner.  I wanted it in the middle of the screen.  The code below allows me to do that.  I made it so that any system dialog should work as long as you you know the title.

TYPE MYINFO
STRING name
UINT millisec
ENDTYPE

MYINFO WaitInfo

'--- used to position Print dialog in center of window ---
WaitInfo.name = "Print"
WaitInfo.millisec = 500

UINT T1 = ET_Thread(&PositionDialog,&WaitInfo)

PrinterName = SelectPrinter()

IF T1<>0 then
CloseHandle(T1)
ENDIF
'----------------------------------------------------------

SUB PositionDialog(POINTER infoptr),INT
STRING title
UINT ms, cnt = 0
UINT hwnd = 0
UINT left, top, width, height
WINRECT lpRect

SETTYPE infoptr, MYINFO

ms = #infoptr.millisec
title = #infoptr.name

WHILE (hwnd = 0) AND (cnt < ms)
Sleep(1)
cnt ++
hwnd = FindWindow(NULL, title)
ENDWHILE

IF (cnt < ms)
GetWindowRect(hwnd, &lpRect)

GETSCREENSIZE width, height
left = (width - (lpRect.right - lpRect.left)) / 2
top = (height - (lpRect.bottom - lpRect.top)) / 2

SetWindowPos(hwnd, 0, left, top, 0, 0, SWP_NOSIZE)
ENDIF

RETURN 0
ENDSUB

SUB ET_Thread(Uint subAsThread, pointer subParam), UINT

UINT threadHandle
UINT tmpHandle

threadHandle = CreateThread(0,0,subAsThread,subParam,0x4,tmpHandle)

IF threadHandle <> 0 THEN ResumeThread(threadHandle)

RETURN threadHandle

ENDSUB

Happy New Year to everyone.

Later,
Clint

ckoehn

I did find an error in the printer.iwb that I was referencing in the above post so I'm including it here if anyone was interested. 

Later,
Clint

billhsln

Thank you for sharing.  Will have to give it a try to see what can be printed and what kinds of interesting things can be done.

Thanks again,
Bill
When all else fails, get a bigger hammer.

Brian

Thanks, Clint. These two files work. Put them both into the same folder, and run "position system dialog.iwb"

Brian

ckoehn

January 02, 2021, 09:35:20 AM #4 Last Edit: January 09, 2021, 06:05:51 AM by ckoehn
That was rough code I posted.  I get lazy commenting things when I program by myself.

This needs to be at the start of the program
$include "windowssdk.inc"
$include "printer.iwb"

TYPE MYINFO
STRING name
UINT millisec
ENDTYPE
MYINFO WaitInfo

This needs to be where you are going to use the printer
'--- used to position Print dialog in centre of window ---
WaitInfo.name="Print"
WaitInfo.millisec=500

UINT T1=ET_Thread(&PositionDialog,&WaitInfo)

STRING PrinterName=SelectPrinter()

IF T1<>0 then
CloseHandle(T1)
ENDIF

IF PrinterName <> ""
    'print things on paper

    '-- remember to close the printer down --------
    EndPrint() ' read manual
ENDIF

This needs to be included in your program somewhere
SUB PositionDialog(POINTER infoptr),INT
STRING title
UINT ms,cnt=0
UINT hWnd=0
UINT left,top,width,height
WINRECT lpRect
SETTYPE infoptr,MYINFO
ms=#infoptr.millisec
title=#infoptr.name
WHILE (hWnd=0) AND (cnt<ms)
Sleep(1)
cnt++
hWnd=FindWindow(NULL,title)
ENDWHILE
IF (cnt<ms)
GetWindowRect(hWnd,&lpRect)
GETSCREENSIZE width,height
left=(width-(lpRect.right-lpRect.left))/2
top=(height-(lpRect.bottom-lpRect.top))/2
SetWindowPos(hWnd,0,left,top,0,0,SWP_NOSIZE)
ENDIF
RETURN 0
ENDSUB

SUB ET_Thread(Uint subAsThread,pointer subParam),UINT
UINT threadHandle,tmpHandle
threadHandle=CreateThread(0,0,subAsThread,subParam,0x4,tmpHandle)
IF threadHandle<>0 THEN ResumeThread(threadHandle)
RETURN threadHandle
ENDSUB

I imagine this is clear as mud...

Later,
Clint