Author Topic: OpenFileDialog  (Read 25713 times)

0 Members and 2 Guests are viewing this topic.

Charles Pegge

  • Guest
Re: OpenFileDialog
« Reply #15 on: April 15, 2012, 11:56:58 PM »

Use mid() with a negative index instead:

print mid ("1234567890",-2) 'result: 90

Charles

Aurel

  • Guest
Re: OpenFileDialog
« Reply #16 on: April 16, 2012, 01:29:49 AM »
Ok Charles ...this way work even looks weird to me :-\
Oh i must say that i hate when i must write all this function but this is exercise right?  :)

Another thing is Triming function.
I found from baCon james functions but it looks that not work in Oxygen as espected.
Quote
FUNCTION LTrim(Main$ As string,Match$ As string) As String
     INT mlen,mtlen,i,j
     i = 0
     j = 0
     mlen = LEN(Main$)
     mtlen = LEN(Match$)
     IF (mlen = 0) or (mtlen = 0)
         RETURN Main$
     END IF
     FOR i = 1 TO mlen
        IF INSTR(Match$,Mid (Main$,i,1),1) = 0
            RETURN Mid(Main$,-(mlen-j))
        ELSE
            j = j + 1
        END IF     
     NEXT
     RETURN Main$
END FUNCTION

string s,r
r=""
s = " James Fuller"
r = LTrim(s," ")
print "res:" + r

So for Trim$ i need both Ltrim & Rtrim functions ,but there is still same problem with Right  ::)

Charles , don't get me wrong but i think that would be good to built in into Oxygen all this string functions.

Charles Pegge

  • Guest
Re: OpenFileDialog
« Reply #17 on: April 16, 2012, 01:59:20 AM »

There is ltrim and rtrim


print ">" ltrim ("  abc  ") "<"
print ">" rtrim ("  abc  ") "<"


The core string functions are:

news / frees
nuls
space
error
(compile) oxygen-dependent
ltrim
rtrim
lcase
ucase
string
print
asc / unic
len
chr / wchr
str
hex
guidval
guidtxt
val
mid  (function)
mid  (command)
left
instr
getfile
putfile



Charles







Aurel

  • Guest
Re: OpenFileDialog
« Reply #18 on: April 16, 2012, 02:59:18 AM »
Oh my ,i don't know that ,sorry...
I even write my own LTRIM  ::)
Code: [Select]
REM' remove all left blank spaces
FUNCTION LTrim(Main$ As string) As String
String blank$= " "
     INT mlen,mtlen,i,j
     i = 0
     j = 0
     mlen = LEN(Main$)
     mtlen = LEN(blank$)
     IF (mlen = 0) or (mtlen = 0)
         RETURN Main$
     END IF
     FOR i = 1 TO mlen
  IF j=0
        IF Mid(Main$,i,1) <> blank$             
            j = i
        END IF
  END IF
     NEXT

     RETURN Mid(Main$,j,mlen)
END FUNCTION

string s,r
r=""
s = "    James"
r = LTrim(s)
print "res:" + r
:D
ok.. ;)

Aurel

  • Guest
Re: OpenFileDialog
« Reply #19 on: April 16, 2012, 08:15:42 AM »
What to say...
This file dialog looks like nightmare .
I espect some problems but i will try one more option.
Then i will see what to do.

Aurel

  • Guest
Re: OpenFileDialog
« Reply #20 on: April 16, 2012, 02:42:34 PM »
I simply don't get it what i do wrong ???
I try way from Freebasic ,and some C examples and no one of options not work.
Here is structure in include file:
Code: [Select]
Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Int
    nFileExtension As Int
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

