This one's probably for Fred

First things first: I don't know if this should work, but would it be possible to have a PB function that will return the value of our program's WinMain 'instance'? I was hoping to try and process messages, etc, by myself (more for learning purposes than anything else), but it would also be very useful if we could at least define an 'over-ride' window class (either for all future windows opened, or to supply as an extra [optional?] parameter to OpenWindow), so we can define the look and 'actions' of the window in advance, rather than having to hack it afterwards with SetWindowLong, etc (which I've never had much success with!)... and of course, supplying an over-ride WndProc could be useful too

Code: Select all
Procedure MyWndProc (hWnd, message, wParam, lParam)
Select message
Case #WM_CREATE
MessageBox_ (#NULL, "Hit Esc To Close This Window.", "So You Know", #MB_OK)
Case #WM_DESTROY
PostQuitMessage_ (0)
Case #WM_SYSKEYDOWN
Case #WM_SYSKEYUP
Case #WM_SYSCHAR
Default
ProcedureReturn DefWindowProc_ (hWnd, message, wParam, lParam)
EndSelect
ProcedureReturn (0)
EndProcedure
; -----------------------------------------------------------------------------
hInstance = 0 ; AAAAAAAAAHHHHHHHHHHH!!!! Need to get this from PB's WinMain!
; -----------------------------------------------------------------------------
DefType.WNDCLASS wndclass
wndclass\style = #CS_HREDRAW | #CS_VREDRAW
wndclass\lpfnWndProc = @MyWndProc ()
wndclass\cbClsExtra = 0
wndclass\cbWndExtra = 0
wndclass\hInstance = hInstance ; **************
wndclass\hIcon = LoadIcon_ (#NULL, #IDI_APPLICATION)
wndclass\hCursor = LoadCursor_ (#NULL, #IDC_ARROW)
wndclass\hbrBackground = CreateSolidBrush_ ($AAAAAA)
wndclass\lpszMenuName = #NULL
w$ = "MyWindowName"
wndclass\lpszClassName = @w$
If RegisterClass_ (@wndclass) = 0
MessageBox_ (#NULL, "Doh!", "Error", #MB_OK)
End
EndIf
; Crash occurs here!
; -----------------------------------------------------------------------------
hWindow = CreateWindowEx_ (#NULL, "MyWindowName", "My Title Bar", #WS_OVERLAPPEDWINDOW, 0, 0, 200, 100, #NULL, #NULL, hInstance, #NULL)
; -----------------------------------------------------------------------------
If hWindow
ShowWindow_ (hWindow, #SW_SHOW)
While done = #FALSE
If PeekMessage_ (@msg.MSG, #NULL, 0, 0, #PM_REMOVE)
If msg\message = #WM_QUIT
done = #TRUE
Else
TranslateMessage_ (@msg)
DispatchMessage_ (@msg)
EndIf
PostQuitMessage_ (0)
done = #TRUE
EndIf
Wend
End
EndIf
See ya,
James L Boyd.
http://www.hi-toro.com/
--