flat assembler
Message board for the users of flat assembler.

Index > Windows > Message Queue problem or something else

Author
Thread Post new topic Reply to topic
asmMe



Joined: 14 Jun 2011
Posts: 18
asmMe
Hi,

This peice of code should display the 4 images in rotation twice, changing the window title to the image name each time. When the 8 images have been shown, the window title should say 'finished'. The problem is that when the 2nd image is shown, the title says finished, then cycles throught the rest of the images correctly but doesn't say finished at the end Question
I had to put the four images in a zip file because the board wouldn't let me upload bitmaps for some reason.

Code:

format PE GUI 4.0
entry start

include '%fasminc%\win32axp.inc'

section '.text' code readable executable

    start:
        invoke  GetModuleHandle, 0
        mov     [wc.hInstance],eax
        invoke  RegisterClass, wc
        invoke  CreateWindowEx, 0, testClass, img1, WS_VISIBLE+WS_OVERLAPPEDWINDOW-WS_THICKFRAME+WS_BORDER, 300, 300, 300, 300, NULL, NULL, [wc.hInstance], NULL
        mov     [hWndMain], eax
        stdcall loadImages
        push    [img1Hnd]
        pop     [thisImgHnd]
        mov     [finished], FALSE
        mov     [showCount], 0
        invoke  GetTickCount
        mov     [myTimer], eax
        jmp     msgLoop
;--------------------------------------------------------------------------------------------------

  msgLoop:
        invoke  PeekMessage, msg, NULL, 0, 0, PM_NOREMOVE
        or      eax,eax
        jz      noMessage
        invoke  GetMessage, msg, NULL, 0, 0
        cmp     eax, 1
        jb      endLoop
        jne     msgLoop
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     msgLoop
    endLoop:
        invoke  ExitProcess, [msg.wParam]
    noMessage:
        cmp     [showCount], 8
        je      @f
        stdcall showImage
    @@:
        cmp     [finished], TRUE
        je      msgLoop
        invoke  SetWindowText, [hWndMain], finStr
        mov     [finished], TRUE
        jmp     msgLoop

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

proc WindowProc hWnd, wMsg, wParam, lParam
        push    ebx esi edi
        cmp     [wMsg], WM_PAINT
        je      .wmPaint
        cmp     [wMsg], WM_DESTROY
        je      .wmDestroy
    .defWndProc:
        invoke  DefWindowProc, [hWnd], [wMsg], [wParam], [lParam]
        jmp     .finish
    .wmPaint:
        invoke  BeginPaint, [hWndMain], ps
        mov     [hDC], eax
        invoke  CreateCompatibleDC, [hDC]
        mov     [hMemDC], eax
        invoke  SelectObject, [hMemDC], [thisImgHnd]
        invoke  BitBlt, [hDC], 100, 100, 100, 100, [hMemDC], 0, 0, SRCCOPY
        invoke  DeleteDC, [hMemDC]
        invoke  EndPaint, [hWndMain], ps
    @@:
        xor     eax, eax
        jmp     .finish
    .wmDestroy:
        invoke  PostQuitMessage, 0
        xor     eax, eax
    .finish:
        pop     edi esi ebx
        ret
endp

;***************************************
proc showImage

        pushad
    .start:
        invoke  GetTickCount
        sub     eax, [myTimer]
        cmp     eax, 1500
        jl      .start
        add     [myTimer], eax
        xor     edx, edx
        mov     ebx, 4
        mov     eax, [showCount]        ;set counter to new tick count
        div     ebx
        mov     ecx, edx                ;ecx = edx = 0, 1, 2 or 3
        shl     ecx, 2
        add     ecx, img1Hnd
        push    dword [ecx]             ;push image handle
        pop     dword [thisImgHnd]
        mov     eax, edx
        xor     edx, edx
        mul     [imgNameLen]
        add     eax, img1               ;now points to image name string
        invoke  SetWindowText, [hWndMain], eax
        invoke  InvalidateRect, [hWndMain], NULL, TRUE
        inc     [showCount]
        popad
    ret
endp

;***************************************
proc loadImages

        push    ebx edi esi
        mov     esi, img1
        mov     edi, img1Hnd
        mov     ecx, 4
    .loadImg:
        push    ecx edi esi
        invoke  LoadImage, [wc.hInstance], esi, IMAGE_BITMAP, NULL, NULL, LR_CREATEDIBSECTION+LR_LOADFROMFILE
        pop     esi edi ecx
        stosd
        add     esi, [imgNameLen]
        loop    .loadImg
        pop     esi edi ebx
        ret
