The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: RuiLoureiro on November 16, 2007, 12:38:51 PM

Title: Window help
Post by: RuiLoureiro on November 16, 2007, 12:38:51 PM
Hi all !
Hutch, how are you ?
Michael, how are you ?
I need to use a window to show what a procedure is doing and i dont know how to do this.
It is like this:
1º - I want to open that window and show a message
2ª - i want to run one procedure
3º - i want to close that window.
What type of window i should use ? What the procedure to call ? It is not MessageBox. What is ?
Thank you
RuiLoureiro
Title: Re: Window help
Post by: hutch-- on November 16, 2007, 12:53:32 PM
Hi Rui,

I gather you want to use the Window for debugging and probably the simplest technique is to use a console window (even if the app is normal gui) and display whever info you need there. when you are finished, remove the console display code and build it as a normal GUI app.
Title: Re: Window help
Post by: Tedd on November 16, 2007, 01:37:54 PM
.586
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib

;***************************************************************************************************

openDbgWin proto
closeDbgWin proto
showDbgMsg proto pMsg:DWORD,lenMsg:DWORD

;***************************************************************************************************

.data
aMessage  db "Hello! I'm a debug message :)",13,10

.data?
hStdOut     HANDLE ?

.code
start:
    invoke openDbgWin

    invoke showDbgMsg, ADDR aMessage,SIZEOF aMessage

    ;;pause.. so we can see it -- only for testing ;)
    invoke Sleep, 3000

    invoke closeDbgWin

    invoke ExitProcess, NULL


;***************************************************************************************************

openDbgWin proc
    invoke AllocConsole
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov hStdOut,eax
    ret
openDbgWin endp

closeDbgWin proc
    invoke FreeConsole
    ret
closeDbgWin endp

showDbgMsg proc pMsg:DWORD,lenMsg:DWORD
    LOCAL chWritten:DWORD
    invoke WriteConsole, hStdOut,pMsg,lenMsg,ADDR chWritten,NULL
    ret
showDbgMsg endp

;***************************************************************************************************
end start


Just copy the procs into your code, and use like in the example :wink
(Don't forget to add newlines to the end of your messages - "13,10")
Title: Re: Window help
Post by: RuiLoureiro on November 16, 2007, 02:13:50 PM
Hi Hutch, many thanks to you

Now i developed a program ( a big program supported by 2 Libs! It runs ) in GUI for wINDOWS xp, so it´s not a console app. I want a to open a window like MessageBox, but not with buttons.

Tedd, many thanks, but i think your code is for a console app. and it not run in GUI for Windows XP. I want to use the window style like MessageBox

Thanks.
RuiLoureiro
Title: Re: Window help
Post by: Mark Jones on November 16, 2007, 04:44:37 PM
Hello Rui, you can open a console prompt from a GUI app, see AllocConsole at:

http://www.masm32.com/board/index.php?topic=8126.0
Title: Re: Window help
Post by: RuiLoureiro on November 16, 2007, 05:35:42 PM
Hi Mark
Yes, it can work but this is not the style of window i want to use, i'm afraid.  There is not another way to do what i want ?
Thank you
Title: Re: Window help
Post by: Tedd on November 16, 2007, 06:49:52 PM
No, it is for a windows app - it just uses a console for the messages.
I just left out all of the window code so it would be easy to understand.
Try it first, only then complain ::)

If you need a debug window that doesn't look like a console, but more like notepad, then you'll have to create a specific window/dialog with an edit-control child, and then append text into that -- it's quite a bit more work.
Title: Re: Window help
Post by: RuiLoureiro on November 16, 2007, 09:26:03 PM
Quote from: Tedd on November 16, 2007, 06:49:52 PM
If you need a debug window that doesn't look like a console, but more like notepad, then you'll have to create a specific window/dialog with an edit-control child, and then append text into that -- it's quite a bit more work.
Yes, Tedd, i think that is what i am looking for: a window that looks like a MesageBox or Dialog boxes. I have to study how to create a dialog window with an edit-control child as you say. I think it is what i am looking for.
Many Thanks for your help, Tedd
RuiLoureiro
Title: Re: Window help
Post by: Mark Jones on November 17, 2007, 03:20:49 AM
Hi Rui, in that case then look through the examples and tutorials that come with MASM32, there should be a few examples of child windows.  :U
Title: Re: Window help
Post by: Vortex on November 17, 2007, 09:32:07 AM
Hi Rui,