then here is declared function by api which is same as in VB or C example:
Code: [Select]
Declare Function GetOpenFileName  Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
And here is Function FileDialog which return nothing in my case: :-\
Code: [Select]
'FileDialog( $ iDir , $ filter ,$ title , % parent ,% flag )
Function FileDialog(iDir As String, filter As String, Title As String, pHwnd As Long,Flags As Long) As String
Dim ofn As OPENFILENAME
String NULL = chr(0)
Dim filename As zstring * 255
INT retval
' Allow only existing files and hide the read-only check box
'IF tFlag = 0
'print "TFLAG:"+ str(tFlag)
'filebox.flags = OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY
'END IF
'IF tFlag = 1
'filebox.flags = OFN_EXPLORER or OFN_OVERWRITEPROMPT or OFN_HIDEREADONLY
'END IF
ofn.lStructSize = sizeof(OPENFILENAME)
ofn.hwndOwner = phWnd
ofn.hInstance = GetModuleHandle( 0 )
ofn.lpstrFilter = filter
ofn.lpstrCustomFilter= NULL
ofn.nMaxCustFilter = 0
ofn.nFilterIndex = 1
ofn.lpstrFile = filename
ofn.nMaxFile = LEN( filename )
ofn.lpstrFileTitle = NULL
ofn.nMaxFileTitle = 0
ofn.lpstrInitialDir = NULL
ofn.lpstrTitle = title
ofn.Flags = OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY
ofn.nFileOffset = 0
ofn.nFileExtension = 0
ofn.lpstrDefExt = NULL
ofn.lCustData = 0
ofn.lpfnHook = 0
ofn.lpTemplateName = NULL





' Execute the dialog box
retval = GetOpenFileName(ofn)
'IF retval <> 0  ' if the dialog box completed successfully
' Remove null space from the file name
'fname = Left(filebox.lpstrFile, InStr(filebox.lpstrFile, chr(0)) - 1)
'Print "The selected file: " + filename
'RETURN filename
'ELSE
'RETURN print "FileBox Not Open!"
'END IF
RETURN filename

End Function

Is anyone have a idea what might be wrong?

Charles Pegge

  • Guest
Re: OpenFileDialog
« Reply #21 on: April 16, 2012, 09:08:27 PM »
Hi Aurel,

This is not perfect, but it works.

Code: [Select]


#define OFN_READONLY                 0x00000001
#define OFN_OVERWRITEPROMPT          0x00000002
#define OFN_HIDEREADONLY             0x00000004
#define OFN_NOCHANGEDIR              0x00000008
#define OFN_SHOWHELP                 0x00000010
#define OFN_ENABLEHOOK               0x00000020
#define OFN_ENABLETEMPLATE           0x00000040
#define OFN_ENABLETEMPLATEHANDLE     0x00000080
#define OFN_NOVALIDATE               0x00000100
#define OFN_ALLOWMULTISELECT         0x00000200
#define OFN_EXTENSIONDIFFERENT       0x00000400
#define OFN_PATHMUSTEXIST            0x00000800
#define OFN_FILEMUSTEXIST            0x00001000
#define OFN_CREATEPROMPT             0x00002000
#define OFN_SHAREAWARE               0x00004000
#define OFN_NOREADONLYRETURN         0x00008000
#define OFN_NOTESTFILECREATE         0x00010000
#define OFN_NONETWORKBUTTON          0x00020000
#define OFN_NOLONGNAMES              0x00040000     // force no long names for 4.x modules
#define OFN_EXPLORER                 0x00080000     // new look commdlg
#define OFN_NODEREFERENCELINKS       0x00100000
#define OFN_LONGNAMES                0x00200000     // force long names for 3.x modules
#define OFN_ENABLEINCLUDENOTIFY      0x00400000     // send include message to callback
#define OFN_ENABLESIZING             0x00800000
#define OFN_DONTADDTORECENT          0x02000000
#define OFN_FORCESHOWHIDDEN          0x10000000    // Show All files including System and hidden files


