flat assembler
Message board for the users of flat assembler.

Index > Windows > problem with TextOut

Thread Post new topic Reply to topic

Joined: 03 Nov 2005
Posts: 12
Location: Ukraine
hi, everyone.
i'm beginning to study win32 assembly, and trying to write a simple prog - it's some kind of digital clock; but it's working not like it should be =)
when program running i don't see any text output in the working area (i studied the program in olly debugger but didn't find the bug), could you please explain to me, what's wrong with it?


format PE GUI 4.0
entry start

include '%fasminc%\win32axp.inc'

section '.data' data readable writeable
;-- -----------------------------------------------------------------------
    wmsg        MSG
    wcls        WNDCLASS
    stime       SYSTEMTIME
    _ps         PAINTSTRUCT
    _ccs        CHOOSECOLOR
    _cfs        CHOOSEFONT
    _logfont    LOGFONT
    _rect       RECT

    whmain      dd    ?
    whinst      dd    ?
    hmenu       dd    ?
    wtitle      db    'bsclock',0
    class_name  db    'class',0
    id_timer    equ   1
    mn_color    equ   101
    mn_close    equ   102
    mn_about    equ   103
    mn_font     equ   104
    _ChooseFont db    'font setup',0
    _color      db    'color setup',0
    _about      db    'about',0
    _close      db    'quit',0
    abt_capt    db    'about bsclock',0
    abt_text    db    'not implemented yet =)',0
    FPointSize  dd    ?
    CustColors  dd 16 dup (?)
    FontColor   dd    ?
    _hfont      dd    ?
    _hdc        dd    ?
    rgbresult   dd    ?
    _date       db      '%02d/%02d/%02d',0
    _time       db      '%02d:%02d:%02d',0
    _buff       rb      9

section '.code' code readable executable
    ;-->    registering the window class --------------------------------

    invoke    GetModuleHandle,NULL
    mov       [whinst],eax
    mov       [wcls.hInstance],eax
    mov       [wcls.style],CS_HREDRAW or CS_VREDRAW
    mov       [wcls.lpfnWndProc],window_procedure
    mov       [wcls.lpszClassName],class_name
    mov       [wcls.hbrBackground],COLOR_WINDOW+1
    invoke    LoadIcon,NULL,IDI_WINLOGO
    mov       [wcls.hIcon],eax
    invoke    LoadCursor,NULL,IDC_ARROW
    mov       [wcls.hCursor],eax
    invoke    RegisterClass,wcls

    ;--> creating the main window --------------------------------
    invoke    CreateWindowEx,\

    mov    [whmain],eax
    invoke ShowWindow,[whmain],SW_SHOWNORMAL

    ;- getting current date -------------------------------------

    movzx    eax,[stime.wDay]
    movzx    ebx,[stime.wMonth]
    movzx    edi,[stime.wYear]
    invoke   wsprintf,_buff,_date,eax,ebx,edi

    ;--> entering the message loop ------------------------------
    invoke    GetMessage,wmsg,NULL,0,0
    or        eax,eax
    je        window_message_loop_end
    invoke    TranslateMessage,wmsg
    invoke    DispatchMessage,wmsg
    jmp        window_msg_loop_start

    invoke    ExitProcess,0

    ;- setting default LOGFONT structure -----------------------------
    mov    [_logfont.lfHeight],10
    mov    [_logfont.lfWidth],9
    mov    [_logfont.lfEscapement],900
    mov    [_logfont.lfOrientation],0
    mov    [_logfont.lfWeight],400
    mov    [_logfont.lfItalic],NULL
    mov    [_logfont.lfUnderline],NULL
    mov    [_logfont.lfStrikeOut],NULL
    mov    [_logfont.lfCharSet],ANSI_CHARSET
    mov    [_logfont.lfOutPrecision],NULL
    mov    [_logfont.lfClipPrecision],NULL
    mov    [_logfont.lfQuality],2
    mov    [_logfont.lfPitchAndFamily],DEFAULT_PITCH

    ;--> the window procedure  -------------------------------------------------------------------------------------------
    proc    window_procedure,hWnd,uMsg,wParam,lParam
    push    ebx esi edi

    invoke    DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]

    cmp    [uMsg],WM_COMMAND
    je     .wm_command
    cmp    [uMsg],WM_CONTEXTMENU
    je     .init_menu
    cmp    [uMsg],WM_DESTROY
    je    .wm_destroy
    cmp    [uMsg],WM_TIMER
    je    .wm_timer
    cmp    [uMsg],WM_CREATE
    je    .wm_create
    cmp   [uMsg],WM_PAINT
    je    .wm_paint
    jmp   .finish

    mov     eax, [lParam]       ;if so, show the popup menu
    and     eax, 0ffffh
    mov     ebx, [lParam]
    shr     ebx, 16
    invoke  TrackPopupMenu,[hmenu],TPM_LEFTALIGN,eax,ebx,0,[hWnd],0
    jmp     .finish

    mov     eax,[wParam]
    cmp     eax,mn_font
    je     .choose_font
    cmp     eax,mn_color
    je      .menu_color
    cmp     eax,mn_about
    je      .about
    cmp     eax,mn_close
    je      .wm_destroy
    jmp     .finish

    invoke SetTimer,[hWnd],id_timer,200,NULL       ;0.2 seconds interval
    invoke  CreatePopupMenu
    mov     [hmenu],eax
    invoke  AppendMenu, [hmenu],MF_STRING,mn_font,_ChooseFont
    invoke  AppendMenu, [hmenu],MF_STRING,mn_color,_color
    invoke  AppendMenu, [hmenu],MF_STRING,mn_about,_about
    invoke  AppendMenu, [hmenu],MF_STRING,mn_close,_close
    jmp     .finish

    invoke    GetLocalTime,stime
    ;getting current time
    movzx     eax,[stime.wHour]
    movzx     ebx,[stime.wMinute]
    movzx     edi,[stime.wSecond]
    invoke    wsprintf,_buff,_time,eax,ebx,edi
    add       esp,14h

    invoke    BeginPaint,[hWnd],_ps
    mov       [_hdc],eax
    invoke    CreateFontIndirect,_logfont
    invoke    SelectObject,[_hdc],eax
    mov       [_hfont],eax
    invoke    lstrlen,_buff
    invoke    TextOut,[_hdc],0,0,_time,eax
    invoke    SelectObject,[_hdc],[_hfont]
    invoke    EndPaint,[hWnd],_ps
    jmp   .finish

    invoke    KillTimer,[hWnd],id_timer
    invoke    PostQuitMessage,0
    jmp   .finish

    invoke   MessageBox,[whmain],abt_text,abt_capt,MB_ICONINFORMATION or MB_OK
    jmp      .finish


    mov      [_ccs.lStructSize],sizeof.CHOOSECOLOR
    mov      eax,[hWnd]
    mov      [_ccs.hwndOwner],eax
    mov      [_ccs.lpCustColors],CustColors
    mov      [_ccs.Flags],CC_FULLOPEN or CC_RGBINIT
    mov      [_ccs.lpTemplateName],NULL
    mov      [_ccs.lpfnHook],NULL

    invoke   ChooseColor,_ccs
    jmp      .finish

     mov     [_cfs.lStructSize],sizeof.CHOOSEFONT
     mov     eax,[hWnd]
     mov     [_cfs.hwndOwner],eax
     mov     eax,[_hdc]
     mov     [_cfs.hDC],eax
     mov     [_cfs.lpLogFont],_logfont
     mov     [_cfs.rgbColors],FontColor
     mov     [_cfs.Flags],CF_SCREENFONTS or CF_EFFECTS

     invoke  ChooseFont,_cfs
     jmp     .finish

    pop    edi esi ebx