Try also Vkim's debugging tool :

http://www.masm32.com/board/index.php?topic=8126.msg59353#msg59353
Title: Re: Window help
Post by: MichaelW on November 17, 2007, 03:34:46 PM
Hi Rui,

The attachment is my attempt at a simple debug (dialog) window that uses a list box to display strings.


[attachment deleted by admin]
Title: Re: Window help
Post by: Mark Jones on November 17, 2007, 07:03:21 PM
Also, another new debugging tool is this: "Useful little debugging tool "peek.dll" (http://www.masm32.com/board/index.php?topic=8135.0)
Title: Re: Window help
Post by: RuiLoureiro on November 19, 2007, 11:07:56 AM
Hi Mark, Vortex
Hi MichaelW, how are you ?
Hi all.
Thank you for your helps. I couldnt reply till now cause a domestic accindent of my wife.
I dont want a window to debug but to send a message to say what the computer is doing like savingi databases. This is the idea. To debug my procedures i use a set of procedures to show data and registers and MessageBoxes to stop the program with «Step 1, step 2, etc. » and so i follow the program. This is the method i use to debug my programs.
Now i am studyng how to use an edit box and how to append a string into it to do the window
Thank you
RuiLoureiro
MichaelW, I read ( in seconds ) your dbgwin.asm and i saw that with ModlessDialogBoxes ( i never used ) i can make the window i am looking for. Go to see
Title: Re: Window help
Post by: hutch-- on November 19, 2007, 02:06:22 PM
Rui,

If I understand ypou properly you want a window to display some data when you need it as part of our application. This is just a simple CreateWindowEx() type of window wiht whatever style you like where you use the original windoew as a parent window to the one you wish to display data with.
Title: Re: Window help
Post by: RuiLoureiro on November 19, 2007, 05:37:06 PM
Hutch,
I think you understood. But i have problems with styles. What´s the style for a window without buttons ?

I tried this 2 types:

.data
; _hInstance and _hWndCur is from the main program.

_EDIT_Class      db "None", 0   ;
;_EDIT_Class     db "EDIT",0                ; name of window class
_EDIT_Name     db "A executar", 0      ; the name is the message for an edit box !
_EDIT_hWnd     dd 0                         ; handle
.code
; ««««««««««««««««««««««««««««««««««««
SendExecMsg         proc                  ; to open the window
                    pushfd
                    pushad
                    ;
                   
invoke  CreateWindowEx, 1h, offset _EDIT_Class, offset _EDIT_Name, 54000000h, \
                         260, 100, 280,  80,\                                                      ; X,Y + Width, Height pixel
                         _hWndCur, 0h, _hInstance, 0
                    ;
                    mov     _EDIT_hWnd, eax
                    ;
                    popad
                    popfd
                    ret
SendExecMsg         endp
; ««««««««««««««««««««««««««««««««««««««««««««««
CloseExecMsg        proc                    ; to close the window
                    pushfd
                    pushad
                    ;
                    invoke   DestroyWindow, _EDIT_hWnd
                    ;
                    popad
                    popfd
                    ret
CloseExecMsg        endp

When i use it with  «_EDIT_Class     db "EDIT",0» it works but with None doesnt work

What i know ?
;------------------------------------------------------------------------------
; This is an example from Test Department (EDIT box)
;------------------------------------------------------------------------------
;push    0h                          ;lpParam, extra pointer data 0=no data
;push    _hInstance                  ;hInstance, handle of our program
;push    910h                        ;hMenu, the child-window ID
;push    _hWnd                       ;hWndParent, handle parent window 0=no
;push    18h                         ;intnHeight, window height pixel
;push    80h                         ;intnWidth, window width pixel
;push    60h                         ;inty, vertical position window
;push    1B0h                        ;intx, horizontal position window
;push    54000000h                   ;dwStyle, static window style
                                     ;WS_CHILD           = 40000000h
                                     ;WS_VISIBLE         = 10000000h
                                     ;WS_CLIBSIBLINGS    =  4000000h
                                     ;WS_TABSTOP         =    10000h
                                     ;                   = 54010000h
