News:

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

Main Menu

One more of many mysteries

Started by clamicun, December 13, 2015, 10:38:27 AM

Previous topic - Next topic

clamicun

I have a parent window.
A_Procedure is called.
I do not exactely know,if the code below is ok, but it works.

If I comment
;invoke MessageBox,0,0,0,0
it does not work !
Some one knows why.

;---------
A_Procedure  proc

INVOKE GetDC,main_hwnd               ;main_hwnd is the handle of the parent window
mov hdc,eax

INVOKE GetClientRect,main_hwnd,addr client   
sub client.bottom,25                         ;minus Statuswindow

INVOKE SetRect,offset client,client.left,client.top,client.right,client.bottom

INVOKE  CreateWindowEx, WS_EX_CLIENTEDGE,offset StaticClass, NULL,WS_CHILD+WS_VISIBLE+WS_VSCROLL,\
                                       0,0,client.right,client.bottom,main_hwnd,NULL,hInstance,NULL
                                       mov child_hnd1, eax   
                 
INVOKE GetClientRect,child_hnd1,offset client
INVOKE SetRect,offset client,client.left,client.top,client.right,client.bottom

;Here the window has no color and a scrollbar - ok.
invoke MessageBox,0,0,0,0

INVOKE CreateSolidBrush,0FF00FFh   ;F3D33h
mov hBrush,eax
INVOKE FillRect,hdc,offset client,hBrush

;Here the window has color -FF00FFh  and a scrollbar - ok.     
;Without the messagbox the window does not change
           
;more
;more
;more

ret
A_Procedure endp
;----------

dedndave

i suppose that MessageBox is providing you with a message loop   :biggrin:

if you want to create a window using CreateWindowEx.....

1) you need a WndProc, a procedure to handle messages (unless you use a system class)
2) you need to register a window class (or use one of the pre-existing system classes)
3) call CreateWindowEx - pay close attention to the window styles and extended styles
4) once CreateWindowEx has succeeded, execution should fall into a message loop

see the attached program...

dedndave

on a side note...

the SetRect calls are not necessary
SetRect is similar to
    mov     rcRect.left,<LeftVal>
    mov     rcRect.top,<TopVal>
    mov     rcRect.right,<RightVal>
    mov     rcRect.bottom,<BottomVal>


the rectangles already have values from previous Get calls

clamicun

dedndave, thank you.

The hint with setrect is ok. I was thinking, if it is unnecessary.

Of course I know the example and know how to do it.
That is exacteley, what I do not want. An  "independent"  new window.

Just a window which paints (clears) the parent window to show output from a database.
I have various in my project, but this one has to have a scrollbar, because this output will not fit into one window. 

So - the question is still the messagebox - what does it destroys ?

dedndave

i can't really say what is happening without complete code
but, i am guessing that the static control has no message loop until you call MessageBox

clamicun

Well, I do not know what you need the code for.
But to understand what I need - here is an example code.

This kind of window I need, but with scrollbars, because the content is larger than on window.


;Small Window - DednDave, 4-2011

        .XCREF
        .NOLIST
        INCLUDE    \masm32\include\masm32rt.inc
        ;INCLUDE    SmallWin.inc
        .LIST
   
;###############################################################################################

MAIN_WIDTH  EQU 600
MAIN_HEIGHT EQU 400

;###############################################################################################

        .DATA
        ALIGN   4
WndProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
IDI_ICON    EQU 501
IDM_1 equ 100

icc INITCOMMONCONTROLSEX <sizeof INITCOMMONCONTROLSEX,0>
wc  WNDCLASSEX <sizeof WNDCLASSEX,NULL,WndProc,0,0,?,?,?,COLOR_SCROLLBAR+1,NULL,szClassName,?>
; cbSize        dd ?
; style         dd ?
; lpfnWndProc   dd ?
; cbClsExtra    dd ?
; cbWndExtra    dd ?
; hInstance     dd ?
; hIcon         dd ?
; hCursor       dd ?
; hbrBackground dd ?
; lpszMenuName  dd ?
; lpszClassName dd ?
; hIconSm       dd ?

xpos dd ?
ypos dd ?

szAppName       db ' Small Window',0
szClassName     db 'SmallWindowClass',0

ButtonClass db "BUTTON",0
buffer1 db "XXXXXXXXXXXXXXXXXXXXXXXXXXX",0
buffer2 db "YYYYYYYYYYYYYYYYYYYYYYYYYYY",0
buffer3 db "ZZZZZZZZZZZZZZZZZZZZZZZZZZZ",0

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

        .DATA?
        ALIGN   4

hwndMain        HWND ?

msg             MSG  <>
client          RECT<>
hBrush dd ?
hdc HDC ?
hFont dd ?

;###############################################################################################

        .CODE
        ALIGN   16

WndProc PROC    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

    mov     eax,uMsg
    .if eax==WM_CREATE
        mov     edx,hWnd
        mov     hwndMain,edx
        xor     eax,eax

