flat assembler
Message board for the users of flat assembler.

Index > Windows > SendMessage, WM_PAINT, DrawText Problem

Author
Thread Post new topic Reply to topic
NicoDean



Joined: 22 May 2007
Posts: 1
NicoDean 22 May 2007, 16:25
Hello,

I want to code a program, which creates a window. From time to time the main program should write a text to the window.

I've done the window and window proc, which reads the WM_PAINT Messages, and uses DrawText to write it to the Window.

Unfortanutally, this just work for the first time, all other times the text will not be drawn to the window. I've searched for many hours, read (non-FASM) examples, where it should work.

Could anybody tell me where the mistake is? Thanks alot!!!

kind regards,
NicoDean

Code:
include '..\fasm\INCLUDE\win32ax.inc'

.data
        WNDC            WNDCLASS
        wRECT           RECT
        wPAINTSTRUCT    PAINTSTRUCT
        wmsg            MSG
        whDC            dd 0x0
        hinst           dd 0x0
        classname       db "ClassName",0x0
        windowname      db "Master's Window",0x0
        windowtext      db "mytext",0x0
        mainhwnd        dd 0x0

.code

  start:
        invoke  GetModuleHandle,0
        mov     [hinst],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [WNDC.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [WNDC.hCursor],eax
        mov     [WNDC.style],0
        mov     [WNDC.lpfnWndProc],WindowProc
        mov     [WNDC.cbClsExtra],0
        mov     [WNDC.cbWndExtra],0
        mov     eax,[hinst]
        mov     [WNDC.hInstance],eax
        mov     [WNDC.hbrBackground],COLOR_BTNFACE+1
        mov     [WNDC.lpszMenuName],0
        mov     [WNDC.lpszClassName], classname
        invoke  RegisterClass,WNDC

        invoke  CreateWindowEx,0,classname,windowname,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,192,192,NULL,NULL,[hinst],NULL
        mov     [mainhwnd],eax

        invoke  ShowWindow, [mainhwnd], SW_SHOW
;        invoke  UpdateWindow, [mainhwnd]


        invoke  SendMessage, [mainhwnd], WM_PAINT, 0x0, windowname

    msgloop:
        invoke  GetMessage, wmsg, 0x0, 0x0, 0x0
        cmp     eax, 0x0
        je      end_msgloop

        invoke  TranslateMessage, wmsg
        invoke  DispatchMessage, wmsg

        invoke  SendMessage, [mainhwnd], WM_PAINT, 0x0, windowtext
        jmp msgloop
    end_msgloop:

;        invoke  Sleep, 2000
;        invoke  SendMessage, [mainhwnd], WM_SETTEXT, 0x0, windowname
;        invoke  Sleep, 2000
;        invoke  SendMessage, [mainhwnd], WM_DESTROY, 0x0, 0x0
;        invoke  SendMessage, [mainhwnd], WM_SETTEXT, 0x0, windowtext
;         invoke  MessageBox, 0x0, "a", "h", 0x0
;        invoke  Sleep, 3000

        invoke  ExitProcess, 0x0


proc WindowProc, hwnd, wmsg, wparam, lparam
  pusha

        cmp     [wmsg],WM_DESTROY
        je      window_wmdestroy

        cmp     [wmsg],WM_PAINT
        je      window_printtext

        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     window_finish


     window_printtext:
        invoke  BeginPaint, [hwnd], wPAINTSTRUCT
        mov     [whDC], eax
        invoke  GetClientRect, [hwnd], wRECT
        invoke  DrawText, [whDC], [lparam], -1, wRECT, DT_LEFT
        invoke  EndPaint, [hwnd], wPAINTSTRUCT

        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     window_finish

     window_wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax, eax
     window_finish:
  popa
  return
endp

.end start    
Post 22 May 2007, 16:25
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 22 May 2007, 17:36
NicoDean,

Try replacing the line:

Code:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
    

within the section handling

Code:
     window_printtext:    


with:

Code:
       xor     eax, eax    


Study--some more--about Windows messages, and handling them, and how you should respond to them.

hth,

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 22 May 2007, 17:36
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.