Results 1 to 3 of 3

Thread: Powerbasic: question OpenGL Window in a SDK Window

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    52
    Posts
    944
    Rep Power
    111

    Powerbasic: question OpenGL Window in a SDK Window

    Update

    Hello Petr,. perhaps you can Help or give an advices how to Insert an OpenGL Window into a SDK Window frame? I cannot find any example because I have lost Most openGl example I have created with Powerbasic..

    Thanks, Frank

    ' test openGL sdk window + window frame included with a control
    ' how to insert an openGL window frame into a sdk window?
    '
    ' a question for petr schreiber :-)
    ' thanks, frank
    '
    #COMPILER PBWIN 10
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE ONCE "Win32API.inc"
    
    %IDC_STATIC=1001
    %IDC_BUTTON=1002
    %BS_PUSHBUTTON      = &H0&
    
    '==============================================================================
    FUNCTION WINMAIN (BYVAL hInstance     AS DWORD, _
                      BYVAL hPrevInstance AS DWORD, _
                      BYVAL lpCmdLine     AS ASCIIZ PTR, _
                      BYVAL iCmdShow      AS LONG) AS LONG
    
    
        LOCAL Msg        AS tagMsg
        LOCAL wce        AS WndClassEx
        LOCAL szAppName  AS ASCIIZ * 80
        LOCAL szAppName2 AS ASCIIZ * 80
        LOCAL hWnd       AS DWORD
        LOCAL hWndOpgl       AS DWORD
    
        szAppName         = "HelloWin"
        wce.cbSize        = SIZEOF(wce)
        wce.STYLE         = %CS_HREDRAW OR %CS_VREDRAW
        wce.lpfnWndProc   = CODEPTR(WndProc)
        wce.cbClsExtra    = 0
        wce.cbWndExtra    = 0
        wce.hInstance     = hInstance
        wce.hIcon         = LoadIcon(hInstance, "HELLOWIN")
        wce.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
        wce.hbrBackground = %NULL ' No class background, we do it outselves
        wce.lpszMenuName  = %NULL
        wce.lpszClassName = VARPTR(szAppName)
        wce.hIconSm       = LoadIcon(hInstance, BYVAL %IDI_APPLICATION)
    
        RegisterClassEx wce
    
    
        szAppName2         = "HelloOpenGL"
        wce.cbSize        = SIZEOF(wce)
        wce.STYLE         = %CS_HREDRAW OR %CS_VREDRAW
        wce.lpfnWndProc   = CODEPTR(WndProc)
        wce.cbClsExtra    = 0
        wce.cbWndExtra    = 0
        wce.hInstance     = hInstance
        wce.hIcon         = LoadIcon(hInstance, "HELLOWIN")
        wce.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
        wce.hbrBackground = %NULL ' No class background, we do it outselves
        wce.lpszMenuName  = %NULL
        wce.lpszClassName = VARPTR(szAppName2)
        wce.hIconSm       = LoadIcon(hInstance, BYVAL %IDI_APPLICATION)
    
        RegisterClassEx wce
    
    
        ' Create a window using the registered class
        hWnd = CreateWindow(szAppName, _
                            "The Hello Program", _
                            %WS_OVERLAPPEDWINDOW, _
                            %CW_USEDEFAULT, _
                            %CW_USEDEFAULT, _
                            %CW_USEDEFAULT, _
                            %CW_USEDEFAULT, _
                            %NULL, _
                            %NULL, _
                            hInstance, _
                            BYVAL %NULL)
    
        IF hWnd = 0 THEN  ' exit on failure
            MSGBOX "Unable to create window"
            EXIT FUNCTION
        END IF
    
       ' Create a window using the registered class
        hWndOpgl = CreateWindow(szAppName2, _
                            "OpenGL window", _
                            %WS_OVERLAPPEDWINDOW, _
                            %CW_USEDEFAULT, _
                            %CW_USEDEFAULT, _
                            %CW_USEDEFAULT, _
                            %CW_USEDEFAULT, _
                            %NULL, _
                            %NULL, _
                            hInstance, _
                            BYVAL %NULL)
    
        IF hWndOpgl = 0 THEN  ' exit on failure
            MSGBOX "Unable to create openGLwindow"
            EXIT FUNCTION
        END IF
    
        LOCAL hCtl AS DWORD
        LOCAL hCtlBtn AS DWORD
        LOCAL hFont AS DWORD
    
        hCtl = CreateWindowEx(0, "Static", "openGL", _
                  %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_TABSTOP OR _
                  %SS_NOTIFY OR %SS_LEFT, _ '%SS_RIGHT
                   18, 40, 440, 324, _
                   hwnd, %IDC_STATIC, GetModuleHandle(""), BYVAL %NULL)
        IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
    
        hCtlBtn = CreateWindowEx(0, "Button", "push-me", _
                  %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR _
                  %WS_CLIPSIBLINGS OR %WS_TABSTOP, _
                   650, 440, 80, 24, _
                   hwnd, %IDC_BUTTON, GetModuleHandle(""), BYVAL %NULL)
        IF hFont THEN SendMessage hCtlBtn, %WM_SETFONT, hFont, 0
    
        IF hWnd = 0 THEN
          MessageBox(0, "Window Creation Failed!", "Error", 0)
          EXIT FUNCTION
        END IF
    
        ' Display the window on the screen
        ShowWindow hWnd, iCmdShow
        UpdateWindow hWnd
    
        DO WHILE GetMessage(Msg, %NULL, 0, 0)
            TranslateMessage Msg
            DispatchMessage Msg
        LOOP
        FUNCTION = msg.wParam
    
    END FUNCTION
    
    
    '==============================================================================
    SUB DrawGradient (BYVAL hDC AS DWORD)
    '------------------------------------------------------------------------------
        ' Custom draw procedure for gradiend fill
        '--------------------------------------------------------------------------
    
        LOCAL rectFill AS RECT
        LOCAL rectClient AS RECT
        LOCAL fStep AS SINGLE
        LOCAL hBrush AS DWORD
        LOCAL lOnBand AS LONG
    
        GetClientRect WindowFromDC(hDC), rectClient
        fStep = rectClient.nbottom / 200
    
        FOR lOnBand = 0 TO 199
            SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
            hBrush = CreateSolidBrush(RGB(0, 0, 255 - lOnBand))
            Fillrect hDC, rectFill, hBrush
            DeleteObject hBrush
        NEXT
    
    END SUB
    
    
    '==============================================================================
    FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
                      BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG
    
        LOCAL hDC    AS DWORD
        LOCAL hInstance AS DWORD
        LOCAL pPaint AS PAINTSTRUCT
        LOCAL tRect  AS RECT
    
        SELECT CASE wMsg
    
        CASE %WM_CREATE
    
        CASE %WM_COMMAND
          SELECT CASE LOWRD(wParam)
          CASE %IDOK
              IF HIWRD(wParam) = %BN_CLICKED THEN
                  'Trigger search code..
              END IF
    
          CASE %IDC_BUTTON
              IF HIWRD(wParam) = %BN_CLICKED THEN
                  MSGBOX "pushed"
              END IF
          END SELECT
    
        CASE %WM_PAINT
            hDC = BeginPaint(hWnd, pPaint)
            GetClientRect hWnd, tRect
            SetBkMode hDC, %TRANSPARENT
            SetTextColor hDC, %WHITE
            DrawText hDC, "Hello, openGL Windows!", -1, tRect, %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
            EndPaint hWnd, pPaint
            FUNCTION = 1
            EXIT FUNCTION
    
        CASE %WM_ERASEBKGND
            hDC = wParam
            DrawGradient hDC
            FUNCTION = 1
            EXIT FUNCTION
    
        CASE %WM_DESTROY
            PostQuitMessage 0
            EXIT FUNCTION
    
        END SELECT
    
        FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
    
    END FUNCTION
    
    Last edited by Lionheart008; 13-11-2024 at 19:01.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

Similar Threads

  1. Powerbasic + OpenGL + Mouseposition
    By Lionheart008 in forum TBGL module by Petr Schreiber
    Replies: 1
    Last Post: 17-12-2023, 09:59
  2. Replies: 1
    Last Post: 15-05-2021, 23:24
  3. One more off the wall question - Window Always Active?
    By garretthylltun in forum thinBasic General
    Replies: 2
    Last Post: 09-06-2014, 21:31
  4. RGBA array -> TBGL window (yet another question)
    By RobbeK in forum TBGL General
    Replies: 3
    Last Post: 15-10-2013, 18:23
  5. OpenGl window
    By ErosOlmi in forum TBGL General
    Replies: 1
    Last Post: 02-11-2005, 13:38

Members who have read this thread: 5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •