flat assembler
Message board for the users of flat assembler.

Index > Windows > basic windows programming

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 730
tthsqe
I tried to alter the MINIPAD example to get a status bar:
Code:
        invoke  CreateStatusWindow,WS_CHILD+WS_VISIBLE+SBS_SIZEGRIP,NULL,[hwnd],0
        or      eax,eax
        jz      .failed
        mov     [hwnd_status],eax
        invoke  SendMessage,[hwnd_status],SB_SETTEXT,0,@f
        xor     eax,eax
        jmp     .finish
        @@: db 'greettings',0    

Sending the message SB_SETTEXT seems to work fine, but after after setting the edit window text , the status bar text does not appear. This is what is not working:
Code:
    .new:
        invoke  SendMessage,[edithwnd],WM_SETTEXT,0,0
        invoke  SendMessage,[hwnd_status],SB_SETTEXT,0,StatusText    

Why is this not working?
Post 08 Jan 2010, 11:14
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1155
ManOfSteel
Your code works fine. I think the "problem" is that the scrollbars are hiding the status bar. Try modifying the WM_SIZE handler code:
Code:
invoke GetClientRect,[hwnd],client
sub [client.bottom],24
invoke MoveWindow,[edithwnd],[client.left],[client.top],[client.right],[client.bottom],TRUE
invoke MoveWindow,[hwnd_status],0,0,0,0,TRUE
    


Also, use or instead of + for styles (in CreateStatusWindow).
Post 08 Jan 2010, 13:10
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 730
tthsqe
Thanks, the window size is definitely as issue. However, if I make a menu command that sets the status bar text to "hello" (like file -> hello), doing (file -> new) and then (file -> hello) produces a visible status bar saying 'hello'. So I think the issue with the code I posted could be that:
even though the the WM_SETTEXT is sent before SB_SETTEXT, the edit window text takes a much longer time to be produced, and so ends up overwriting the status bar. Does this sound plausible?
Post 08 Jan 2010, 16:15
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1155
ManOfSteel
I don't really understand your problem. Could you post the entire code, including the code I posted in my last message, and the faulty menu items?

BTW, WM_SIZE is sent when the window's size has changed, but the issue is not the window's size itself, but the editbox's and statusbar's sizes when the window is resized (or created).
Post 08 Jan 2010, 18:55
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 730
tthsqe
Oh - I was still talking about the code with overlapping windows.
I understand that the two windows are being drawn on top of each other, but I don't understand why the 'new' command ends up drawing the edit window over the status window when the 'hello' command works as expected.
NOTE: no horizontal scroll bar
Code:
; Simple text editor - fasm example program

format PE GUI 4.0
entry start

include 'win32a.inc'

IDM_NEW   = 101
IDM_EXIT  = 102
IDM_HELLO = 103
IDM_ABOUT = 901

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  LoadIcon,eax,17
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc
        test    eax,eax
        jz      error

        invoke  LoadMenu,[wc.hInstance],37
        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_OVERLAPPEDWINDOW,144,128,256,256,NULL,eax,[wc.hInstance],NULL
        test    eax,eax
        jz      error

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_CREATE
        je      .wmcreate
        cmp     [wmsg],WM_SIZE
        je      .wmsize
        cmp     [wmsg],WM_SETFOCUS
        je      .wmsetfocus
        cmp     [wmsg],WM_COMMAND
        je      .wmcommand
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmcreate:
        invoke  GetClientRect,[hwnd],client
        invoke  CreateWindowEx,WS_EX_CLIENTEDGE,_edit,0,WS_VISIBLE+WS_CHILD++WS_VSCROLL+ES_AUTOVSCROLL+ES_MULTILINE,[client.left],[client.top],[client.right],[client.bottom],[hwnd],0,[wc.hInstance],NULL
        or      eax,eax
        jz      .failed
        mov     [edithwnd],eax
        invoke  CreateFont,16,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH+FF_DONTCARE,NULL
        or      eax,eax
        jz      .failed
        mov     [editfont],eax
        invoke  SendMessage,[edithwnd],WM_SETFONT,eax,FALSE
        xor     eax,eax
        invoke  CreateStatusWindow,WS_CHILD+WS_VISIBLE+SBS_SIZEGRIP,NULL,[hwnd],0
            test eax,eax
            jz   .failed
        mov     [hStatusWnd],eax
        invoke  SendMessage,[hStatusWnd],SB_SETTEXT,0,@f
        xor     eax,eax
        jmp     .finish
                           @@: db 'greetings',0
      .failed:
        or      eax,-1
        jmp     .finish
  .wmsize:
        invoke  GetClientRect,[hwnd],client
        invoke  MoveWindow,[edithwnd],[client.left],[client.top],[client.right],[client.bottom],TRUE
        xor     eax,eax
        jmp     .finish
  .wmsetfocus:
        invoke  SetFocus,[edithwnd]
        xor     eax,eax
        jmp     .finish
  .wmcommand:
        mov     eax,[wparam]
        and     eax,0FFFFh
        cmp     eax,IDM_NEW
        je      .new
        cmp     eax,IDM_ABOUT
        je      .about
        cmp     eax,IDM_HELLO
        je      .hello
        cmp     eax,IDM_EXIT
        je      .wmdestroy
        jmp     .defwndproc
      .new:
        invoke  SendMessage,[edithwnd],WM_SETTEXT,0,0
        invoke  SendMessage,[hStatusWnd],SB_SETTEXT,0,@f;this is not seen
        jmp     .finish
                        @@: db 'hello',0
      .hello:
        invoke  SendMessage,[hStatusWnd],SB_SETTEXT,0,@b
        jmp     .finish
      .about:
        invoke  MessageBox,[hwnd],_about_text,_about_title,MB_OK
        jmp     .finish
  .wmdestroy:
        invoke  DeleteObject,[editfont]
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        pop     edi esi ebx
        ret
