Page 1 of 1

Windows GUI / DirectX?

Posted: Thu Nov 10, 2005 5:41 pm
by techjunkie
Hi!

Have I dreamt or wasn't there a post in this forum with a way to show Requesters on a DirectX (DirectDraw) screen. What I remembered it used some smart API calls?!?!

Or was it a dream? :lol:

Re: Windows GUI / DirectX?

Posted: Thu Nov 10, 2005 6:00 pm
by Num3
techjunkie wrote:Hi!

Have I dreamt or wasn't there a post in this forum with a way to show Requesters on a DirectX (DirectDraw) screen. What I remembered it used some smart API calls?!?!

Or was it a dream? :lol:
It's a user library that has includes for that....

SpriteX i think ...

Anyway, DX9 has a built in GUI ... eheheh

Posted: Thu Nov 10, 2005 6:35 pm
by benny
@tech-junkie:

Do you mean this code by Stefan M. :?:

Code: Select all


!extrn _PB_DirectX_ScreenWidth
!extrn _PB_DirectX_ScreenHeight
!extrn _PB_DirectX_WindowedMode
!extrn _PB_DirectX_PrimaryBuffer
!extrn _PB_DirectX_BackBuffer
!extrn _PB_DDrawBase


Procedure ScreenRequesterCB(hWnd,Msg,wParam,lParam)
  Addr=GetWindowLong_(hWnd,#GWL_USERDATA)
  If Addr
    Result=CallWindowProc_(PeekL(Addr),hWnd,Msg,wParam,lParam)
   
    If Msg=#WM_DESTROY
      GlobalFree_(Addr)
      SetWindowLong_(hWnd,#GWL_USERDATA,0)
    EndIf
   
    If Msg=#WM_PAINT Or Msg=#WM_MOVING Or Msg=#WM_MOVE Or Msg=#WM_ERASEBKGND
      DC=GetDC_(ScreenID())
      BitBlt_(DC,0,0,PeekL(Addr+8),PeekL(Addr+12),PeekL(Addr+4),0,0,#SRCCOPY)
      ReleaseDC_(ScreenID(),DC)
    EndIf
  Else
    Result=DefWindowProc_(hWnd,Msg,wParam,lParam)
  EndIf
  ProcedureReturn Result
EndProcedure

Procedure ScreenAlertBox(Title.s,Text.s,Buttons.s)
  Global ScreenWidth,ScreenHeight,Windowed,DDrawBase.IDirectDraw7,BackDDS.IDirectDrawSurface7
 
  !MOV Eax,[_PB_DirectX_WindowedMode]
  !MOV [v_Windowed],Eax
  !MOV Eax,[_PB_DirectX_ScreenWidth]
  !MOV [v_ScreenWidth],Eax
  !MOV Eax,[_PB_DirectX_ScreenHeight]
  !MOV [v_ScreenHeight],Eax
 
  If Windowed=0
    !MOV Eax,[_PB_DDrawBase]
    !MOV [v_DDrawBase],Eax
    !MOV Eax,[_PB_DirectX_BackBuffer]
    !MOV [v_BackDDS],Eax
    DDrawBase\GetGDISurface(@GDI_DDS.IDirectDrawSurface7)
    If GDI_DDS=BackDDS
      BackDDS\BltFast(0,0,GDI_DDS,0,0)
      FlipBuffers()
    EndIf   
  EndIf
  ShowCursor_(-1)
  DC=GetDC_(ScreenID())
  MemDC=CreateCompatibleDC_(DC)
  hBmp=CreateCompatibleBitmap_(DC,ScreenWidth,ScreenHeight)
  oldBmp=SelectObject_(MemDC,hBmp)
  BitBlt_(MemDC,0,0,ScreenWidth,ScreenHeight,DC,0,0,#SRCCOPY)
  ReleaseDC_(ScreenID(),DC)
 
  If Font=0:Font=GetStockObject_(#SYSTEM_FONT):EndIf
  Structure Button
    Text.s
    Width.l
  EndStructure
  Dim Button.Button(100)
  Buttons+"|"
  Text+Chr(13)
 
  TmpDC=CreateCompatibleDC_(0)
  SelectObject_(TmpDC,Font)
 
  For M=1 To Len(Buttons)
    If Mid(Buttons,M,1)="|"
      GetTextExtentPoint32_(MemDC,@Str$,Len(Str$),sz.size)
      Button(ButtonAnz)\Width=sz\cx+10
      Button(ButtonAnz)\Text=Str$
     
      If sz\cy+5>ButtonHeight:ButtonHeight=sz\cy+5:EndIf
     
      GesButtonWidth=GesButtonWidth+sz\cx+10
      Str$=""
      ButtonAnz+1
    Else
      Str$=Str$+Mid(Buttons,M,1)
    EndIf
  Next
 
  For M=1 To Len(Text)
    If Mid(Text,M,1)=Chr(13)
      GetTextExtentPoint32_(MemDC,@Str$,Len(Str$),sz.size)
      TextHeight+sz\cy
      If sz\cx+10>TextWidth:TextWidth=sz\cx+10:EndIf
      Str$=""
    Else
      Str$=Str$+Mid(Text,M,1)
    EndIf
  Next
  DeleteDC_(TmpDC)
 
  WindowWidth=GesButtonWidth+10
  If WindowWidth<150:WindowWidth=150:EndIf
  If WindowWidth<TextWidth:WindowWidth=TextWidth:EndIf
 
  WindowHeight=TextHeight+ButtonHeight+10
 
  Flags=#PB_Window_ScreenCentered|#PB_Window_TitleBar
  OpenWindow(1000,0,0,WindowWidth,WindowHeight,Flags,Title,ScreenID())
  CreateGadgetList(WindowID())
  TextGadget(0,XAbs,YAbs,WindowWidth,TextHeight,Text,#PB_Text_Center)
  ;SetGadgetFont(0,Font)
 
  XAbs=(WindowWidth-GesButtonWidth)/2
  YAbs=TextHeight
 
  X=XAbs
  For M=0 To ButtonAnz-1
    ButtonGadget(M+2,X,YAbs,Button(M)\Width,ButtonHeight,Button(M)\Text)
    ;SetGadgetFont(M+2,Font)
    X+Button(M)\Width
  Next
  OldCB=SetWindowLong_(WindowID(),#GWL_WNDPROC,@ScreenRequesterCB())
  Addr=GlobalAlloc_(#GMEM_FIXED,16)
  PokeL(Addr,OldCB)
  PokeL(Addr+4,MemDC)
  PokeL(Addr+8,ScreenWidth)
  PokeL(Addr+12,ScreenHeight)
  SetWindowLong_(WindowID(),#GWL_USERDATA,Addr)
 
  Quit=0
  Repeat
    Event=WaitWindowEvent()
    Gadget=EventGadgetID()
    If Gadget>=2 And Gadget<ButtonAnz+2 And Event=#PB_Event_Gadget:Quit=1:EndIf
  Until Quit=1
  Result=Gadget-1
 
  Repeat:Until WindowEvent()=0
  ShowCursor_(0)
  SetWindowPos_(ScreenID(),#HWND_TOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
  CloseWindow(1000)
  SetWindowPos_(ScreenID(),#HWND_NOTOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
 
  DC=GetDC_(ScreenID())
  BitBlt_(DC,0,0,ScreenWidth,ScreenHeight,MemDC,0,0,#SRCCOPY)
  ReleaseDC_(ScreenID(),DC)
  SelectObject_(MemDC,oldBmp)
  DeleteObject_(hBmp)
  DeleteDC_(MemDC)
  ProcedureReturn Result
EndProcedure





Procedure.s ScreenInputRequester(Title$,Text$,Eing$)
  Global ScreenWidth,ScreenHeight,Windowed,DDrawBase.IDirectDraw7,BackDDS.IDirectDrawSurface7
 
  !MOV Eax,[_PB_DirectX_WindowedMode]
  !MOV [v_Windowed],Eax
  !MOV Eax,[_PB_DirectX_ScreenWidth]
  !MOV [v_ScreenWidth],Eax
  !MOV Eax,[_PB_DirectX_ScreenHeight]
  !MOV [v_ScreenHeight],Eax
 
  If Windowed=0
    !MOV Eax,[_PB_DDrawBase]
    !MOV [v_DDrawBase],Eax
    !MOV Eax,[_PB_DirectX_BackBuffer]
    !MOV [v_BackDDS],Eax
    DDrawBase\GetGDISurface(@GDI_DDS.IDirectDrawSurface7)   
    If GDI_DDS=BackDDS
      BackDDS\BltFast(0,0,GDI_DDS,0,0)
      FlipBuffers()
    EndIf   
  EndIf
  ShowCursor_(-1)
  DC=GetDC_(ScreenID())
  MemDC=CreateCompatibleDC_(DC)
  hBmp=CreateCompatibleBitmap_(DC,ScreenWidth,ScreenHeight)
  oldBmp=SelectObject_(MemDC,hBmp)
  BitBlt_(MemDC,0,0,ScreenWidth,ScreenHeight,DC,0,0,#SRCCOPY)
  ReleaseDC_(ScreenID(),DC)
 
  Flags=#PB_Window_ScreenCentered|#PB_Window_TitleBar
  OpenWindow(1000,0,0,320,90,Flags,Title$,ScreenID())
  OldCB=SetWindowLong_(WindowID(),#GWL_WNDPROC,@ScreenRequesterCB())
  Addr=GlobalAlloc_(#GMEM_FIXED,16)
  PokeL(Addr,OldCB)
  PokeL(Addr+4,MemDC)
  PokeL(Addr+8,ScreenWidth)
  PokeL(Addr+12,ScreenHeight)
 
  SetWindowLong_(WindowID(),#GWL_USERDATA,Addr)
 
  CreateGadgetList(WindowID())
  TextGadget(1,0,0,320,60,Text$)
  gadget=StringGadget(2,0,60,270,20,Eing$)
  ButtonGadget(3,275,60,40,20,"&Ok",#PB_Button_Default)
 
  SetFocus_(gadget)
  SendMessage_(gadget,#EM_SETSEL,0,Len(Eing$))
  SetWindowPos_(WindowID(),#HWND_TOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE) 
  Quit=0
 
  Repeat
    Event=WaitWindowEvent()
   
    If EventGadgetID()=3 And Event=#PB_Event_Gadget:Quit=1:EndIf
  Until Quit=1
  Result.s=GetGadgetText(2)
 
  Repeat:Until WindowEvent()=0
  ShowCursor_(0)
  SetWindowPos_(ScreenID(),#HWND_TOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
  CloseWindow(1000)
  SetWindowPos_(ScreenID(),#HWND_NOTOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
 
  DC=GetDC_(ScreenID())
  BitBlt_(DC,0,0,ScreenWidth,ScreenHeight,MemDC,0,0,#SRCCOPY)
  ReleaseDC_(ScreenID(),DC)
  SelectObject_(MemDC,oldBmp)
  DeleteObject_(hBmp)
  DeleteDC_(MemDC) 
  ProcedureReturn Result.s
EndProcedure








;Beispiel:


InitKeyboard()
InitSprite()
InitMouse()
OpenScreen(640,480,16,"ScreenRequester")
;OpenWindow(1,0,0,640,480,1,"ScreenRequester")
;OpenWindowedScreen(WindowID(),0,0,640,480,1,0,0)

CreateSprite(1,640,480)
StartDrawing(SpriteOutput(1))
Box(0,0,640,480,#Blue)
Circle(320,240,200,#Green)
StopDrawing()

S=GetTickCount_()
Repeat
 
  DisplaySprite(1,0,0)
  FlipBuffers()
 
  If GetTickCount_()-S>2500
     
    Text$="This is a text"+Chr(13)
    Text$+"This is a text"+Chr(13)
    Text$+"This is a text"+Chr(13)
    Text$+"This is a text"+Chr(13)
   
    ScreenInputRequester("ScreenInputRequester",Text$,"Text")
   
     If ScreenAlertBox("ScreenAlertBox",Text$+"Quit ?","&Yes|&No")=1:Quit=1:EndIf
       
    S=GetTickCount_()
  EndIf
 
Until Quit

Posted: Fri Nov 11, 2005 2:56 pm
by techjunkie
benny wrote:@tech-junkie:

Do you mean this code by Stefan M. :?:
Yeah!! Thanks!! :D

Posted: Fri Nov 18, 2005 2:38 pm
by Joakim Christiansen
You can use messageboxes and popupmenues in gamemaker when running fullscreen, I wonder why we can't do that in PureBasic? :evil:
I also seen that in Soldat: http://www.soldat.pl/main.php

Posted: Fri Nov 18, 2005 2:52 pm
by Dare2
Normal windows ones?

You can get a messagerequester in fullscreen mode.

Code: Select all

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't open DirectX 7 or later", 0)
  End
EndIf
If OpenScreen(640, 480, 16, "Sprite")
  LoadSprite(0, "Data\PureBasic.bmp", 0)
  CopySprite(0,1,0)
  If StartDrawing(SpriteOutput(1))
    FrontColor(RGB(255, 0, 0))
    For k = 0 To SpriteHeight(1) Step 2
      Line(0, k, SpriteWidth(1), 0)
    Next
    StopDrawing()
  EndIf
  Repeat
    FlipBuffers()
    ClearScreen(0,0,0)
    ClipSprite(0, 0, 0, x, x/8)
    DisplaySprite(0, x, 100)
    DisplaySprite(1, x, x)
    DisplaySprite(0, 600-x, x)
    x+1
    ExamineKeyboard()
;---------
    If KeyboardReleased(#PB_Key_Return)
      MessageRequester("!","!!!!",0)
    EndIf
;---------
  Until x > 500 Or KeyboardPushed(#PB_Key_Escape)
Else
  MessageRequester("Error", "Can't open a 640*480 - 16 bit screen !", 0)
EndIf
End
But don't use keyboardpushed, or it spits out dozens! :0

Pointless post by me. :)
PostCount + 1