/*
typedef struct tagOFNA {
   DWORD        lStructSize;
   HWND         hwndOwner;
   HINSTANCE    hInstance;
   LPCSTR       lpstrFilter;
   LPSTR        lpstrCustomFilter;
   DWORD        nMaxCustFilter;
   DWORD        nFilterIndex;
   LPSTR        lpstrFile;
   DWORD        nMaxFile;
   LPSTR        lpstrFileTitle;
   DWORD        nMaxFileTitle;
   LPCSTR       lpstrInitialDir;
   LPCSTR       lpstrTitle;
   DWORD        Flags;
   WORD         nFileOffset;
   WORD         nFileExtension;
   LPCSTR       lpstrDefExt;
   LPARAM       lCustData;
   LPOFNHOOKPROC lpfnHook;
   LPCSTR       lpTemplateName;
} OPENFILENAMEA, *LPOPENFILENAMEA;
*/

Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter as sys 'string
    lpstrCustomFilter As sys 'string
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As sys 'string
    nMaxFile As Long
    lpstrFileTitle As sys 'string
    nMaxFileTitle As Long
    lpstrInitialDir As sys 'string
    lpstrTitle As sys 'string
    flags As Long
    nFileOffset As word
    nFileExtension As word
    lpstrDefExt As sys 'string
    lCustData As Long
    lpfnHook As sys
    lpTemplateName As sys 'string
End Type
'76 bytes

def NULL 0

Declare GetModuleHandle  lib "kernel32.dll" alias "GetModuleHandleA" (sys n) as sys

Declare Function GetOpenFileName  Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As sys

Declare CommDlgExtendedError Lib "comdlg32.dll" () as dword


'FileDialog( $ iDir , $ filter ,$ title , % parent ,% flag )

Function FileDialog(string iDir, filter, Title, sys Hwnd, Flags) As String
'==================
Dim ofn As OPENFILENAME
Dim filename[255] As zstring
int retval
' Allow only existing files and hide the read-only check box
'IF tFlag = 0
'print "TFLAG:"+ str(tFlag)
'filebox.flags = OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY
'END IF
'IF tFlag = 1
'filebox.flags = OFN_EXPLORER or OFN_OVERWRITEPROMPT or OFN_HIDEREADONLY
'END IF
ofn.lStructSize = sizeof(OPENFILENAME)
ofn.hwndOwner = hWnd
ofn.hInstance = GetModuleHandle(0)
ofn.lpstrFilter = ?filter
ofn.lpstrCustomFilter= NULL
ofn.nMaxCustFilter = 0
ofn.nFilterIndex = 2
ofn.lpstrFile = @filename 'zstring buffer
ofn.nMaxFile = 255
ofn.lpstrFileTitle = NULL
ofn.nMaxFileTitle = 0
ofn.lpstrInitialDir = ?idir
ofn.lpstrTitle = ?title
ofn.Flags = OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY
ofn.nFileOffset = 0
ofn.nFileExtension = 0
ofn.lpstrDefExt = NULL
ofn.lCustData = 0
ofn.lpfnHook = 0
ofn.lpTemplateName = NULL
'
retval = GetOpenFileName(ofn)
'http://msdn.microsoft.com/en-us/library/windows/desktop/ms646916(v=vs.85).aspx
'if retval=0 then print "Dialog Error " CommDlgExtendedError
return filename
'
End Function

'dir="C:\cevp\projects\opcode\OxygenBasic\examples\GUI"
dir=""
sep=chr(0)
'filter=""
filter="text"+sep+"*.txt"+sep+
       "basic"+sep+"*.bas;*.o2bas"+sep+
       "include"+sep+"*.inc"+sep+
       "header"+sep+"*.h"+sep+
       sep

title="Test File Opening Dialog"
hwnd=0
print FileDialog(dir,filter,title,hwnd,OFN_EXPLORER or OFN_OVERWRITEPROMPT or OFN_HIDEREADONLY)


Charles

Aurel

  • Guest
Re: OpenFileDialog
« Reply #22 on: April 16, 2012, 10:24:47 PM »
Thank you Charles... ;)
So that's why don't work, insted of string must be pointer sys.
In Dlib for example is used adress of string like :
Code: [Select]
OPENFILENAME\lStructSize        = 76
OPENFILENAME\hwndOwner          = _hwnd
OPENFILENAME\lpstrFilter        = _filefilter
OPENFILENAME\lpstrFile          = @_result
OPENFILENAME\nMaxFile           = #MAX_PATH
OPENFILENAME\lpstrTitle         = @_title
OPENFILENAME\lpstrInitialDir    = @_directory
OPENFILENAME\Flags              = _flags
OPENFILENAME\lpstrDefExt        = @_defext