;push    0h                          ;lpWindowName, pointer to window name
;push    OFFSET _EDIT_Class          ;lpClassName, pointer to class name
;push    1h                          ;dwExStyle,look WIN32.HLP + windows.inc
;call    CreateWindowExA             ;- API Function -
;mov     _EDIT1_hWnd, eax            ;hwnd, return value=handle of window

Why the window doesnt open ? Do i need to use RegisterClassEx ?
Thank you for some help.
RuiLoureiro
Title: Re: Window help
Post by: hutch-- on November 19, 2007, 06:50:06 PM
Rui,

Unless you are using a predefined class like a control, you must create a class for your own window using the WNDCLASSEX structure and RegisterClassEx().

Create the windows with the "WS_POPUP or WS_CAPTION" styles for a windows with a titlebar and no buttons.
Title: Re: Window help
Post by: RuiLoureiro on November 19, 2007, 07:14:32 PM
Quote from: hutch-- on November 19, 2007, 06:50:06 PM
Unless you are using a predefined class like a control, you must create a class for your own window using the WNDCLASSEX structure and RegisterClassEx().

Create the windows with the "WS_POPUP or WS_CAPTION" styles for a windows with a titlebar and no buttons.

Very Good !!!
Hutch, thanky so much ! I am going to work. Have a nice day or night !
RuiLoureiro
Title: Re: Window help
Post by: RuiLoureiro on November 19, 2007, 07:52:55 PM
Hutch, what's wrong ? The window doesnt open or is closed before CloseExecMsg be called.
When i call SendExecMsg, the window doesnt appear.

.data
; Child Window
;
_ClassChild      db "WinChild", 0               ; class name
_NameChild       db "A executar ...", 0     ; title name
_hWndChild       dd 0                            ; handle
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
.data?
align 4
_wcChild        WNDCLASSEX <?>
;»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
.code
WinMain     proc hInst:DWORD, hPrevInst:DWORD, CmdLine:LPSTR, CmdShow:DWORD
             ;.................................................................
            ;
            ; Preencher a estrutura WNDCLASSEX para a janela CHILD
            ; ----------------------------------------------------
            mov   _wcChild.cbSize,      SIZEOF WNDCLASSEX
            mov   _wcChild.style,       WS_OVERLAPPED or WS_BORDER or WS_CHILD or     WS_POPUP   or   WS_CAPTION

             mov   _wcChild.lpfnWndProc, 0
             mov   _wcChild.cbClsExtra,  NULL
             mov   _wcChild.cbWndExtra,  NULL
             push  _hInstance
             pop   _wcChild.hInstance
             mov   _wcChild.hbrBackground, COLOR_BACKGROUND+1    ; COLOR_WINDOW+1       
             mov   _wcChild.lpszMenuName, 0                              ; menu name in resource file
             mov   _wcChild.lpszClassName, offset _ClassChild          ; name of windows class
            ;
            ; Registar a classe WNDCLASSEX da janela Child
            ; --------------------------------------------------------------
            invoke RegisterClassEx, addr _wcChild                           ; new
;.........................................
        ............................
        ............................
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««
SendExecMsg         proc   
                    pushfd
                    pushad
                    ;
invoke  CreateWindowEx, 300h, offset _ClassChild, offset _NameChild,\
                         WS_BORDER or WS_CHILD or WS_POPUP or WS_CAPTION, \
                         260, 100, 280,  80,\                  ; X,Y + Width, Height pixel
                         _hWndCur, 0h, _hInstance, 0
                    ;
                    mov     _hWndChild, eax
                    ;
                    ;invoke  ShowWindow, _hWndChild, SW_SHOWNORMAL
                    ;
                    popad
                    popfd
                    ret
SendExecMsg         endp
; ««««««««««««««««««««««««««««««««««««««««««««
CloseExecMsg        proc
                    pushfd
                    pushad
                    ;
                    invoke   DestroyWindow, _hWndChild
                    ;
                    popad
                    popfd
                    ret
CloseExecMsg        endp
;*******************************************************
New: CreateWindowEx  returns  0 . Why ? Need a processor ?
;*******************************************************
Title: Re: Window help
Post by: hutch-- on November 20, 2007, 01:50:25 AM
Rui,

Here is a simple example of how to create a child window of the type you require. Look at the childwin code at the end of the source code.