INVOKE  CreateWindowEx,0,offset ButtonClass,0,WS_CHILD+WS_VISIBLE+BS_PUSHBUTTON,0,0,  100,30,hwndMain,IDM_1,NULL,NULL

    .elseif eax==WM_CLOSE
        INVOKE  DestroyWindow,hWnd
        xor     eax,eax

    .elseif eax==WM_DESTROY
        INVOKE  PostQuitMessage,NULL
        xor     eax,eax

.elseif eax==WM_COMMAND
mov eax,wParam
.if eax==IDM_1
jmp window1
.endif

    .else
        INVOKE  DefWindowProc,hWnd,uMsg,wParam,lParam

    .endif
    ret

finish:
xor eax,eax
ret

;--------------
window1:
invoke MessageBox,0,0,0,0

INVOKE GetDC,hwndMain
mov hdc,eax

INVOKE GetClientRect,hwndMain,addr client
INVOKE CreateSolidBrush,0FF00FFh
mov hBrush,eax
INVOKE SelectObject,hdc,hBrush
INVOKE FillRect,hdc,offset client,hBrush
;-----Rect ends   

RGB 255,255,255
INVOKE SetTextColor,hdc,eax
RGB    51,51,15
INVOKE SetBkColor,hdc,eax
invoke MessageBox,0,0,0,0

;1
INVOKE CreateFont,40,0,0,0,400,0,0,0,ANSI_CHARSET,\
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
DEFAULT_QUALITY,DEFAULT_PITCH, NULL
mov hFont,eax
INVOKE SelectObject,hdc, hFont

INVOKE GetClientRect,hwndMain,addr client
add client.top,100

INVOKE lstrlen,offset buffer1
INVOKE DrawText,hdc,offset buffer1,eax,offset client,DT_CENTER
INVOKE DeleteObject,hFont

;2
INVOKE CreateFont,25,0,0,0,400,0,0,0,ANSI_CHARSET,\
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
DEFAULT_QUALITY,DEFAULT_PITCH, NULL
mov    hFont,eax
INVOKE SelectObject,hdc, hFont

INVOKE GetClientRect,hwndMain,addr client
add client.top,140

INVOKE lstrlen,offset buffer2
INVOKE DrawText,hdc,offset buffer2,eax,offset client,DT_CENTER

INVOKE DeleteObject,hFont

;3
INVOKE CreateFont,15,0,0,0,400,0,0,0,ANSI_CHARSET,\
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
DEFAULT_QUALITY,DEFAULT_PITCH, NULL
mov    hFont,eax
INVOKE SelectObject,hdc, hFont

INVOKE GetClientRect,hwndMain,addr client
add client.top,170

INVOKE lstrlen,offset buffer3
INVOKE DrawText,hdc,offset buffer3,eax,offset client,DT_CENTER

INVOKE DeleteObject,hFont
INVOKE DeleteObject,hdc

jmp finish
;--------------

WndProc ENDP

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

_main   PROC

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

;initialize common controls

        INVOKE  InitCommonControlsEx,offset icc

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

;register the window class

        xor     edi,edi                                 ;EDI = 0
        mov     esi,offset wc                           ;ESI = offset wc
        INVOKE  GetModuleHandle,edi
        mov     [esi].WNDCLASSEX.hInstance,eax
        xchg    eax,ebx                                 ;EBX = wc.hInstance
        INVOKE  LoadIcon,ebx,IDI_ICON
        mov     [esi].WNDCLASSEX.hIcon,eax
        mov     [esi].WNDCLASSEX.hIconSm,eax
        INVOKE  LoadCursor,edi,IDC_ARROW
        mov     [esi].WNDCLASSEX.hCursor,eax
        INVOKE  RegisterClassEx,esi

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

;create the window
     
      INVOKE     GetSystemMetrics, SM_CXSCREEN
         sub     eax, MAIN_WIDTH
         shr     eax, 1
         mov xpos,eax
      INVOKE     GetSystemMetrics, SM_CYSCREEN
         sub     eax, MAIN_HEIGHT
         shr     eax, 1
         mov ypos,eax
       
             
        INVOKE  CreateWindowEx,edi,offset szClassName,offset szAppName,
                WS_OVERLAPPEDWINDOW or WS_VISIBLE or WS_CLIPCHILDREN,\
                xpos,200,MAIN_WIDTH,MAIN_HEIGHT,0,0,ebx,edi
        INVOKE  UpdateWindow,eax

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

;message loop

        mov     esi,offset msg                          ;ESI = msg structure address
        jmp short mLoop1

mLoop0: INVOKE  TranslateMessage,esi
        INVOKE  DispatchMessage,esi

mLoop1: INVOKE  GetMessage,esi,edi,edi,edi
        inc     eax                                     ;exit only
        shr     eax,1                                   ;if 0 or -1
        jnz     mLoop0                                  ;otherwise, we loop

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

;exit program

        INVOKE  ExitProcess,[esi].MSG.wParam

_main   ENDP

;###############################################################################################

        END     _main


clamicun

ok, dedndave you are right.

The only solution seems to be  - like you said - to create a "complete" childwindow with a scrollbar.
Creating the main parent window with a scrollbar does not help either.
The "RECT" has the size which it has.
Thank you and a good evening.
Clamicun