And structsize is 76 bytes.
Another thing is which i don't know what to use is :
Dim filename[255] As zstring - array of characters.... ::)
Again thanks ,without your help i will be still in dark...  :-[
« Last Edit: April 22, 2012, 03:36:49 AM by Aurel »

Charles Pegge

  • Guest
Re: OpenFileDialog
« Reply #23 on: April 17, 2012, 12:29:25 AM »

Yes, the string pointer issue was one of the main problems, and I think Oxygen should allow a zstring pointer member to accept a string directly, so I will try to resolve this today.

zstring is the equivalent of C char, so the dimension in square brackets is the number of bytes reserved for it.

2 members of the structure were word, not int, so the length has come down from 80 to 76 bytes.

Anyway, the other dialogs should be a lot easier to get working now.

Charles

Aurel

  • Guest
Re: OpenFileDialog
« Reply #24 on: April 19, 2012, 01:19:22 PM »
Ok.
After few hours (in a free time) and some troubles with figuring what is what .
Hmm ,i don't espect such a complications with this 'file dialogs' stuff.
Here is what i have done that work as is ( im not still quite hapy how work ).
But i think that work for you too.
Code: [Select]
'#Include "awinh.inc"
 '#include "../../inc/awinh.inc"
Include "awinh.inc"
#lookahead ' for procedures
% LR_LOADTRANSPARENT = &H20
% LR_LOADMAP3DCOLORS = &H1000
INT TransparentMap3D = LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
INT win
INT winstyle
INT button1,button2,button3
INT edit1,edit2,edit3
INT Lbox,static1,static2,static3,richedit1
INT ed1ID,ed2ID,ed3ID
INT b1ID,b2ID,b3ID,b4ID,b5ID,b6ID,b7ID
INT LboxID = 300
INT st1ID,st2ID
INT reID
b1ID=100
b2ID=101
b3ID=102

'-----------------
ed1ID=200
ed2ID=201
ed3ID=202
'----------------
st1ID=350
st2ID=351
st3ID=352
'----------------
reID=400
'loadbmp
'##########################################
INT bmpB1,bmpS1
bmpB1 = LoadImage(0,"data/xpBopen.bmp",0,76,20,16)
bmpS1 = LoadImage(0,"data/xpStatic.bmp",0,82,82,16)
'##########################################

winstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN
'create window **************************************************
win = SetWindow("Test AwinH",100,100,640,480,winstyle)
'****************************************************************

'create buttons ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
button1 = SetButton(win,280,20,100,24,"OpenFileDialog",0x50000000,0x200,b1ID)
'set bitmap on button 1
SendMessage button1 , BM_SETIMAGE, 0, bmpB1
button2 = SetButton(win,390,20,80,24,"Run Counter",0x50000000,0x200,b2ID)
button3 = SetButton(win,490,20,80,24,"Load Text",0x50000000,0x200,b3ID)


':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'create edit control
edit1 = SetEditBox(win,100,80,380,23,"edit 1",0x50004000,0x200,ed1ID)

'create listbox
Lbox = SetListBox(win,100,140,180,150,"LB 1",0x50000140,0x200,LboxID)

'create static control
static1 = SetStatic(win,10,20,254,16," This is a STATIC text control with EX_CLIENTEDGE",0,0x200,st1ID)
static2 = SetStatic(win,10,40,254,13," This is a STATIC text control without ex_ClientEdge     ",0,0,st1ID)
'crete static control with bitmap
static3 = SetStatic(win,10,60,82,82,"",0x5000030E,0,st3ID)
SendMessage static3 ,370, 0, bmpS1

'create Rich Edit control
INT reStyle = WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_SUNKEN
'INT reStyle = 0x508010C4
richedit1 = SetRichEdit(win,300,120,300,200,"Text in Richedit...",reStyle ,0x200,reID)

'---------------------------------------------------------------------
GoSub AddListboxItems
'WHILE GetMessage (&wm,0,0,0)<>0
'TranslateMessage &wm
'DispatchMessage &wm
'WEND
sys bRet
  '
  Do While bRet := GetMessage (&wm, 0, 0, 0)
    If bRet = -1 then
      'show an error message
    Else
      TranslateMessage &wm
      DispatchMessage &wm
    End If
  Wend



Function WndProc(byval hWnd as long,byval wMsg as long, byval wParam as long,byval lparam as long) as long callback

SELECT wMsg
'----------------------------

CASE WM_DESTROY
PostQuitMessage 0
'-------------------------------------------------------------
CASE WM_COMMAND
controlID = LoWord(wParam) 'get control ID
notifyCode = HiWord(wParam) 'get notification message

Select controlID
   CASE b1ID
If notifycode=0 
'Beep(1660,50)
    'Print "Button 1 Clicked!"
Gosub Test
End If
   CASE b2ID
     If notifycode=0
UpdateWindow(win)
    SetControlText()
End If
  CASE b3ID
If notifycode=0
LoadFromFile()

End If


End Select
'-----------------------------------------------------
END SELECT


FUNCTION = DefWindowProc hwnd,wMsg,wParam,lParam


END FUNCTION

'########################################################
SUB AddListboxItems
bstring i$ : i$=""

For n = 0 To 100
i$=Str(n) + "..listbox item"
SendMessage Lbox,LB_ADDSTRING,0,i$
Next n
END SUB
'#########################################################
SUB SetControlText
bstring n$
n$=""

'loop
For i = 0 To 10000
n$ = Str(i)
SendMessage edit1,WM_SETTEXT,0,n$
UpdateWindow(edit1)
Next

END SUB
'#########################################################
SUB LoadFromFile

string fName = "richtext.txt"
bstring source =  getfile fName
SendMessage richedit1,WM_SETTEXT,0,source

if not source
    print fName " file not found"
end if

END SUB

'************************************************************

Sub Test
bstring fR
dir=""
bstring sep=chr 0
filter="Text files"+sep+"*.txt"+ sep+"All Files"+sep+"*.*"+sep
'filter="text"+sep+"*.txt"+sep+
       '"basic"+sep+"*.bas;*.o2bas"+sep+
       '"include"+sep+"*.inc"+sep+
       '"header"+sep+"*.h"+sep+
       'sep

title="Test File Opening Dialog"
hwnd=0
fR = FileDialog(dir,*filter,*title,0,0,"txt")

SendMessage edit1,WM_SETTEXT,0,fR

End Sub

awinh.inc is in attachment....

Aurel

  • Guest
Re: OpenFileDialog
« Reply #25 on: April 22, 2012, 03:35:18 AM »
Just a small addition to Sub Test.
Use returned file path from function FileDialog()
and load selected file into richedit control.
Seems that work fine.... ;)
Code: [Select]
Sub Test
bstring fR
dir=""
bstring sep=chr 0
filter="Text files"+sep+"*.txt"+ sep+"All Files"+sep+"*.*"+sep
'filter="text"+sep+"*.txt"+sep+
       '"basic"+sep+"*.bas;*.o2bas"+sep+
       '"include"+sep+"*.inc"+sep+
       '"header"+sep+"*.h"+sep+
       'sep

