Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29417 Discussions

Change Background Color and center Dialog boxes

kaffee46
Beginner
930 Views
Hi,

i am programming a QuickWIN Application.
Sorry for the "simple" questions, but i am just learning to program apps.

1. I want to change the background color of the child window from black to anything else...
I tried to use

ibackcolor = rgb(255,255,255)
iret = SETBKCOLORRGB(ibackcolor)

directly after the OPEN-command, but this does not work,
child window stays black..

2. I want the dialog boxes to open centered to the frame window.
At the moment they open on the upper left corner.
Where do i have to add which code?


Thanks a lot
Marco
0 Kudos
1 Reply
Paul_Curtis
Valued Contributor I
930 Views
Quoting - kaffee46
2. I want the dialog boxes to open centered to the frame window.
At the moment they open on the upper left corner.
Where do i have to add which code?

To learn Windows programming, read any of Petzold's older (pre-.NET) how-to books. Quickwin adds a layer of abstraction which subtracts from the ability to develop full-featured F90 GUI programs -- there is no magic shortcut to avoid processing your own message loops. Here is how to center a child window on its parent (IFWIN and IFWINTY are assumed USEd module-local):

[cpp]!
! Centers a child window on a parent window
SUBROUTINE CenterWindow (hwndChild, hwndParent)
    IMPLICIT NONE
    INTEGER(HANDLE), INTENT(IN)    :: hwndChild
    INTEGER(HANDLE), INTENT(IN)    :: hwndParent
    TYPE (T_RECT)                  :: rChild
    TYPE (T_RECT)                  :: rParent
    INTEGER                        :: wChild
    INTEGER                        :: hChild
    INTEGER                        :: wParent
    INTEGER                        :: hParent
    INTEGER                        :: wScreen
    INTEGER                        :: hScreen
    INTEGER                        :: xNew
    INTEGER                        :: yNew
    INTEGER                        :: hdc
    INTEGER                        :: retval

    ! Get the Height and Width of the child window
    retval = GetWindowRect(hwndChild, rChild)
    wChild = rChild.right - rChild.left
    hChild = rChild.bottom - rChild.top

    ! Get the Height and Width of the parent window
    retval  = GetWindowRect (hwndParent, rParent)
    wParent = rParent.right - rParent.left
    hParent = rParent.bottom - rParent.top

    ! Get the display limits
    hdc = GetDC (hwndChild)
    wScreen = GetDeviceCaps(hdc, HORZRES)
    hScreen = GetDeviceCaps(hdc, VERTRES)
    retval = ReleaseDC(hwndChild, hdc)

    ! Calculate new X position, then adjust for screen
    xNew = rParent.left + ((wParent - wChild) /2)
    IF (xNew .LT. 0) THEN
        xNew = 0
    ELSE IF ((xNew+wChild) .GT. wScreen) THEN
        xNew = wScreen - wChild
    END IF

    ! Calculate new Y position, then adjust for screen
    yNew = rParent.top  + ((hParent - hChild) /2)
    IF (yNew .LT. 0) THEN
        yNew = 0
    ELSE IF ((yNew+hChild) .GT. hScreen) THEN
        yNew = hScreen - hChild
    END IF

    ! Set it, and return
    retval = SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, &
						   IOR(SWP_NOSIZE , SWP_NOZORDER))

END SUBROUTINE CenterWindow


SUBROUTINE CenterDialog (hwnd)
    IMPLICIT NONE
    INTEGER(HANDLE), INTENT(IN)    :: hwnd
    CALL CenterWindow (hwnd, GetParent(hwnd))
END SUBROUTINE CenterDialog
[/cpp]

0 Kudos
Reply