News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

PopUp Window

Started by RuiLoureiro, August 27, 2008, 09:10:52 PM

Previous topic - Next topic

RuiLoureiro

Hi all,
        i am playing with windows, and now i want to create a POPUP window but
        i want a CLOSE button on it.
        Whats the style value ?

        I am using this:

invoke  CreateWindowEx, WS_EX_LEFT or WS_EX_NOPARENTNOTIFY,
                                    offset _ClassChild, offset _MsgExecMsg,
                                    WS_POPUP or WS_CAPTION,
                                    100, 80, 280,  80,               ; X,Y + Wid,Hei pixel
                                    _hWnd, 0h, _hInstance, 0

          EDIT:  i found the solution for this problem:
                                         WS_POPUP or WS_CAPTION or WS_SYSMENU,
                    Thank you

Thanks
Rui

RuiLoureiro

#1
Hi,
       I created a popup window (inside the main window) but it is moveable
       (we can move it taking it with the mouse but it crashes if we move it
       to outside the screen).
       How to create it in a fixed position in such a way that we cannot move it ?
       Is it possible? Is there a style ? Other means ?

       I attached PopUp5.zip (asm & exe) and you can see the problem:
       PopUp -> Open PopUp1 -> move it

Thanks for any help
Rui


[attachment deleted by admin]

hutch--

Rui,

If you want another window attached in an imovable way to a main window, you normally set the CHILD style for it using the main window as it parent. Note the you cannot have BOTH the WS_CHILD and WS_POPUP set for the same window.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

RuiLoureiro

#3
Quote from: hutch-- on August 28, 2008, 12:22:11 PM
If you want another window attached in an imovable way to a main window, you normally set the CHILD style for it using the main window as it parent.

Hi Hutch,
          Thank you

          Ok i created the same prog. as PopUp5 ( Child6.zip ) but now i set

invoke  CreateWindowEx, WS_EX_LEFT,                             ; Extended Style
                        offset _ClassChild,                     ; Class name
                        offset _MsgExecMsg,                     ; Title
                        WS_CHILD or WS_CAPTION or WS_VISIBLE,   ; Style
                        80, 120, 280, 80,                       ; X,Y,W,H
                        _hWnd, 0, _hInstance, 0

        It doesnt Print the messages !!!
        And
        It moves AND if i move the window the program crashes, too !!!

        Could you see my code to see if i am doing something wrong, please

Quote from: hutch-- on August 28, 2008, 12:22:11 PM
Note the you cannot have BOTH the WS_CHILD and WS_POPUP set for the same window.
             Ok i know that

Thanks
Rui


[attachment deleted by admin]

jj2007

Rui, for testing your code it is essential that you post all necessary components, preferably in one zip file. Sound5.wav is missing.

RuiLoureiro

Quote from: jj2007 on August 28, 2008, 01:32:30 PM
Rui, for testing your code it is essential that you post all necessary components

Hi jj,
          The EXE should run without sound efect. It is used when we close the Child window
           In any way here is Child6 and rsrc without sound. Sound is not the problem
           You can see the file Child6.ASM and run Child6.EXE. Doesnt run ?

Thank you
Rui

[attachment deleted by admin]

BlackVortex

My eyes !

Rui, you should read iczelion's tutorials to see how to properly construct message processing loops. You'll keep stumbling to new problems if you continue on this source base.

RuiLoureiro

Quote from: BlackVortex on August 28, 2008, 05:43:11 PM
... to see how to properly construct message processing loops.

Hi BlackVortex,
                      Thank you for your reply.
                      But could you say something more exactly, if you dont mind
Thanks
Rui
     

BlackVortex

Check here :

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

I'm sure you will want to write your proggy from start !

P.S.: There are sources and examples for all those tutorials of course

jj2007

Quote from: RuiLoureiro on August 28, 2008, 02:05:31 PM
          The EXE should run without sound efect. It is used when we close the Child window
           In any way here is Child6 and rsrc without sound. Sound is not the problem
           You can see the file Child6.ASM and run Child6.EXE. Doesnt run ?

Your error is here:
                   mov     eax, dword ptr [esi + ebx * 4]
                   ;
_nOpenExecMsg:      mov     _pMsgPas, eax