title="Test File Opening Dialog"
hwnd=0
fR = FileDialog(dir,*filter,*title,0,0,"txt")
'show file path in edit control
SendMessage edit1,WM_SETTEXT,0,fR
'load file into richedit control -------------
bstring tx =  getfile fR
SendMessage richedit1,WM_SETTEXT,0,tx
'---------------------------------------------
End Sub

Aurel

  • Guest
Re: OpenFileDialog
« Reply #26 on: April 22, 2012, 04:15:21 AM »
Next step...
I have tested api GetLineCount message.
Use this constants:
Code: [Select]
'edit messages
% EM_GETLINECOUNT = 0xBA
% EM_LINEINDEX = 0xBB
% EM_LINELENGTH = 0xC1
% EM_GETLINE = 0xC4

Add new button on window:
first add new global vars:
INT button4,b4ID
b4ID=103
Code: [Select]
button4 = SetButton(win,500,80,84,24,"Get Line Count",0x50000000,0x200,b4ID)
Then add new subroutine:
Code: [Select]
SUB GetLineCount
INT LCount = 0
LCount = SendMessage richedit1,EM_GETLINECOUNT,0,0
bstring count$ = ""
count$ = Str(LCount)
SendMessage edit1,WM_SETTEXT,0,count$

END SUB