section '.idata' import data readable writeable
     library   kernel32, 'KERNEL32.DLL',\
               user32,   'USER32.DLL',\
               gdi32,    'GDI32.DLL',\
               comdlg32,   'comdlg32.dll'

     import    kernel32,\
           GetModuleHandle,    'GetModuleHandleA',\
           ExitProcess,        'ExitProcess',\
           GetLocalTime,       'GetLocalTime',\
           lstrlen,            'lstrlenA'

     import    comdlg32,\
           ChooseColor,         'ChooseColorA',\
           ChooseFont,          'ChooseFontA'

     import    user32,\
           MessageBox,          'MessageBoxA',\
           AppendMenu,          'AppendMenuA',\
           CreatePopupMenu,     'CreatePopupMenu',\
           TrackPopupMenu,      'TrackPopupMenu',\
           RegisterClass,       'RegisterClassA',\
           CreateWindowEx,      'CreateWindowExA',\
           DefWindowProc,       'DefWindowProcA',\
           ShowWindow,          'ShowWindow',\
           UpdateWindow,        'UpdateWindow',\
           LoadCursor,          'LoadCursorA',\
           LoadIcon,            'LoadIconA',\
           BeginPaint,          'BeginPaint',\
           InvalidateRect,      'InvalidateRect',\
           EndPaint,            'EndPaint',\
           GetMessage,          'GetMessageA',\
           GetClientRect,       'GetClientRect',\
           GetDC,               'GetDC',\
           ReleaseDC,           'ReleaseDC',\
           DrawText,            'DrawTextA',\
           TranslateMessage,    'TranslateMessage',\
           DispatchMessage,     'DispatchMessageA',\
           PostQuitMessage,     'PostQuitMessage',\
           wsprintf,            'wsprintfA',\
           SetTimer,            'SetTimer',\
           KillTimer,           'KillTimer'

     import    gdi32,\
           TextOut,             'TextOutA',\
           CreateFontIndirect,  'CreateFontIndirectA',\
           SelectObject,        'SelectObject'

{D is for demoscene}
Post 02 Oct 2006, 14:25
View user's profile Send private message ICQ Number Reply with quote

Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
Remove DefWindowProc from the beginning of your message procedure and put it right after .finish label.
Also you probably will want to pass __buff as a third argument to TextOut and not _time.
Post 02 Oct 2006, 15:06
View user's profile Send private message Reply with quote

Joined: 15 Sep 2006
Posts: 181
Actually you're supposed to call DefWindowProc only when you don't handle the message yourself. So it should go between "je .wm_paint" and "jmp .finish".

The code that sets up _logfont never gets executed, and with the lfEscapement set to 90 degrees the text would go straight up and ends up entirely outside the window.

Also your wm_paint doesn't delete the font it created after it's done.
Post 02 Oct 2006, 16:26
View user's profile Send private message Reply with quote

Joined: 11 Aug 2006
Posts: 392
Location: Russian
kb_08h and here you are too Smile
I've made some quick code upon your one and post it now here. Questions & Bug reports are welcomed (but i hope i made it all correct)

Description: modified code
Filename: clock.rar
Filesize: 3.76 KB
Downloaded: 118 Time(s)

Any offers?
Post 02 Oct 2006, 21:27
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.