[attachment deleted by admin]
Title: Re: Window help
Post by: RuiLoureiro on November 20, 2007, 04:39:44 PM
Hutch,
Thank you for the example. I dont know where was the problem but now it works. I have my Child window.
The problem, now is that i print the message, but the system erase the client area and we dont see the message.
Here is my last version. I think you understand in a few seconds what im doing.
Another problem is with the background color of the text  (new: it is solved )
;.................................................................
Amarelo         equ 00FFFFh
;.....................................
.data
_pMsgToSend     dd 0
_hWndChild        dd 0

.data?
_WidthChr           dd ?
                          dd ?
_wcChild        WNDCLASSEX <?>
.code
;..................................................
WinMain     proc hInst:DWORD, hPrevInst:DWORD, CmdLine:LPSTR, CmdShow:DWORD
            ;.................................................................
            ;
            ; Preencher a estrutura WNDCLASSEX para a janela CHILD
            ; ----------------------------------------------------
   Â      mov   _wcChild.cbSize,      SIZEOF WNDCLASSEX
                      mov   _wcChild.style,       CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW
       Â      mov   _wcChild.lpfnWndProc, offset WndProcB
           Â      mov   _wcChild.cbClsExtra,  NULL
   Â      mov   _wcChild.cbWndExtra,  NULL
   Â      push  _hInstance
   Â      pop   _wcChild.hInstance
           Â      mov   _wcChild.hbrBackground, COLOR_BACKGROUND+1  ; COLOR_WINDOW+1       
   Â      mov   _wcChild.lpszMenuName, 0                      ; menu name in resource file
   Â      mov   _wcChild.lpszClassName, offset _ClassChild    ; name of windows class
            ; --------------------------------------------
            ; Registar a classe WNDCLASSEX da janela Child
            ; --------------------------------------------
            invoke RegisterClassEx, addr _wcChild
;....................................
;      other
;--------------------------------------------------------------------
; ««««««« for CHILD WINDOW «««««««««««««««««««««««««««««««««««««
WndProcB        proc    hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
                      pushad                                 
                      ;
                      mov     eax, uMsg
                      cmp     eax, WM_PAINT
                      jne     _eWndProcB
                     ;
                     ; imprime a mensagem
                     ; ----------------------------
                     call       PrPasMsg           
                     ;
_eWndProcB:  popad
                      ;
                      invoke  DefWindowProc, hWnd, uMsg, wParam, lParam
                      ret
WndProcB        endp

;»»»»» In the file saved to a LIB i have »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
SendExecMsg         proc    NMsg:DWORD   
                            pushfd
                            pushad
                            ;
                            cmp     _hWndChild, 0
                            jne     _eSendExecMsg
                   
                            invoke  CreateWindowEx, WS_EX_LEFT,
                                    offset _ClassChild, offset _NameChild,
                                    WS_POPUP or WS_CAPTION,
                                    260, 380, 280,  80,                                 ; X,Y + Wid,Hei pixel
                                    _hWndCur, 0h, _hInstance, 0
                           ;
                           mov     _hWndChild, eax
                           ;
                           invoke  ShowWindow, _hWndChild, SW_SHOW         
;...........................................................................
                    ;
                    ; Get Message from the table
                    ; --------------------------------------
                           mov     esi, offset _TblExecMsg             ; message table   
                           mov     ebx, NMsg
                           cmp     ebx, 0
                            je      _eSendExecMsg
                            ;
                           cmp     ebx, dword ptr [esi - 4]            ; number of messages
                            ja      _eSendExecMsg
                            ;
                            dec     ebx
                            shl       ebx, 2
                            mov     eax, dword ptr [esi + ebx]        ; eax =message pointer
                            mov     _pMsgToSend, eax
                            ;
                            call       PrPasMsg
                            ;
_eSendExecMsg:     popad
                            popfd
                            ret
