API for OpenWindow()?

Just starting out? Need help? Post your questions and find answers here.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

API for OpenWindow()?

Post 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!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post 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.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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.
El_Choni
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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 :?
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hi
Try CreateWindowEx_(......

Best Henrik
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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.
--Kale

Image
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Thanks, there might be no easier one :\

Just wanted this for my interpeter :lol:
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post 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?
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

No, it is just an exe that reads commands from a text file and executes them during runtime.
Post Reply