If you do everything ok...load any text into richedit control.
Then click new button named 'Get Line Count'.
You will see number of visible lines in richedit control written as number in EDIT control.

Aurel

Aurel

  • Guest
Re: OpenFileDialog
« Reply #27 on: April 22, 2012, 09:35:23 AM »
Uf after lookin' into many examples for GETLINE api finally i get
how GetLine work.
Here is complete code with GetLine() subroutine.
Code: [Select]
'#Include "awinh.inc"
 '#include "../../inc/awinh.inc"
Include "awinh.inc"
#lookahead ' for procedures
% LR_LOADTRANSPARENT = &H20
% LR_LOADMAP3DCOLORS = &H1000
INT TransparentMap3D = LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
INT win
INT winstyle
INT button1,button2,button3,button4,button5
INT edit1,edit2,edit3
INT Lbox,static1,static2,static3,richedit1
INT ed1ID,ed2ID,ed3ID
INT b1ID,b2ID,b3ID,b4ID,b5ID,b6ID,b7ID
INT LboxID = 300
INT st1ID,st2ID
INT reID
b1ID=100
b2ID=101
b3ID=102
b4ID=103
b5ID=104
'-----------------
ed1ID=200
ed2ID=201
ed3ID=202
'----------------
st1ID=350
st2ID=351
st3ID=352
'----------------
reID=400
'loadbmp
'##########################################
INT bmpB1,bmpS1
bmpB1 = LoadImage(0,"data/xpBopen.bmp",0,76,20,16)
bmpS1 = LoadImage(0,"data/xpStatic.bmp",0,82,82,16)
'##########################################

winstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN
'create window **************************************************
win = SetWindow("Test AwinH",100,100,640,480,winstyle)
'****************************************************************

'create buttons ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
button1 = SetButton(win,280,20,100,24,"OpenFileDialog",0x50000000,0x200,b1ID)
'set bitmap on button 1
SendMessage button1 , BM_SETIMAGE, 0, bmpB1
button2 = SetButton(win,390,20,80,24,"Run Counter",0x50000000,0x200,b2ID)
button3 = SetButton(win,490,20,80,24,"Load Text",0x50000000,0x200,b3ID)
button4 = SetButton(win,490,50,84,24,"Get Line Count",0x50000000,0x200,b4ID)
button5 = SetButton(win,490,80,84,24,"Get Line 2",0x50000000,0x200,b5ID)

':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'create edit control
edit1 = SetEditBox(win,100,80,380,23,"edit 1",0x50004000,0x200,ed1ID)

'create listbox
Lbox = SetListBox(win,100,140,180,150,"LB 1",0x50000140,0x200,LboxID)

'create static control
static1 = SetStatic(win,10,20,254,16," This is a STATIC text control with EX_CLIENTEDGE",0,0x200,st1ID)
static2 = SetStatic(win,10,40,254,13," This is a STATIC text control without ex_ClientEdge     ",0,0,st1ID)
'crete static control with bitmap
static3 = SetStatic(win,10,60,82,82,"",0x5000030E,0,st3ID)
SendMessage static3 ,370, 0, bmpS1

'create Rich Edit control
INT reStyle = WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_SUNKEN
'INT reStyle = 0x508010C4
richedit1 = SetRichEdit(win,300,120,300,200,"Text in Richedit...",reStyle ,0x200,reID)

'---------------------------------------------------------------------
GoSub AddListboxItems
'WHILE GetMessage (&wm,0,0,0)<>0
'TranslateMessage &wm
'DispatchMessage &wm
'WEND
sys bRet
  '
  Do While bRet := GetMessage (&wm, 0, 0, 0)
    If bRet = -1 then
      'show an error message
    Else
      TranslateMessage &wm
      DispatchMessage &wm
    End If
  Wend



