Hi,
    I want use the idle time to poll port status, but the Status bar do not work correct:

    invoke ShowWindow, hwnd,SW_SHOWNORMAL
    invoke UpdateWindow, hwnd
        .WHILE TRUE
                invoke GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                invoke TranslateMessage, ADDR msg
                invoke DispatchMessage,  ADDR msg
                invoke CheckPortBusy,hwnd
               
        .ENDW
        mov    eax,msg.wParam
        ret

and

CheckPortBusy Proc hWnd:HWND
    push eax
    ;Get Busy Line's Status
   
    invoke GetPortVal,StatusPortAddr,Addr PortStatus,1
    xor    eax,eax
    mov    al,PortStatus
    and    al,80h                  ;get Status port registre bit7 hi/low
    .if    al == 80h
      ;Something undo
    .endif
    invoke InvalidateRect,hWnd,addr rcClient,FALSE
  pop eax
ret

CheckPortBusy endp


so what's wrong with this message pump routine?
How to corret?
Thanks in advance,
With Best RGS.
Posted on 2005-11-22 11:30:07 by Luckrock
invoke InvalidateRect,hWnd,addr rcClient,FALSE
this is the wrong thing.
You invalidate the same window again and again with no repetitions/second limit.

Invalidate the hWnd only when necessary.
Posted on 2005-11-22 11:42:53 by Ultrano
Hi,Ulrano
  Thanks for your tips.
 
  I delete it and the former bug remains:
CheckPortBusy Proc hWnd:HWND
    push eax
      ;Get Busy Line's Status
   
    invoke GetPortVal,StatusPortAddr,Addr PortStatus,1
  ;    xor    eax,eax
  ;    mov    al,PortStatus
  ;    and    al,80h                  ;get Status port registre bit7 hi/low
    ;  .if    al == 80h
     
    ;  .endif
      ; invoke
  ; invoke InvalidateRect,hWnd,addr rcKnob,FALSE
  pop eax
ret

CheckPortBusy endp


the status bar resize routine:
    .elseif uMsg==WM_SIZE
        ;Get the client area window width and height
        LOWORD lParam
    m2m ClientAreaWidth,  eax  ; client area width
    HIWORD lParam
        m2m ClientAreaHeight, eax  ; client area height
       
        ;re-size status bar window
        invoke GetWindowRect,hStatus,ADDR rect                   
        mov eax, rect.bottom
        sub eax, rect.top                                         
        sub ClientAreaHeight, eax                               
     
        invoke MoveWindow,hStatus,0,0,0,0,TRUE


so the status bar remain the same position whenever you adjust the window
   
    I am using winxp /sp2.
   
  what's the matter  for sp2?
  BEST RGS!
Posted on 2005-11-22 11:59:54 by Luckrock
invoke MoveWindow,hStatus,0,0,0,0,TRUE

you just don't move the status window at all - that's why...
Posted on 2005-11-22 12:06:06 by Ultrano
Well,
  Just Modify FALSE to TRUE, ==> Same
     
   mov eax, rect.bottom
        sub eax, rect.top   
        mov StatusH,eax 
                         
        sub ClientAreaHeight, eax                               
     
        invoke MoveWindow,hStatus,0,1000,20,800,TRUE


I think the real reason lie at WM_PAINT message routine.May be I don't redraw the entire window.
I will check this.
Posted on 2005-11-22 12:19:21 by Luckrock
Luckrock,

Do yourself this favour, unless you are directly processing keystrokes in the main message loop, try and do your message processing in the WndProc as not all messages are sent to the main message loop.

Write a main message loop something like this.


    LOCAL msg:MSG

    jmp jumpin                                  ; JMP to GetMessage()

    StartLoop:
      invoke TranslateMessage, ADDR msg        ; translate any keystrokes
    ; --------------------------------------
    ; process any keys here directly
    ; from the MSG structure values
    ; --------------------------------------
      invoke DispatchMessage,  ADDR msg        ; dispatch the message to the WndProc
    jumpin:
      invoke GetMessage,ADDR msg,NULL,0,0      ; fill the MSG structure
      test eax, eax                            ; test its return value
      jne StartLoop                            ; loop back if its not ZERO


Regards,

hutch at movsd dot com
Posted on 2005-11-22 20:45:21 by hutch--
Remember that GetMessage may fail with -1, so coding something like "if eax != 0 then do the work" is a bad habit.

