Author Topic: DoEvents  (Read 8554 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
DoEvents
« on: March 19, 2012, 09:58:31 AM »
Hi..
The way how doevents function work is not very good option for gui
programming at all.
It is a good option for games.
Im looking into a way to simplify message loop,
what would be simpliest solution?
creating some sort of callback function in OpenWindow(setwindow) function or
maybe something else.
I also lookin in Xblite option.
any suggestion....?

Aurel

  • Guest
Re: DoEvents
« Reply #1 on: March 21, 2012, 07:21:51 AM »
I stuck again with message processing.
Example is translated from xblite example.
Is anyone here who can explain me why message is not translated or dispatched:
Code: [Select]
Include "awinh.inc"
#lookahead ' for procedures

INT win
INT winstyle
INT button1
INT ed1
INT Lb1

winstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN
'create window
win = SetWindow("Test AwinH",100,100,640,480,winstyle)
print str(win)
'create button
button1 = SetButton(win,200,40,80,24,"button_1",0x50000001,0x200)
'create edit control
ed1 = SetEditBox(win,200,80,80,24,"edit 1",0,0)
'create listbox
Lb1 = SetListBox(win,200,140,180,240,"LB 1",0,0)


'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 win as INT,byval wMsg as INT,byval wParam as INT,byval lParam as INT)as INT callback

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

CASE WM_DESTROY
PostQuitMessage 0
'--------------------------------------
CASE WM_COMMAND
controlID = LoWord(wParam)
notifyCode = HiWord(wParam)

SELECT notifyCode

CASE BN_CLICKED

select controlID
             case button1
    Print str(button1)
end select


END SELECT





CASE ELSE
FUNCTION = DefWindowProc win,wMsg,wParam,lParam

END SELECT


END FUNCTION




Aurel

  • Guest
Re: DoEvents
« Reply #2 on: March 21, 2012, 10:58:24 AM »
I search more and almost think that something is wrong because i can't
intercept wMsg then i test message wm_destroy like this:
Code: [Select]
SELECT wMsg
'----------------------------

CASE WM_DESTROY
PRINT "CLOSED"
PostQuitMessage 0
'--------------------------------------
CASE WM_COMMAND
controlID = LoWord(wParam)
notifyCode = HiWord(wParam)

SELECT notifyCode

CASE BN_CLICKED

select controlID
             case button1
    Print str(button1)
end select

And it works but why then wm_command don't work is a mistery  :-\
it is really weird.
i will try more... ;)

Aurel

  • Guest
Re: DoEvents
« Reply #3 on: March 21, 2012, 11:49:18 AM »
Hmmm i finally got to work something but still not as i espected :-\
BN_CLICKED respond but on every control which is created  ::)
It looks that don't respond on controlID = LoWord(wParam)
So , i will try check again function LoWord....

Charles Pegge

  • Guest
Re: DoEvents
« Reply #4 on: March 21, 2012, 08:12:01 PM »

Hi Aurel,

Could we see AWinh.inc?

Charles

Aurel

  • Guest
Re: DoEvents
« Reply #5 on: March 21, 2012, 10:49:40 PM »
yes of course..
nothing special as i say before just derived from peter wFunc ,and i just remove
wndproc function.

I'm not sure but LoWord & HiWord functions looks little bit weird to me.
what is exactly:
and lo,&hffff
shr hi,16
shr->what's that mean  ???

another thing which i probably made wrong is when i create control.
Each control is without ID  ::)
just return hendle this might couse problem,right?
like:
Code: [Select]
hButton = CreateWindowEx(_ext,"BUTTON",_btext,_bflag,_bx,_by,_bw,_bh,_bhwnd,0,0,0)and better will be:
Code: [Select]
hButton = CreateWindowEx(_ext,"BUTTON",_btext,_bflag,_bx,_by,_bw,_bh,_bhwnd,controlID,0,0)
hmmm....what you mean ?

Aurel

  • Guest
Re: DoEvents
« Reply #6 on: March 22, 2012, 03:29:31 AM »
YES...
I finally got it what is wrong ,i add control ID in SetButton() function and work.
Code: [Select]
'syn : SetButton (hwnd,x,y,w,h,caption$,style,ext,controlID)
Function SetButton(byval _bhwnd as int,byval _bx as int,byval _by as int,byval _bw as int,byval _bh as int, byval _btext as string,byval _bflag as int,byval _ext as int,byval _cID as INT) as int
If _bflag=0
    _bflag = 0x50000000
EndIf
_ext = 0
hButton = CreateWindowEx(_ext,"BUTTON",_btext,_bflag,_bx,_by,_bw,_bh,_bhwnd,_cID,0,0)
UpdateWindow _bhwnd
Function = hButton
End Function

