Hello Patrice.. perhaps you can Help?
I want to include an openGl Window into a SDK winapi frame. Whats the correct way? My attempt so far.. regards frank
' test openGL sdk window + window frame included with a control
' how to insert an openGL window frame into a sdk window?
'
#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
[/Post]