SendExecMsg         endp
; ----------------------------------------------------------------------------------------------
PrPasMsg        proc 
                    pushad   
                     ;
                     invoke  HideCaret, _hWndChild               ; never show caret
               
                     invoke  GetDC, _hWndChild
                     mov     _hdcChild, eax
                    ;
                    ; calcula comprimento da string
                    ; ----------------------------------------
                    mov      ebx, _pMsgToSend
                    movzx    ecx, byte ptr [ebx - 1]                   
                    invoke   GetTextExtentPoint32, _hdcChild, ebx, ecx, addr _WidthChr
                    ;
                    mov      edx, 280
                    sub       edx, _WidthChr
                    shr        edx, 1
                    mov      _WidthChr, edx
                    ;
                    ; Cor Foreground
                    ; ---------------------
                    invoke   SetTextColor, _hdcChild, Amarelo
                    ;
                    ; Cor Background
                    ; ---------------------
                    invoke  GetSysColor, COLOR_BACKGROUND        ; window background color
                    invoke   SetBkColor, _hdcChild, eax                     
                    ;
                     ; Print Test
                     ; -------------
                     mov      ebx, _pMsgToSend 
                     movzx    ecx, byte ptr [ebx - 1]
                     invoke   TextOut, _hdcChild, _WidthChr, 20, ebx , ecx               

                     invoke  ReleaseDC, _hWndChild, _hdcChild
                     ;
                     popad
                     ret
PrPasMsg        endp
; ««««««««««««««««««««««««««««««««««««««««««««««««««
CloseExecMsg        proc
                           pushfd
                           pushad
                           ;
                          cmp     _hWndChild, 0
                           je      _eCloseExecMsg                  ; is closed -> exit !
                   
                           invoke   DestroyWindow, _hWndChild
                           ;
                           mov     _hWndChild, 0                     
                           ;
_eCloseExecMsg:    popad
                           popfd
                           ret
CloseExecMsg        endp
;.................. END

NEW: the first time i call SendExecMsg, it doesnt show the message. The second and so forth it shows
         How to give the text the same background color as the background of the window ? Can you help me ? (NEW: now, it works. Thank you Hutch)
Title: Re: Window help
Post by: hutch-- on November 20, 2007, 09:16:15 PM
Rui,

If you want to draw the text on the child window yourself you must do it from the WM_PAINT message for the child window so that it will remain visible when other windows have overlapped it. In most instances it would be easier for you to use a control like a text edit control or a static control as either will handle large amounts of text without display problems.

The basic code you are using does not appear to have been written by someone who properly understands how a window and its messaging works. I would ensure that all messages processed are done according to the documentation in either the old winhelp file win32.hlp or the later MSDN/SDK style help.
Title: Re: Window help
Post by: RuiLoureiro on November 21, 2007, 03:09:56 PM
Quote from: hutch-- on November 20, 2007, 09:16:15 PM
... you must do it from the WM_PAINT message for the child window so that it will remain visible when other windows have overlapped it. In most instances it would be easier for you to use a control like a text edit control or a static control as either will handle large amounts of text without display problems.
Hutch,
Thanks for the reply.
I have not problems with documentation. I corrected the last version. As you know, it is my first window program. And, many times (!) I forget some details (like many people). And there are details i dont know and i ask for help. Isnt it correct ?
In this case (printing a msg), i am seeing that it is easier to use a text edit control.
Thank you, Hutch (and all that want to help me )
Rui Loureiro
Title: Re: Window help
Post by: Mark Jones on November 21, 2007, 04:57:30 PM
Hi Rui, consider going through the Iczelion tutorials at:

http://win32assembly.online.fr/tutorials.html

This should give you many ideas for your program. :U
Title: Re: Window help
Post by: MichaelW on November 22, 2007, 09:20:39 PM
Rui,

This example is an attempt to answer your recent questions.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .data

        hInst     dd          0
        hWnd      dd          0

        fTextOut  dd          not 0
        fWhite    dd          not 0

        wcx       WNDCLASSEX  <>
        msg       MSG         <>

        className db "test_window_class", 0

        txt       db 13,10
                  db "Press F1 to toggle this text between "
                  db "on and off.",13,10,13,10
                  db "Press F2 to toggle the window background "
                  db "color between white and light gray.", 13,10,13,10
                  db "Press Escape to close this window.", 0

    .code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

