flat assembler
Message board for the users of flat assembler.

Index > Windows > Problems with special windows

Author
Thread Post new topic Reply to topic
flona



Joined: 05 Nov 2008
Posts: 7
Location: Germany
flona
Hi
I have some problems using static windows, listviews, treeviews and tab controls.

Static window: I can create them and set some text. But if the window is resized the static window is still on its previous position.

Listview: I've managed to create a listview and to add items. But if I click on a item, it is not selected.

Treeview: There I have the same problem as with Listviews and the treeview doesn't expand if I click on one of the buttons.

Tab control: It doesn't change the tab if I click on one.

Where is the fault? Do I have to process any messages? Should I set any flags?

Thanks ...

_________________
My english is not very well. Pardon.
Post 13 Feb 2009, 19:25
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Hi flona!
As for static window - you should process WM_SIZE message of main window and change size/position of static window there as needed.
Post 13 Feb 2009, 20:50
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Tab control: ensure that in case of WM_NOTIFY message from tab control
with nmhdr.code = TCN_SELCHANGING main window procedure returns FALSE, as it allows selection to be changed in this case (see MSDN for details).
Post 13 Feb 2009, 20:58
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
ListView control - looks like the same as in tab control, WM_NOTIFY from listview with nmhdr.code = LVN_ITEMCHANGING, ensure that main window procedure returns FALSE in this case.
TreeView - WM_NOTIFY from treeview with nmhdr.code = TVN_SELCHANGING, return not TRUE in order selection to be changed, and
with nmhdr.code = TVN_ITEMEXPANDING return not TRUE also in order to treeview item to be collapsed/expanded. (see Win32SDK help or MSDN).
Hope this will help you.
Best regards.
Post 13 Feb 2009, 21:12
View user's profile Send private message Reply with quote
flona



Joined: 05 Nov 2008
Posts: 7
Location: Germany
flona
Thanks for your reply. I've first tried to fix the tab control, but the following code doesn't work. Embarassed

Code:
format PE GUI 4.0
entry start
include '........\ASSEMBLER\INCLUDE\win32a.inc'
section '.data' data readable writeable
  hInstance dd 0
  msg MSG 0
  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_WINDOW,NULL,WindowClass
  _Window db "Window",0
  _IText db "Test",0
  WindowClass db "WindowClass",0
  SysTabControl32 db "SysTabControl32",0
  tci dd TCIF_TEXT,0,0,_IText,0,0,0

section '.code' code readable executable
 start:
   invoke GetModuleHandle,0
   mov dword [hInstance],eax
   mov dword [wc.hInstance],eax

   invoke LoadIcon,0,IDI_APPLICATION
   mov dword [wc.hIcon],eax

   invoke LoadCursor,0,IDC_ARROW
   mov dword [wc.hCursor],eax

   invoke RegisterClass,wc
   call WinMain

   proc WinMain
      local hTab:DWORD
      call [GetDesktopWindow]
      invoke CreateWindowEx,0,WindowClass,_Window,\
             WS_VISIBLE+WS_CLIPSIBLINGS+WS_CLIPCHILDREN+WS_TABSTOP+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX,\
             50,50,600,500,eax,0,dword [hInstance],0
      invoke CreateWindowEx,0,SysTabControl32,0,WS_VISIBLE+WS_CHILD,10,10,200,200,eax,0,dword [hInstance],0
      mov [hTab],eax

      invoke SendMessage,[hTab],TCM_INSERTITEM,0,tci
      invoke SendMessage,[hTab],TCM_INSERTITEM,1,tci

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

      ret
   endp

   proc WindowProc hwnd,Message,wparam,lparam
      push eax ebx esi edi
      cmp [Message],WM_NOTIFY
        je notify
      cmp [Message],WM_CLOSE
        je close
      cmp [Message],WM_DESTROY
        je destroy
      jmp default
    notify:
      mov ecx,[lparam]
      cmp dword [ecx+8],TCN_SELCHANGING
      jne default
        mov eax,FALSE
      jmp ende
    close:
      invoke ExitProcess,0
      jmp ende
    destroy:
      invoke PostQuitMessage,0
      jmp ende
     default:
      push [lparam]
      push [wparam]
      push [Message]
      push [hwnd]
      call [DefWindowProc]
      ende:
      pop edi esi ebx eax
      ret
   endp