Check the value of _pMsgPas... if it is 16 =10h, you'd better not use it.
P.S.: When files required by rsrc.rc are missing, eg. sound.wav, the whole project will not assemble.
EDIT: P.P.S.: The advice of BlackVortex is a good one...!

BlackVortex

@ jj2007

Well, you could probably use an empty file with the correct name.

RuiLoureiro

Quote from: BlackVortex on August 28, 2008, 05:57:10 PM
Check here :

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

I'm sure you will want to write your proggy from start !

P.S.: There are sources and examples for all those tutorials of course

BlackVortex,
                    We know, but the problem is with the example i posted.
Thanks
Rui

RuiLoureiro

Quote from: jj2007 on August 28, 2008, 05:57:35 PM
Your error is here:
                   mov     eax, dword ptr [esi + ebx * 4]
                   ;
_nOpenExecMsg:      mov     _pMsgPas, eax


Hi jj,
         The problem is not where you say

; replace this      
   
                    jmp     _nOpenExecMsg
@@:                 dec     ebx
                    mov     eax, dword ptr [esi + ebx * 4]
                    ;
_nOpenExecMsg:      mov     _pMsgPas, eax


; by this

                    jmp     _nOpenExecMsg
@@:                 dec     ebx
                    shl     ebx, 2                                       ; its the same
            ;**********************************************                   
                        .if  ebx == 0
                          debWnd "EBX = 0", _hWnd
                        .elseif ebx == 4
                          debWnd "EBX = 4", _hWnd
                        .else
                          debWnd "EBX = outro valor", _hWnd
                        .endif
            ;**********************************************
                    mov     eax, dword ptr [esi + ebx]
                    ;
_nOpenExecMsg:      mov     _pMsgPas, eax

************************************************************
In the example, there are only 3 cases:

1. invoke  OpenExecMsg, 1       => EBX= 1  -> dec ebx    ...                 => ebx= 0
2. invoke  OpenExecMsg, 2       => EBX= 2  -> dec ebx = 1 -> shl ebx, 2 => ebx=4
3 .invoke  OpenExecMsg, 0       => mov  eax, dword ptr [esi - 8]

Thank you
Rui

jj2007

Quote from: RuiLoureiro on August 28, 2008, 06:51:15 PM
         The problem is not where you say

I've let it crash in OllyDbg, and it crashed precisely because it reads from the address in eax passed here:
                    invoke   PasMsgPr, hWnd, _pMsgPas
You use a debugger, I suppose?

RuiLoureiro

#14
Hi jj2007,

         1st: Thank you for your reply

         2nd: No, I never tried

         3rd: It seems the problem is not there.
              The problem seems to be another thing

            EDITED 1: jj, i used PEEK «Useful little debugging tool "peek.dll"». It is elsewhere
                        in this Workshop. The value in _pMsgPas is correct, the same we get
                        at the starting point. It seems to be inside PasMsgPr.
                Remove THIS and it WORKS:
                    ;************************************************
                    ;mov      eax, pPas
                    ;movzx    edx, byte ptr [eax - 1]
                    ;invoke   GetTextExtentPoint32, hDC, eax, edx, addr _WidthStr
                    ;mov      edx, 280           ;CHILD_W
                    ;sub      edx, _WidthStr
                    ;shr      edx, 1
                    ;mov      _WidthStr, edx

EDITED 2:: The problem is exactly with _WidthStr. It was defined as DD
                           and it should be 2 DD.
                           I made some corrections and now you can see the file Child10
***********************************************************
Hi BlackVortex,

        I am trying to be clear ( sorry, i hadnt time yesterday )

        You said:
         «Rui, you should read iczelion's tutorials to see how to properly
          construct message processing loops.»
         
        It seems you have reason. But ...

        1st: If i understood your question the problem is about this:

«FROM Windows User Interface -> ... Designing a Window Procedure

The following example shows the structure of a typical window procedure.
...
Notice that each case returns a specific value for each message.
For messages that it does not process, the window procedure calls the DefWindowProc function.

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_CREATE:
            // Initialize the window.
            return 0;               

        case WM_PAINT:
            // Paint the window's client area.
            return 0;

        case WM_SIZE:
            // Set the size and position of the window.
            return 0;

        case WM_DESTROY:
            // Clean up window-specific data objects.
            return 0;
        //
        // Process other messages.
        //
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}
»
comment:
[ note1:  return 0  means     mov     eax, 0
                              ret               
          and                   

          return DefWindowProc(hwnd, uMsg, wParam, lParam)
          means

          invoke    DefWindowProc, hwnd, uMsg, wParam, lParam
          ret                   ; return the value DefWindowProc returns
]