WndProc proc hwnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

    LOCAL ps:PAINTSTRUCT
    LOCAL rc:RECT
    LOCAL hdc:HDC

    SWITCH uMsg

      CASE WM_CREATE

      CASE WM_KEYDOWN

        SWITCH wParam

          CASE VK_ESCAPE

            invoke PostQuitMessage, NULL

          CASE VK_F1

            ; --------------------------------------------------------
            ; Invalidating the client area causes it to be repainted.
            ; --------------------------------------------------------

            not fTextOut
            invoke GetClientRect, hwnd, ADDR rc
            invoke InvalidateRect, hwnd, ADDR rc, TRUE

          CASE VK_F2

            .IF fWhite
              invoke GetStockObject, LTGRAY_BRUSH
            .ELSE
              invoke GetStockObject, WHITE_BRUSH
            .ENDIF
            not fWhite
            invoke SetClassLong, hwnd, GCL_HBRBACKGROUND, eax
            invoke GetClientRect, hwnd, ADDR rc
            invoke InvalidateRect, hwnd, ADDR rc, TRUE

       ENDSW

      CASE WM_PAINT

        ; --------------------------------------------------
        ; For the text to persist it must be redrawn each
        ; time the client area of the window is repainted.
        ; --------------------------------------------------

        invoke BeginPaint,hwnd,ADDR ps

        .IF fTextOut

          ; ------------------------------------------------------
          ; Setting the background mix mode to TRANSPARENT causes
          ; DrawText to write the foreground pixels and leave the
          ; background pixels untouched.
          ; ------------------------------------------------------

          invoke SetBkMode, ps.hdc, TRANSPARENT

          invoke GetClientRect, hwnd, ADDR rc
          invoke szLen, ADDR txt
          mov ecx, eax
          invoke DrawText, ps.hdc, ADDR txt, ecx, ADDR rc,
                           DT_WORDBREAK

        .ENDIF

        invoke EndPaint,hwnd,ADDR ps

      CASE WM_CLOSE

        ;invoke PostQuitMessage,NULL    ; ERROR IN ORIGINAL POSTING

        invoke DestroyWindow, hwnd

      CASE WM_DESTROY

        invoke PostQuitMessage,NULL

      DEFAULT

        invoke DefWindowProc, hwnd, uMsg, wParam, lParam

        ret

    ENDSW

    return 0

    ret

WndProc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke GetModuleHandle, NULL
    mov hInst, eax

    mov wcx.cbSize,        sizeof WNDCLASSEX
    mov wcx.style,         CS_HREDRAW or CS_VREDRAW \
                            or CS_BYTEALIGNWINDOW
    mov wcx.lpfnWndProc,   OFFSET WndProc
    mov wcx.cbClsExtra,    NULL
    mov wcx.cbWndExtra,    NULL
    m2m wcx.hInstance,     hInst
    invoke GetStockObject, WHITE_BRUSH
    mov wcx.hbrBackground, eax
    mov wcx.lpszMenuName,  NULL
    mov wcx.lpszClassName, OFFSET className
    invoke LoadIcon, NULL, IDI_APPLICATION
    mov wcx.hIcon,         eax
    invoke LoadCursor, NULL, IDC_ARROW
    mov wcx.hCursor,       eax
    mov wcx.hIconSm,       0

    invoke RegisterClassEx,ADDR wcx

    ; -------------------------------------------------------------
    ; The WS_POPUP style will produce a fixed-size window with no
    ; title bar. The WS_BORDER style can be combined with WS_POPUP
    ; to create a wider border. The WS_CAPTION style will add a
    ; title bar with no buttons, and increase the width of the
    ; border. Using the WS_OVERLAPPEDWINDOW style instead will
    ; produce a normal application window.
    ; -------------------------------------------------------------

    invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,
                          ADDR className,
                          chr$("Test"),
                          WS_POPUP or WS_CAPTION,
                          0,0,400,300,
                          NULL,NULL,
                          hInst,NULL
    mov hWnd, eax

    invoke ShowWindow, hWnd, SW_SHOWNORMAL
    invoke UpdateWindow, hWnd

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

  msgLoop:

    invoke GetMessage, ADDR msg, NULL, 0, 0
    .IF (eax != 0)
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
        jmp msgLoop
    .ENDIF
    exit msg.wParam

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start


If you were doing this as an exercise almost anything would be reasonable. But if your goal is to create a window that can display debug messages, then displaying the messages directly on the client area of the window is doing it the hard way. Using an appropriate control to display the messages would be much easier. In my previous example I used a list box because I felt it was the best choice for displaying short messages. Another possibility for displaying longer messages would be an edit control. And another possibility would be a static text control, but for displaying multiple messages it has the drawback of not being user scrollable.
Title: Re: Window help
Post by: RuiLoureiro on November 26, 2007, 09:06:38 PM
Hi MichaelW,
Isnt there another direct method to clear the screen ? InvalidateRect doesnt send WM_PAINT immediatly.
Thank you
Rui
Title: Re: Window help
Post by: Tedd on November 27, 2007, 01:23:20 PM
InvalidateRect.. then UpdateWindow..