Warning 
Because the return value can be nonzero, zero, or -1, avoid code like this:

while (GetMessage( lpMsg, hWnd, 0, 0)) ...
The possibility of a -1 return value means that such code can lead to fatal application errors. Instead, use code like this:

BOOL bRet;

while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
    if (bRet == -1)
    {
        // handle the error and possibly exit
    }
    else
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
Posted on 2005-11-22 22:05:19 by ti_mo_n
Hi, Hutch
   Many Thanks:
    1) My purpose is like this(in proto):
      ;=======================
     Loop:
            invoke GetMessage,ADDR msg,NULL,0,0

                    if   Message==0
                            ;o.k.system is idle now , process my self defined  background work
                            invoke BACKGROUND_Procedure

                   if   Message !=0
                           TranslateMessage
                           DispatchMessage
      Jump To Loop
     ;===================================

      2) Well, Finally I debug the "BACKGROUND_Procedure", find that it does not execute at all.
         I think even the return value of GetMessage equal ZERO,the windows still do not switch to myself difined work.
        ==> By this way , I could not use system IDLE time.
     3) Polling Peripheral device's status is time lasting and I want to avoid a custom ISR/driver to this App.
     4) And the intervals of WM_MESSAGE sent by windows has a min value of 1ms
     5) Also this WM_MESSAGE is not  pricise and accurate, could not be used for communicate with Peripheral device efficiently.

     so ,besides of  WDM and WM_MESSAGE, could I use another worker thread to monitor the Peripheral device' status and communication, for a better performance/speed?
            With BST RGS!
   
Hi, ti_mon
    Thanks for your tips.
     Certainly I have revised the message pump as normal, as descipted above.
     With BST RGS!

Posted on 2005-11-23 05:16:36 by Luckrock
Luckrock,

I wrote the message loop in that form for a reason, the type of messages you process in a mesage loop are primarily keyboard messages so you do your message processing AFTER TrasnlateMessage() and before DespatchMessage() so you get the correct results. Do not assume that all messages are sent directly in the message loop as many are sent directly to the WndProc. The message loop is available in that format primarily for keystroke processing although if you are careful you can poll specialied things within it as well.

You cannot make use of system idle time as a message loop only responds when a message is available, otherwise it sits there doing nothing. If you really had to poll some event not related to Windows messaging, you would write a polling loop with a timed interval between iterations and test for the condition each iteration.
Posted on 2005-11-23 06:40:50 by hutch--

      ;=======================
     Loop:
            invoke GetMessage,ADDR msg,NULL,0,0

                    if   Message==0
                            ;o.k.system is idle now , process my self defined  background work
                            invoke BACKGROUND_Procedure

                   if   Message !=0
                           TranslateMessage
                           DispatchMessage
      Jump To Loop
     ;===================================

      2) Well, Finally I debug the "BACKGROUND_Procedure", find that it does not execute at all.
         I think even the return value of GetMessage equal ZERO,the windows still do not switch to myself difined work.
        ==> By this way , I could not use system IDLE time.


GetMessage does not return when the system is idle. It waits for a message, if there aren't any current ones. Instead, check out PeekMessage, which has an option for returning immediately if there are no messages.
Posted on 2005-11-24 02:00:19 by tenkey
Actually PeekMessage always 'returns immediately'. It has the option of removing the message from the message queue (as well as some additional options).
Posted on 2005-11-24 09:16:03 by ti_mo_n
Hi,
      Thanks for your reply
      I knew PeekMessage in reading  book of  Charlse Petzold "Programming windows" ,but I never see any example or routine using  PeekMessag for message pump. and I've never use it.
    So, any of the PeekMessage sample or guideline  in MASM?
      With My BST RGS!

   
Posted on 2005-11-25 06:03:04 by Luckrock
either:

1) call PeekMessage with PM_REMOVE
2) if there's any message message, then call TranslateMessage and Distpatch message. quit if NULL
3) do your work
4) go to 1

or:

1) call PeekMessage with PM_NOREMOVE
2) if there's any message message, then call GetMessage, TranslateMessage and Distpatch message. quit if NULL
3) do your work
4) go to 1

PeekMessage is like GetMessage, except that PeekMessage returns immediately even if there are no messages.
Posted on 2005-11-25 18:02:39 by ti_mo_n