News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Redrawing Text

Started by Don57, October 20, 2012, 06:05:10 AM

Previous topic - Next topic

Don57

I am trying to display an update user message in the main window using WM_PAINT


   WndProc proc hWnd:HWND, uMsg:UINT, wParam, lParam

      LOCAL hdc:HDC                                                           ; handle to device context
      LOCAL hMemDC:HDC                                                        ; handle to memory draw buffer
      LOCAL ps:PAINTSTRUCT                                                    ; pointer to paint structure

      .IF uMsg==WM_CREATE

          CALL Check_Admin                                                       ; check if program is being run as administrator

          invoke CreateWindowEx,NULL, ADDR sz_Button,ADDR sz_ButtonText,\        ; create button
                                WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
                                130,110,140,25,hWnd,BUTTON_ID,hInstance,NULL
       mov  hwndButton,eax                                                    ; save button handle

      .ELSEIF uMsg==WM_PAINT

       invoke BeginPaint,hWnd, ADDR ps
          mov    hdc,eax

          .IF dw_Text_Flag ==0

             invoke lstrlen, ADDR sz_WarningText                                  ; length of string returned in eax
             invoke TextOut, hdc, TEXT_LEFT, TEXT_TOP, ADDR sz_WarningText, eax   ; output text to window
             mov dw_Text_Flag, 1

          .ELSE

             invoke lstrlen, ADDR sz_ProgressText                                  ; length of string returned in eax
             invoke TextOut, hdc, TEXT_LEFT, TEXT_TOP, ADDR sz_ProgressText, eax   ; output text to window

          .ENDIF
         

          invoke EndPaint,hWnd, ADDR ps

      .ELSEIF uMsg==WM_COMMAND

          mov eax,wParam

          .IF eax==BUTTON_ID                                                  ; was the button pressed     

              .IF dw_Admin_Flaq==1

                  mov eax,hWnd                                                ; save handle in eax
                  mov hGlobal_Wnd,eax                                         ; need for Create_Progress_Bar
             

                  CALL Get_ELog_List                                          ; creates Event Log text file and dumps to buffer

                  CALL Count_ELogs                                            ; count the number of log files and calcs progress increment

;--------------------------------------------------------------

                  invoke SendMessage,hWnd, WM_PAINT,0,0     ; text update

;--------------------------------------------------------------

                  CALL Create_Progress_Bar

                  CALL Clear_ELogs                                            ; get file names and clears logs
                 
   
                  invoke MessageBox, NULL,addr sz_MsgBoxDoneText, addr sz_MsgDoneCaption, MB_OK

                  invoke PostMessage,hWnd,WM_SYSCOMMAND,SC_CLOSE,NULL                                  ; termination message for OS

                  xor eax,eax                                                                          ; return 0  termination code

              .ELSE

dedndave

that code looks like it ought to work
however - there is probably no need to use lstrlen if the strings are fixed
you can use the SIZEOF operator, and because they are null-terminated...
        INVOKE  TextOut, hdc, TEXT_LEFT, TEXT_TOP, ADDR sz_WarningText, sizeof sz_WarningText-1
or you can drop the null terminator and the "-1" and probably the "z" in the names   :P

what you are probably missing is some code, triggered by some event, that causes a WM_PAINT message to be sent
you can see if that's the case by minimizing, then restoring the window
it will cause a WM_PAINT message to be sent to the window

you can cause it to redraw a few different ways
InvalidateRect, then UpdateWindow
or with RedrawWindow

Don57

There seems to be something seriously wrong, in the structure of my code. If I try to drag or minimize the window I get a not responding error, howere the deletion of the logs continue. The code will still reach the exit albeit alot slower.

MichaelW

Your attachment is not a valid zip file, what is it?
Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Michael,
His files open with 7-Zip. Here is the source as "ordinary" zip.

Don,
You should check if ecx is non-zero:
      mov ecx, dw_Log_Count                                      ; get the count
      jecxz @F
      div ecx                                                                 ; file count in ecx
@@:
      mov dw_Progress_Increment, eax                      ; save it

Don57

I assume you mean for a standard error check. I usually add those after I get a program working.

Log_Count 1E3 - 483d

I get valid number all through the Create_Progress_Bar routine

The program does clear all event log files, but is not very OS friendly. If you just press the button and leave it alone it runs fine. However if you try to minimize the window or drag the window, you get a program not responding error. However the program will still clear all event logs and exit properly. The problem appears to be in the Clear_One_Log proc. It calls CreateProcess 483 times, once for each log.
I have tried lowering the priority of the process, but that  doesn't work. It is like the event handler is not working while the program executes that proc.

Thanks for the help. :t

jj2007

Quote from: Don57 on October 20, 2012, 12:23:43 PM
I assume you mean for a standard error check. I usually add those after I get a program working.

In my case, the log count ecx is zero and therefore div ecx produces an exception.

sinsi

WM_PAINT is a pretty low priority message, maybe your processing the logs from WndProc stalls it?

Can you do the bulk of the work in a thread? I usually have the main WndProc purely to update GUI stuff and
do the work in a thread, this gives the GUI time for feedback and not 'freeze'.

japheth



                  invoke SendMessage,hWnd, WM_PAINT,0,0     ; text update


WM_PAINT should not be sent directly. If you want to achieve a synchronous update of the screen, use InvalidateRect() followed by UpdateWindow().