section '.idata' import data readable writeable
   library user32,'user32.dll',\
           kernel32,'kernel32.dll'
   import user32,\
          CreateWindowEx,'CreateWindowExA',\
          UpdateWindow,'UpdateWindow',\
          SendMessage,'SendMessageA',\
          GetDesktopWindow,'GetDesktopWindow',\
          DefWindowProc,'DefWindowProcA',\
          PostQuitMessage,'PostQuitMessage',\
          GetMessage,'GetMessageA',\
          TranslateMessage,'TranslateMessage',\
          DispatchMessage,'DispatchMessageA',\
          LoadIcon,'LoadIconA',\
          LoadCursor,'LoadCursorA',\
          RegisterClass,'RegisterClassA'
   import kernel32,\
          ExitProcess,'ExitProcess',\
          GetModuleHandle,'GetModuleHandleA'    

_________________
My english is not very well. Pardon.
Post 13 Feb 2009, 22:27
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Try this code, flona:

Code:
format PE GUI 4.0
entry Main
include '........\ASSEMBLER\INCLUDE\win32a.inc'
section '.data' data readable writeable
  hInstance dd 0
  msg MSG 0
  wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_WINDOW + 1,NULL,WindowClass
  _Window db "Window",0
  _IText db "Test",0
  WindowClass db "WindowClass",0
  SysTabControl32 db "SysTabControl32",0
  tci dd TCIF_TEXT,0,0,_IText,0,0,0

section '.code' code readable executable
 proc Main

   local hTab : DWORD

   invoke GetModuleHandle,0
   mov dword [hInstance],eax
   mov dword [wc.hInstance],eax

   invoke LoadIcon,0,IDI_APPLICATION
   mov dword [wc.hIcon],eax

   invoke LoadCursor,0,IDC_ARROW
   mov dword [wc.hCursor],eax

   invoke RegisterClass,wc

   invoke CreateWindowEx,0,WindowClass,_Window,\
           WS_VISIBLE+WS_CLIPSIBLINGS+WS_CLIPCHILDREN+WS_TABSTOP+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX,\
           50,50,600,500,NULL,0,[hInstance],0
   invoke CreateWindowEx,0,SysTabControl32,0,WS_VISIBLE+WS_CHILD,10,10,200,200,eax,0,[hInstance],0
   mov [hTab],eax

   invoke SendMessage,[hTab],TCM_INSERTITEM,0,tci
   invoke SendMessage,[hTab],TCM_INSERTITEM,1,tci

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

   invoke ExitProcess,0
 endp

   proc WindowProc hwnd,Message,wparam,lparam
      mov eax,[Message]
      cmp eax,WM_NOTIFY
        je notify
      cmp eax,WM_CLOSE
        je close
      cmp eax,WM_DESTROY
        je destroy
      jmp default
    notify:
      mov ecx,[lparam]
      cmp dword [ecx+8],TCN_SELCHANGING
      jne default
        mov eax,FALSE
      jmp ende
    close:
      invoke DestroyWindow,[hwnd]
      jmp ende
    destroy:
      invoke PostQuitMessage,0
      jmp ende
     default:
      invoke DefWindowProc,[hwnd],eax,[wparam],[lparam]
      ende:
      ret
   endp

 invoke InitCommonControls

section '.idata' import data readable writeable

   library user32,'user32.dll',\
           kernel32,'kernel32.dll',\
           comctl32, 'comctl32.dll'

   include "........\ASSEMBLER\INCLUDE\apia\kernel32.inc"
   include "........\ASSEMBLER\INCLUDE\apia\user32.inc"
   include "........\ASSEMBLER\INCLUDE\apia\comctl32.inc"    


Some words about changes i have made.
First, there is no need in "push eax ebx esi edi" / "pop edi esi ebx eax" in WindowProc - none of registers that must be saved/restored is used here. And after "pop eax" your return value will be changed.
Second, it is better to use register for [Message] comparison, as it is less in size and little faster.
Third, you should load "comctl32.dll" dynamically (via LoadLibrary) or via import table, because tab, listview and treeview controls implemented there and their classes are registering when this DLL is loading. That's why "InitCommonControls" call is put in code, but not executed - just for "comctl32.dll" to be loaded.
Forth, it is better IMHO to use fasm standard imports includes (apia\kernel32.inc and others) - there is no need in this case to correct "import" macro parameters when new function from DLL is used. And if function from DLL is not used - it will not be in import table.
And fifth - there is no need in "call WinMain", as this call is just unnecessary, it is better just to continue execution after "RegisterClass".
Maybe it's enough ... Embarassed
Regards.
Post 14 Feb 2009, 02:30
View user's profile Send private message Reply with quote
flona



Joined: 05 Nov 2008
Posts: 7
Location: Germany
flona
It works Very Happy
Arrow Thank you!!

I'm now trying get the other controls work.

_________________
My english is not very well. Pardon.
Post 14 Feb 2009, 10:34
View user's profile Send private message Visit poster's website ICQ Number 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.