DialogBox from .res file?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by FloHimself.

hi,

anyone knows how to use dialog boxes from resource files (.res)?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

Not possible for now. the only way is using dialogs in memory. you will need to know about the dialog procedure, for advanced users.

the dialog is designed using a tool i did.

Code: Select all

;Purebasic Window Editor v2.91

;GADGET IDs
#BT_MSHOW=0
#BT_MCANCEL=1

;DIALOG IDs
#Text0=0
#ED_PASSWORD=1
#BT_OK=2
#BT_CANCEL=3

;WINDOW ID
#Window1=0

structure PASS
  psw.s
endstructure
spw.PASS

global hwmain,gcharbuf$,spw,hinst

gcharbuf$=space(#MAX_PATH)
hinst=getmodulehandle_(0)

;Dialog Procedure
Procedure Dialogproc(hdlg,msg,wparam,lparam)
  Select msg
   
    Case #WM_COMMAND
      Select peekw(@wparam)
        Case #BT_OK
          rtlzeromemory_(@gcharbuf$,#MAX_PATH)
          getdlgitemtext_(hdlg,#ED_PASSWORD,@gcharbuf$,#MAX_PATH)
          spw\psw=gcharbuf$ 
          EndDialog_(hdlg,1)
          retval=1

        Case #BT_CANCEL
          EndDialog_(hdlg,0)
          retval=1

      EndSelect

    Case #WM_CLOSE
      EndDialog_(hdlg,0)

    Default
      retval=0

  EndSelect
  ProcedureReturn retval
EndProcedure

;WINDOW
hwmain=OpenWindow(#Window1,264,164,257,114,#PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered,"Main")
CreateGadgetList(WindowID(#Window1))

ButtonGadget(#BT_MSHOW,20,56,90,24,"Show Dialog")
ButtonGadget(#BT_MCANCEL,140,56,90,24,"Cancel")


;EVENT LOOP
Repeat
  EventID=WaitWindowEvent()
    Select EventID
      Case #PB_EventGadget
        Select EventGadgetID()
          Case #BT_MSHOW
            if DialogBoxIndirectParam_(hinst,?dialogdata,hwmain,@Dialogproc(),0)
              messagerequester("Pass:",spw\psw,0)
            endif

          Case #BT_MCANCEL
            close=1

        EndSelect
    EndSelect
Until EventID=#PB_EventCloseWindow or close
end

;DIALOG TEMPLATE (Modal)
datasection
dialogdata:
data.b 193,8,200,20, 0,0,0,1, 4,0, 181,0, 98,0, 143,0, 59,0
data.b 0,0, 0,0, 77,0,111,0,100,0,97,0,108,0,32,0,68,0,105,0,97,0,108,0,111,0,103,0,0,0, 1,0, 77,0,83,0,32,0,83,0,97,0,110,0,115,0,32,0,83,0,101,0,114,0,105,0,102,0,0,0 ,0,0

data.b 0,0,0,80, 0,0,0,0, 7,0, 10,0, 60,0, 15,0, 0,0
data.b 83,0,116,0,97,0,116,0,105,0,99,0,0,0, 69,0,110,0,116,0,101,0,114,0,32,0,112,0,97,0,115,0,115,0,119,0,111,0,114,0,100,0,58,0,0,0 ,0,0 ,0,0

data.b 32,0,129,80, 0,0,0,0, 67,0, 10,0, 67,0, 15,0, 1,0
data.b 69,0,100,0,105,0,116,0,0,0, 0,0 ,0,0

data.b 0,0,1,80, 0,0,0,0, 7,0, 34,0, 60,0, 15,0, 2,0
data.b 66,0,117,0,116,0,116,0,111,0,110,0,0,0, 79,0,107,0,0,0 ,0,0

data.b 0,0,1,80, 0,0,0,0, 73,0, 34,0, 60,0, 15,0, 3,0
data.b 66,0,117,0,116,0,116,0,111,0,110,0,0,0, 67,0,97,0,110,0,99,0,101,0,108,0,0,0 ,0,0
enddatasection
Post Reply