OR

«iczelion's tutorials
...
IF uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL
.ELSE
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
.ENDIF
xor   eax,eax            ; <=>  mov    eax, 0
ret
WndProc endp

Here comes the crucial part.
...
Your code must check the Windows message to see if it's a message it's interested in.

If it is, do anything you want to do in response to that message
and then return with zero in eax.

If it's not, you MUST call  DefWindowProc, passing all parameters you received
to it for default processing.. »

So, IF we process the message THEN   
                                     mov    eax, 0
                                     ret
    IF we dont process      THEN

                                     invoke DefWindowProc,hWnd,uMsg,wParam,lParam
                                     ret
                                     
    question A: Is there something wrong ?

    One doubt: what does OS consider "we process the message" ?
               It seems "when we pass EAX=0 and we dont call DefWindowProc"

    2nd: Now, comes the practical example part:
   
         In the files PopUp6.asm & PopUp7.asm
         we can see this: ( WndProc is the WinMain message processor )

WndProc         proc    hWnd:DWORD, iMsg:DWORD, wParam:DWORD, lParam:DWORD
                mov     eax, iMsg
                mov     edx, wParam
                ;
                cmp     eax, WM_SIZE
                jne     _WM_COMMAND
                ;
                ;   Client region
                ; ----------------
                invoke  GetClientRect, hWnd, addr _ClientLeftX
                mov     eax, 0                                  ; OK processed
                ret
                ;jmp     _eWndProc      ; removed               
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««               
_WM_COMMAND:    cmp     eax, WM_COMMAND
                jne     _WM_CLOSE
                ;
                ;=============== menu commands =======================
                cmp     edx, IDM_Open1
                jne     @F                 
               
                ; ******************
                ; Open PopUp window
                ; ******************
                invoke  OpenExecMsg, 1
               
                ; **********************************
                ; Why to pass it to DefWindowProc ? And Why not ?
                ; **********************************
                mov     eax, 0              ; OK processed
                ret
                ;jmp     _eWndProc      ; removed

@@:             cmp     edx, IDM_Open2
                jne     @F                 
               
                ; ******************
                ; Open PopUp window
                ; ******************
                invoke  OpenExecMsg, 2
                mov     eax, 0              ; OK processed
                ret               
                ;jmp     _eWndProc      ; removed

@@:             cmp     edx, IDM_Open3
                jne     @F                 
               
                ; ******************
                ; Open PopUp window
                ; ******************
                invoke  OpenExecMsg, 5
                mov     eax, 0              ; OK processed
                ret                               
                ;jmp     _eWndProc      ; removed

@@:             cmp     edx, IDM_Close1
                jne     @F         

                ; ******************
                ; Close PopUp window
                ; ******************
                call    CloseExecMsg
                mov     eax, 0              ; OK processed
                ret                               
                ;jmp     _eWndProc      ; removed
;...................................                       
@@:             cmp     edx, IDM_End
                jne     _eWndProc
                ;
                invoke   SendMessage, hWnd, WM_SYSCOMMAND, SC_CLOSE, NULL
                mov     eax, 0                                          ; OK processed
                ret                               
                ;jmp     _eWndProc      ; removed
                ;
                ;============= end menu commands =====================
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
_WM_CLOSE:      cmp     eax, WM_CLOSE
                je      @F

                cmp     eax, WM_DESTROY
                jne     _eWndProc
                ;
@@:             invoke  PostQuitMessage, NULL
                mov     eax, 0                      ; OK processed
                ret
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
                ;
                ; Pass to OS to be processed
                ; **************************
_eWndProc:      invoke  DefWindowProc, hWnd, iMsg, wParam, lParam
                ret
WndProc         endp

    question B: Now, is there something wrong ?

                I will appreciate any well intended comments

           EDITED: i updated the files PopUp5 and Child6

    Thank you
Rui


[attachment deleted by admin]