Page 1 of 2
Posted: Tue Feb 26, 2002 9:31 pm
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.
For demontration purposes (i'm fighting with a visual basic guy

) i need a codesnipped with the Win API function CreateWindowEx_
Exactly the code should open a normal application window like (PB-style):
Code: Select all
hWnd = OpenWindow(0, 0, 0, 640, 440, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_Invisible ,"Demo")
*entirely* with the API-call CreateWindowEx_()
It would be easer to use CreateWindow_, but this function seems not to be known by PB, and currently I've some problems with initiating the right structures for CreateWindowEx_().
Can someone help me out?
Registered PureBasic Coder
Edited by - FAKEFACTORY on 26 February 2002 21:33:15
Posted: Wed Feb 27, 2002 5:46 pm
by BackupUser
Restored from previous forum. Originally posted by preacher.
Hi FakeFactory.
I hope the following code is what you need to win the 'fight'...
Procedure.l ownwindowproc(lParam,wParam,Msg,hWnd); needs to be reversed for Purebasic to make it work
If Msg=#WM_CREATE ;window created
ProcedureReturn 0
EndIf
If Msg=#WM_LBUTTONDOWN ;mousebutton clicked...
EndIf
If Msg=#WM_SIZE ;window has been sized
w.w=lParam ;get width of sized window
h.w=lParam >> 16 ;get height of sized window
EndIf
If Msg=#WM_ERASEBKGND ;draw window
EndIf
If Msg=#WM_MOUSEMOVE
xPos.w=lParam
yPos.w=lParam >> 16
EndIf
If Msg=#WM_CLOSE
PostQuitMessage_(0)
EndIf
ProcedureReturn DefWindowProc_(hWnd,Msg,wParam,lParam)
EndProcedure
ClassName.s = "ownwindow"
wc.WNDCLASSEX
wc\cbSize = SizeOf(WNDCLASSEX)
wc\style = #CS_HREDRAW | #CS_VREDRAW ;| #CS_GLOBALCLASS
wc\lpfnWndProc = @ownwindowproc()
wc\cbClsExtra = 0
wc\cbWndExtra = 0
wc\hInstance = GetModuleHandle_(0)
wc\hIcon = 0
wc\hCursor = LoadCursor_(#NULL,#IDC_CROSS)
wc\hbrBackground = GetStockObject_(#LTGRAY_BRUSH);#WHITE_BRUSH);
wc\lpszMenuName = 0
wc\lpszClassName = @ClassName
wc\hIconSm = 0
If RegisterClassEx_(@wc)
Else
MessageRequester("","Failed to open window...",0)
End
EndIf
;remove #PB_Window_Invisible to make the window invisible
hwnd=CreateWindowEx_(0,"ownwindow",@"DEMO",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_Invisible,100,100,200,200,0,0,GetModuleHandle_(0),0)
msg.MSG
While GetMessage_(@msg,0,0,0)
TranslateMessage_(@msg);
DispatchMessage_(@msg);
Wend
End
[Preacher]
Posted: Wed Feb 27, 2002 6:23 pm
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.
Hi, Preacher!
Many thanks! Code works perfectly. Now i can start the next round in the battle..
Registered PureBasic Coder
Posted: Wed Feb 27, 2002 9:17 pm
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.
And a further question:
After creating a window with the APi functions... is it possible to "hook up" this window to the Purebasic handler, so i can use normal CreateGadget functions on this window?
Registered PureBasic Coder
Posted: Wed Feb 27, 2002 9:26 pm
by BackupUser
Restored from previous forum. Originally posted by preacher.
nice you could use the code. When it comes to using Purebasic's handler to setup gadgets I wouldn't know if it is possible (guess not) but prehaps fred could say.
[Preacher]
Posted: Wed Feb 27, 2002 9:45 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> i'm fighting with a visual basic guy
What about? What's he saying?
PB - Registered PureBasic Coder
Posted: Wed Feb 27, 2002 10:11 pm
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.
He mentioned, Purebasic is "not 100 % OS-conform".
I needed the code because of my old problem with windowblinds. Purebasic-style opened windows does not receive the #WM_CLOSE event - therefore you never can close the program, but the CreateWindowEx_ window do.
After presenting Preachs code-snipped, he was impressed, but still is believing, VB and Powerbasic are the only really OS-proof languages with complete API-support.
Registered PureBasic Coder
Posted: Wed Feb 27, 2002 11:02 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> He mentioned, Purebasic is "not 100 % OS-conform".
Only the author of PureBasic can say that. Besides, if VB is so OS-conforming,
ask him why he has to declare all API constants and routines before he can
actually even use them with VB.
> [he] is believing, VB and Powerbasic are the only really OS-proof languages
> with complete API-support.
PureBasic has 100% API support, and is still being updated. VB isn't. Ask him
what he thinks of that, and ask him why VB needs a 1.5 MB runtime file just to
run. That should put him in his place. I used to love VB too, but then saw
the light with PureBasic.
PB - Registered PureBasic Coder
Posted: Wed Feb 27, 2002 11:08 pm
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.
>Only the author of PureBasic can say that. Besides, if VB is so OS-conforming,
>ask him why he has to declare all API constants and routines before he can
>actually even use them with VB.
Allready done
>PureBasic has 100% API support, and is still being updated. VB isn't. Ask him
>what he thinks of that, and ask him why VB needs a 1.5 MB runtime file just to
>run.
Allready done
I guess, he will run out of options shortly.
Registered PureBasic Coder
Edited by - FAKEFACTORY on 27 February 2002 23:08:29
Posted: Wed Feb 27, 2002 11:30 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
After creating a window with the APi functions... is it possible to "hook up" this window to the Purebasic handler, so i can use normal CreateGadget functions on this window?
Yes, use the window handle as argument instead of WindowID() CreateGadgetList(). I think you can even get EventGadgetIds of API created controls by using an index number (as #Gadget) in the hMenu field of CreateWindowEx_().
Bye,
El_Choni
Posted: Wed Feb 27, 2002 11:46 pm
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.
Ah, ok.
But it's not possible to use the
Repeat : Event.l = WaitWindowEvent() : Until.... loop
and all the EventGadget, EventMenu stuff...
because PB crashs with a "No window opened" error.
Registered PureBasic Coder
Posted: Thu Feb 28, 2002 1:10 am
by BackupUser
Restored from previous forum. Originally posted by Franco.
Ah, ok.
But it's not possible to use the
Repeat : Event.l = WaitWindowEvent() : Until.... loop
and all the EventGadget, EventMenu stuff...
because PB crashs with a "No window opened" error.
Yes that's right!
Hi all,
following a sample how to manage the CreateWindowEx Events
Code: Select all
;Manage CreateWindowEx Events
#WindowWidth = 320
#WindowHeight = 240
Global Main_hWnd, BG_hWnd1, BG_hWnd2, BG_hWnd3, CB_hWnd
Procedure Error(errorstring.s)
MessageRequester("Error", errorstring, #MB_ICONERROR)
End
EndProcedure
Procedure HiWord(Var)
ProcedureReturn Var >> 16
EndProcedure
Procedure LoWord(Var)
ProcedureReturn PeekW(@Var)
EndProcedure
Procedure RunApplication()
Shared WndProcMsg.MSG
While GetMessage_(@WndProcMsg,0,0,0)
TranslateMessage_(@WndProcMsg);
DispatchMessage_(@WndProcMsg);
Wend
EndProcedure
Procedure.l WndProc(hWnd,Msg,wParam,lParam)
Select Msg
Case #WM_CONTEXTMENU;this is for some Mouse Right Click on some Gadgets (not all!!!)
; MessageRequester("MOUSE","WM_CONTEXTMENU "+Str(Msg)+" "+Str(LoWord(wParam))+" "+Str(LoWord(wParam))+" "+Str(LoWord(lParam))+" "+Str(HiWord(lParam)), 0)
If wParam = CB_hWnd
MessageRequester("You right-clicked", "in the ComboBox gadget.", 0)
EndIf
Case #WM_PARENTNOTIFY
; MessageRequester("MOUSE","WM_PARENTNOTIFY "+Str(Msg)+" "+Str(LoWord(wParam))+" "+Str(HiWord(wParam))+" "+Str(LoWord(lParam))+" "+Str(HiWord(lParam)), 0)
If LoWord(wParam) = 516 And LoWord(lParam) > 5 And LoWord(lParam) 150 And HiWord(lParam) #WindowWidth-110 And LoWord(lParam) 5 And HiWord(lParam) #WindowWidth-60 And LoWord(lParam) 5 And HiWord(lParam) > 16 ;get height of sized window
Case #WM_ERASEBKGND ;draw window
Case #WM_MOUSEMOVE
xPos.w=lParam
yPos.w=lParam >> 16
Case #WM_CLOSE
MessageRequester("MOUSE","WM_CLOSE "+Str(Msg)+" "+Str(LoWord(wParam))+" "+Str(LoWord(wParam))+" "+Str(LoWord(lParam))+" "+Str(HiWord(lParam)), 0)
PostQuitMessage_(0)
; End
EndSelect
ProcedureReturn DefWindowProc_(hWnd,Msg,wParam,lParam)
EndProcedure
ClassName.s = "ownwindow"
wc.WNDCLASSEX
wc\cbSize = SizeOf(WNDCLASSEX)
wc\style = #CS_HREDRAW | #CS_VREDRAW ;| #CS_GLOBALCLASS
wc\lpfnWndProc = @WndProc()
wc\cbClsExtra = 0
wc\cbWndExtra = 0
wc\hInstance = GetModuleHandle_(0)
wc\hIcon = 0
wc\hCursor = LoadCursor_(#NULL,#IDC_CROSS)
;wc\hbrBackground = GetStockObject_(#LTGRAY_BRUSH); #WHITE_BRUSH);
Brush.LOGBRUSH\lbColor = GetSysColor_(#COLOR_BTNFACE)
wc\hbrBackground = CreateBrushIndirect_(Brush)
wc\lpszMenuName = 0
wc\lpszClassName = @ClassName
wc\hIconSm = 0
If RegisterClassEx_(@wc)
;everithing is OK!
Else
MessageRequester("","Failed to open window...",0)
End
EndIf
;remove #PB_Window_Invisible to make the window invisible
hWnd=CreateWindowEx_(0,"ownwindow",@"DEMO",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_Invisible,200,200,#WindowWidth,#WindowHeight,0,0,GetModuleHandle_(0),0)
;OK! without a Button in the TaskBar!
;hWnd=CreateWindowEx_(#WS_EX_TOOLWINDOW,"ownwindow",@"DEMO",#WS_POPUPWINDOW|#WS_DLGFRAME|#WS_CLIPSIBLINGS|#WS_VISIBLE|#DS_MODALFRAME|#DS_3DLOOK,200,200,320,240,0,0,GetModuleHandle_(0),0)
SetWindowPos_(hWnd,#HWND_TOPMOST,(GetSystemMetrics_(#SM_CXSCREEN)/2)-#WindowWidth/2,(GetSystemMetrics_(#SM_CYSCREEN)/2)-240/2,#WindowWidth,#WindowHeight, 0 )
If InitGadget(4) = 0 : Error("Cannot initialize gadgets.") : EndIf
If CreateGadgetList(hWnd) : Else : Error("Could not create gadget list.") : EndIf
CB_hWnd = ComboBoxGadget(0, 5, 5, #WindowWidth-120, 100)
; MessageRequester("Button 1",Str(CB_hWnd),0)
AddGadgetItem(0, -1, "Spaghetti")
AddGadgetItem(0, -1, "Great sole")
AddGadgetItem(0, -1, "Potato omelette")
AddGadgetItem(0, -1, "Fondue chinoise")
AddGadgetItem(0, -1, "Tapioca soup")
AddGadgetItem(0, -1, "Duck liver")
AddGadgetItem(0, -1, "Kebap")
BG_hWnd1 = ButtonGadget(1,5,150,120,24,"Butt1")
; MessageRequester("Button 1",Str(BG_hWnd1),0)
BG_hWnd2 = ButtonGadget(2,#WindowWidth-110,5,50,24,"Butt2")
; MessageRequester("Button 1",Str(BG_hWnd2),0)
BG_hWnd3 = ButtonGadget(3,#WindowWidth-60,5,50,24,"Butt3")
; MessageRequester("Button 2",Str(BG_hWnd3),0)
TextGadget(4, 5, 100, #WindowWidth-10, 24, "Capturing the item-selected event.")
RunApplication()
End
If you look through the code (I hope so...) you can see this is not only my work.
some code is related from El_Choni and some is from Preacher.
Hope this helps...
BTW: YES I'm back on track
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
CODE CHANGED BECAUSE OF THE CHANGES OF PureBasic v3
Edited by - Franco on 05 April 2002 22:26:09
Posted: Thu Feb 28, 2002 1:50 pm
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.
Thanks, Franco!
Good to see you back in business
Registered PureBasic Coder
Posted: Fri Apr 05, 2002 9:19 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.
With PureBasic v3 you need to change the parameters of 'Procedure ownwindowproc' to:
Procedure.l ownwindowproc(hWnd,Msg,wParam,lParam)
to make it work.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Edited by - Franco on 05 April 2002 22:23:24
Posted: Sat Apr 06, 2002 2:27 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.
> With PureBasic v3 you need to change the parameters of
> 'Procedure ownwindowproc' to:
> Procedure.l ownwindowproc(hWnd,Msg,wParam,lParam)
I used the same order before and it worked fine.
Dont think this has changed with 3.0 !?
cya,
...Danilo
(registered PureBasic user)