Note:this function is inside awinh.inc
So now example code look like this :
Code: [Select]
Include "awinh.inc"
#lookahead ' for procedures

INT win
INT winstyle
INT button1,button2
INT ed1
INT Lb1
int ed2
INT b1ID,b2ID,b3ID,b4ID,b5ID,b6ID,b7ID
b1ID=100
b1ID=101
b1ID=102
b1ID=103
b1ID=104
b1ID=105

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

'create buttons
button1 = SetButton(win,200,40,80,24,"button_1",0x50000001,0x200,b1ID)
button2 = SetButton(win,300,40,80,24,"button_2",0x50000001,0x200,b2ID)

'create edit control
ed1 = SetEditBox(win,200,80,80,24,"edit 1",0,0)
'create listbox
Lb1 = SetListBox(win,200,140,180,240,"LB 1",0,0)


'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         
    Print "Button 1 Clicked!"
End If
   Case b2ID
     If notifycode=0         
    Print "Button 2 Clicked!"
End If



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




FUNCTION = DefWindowProc hwnd,wMsg,wParam,lParam



END FUNCTION




Aurel

  • Guest
Re: DoEvents
« Reply #7 on: March 22, 2012, 02:09:47 PM »
Next step is set default gui font and add string to listbox.
Look into attachment,manifest work fine ;)

Code: [Select]
Include "awinh.inc"
#lookahead ' for procedures

INT win
INT winstyle
INT button1,button2
INT edit1,edit2,edit3
INT Lbox
INT ed1ID,ed2ID,ed3ID
INT b1ID,b2ID,b3ID,b4ID,b5ID,b6ID,b7ID
INT LboxID=300
b1ID=100
b1ID=101
b1ID=102
b1ID=103
b1ID=104
b1ID=105

ed1ID=200
ed2ID=201
ed3ID=202

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

'create buttons
button1 = SetButton(win,200,40,80,24,"button_1",0x50000000,0x200,b1ID)
button2 = SetButton(win,300,40,80,24,"button_2",0x50000000,0x200,b2ID)

'create edit control
edit1 = SetEditBox(win,200,80,180,24,"edit 1",0x50004000,0x200,ed1ID)
'create listbox
Lbox = SetListBox(win,200,140,180,240,"LB 1",0x50000140,0x200,LboxID)
SendMessage Lbox,LB_ADDSTRING,0,"First Item"

'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         
    Print "Button 1 Clicked!"
End If
   Case b2ID
     If notifycode=0         
    Print "Button 2 Clicked!"
End If



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




FUNCTION = DefWindowProc hwnd,wMsg,wParam,lParam



END FUNCTION




izzy77

  • Guest
Re: DoEvents
« Reply #8 on: March 22, 2012, 03:18:24 PM »
SHR

Means Shift right the bits in a value. shr hi,16


A wparam is a 4 byte variable and the two most significant bytes are considered the Hiword of the wparam.

The two least significant bytes are the Loword of the wparam.

To get the value of the Hiword out of the wparam you shift the value 16 bits to the right which places the Hiword in the Loword position and it can be extracted as a word value this way.

Aurel

  • Guest
Re: DoEvents
« Reply #9 on: March 22, 2012, 10:20:02 PM »
thanks izzy77 on explanation ;)

Aurel

  • Guest
Re: DoEvents
« Reply #10 on: March 23, 2012, 03:03:10 PM »
Small step next...added bitmap button.
Code: [Select]
'loadbmp
'##########################################
INT bmpB1
bmpB1 = LoadImage(0,"data/xpBopen.bmp",0,76,20,16)

then:
Code: [Select]
button1 = SetButton(win,200,40,80,24,"",0x50000080,0x200,b1ID)
'set bitmap on button 1
SendMessage button1 , BM_SETIMAGE, 0, bmpB1

Aurel

  • Guest
Re: DoEvents
« Reply #11 on: March 29, 2012, 01:56:10 PM »
Just tested and added static control creation.
Here is code:
Code: [Select]
'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

In attachment is screenshot how look.

kryton9

  • Guest
Re: DoEvents
« Reply #12 on: March 29, 2012, 09:50:53 PM »
Looking good!

Aurel

  • Guest
Re: DoEvents
« Reply #13 on: March 29, 2012, 09:51:46 PM »
Thanks Kent ;)

Aurel

  • Guest
Re: DoEvents
« Reply #14 on: March 30, 2012, 12:00:31 PM »
I try to add function SetText and found some weird problem.
When i try to change edit control text with:
Code: [Select]
SUB SetControlText
string n$
int n=3


n$ = str(n)
print n$   '....this work properly
SendMessage edit1,WM_SETTEXT,1,n$
but  text in control is not changed ???
So i try change variable type to sys n$="new text"
and sometimes work and sometimes not.