But do you really need to update immediately?
Title: Re: Window help
Post by: RuiLoureiro on November 27, 2007, 02:37:13 PM
Tedd,
I think i need, but i need to see how it works in my program.
Title: Re: Window help
Post by: RuiLoureiro on December 10, 2007, 11:58:44 AM
Quote from: Tedd on November 27, 2007, 01:23:20 PM
But do you really need to update immediately?

Hi
           At some point of my prog i have one screen drawn. And then i press a key and i want to draw another screen before openning a commom control dialog box to get some data.
           To draw the new screen i need to clear the screen (client area).

           It is something like this:

1º  - i have screen drawn
2ª  - press a key
3ª  - clear the screen and draw another ( this proc is under WM_PAINT too )
4ª  - open a commom control dialog box and wait for data
5ª  - Return to DefWindowProc

         How to clean the screen ?

Rui
Title: Re: Window help
Post by: Tedd on December 10, 2007, 01:00:53 PM
InvalidateRect will cause the contents of your window to be repainted - that means you will get a WM_PAINT message, with the whole client area to be redrawn. Just redraw the contents of your window according to the state changed by the keypresses. The dialog can be created on the keypress (after invalidate) - it's a separate window, so it shouldn't stop the main window from being redrawn.
Title: Re: Window help
Post by: RuiLoureiro on December 10, 2007, 02:01:45 PM
Quote from: Tedd on December 10, 2007, 01:00:53 PM
The dialog can be created on the keypress (after invalidate) - it's a separate window, so it shouldn't stop the main window from being redrawn.

Hi Tedd,
              I am learning this little questions of windows. Thank you so much

Rui
Title: Re: Window help
Post by: RuiLoureiro on December 10, 2007, 05:26:55 PM
How to change the window background color after creating a window ? I didnt find out yet.

InvalidateRect - UpdateWindow doesnt work. It doesnt clean the previous screen.
Rui
Title: Re: Window help
Post by: hutch-- on December 11, 2007, 12:08:21 AM
Rui,

Its done by changing the background brush in the window class.
Title: Re: Window help
Post by: donkey on December 11, 2007, 12:15:21 AM
invoke SetClassLong, [hwnd], GCL_HBRBACKGROUND, [hNewBrush]
// If the class is using a brush you created use DeleteObject here to destroy the returned hBrush
invoke InvalidateRect, NULL, TRUE
Title: Re: Window help
Post by: Tedd on December 11, 2007, 01:08:34 PM
You can set the 'default' background colour by setting a colour value as the background brush for your window - in the window-class structure, given to registerclass (e.g. "00000ffh" instead of "COLOR_WINDOW+1")
To dynamically change it, you can either modify the class brush (donkey's method) if you don't need to change often, or simply use FillRect (or Rectangle) if you need to change the colour many times.
Title: Re: Window help
Post by: RuiLoureiro on December 11, 2007, 05:23:21 PM
Hutch, Donkey and Tedd,
                                    Thank you !

I used IvalidateRect, hWnd, NULL, TRUE ... and doenst work ... yet.

I have only one main window, style CS_OWNDC;
The client area is divided in 3 areas: header, workspace and bottom;

I have    Table1: values and pointers     ( set 1 )
             Table2: values and pointers    ( set 2 )
             pActiveTable = offset Table1  (points to Table1 at the beginning )

The proc under WM_PAINT uses pActiveTable to print data on the screen;
Pressing one given key pActiveTable = offset Tabel2
and before calling the commom control dialog box i put

                     IvalidateRect, hWnd, NULL, TRUE
                     UpdateWindow, hWnd

What happens ? When i press the key the header and bottom change but the previous workspace content stay on the screen when the dialog box opens. It doenst print anything on the worksapce because it should not print anything and it is correct.
In the menu i have a proc that shows all values and pointers in the ActiveTable and all things are correct.
Is there any reason to not clean the screen ? How to clean it ?

note: dont worry, it's a high tech proggy !

Rui

Title: Re: Window help
Post by: RuiLoureiro on December 15, 2007, 06:20:49 PM
Hi all
       The problem is solved.
        Thanks