endp

section '.data' data readable writeable

  _title TCHAR 'MiniPad',0
  _about_title TCHAR 'About MiniPad',0
  _about_text TCHAR 'This is Win32 example program created with flat assembler.',0
  _error TCHAR 'Startup failed.',0

  _class TCHAR 'MINIPAD32',0
  _edit TCHAR 'EDIT',0

  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

  edithwnd dd ?
  editfont dd ?
  hStatusWnd dd ?


  msg MSG
  client RECT

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          comctl,'COMCTL32.DLL',\
          gdi,'GDI32.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess'

  import user,\
         RegisterClass,'RegisterClassA',\
         CreateWindowEx,'CreateWindowExA',\
         DefWindowProc,'DefWindowProcA',\
         SetWindowLong,'SetWindowLongA',\
         RedrawWindow,'RedrawWindow',\
         GetMessage,'GetMessageA',\
         TranslateMessage,'TranslateMessage',\
         DispatchMessage,'DispatchMessageA',\
         SendMessage,'SendMessageA',\
         LoadCursor,'LoadCursorA',\
         LoadIcon,'LoadIconA',\
         LoadMenu,'LoadMenuA',\
         GetClientRect,'GetClientRect',\
         MoveWindow,'MoveWindow',\
         SetFocus,'SetFocus',\
         MessageBox,'MessageBoxA',\
         PostQuitMessage,'PostQuitMessage'

  import comctl,\
         CreateStatusWindow,'CreateStatusWindowA'

  import gdi,\
         CreateFont,'CreateFontA',\
         DeleteObject,'DeleteObject'

section '.rsrc' resource data readable

  ; resource directory

  directory RT_MENU,menus,\
            RT_ICON,icons,\
            RT_GROUP_ICON,group_icons,\
            RT_VERSION,versions

  ; resource subdirectories

  resource menus,\
           37,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu

  resource icons,\
           1,LANG_NEUTRAL,icon_data

  resource group_icons,\
           17,LANG_NEUTRAL,main_icon

  resource versions,\
           1,LANG_NEUTRAL,version

  menu main_menu
       menuitem '&File',0,MFR_POPUP
                menuitem '&New',IDM_NEW
                menuitem '&Hello',IDM_HELLO
                menuseparator
                menuitem 'E&xit',IDM_EXIT,MFR_END
       menuitem '&Help',0,MFR_POPUP + MFR_END
                menuitem '&About...',IDM_ABOUT,MFR_END

  icon main_icon,icon_data,'minipad.ico'

  versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
              'FileDescription','MiniPad - example program',\
              'LegalCopyright','No rights reserved.',\
              'FileVersion','1.0',\
              'ProductVersion','1.0',\
              'OriginalFilename','MINIPAD.EXE'
    
[/code]
Post 08 Jan 2010, 21:33
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1155
ManOfSteel
Both controls (editbox and statusbar) are wrongly positioned and are overlapping. This will cause all sorts of odd "visual effects".
What is expected is the bottom arrow of the editbox's vertical scrollbar being visible all the time, including at startup.

The editbox is getting the focus when you're clearing it in .new. That's why it's getting drawn and it's hiding the statusbar.
Modify the code as I previously mentioned and everything will work as you want it.
Post 09 Jan 2010, 00:35
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.