endp

;**************************************************************************************************
section '.data' data readable writeable

wc              WNDCLASS 0, WindowProc, 0, 0, NULL, NULL, NULL, COLOR_BTNFACE+1, NULL, testClass
msg             MSG
hWndMain        dd 0
testClass       db "testClass", 0
img1            db '01.bmp', 0
img2            db '02.bmp', 0
img3            db '03.bmp', 0
img4            db '04.bmp', 0

thisImgHnd      dd 0
img1Hnd         dd 0
img2Hnd         dd 0
img3Hnd         dd 0
img4Hnd         dd 0
imgNameLen      dd img2-img1
myTimer         dd ?
showCount       dd 0
ps              PAINTSTRUCT
hDC             dd ?
hMemDC          dd ?
finStr          db "finished", 0
finished        db FALSE





;**************************************************************************************************
section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
        user32,  'USER32.DLL',\
        gdi32,   'GDI32.DLL',\
        comdlg32,'COMDLG32.DLL',\
        advapi32,'ADVAPI32.DLL',\
        shell32, 'SHELL32.DLL',\
        comctl32,'COMCTL32.DLL'

include '%fasminc%\api\Kernel32.inc'
include '%fasminc%\api\User32.inc'
include '%fasminc%\api\Gdi32.inc'
include '%fasminc%\api\Comdlg32.inc'
include '%fasminc%\api\Advapi32.inc'
include '%fasminc%\api\Comctl32.inc'
include '%fasminc%\api\Shell32.inc'



    


Description:
Download
Filename: images.zip
Filesize: 858 Bytes
Downloaded: 58 Time(s)

Post 14 Jul 2011, 14:59
View user's profile Send private message Reply with quote
asmMe



Joined: 14 Jun 2011
Posts: 18
asmMe
Duh!

Just spotted the problem Embarassed
Post 14 Jul 2011, 15:26
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
so what is it?
Post 14 Jul 2011, 18:23
View user's profile Send private message Reply with quote
asmMe



Joined: 14 Jun 2011
Posts: 18
asmMe
Hi typedef,

Code:
    noMessage:
        cmp     [showCount], 8
        je      @f
        stdcall showImage               ; should jmp out of loop here
                                        ; as [finished] should be FALSE 
                                        ; until all 8 images shown.
                                        ; so just needed...
                       jmp msgLoop      ;here
    @@:
        cmp     [finished], TRUE
        je      msgLoop
        invoke  SetWindowText, [hWndMain], finStr
        mov     [finished], TRUE
        jmp     msgLoop 
    
Post 14 Jul 2011, 21:26
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
it loops like crazy and munching my CPU.
Post 14 Jul 2011, 23:34
View user's profile Send private message Reply with quote
asmMe



Joined: 14 Jun 2011
Posts: 18
asmMe
My original problem was with a routine ( a lot longer than this) similar to completing a jigsaw puzzle.
I had a proc written to try pieces in a particular position\orientation, if it fitted then jump out of proc, update window to show placement, then return to get next matching piece. The bug in the earlier code was simply because of a quick (to make it smaller) rewrite.

The original problem remains though.

How to completely break out of the loop when the puzzle is completed?
Maybe I should be doing this in a thread?
Is there a way without threading?

Question
Post 14 Jul 2011, 23:51
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Maybe you should just stick with GetMessage instead
Post 15 Jul 2011, 00:07
View user's profile Send private message Reply with quote
asmMe



Joined: 14 Jun 2011
Posts: 18
asmMe
but in the example given, where do I place the 'showImage' calls?
If it is outside of msgLoop, WM_PAINT is not received until [finished]=TRUE so the window is only updated on completion, *not* when a piece is place correctly
Post 15 Jul 2011, 00:52
View user's profile Send private message Reply with quote
Enko



Joined: 03 Apr 2007
Posts: 678
Location: Mar del Plata
Enko
Code:
while( msg.message!=WM_QUIT )
{
   while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
   {
       TranslateMessage( &msg );
       DispatchMessage( &msg );
   }
   
   ;TODO: DRAW ROUTINS HERE
}
    


This is the loop from VCpp DirectX example.
Post 15 Jul 2011, 01:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.