Function WndProc(byval hWnd as long,byval wMsg as long, byval wParam as long,byval lparam as long) as long callback

SELECT wMsg
'----------------------------

CASE WM_DESTROY
PostQuitMessage 0
'-------------------------------------------------------------
CASE WM_COMMAND
controlID = LoWord(wParam) 'get control ID
notifyCode = HiWord(wParam) 'get notification message

Select controlID
   CASE b1ID
If notifycode=0 
'Beep(1660,50)
    'Print "Button 1 Clicked!"
Gosub Test
End If
   CASE b2ID
     If notifycode=0
UpdateWindow(win)
    SetControlText()
End If
  CASE b3ID
If notifycode=0
LoadFromFile()
End If
  CASE b4ID
If notifycode=0
GetLineCount()
End If
  CASE b5ID
If notifycode=0
GetLine()
End If




End Select
'-----------------------------------------------------
END SELECT


FUNCTION = DefWindowProc hwnd,wMsg,wParam,lParam


END FUNCTION

'########################################################
SUB AddListboxItems
bstring i$ : i$=""

For n = 0 To 100
i$=Str(n) + "..listbox item"
SendMessage Lbox,LB_ADDSTRING,0,i$
Next n
END SUB
'#########################################################
SUB SetControlText
bstring n$
n$=""

'loop
For i = 0 To 10000
n$ = Str(i)
SendMessage edit1,WM_SETTEXT,0,n$
UpdateWindow(edit1)
Next

END SUB
'#########################################################
SUB LoadFromFile

string fName = "richtext.txt"
bstring source =  getfile fName
SendMessage richedit1,WM_SETTEXT,0,source

if not source
    print fName " file not found"
end if

END SUB

'************************************************************

Sub Test
bstring fR
dir=""
bstring sep=chr 0
filter="Text files"+sep+"*.txt"+ sep+"All Files"+sep+"*.*"+sep
'filter="text"+sep+"*.txt"+sep+
       '"basic"+sep+"*.bas;*.o2bas"+sep+
       '"include"+sep+"*.inc"+sep+
       '"header"+sep+"*.h"+sep+
       'sep

title="Test File Opening Dialog"
hwnd=0
fR = FileDialog(dir,*filter,*title,0,0,"txt")

SendMessage edit1,WM_SETTEXT,0,fR
bstring tx =  getfile fR
SendMessage richedit1,WM_SETTEXT,0,tx

End Sub
'*************************************************************

SUB GetLineCount
INT LCount = 0
LCount = SendMessage richedit1,EM_GETLINECOUNT,0,0
bstring count$ = ""
count$ = Str(LCount)
SendMessage edit1,WM_SETTEXT,0,count$

END SUB

'*************************************************************

SUB GetLine
INT Lpos = 2
INT LLen
LLen = SendMessage richedit1, EM_LINELENGTH,Lpos, 0
print "LineLen;" + str(LLen)
pText = Space (LLen)
SendMessage richedit1,EM_GETLINE,Lpos,*pText
print "LineText;" + pText
'convert to bstring & show line in edit control
bString LText = pText
SendMessage edit1,WM_SETTEXT,0,LText

END SUB

PS.Line counter use zero-based index,so first line have index NULL.
« Last Edit: April 22, 2012, 09:42:42 AM by Aurel »

Charles Pegge

  • Guest
Re: OpenFileDialog
« Reply #28 on: April 23, 2012, 05:55:59 AM »
Thanks Aurel,

The latest Oxygen has a built-in strptr and also null, which I hope will make OS strings easier to handle. No need to figure out the indirection level of different strings using @ ? or *

Charles

Peter

  • Guest
Re: OpenFileDialog
« Reply #29 on: April 23, 2012, 06:37:50 AM »
Hi Charles,

if I have the latest  OB version,  must I write

wc.lpszMenuName  = NULL
wc.lpszClassName = StrPtr "Oxygen"