Page 1 of 1

API for OpenWindow()?

Posted: Tue Dec 27, 2005 4:49 pm
by josku_x
Hello!

I am looking for the API of OpenWindow, I mean sure it's maybe done with CreateWindowEx_(), but how does the procedure look and without CallBack?

CodeArchiv showed me some good codes on how to use CreateWindowEX_(), but all used CallBacks...

So I want the procedure for OpenWindow, trying now 2 days with no luck.
I need also help with the WNDCLASSEX class, is it possible to have a window without this class?

Please help, thanks!

Posted: Tue Dec 27, 2005 5:17 pm
by srod
There is no OpenWindow() API function. You have to use CreateWindow_() or CreateWindowEX_().

Both of these API functions require that you first register a window class (or use a predefined one such as "edit" for an edit control etc.) and a window class has to have an associated callback function which all windows belonging to the class will use. Without the callback, messages will not get processed and your window will be about as much use as a brick made of paper!

So, I'm afraid if you're relying upon the API, then there is no escaping CreateWindowEx_(), no escaping window classes, and no escaping callbacks! :D

Posted: Tue Dec 27, 2005 5:21 pm
by Xombie
It's impossible to create a main application window with CreateWindow_() / CreateWindowEx_() and use native PB commands against it. Sorry. You're going to get into some advanced code if you start to create your own windows and handle messages. I have some code here on doing this - mine was in order to create a unicode capable window via CreateWindowExW_() and I had to handle a lot. Search for my nickname and the word 'unicode' and you should see it.

Otherwise, yeah, it's impossible. From what I understand, there are many things that PB does internally and it has it's own way of handling it's own windows. fred or freak or other gurus, please correct me if I'm wrong here.

Posted: Tue Dec 27, 2005 5:30 pm
by El_Choni
I think you can mix some of the API and PB native commands for windows, but I can't be more precise, I don't have the code here. For example, I think you can put PB gadgets in a API window, but I'm not sure.

Posted: Tue Dec 27, 2005 6:48 pm
by Trond
El_Choni wrote:For example, I think you can put PB gadgets in a API window, but I'm not sure.
Yes, if you turn off the debugger.

Posted: Tue Dec 27, 2005 7:43 pm
by josku_x
Hey people. you all got me wrong. damn :lol:

I wanted to have a procedure that works just like PB's OpenWindow, but in API.

Just like using MessageBox_() instead of MessageRequester(), or Sleep_() instead of Delay().

BTW: PB doesn't support CreateWindow_()? It doesn't recognize it, always tells me that CreateWindow_() is not a function array or a linked list?

This is crazy, how do you translate PB's OpenWindow to API?

Please translate this for me into API:

Code: Select all

OpenWindow(0, 0, 0, 300, 300, #PB_Window_SystemMenu, "Test?")
Thanks mates!
:arrow: I hope you now got me :?

Posted: Tue Dec 27, 2005 7:50 pm
by Henrik
Hi
Try CreateWindowEx_(......

Best Henrik

Posted: Tue Dec 27, 2005 8:10 pm
by Kale
Henrik wrote:Hi
Try CreateWindowEx_(......

Best Henrik
This is used rather than the normal 'CreateWindow_(..' because with this you dont need the normal version.

Mixing API and native PB code is simple, you just have to know API in order to correctly handle events in the callback.

Here is a simple bit of code i have in my bits box here:

Code: Select all

;===========================================================================
;-PROCEDURES
;===========================================================================

;Window callback
Procedure WindowCallback(hWnd, Message, wParam, lParam)
	Debug Message
    Select Message
        Case #WM_CLOSE
            UnregisterClass_("WindowClass", GetModuleHandle_(#Null))
            DestroyWindow_(hWnd)
            ProcedureReturn 0
        Case #WM_DESTROY
            UnregisterClass_("WindowClass", GetModuleHandle_(#Null))
            PostQuitMessage_(0)
            ProcedureReturn 0
    EndSelect
    Result = DefWindowProc_(hWnd, Message, wParam, lParam) 
    ProcedureReturn Result
EndProcedure

;Window class
WindowClass.WNDCLASS

WindowClass\style = #CS_HREDRAW | #CS_VREDRAW
WindowClass\lpfnWndProc = @WindowCallback()
WindowClass\cbClsExtra = 0
WindowClass\cbWndExtra = 0
WindowClass\hInstance = GetModuleHandle_(#Null)
WindowClass\hIcon = LoadIcon_(#Null, #IDI_APPLICATION)
WindowClass\hCursor = LoadCursor_(#Null, #IDC_ARROW)
WindowClass\hbrBackground = GetStockObject_(#WHITE_BRUSH)
WindowClass\lpszMenuName = #Null
WindowClass\lpszClassName = @"WindowClass"
RegisterClass_(WindowClass)

;===========================================================================
;-GEOMETRY
;===========================================================================

;Calculate the window position to display it centrally
ScreenWidth.l = GetSystemMetrics_(#SM_CXSCREEN)
ScreenHeight.l = GetSystemMetrics_(#SM_CYSCREEN)
WindowWidth.l = 400
WindowHeight.l = 300
WindowXPosition.l = (ScreenWidth / 2) - (WindowWidth / 2)
WindowYPosition.l = (ScreenHeight/ 2) - (WindowHeight/ 2)

;Open a window 
hWnd.l = CreateWindowEx_(0, "WindowClass", "Hello World", #WS_VISIBLE | #WS_OVERLAPPEDWINDOW | #WS_SIZEBOX , WindowXPosition, WindowYPosition, WindowWidth, WindowHeight, 0, 0, GetModuleHandle_(#Null), 0) 
	CreateGadgetList(hWnd)
		ButtonGadget(1, 10, 10, 100, 21, "Close")


;===========================================================================
;-MAIN LOOP
;===========================================================================

If hWnd
    While GetMessage_(Message.MSG, 0, 0, 0)
        TranslateMessage_(Message)
        DispatchMessage_(Message)
    Wend
EndIf
notice the window is API and the button is PB. :)

I also mixed the two in this screensaver:
http://www.garyw.uklinux.net/pb/Screens ... Source.zip
see the 'ExecutePreview()' procedure.

Posted: Tue Dec 27, 2005 8:23 pm
by josku_x
Thanks, there might be no easier one :\

Just wanted this for my interpeter :lol:

Posted: Tue Dec 27, 2005 10:45 pm
by okasvi
josku_x wrote:Thanks, there might be no easier one :\

Just wanted this for my interpeter :lol:
is it bytecode compiler or what?

Posted: Tue Dec 27, 2005 10:53 pm
by josku_x
No, it is just an exe that reads commands from a text file and executes them during runtime.