flat assembler
Message board for the users of flat assembler.

Index > Windows > Child window with different color

Author
Thread Post new topic Reply to topic
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
How can I get a different backgroundcolor into a child window ?
It can not be very complicated, but I do not succeed.

Here is the source...

Code:
format PE GUI 4.0
entry start

;you might have to change the path
include '..\include\win32a.inc'

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
;        invoke  LoadIcon,eax,1
;        mov     [wc.hIcon],eax
;        invoke  LoadCursor,0,IDC_ARROW
;        mov     [wc.hCursor],eax
        invoke  LoadMenu,[wc.hInstance],7
        mov     [menuhandle],eax
        invoke CreateSolidBrush,YELLOW
        mov    [wc.hbrBackground],eax
        invoke  RegisterClass,wc

        invoke  CreateWindowEx,WS_EX_CLIENTEDGE,_class,_title,WS_VISIBLE+WS_SYSMENU\
+WS_MAXIMIZE+WS_CAPTION+WS_MINIMIZEBOX,200,200,400,300,
NULL,[menuhandle],[wc.hInstance],NULL
        mov [wndhandle],eax

  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

  end_loop:
        invoke  ExitProcess,[msg.wParam]
;----------
proc WindowProc wndhandle,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_COMMAND
        je      .wmcommand
        cmp     [wmsg],WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        invoke  DefWindowProc,[wndhandle],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmcommand:
        mov     eax,[wparam]
        and     eax,0FFFFh
        cmp     eax,IDM_YELLOW
        je      .yellow
        cmp     eax,IDM_BLUE
        je      .blue
        cmp     eax,IDM_EXIT
        je      .wmdestroy
        jmp     .finish

  .yellow:
        invoke CreateWindowEx,WS_EX_CLIENTEDGE,_class,NULL,WS_CHILD+WS_VISIBLE,30,30,200,150,[wndhandle],NULL,[wc.hInstance],NULL
        mov [yellowhnd],eax                ;for further action
        jmp    .finish

  .blue:
;        invoke CreateSolidBrush,BLUE      ;what ever I do here, it is not working !!
;        mov    [wc.hbrBackground],eax     ;so what I am supposed to do ?

        invoke CreateWindowEx,WS_EX_CLIENTEDGE,_class,NULL,WS_CHILD+WS_VISIBLE,90,90,180,130,[wndhandle],NULL,[wc.hInstance],NULL
        mov [bluehnd],eax                  ;for further action
        jmp    .finish

  .wmdestroy:
        invoke  ExitProcess,0
  .finish:
        pop     edi esi ebx
        ret
endp
;----------
section '.data' data readable writeable

YELLOW = 0FFFFH
BLUE   = 0FF0000H

IDM_YELLOW = 101
IDM_BLUE   = 102
IDM_EXIT   = 103

_title TCHAR 'WIN32',0
_class TCHAR 'WIN32',0

wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,hbrBackground,NULL,_class

wndhandle      dd ?,0
menuhandle     dd ?,0
hbrBackground  dd ?,0
yellowhnd      dd ?,0
bluehnd        dd ?,0

msg MSG

section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
        user32,'USER32.DLL',\
        gdi32,'GDI32.DLL'

;you might have to change the path

include '..\include\api\kernel32.inc'
include '..\include\api\user32.inc'
include '..\include\api\gdi32.inc'

section '.rsrc' resource data readable

directory RT_MENU,menus

resource menus,\
           7,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu

menu main_menu
       menuitem '&File',0,MFR_POPUP +MFR_END
                menuitem '&Yellow',IDM_YELLOW
                menuseparator
                menuitem '&Blue',IDM_BLUE
                menuseparator
                menuitem 'E&xit',IDM_EXIT,MFR_END    
Edit by revolution: Code tags are your friend.
Post 17 Feb 2014, 12:15
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1413
Location: Toronto, Canada
AsmGuru62
I think the frame window (a parent for child windows) should not have the
same WndProc as a child window. It, kind of, contradicts the proper application design.
And once you have separate procedures - have a child window respond to
WM_ERASEBKGND and paint the background with currently selected brush (a global COLORREF variable).

I can try and create a prototype for you.
Post 17 Feb 2014, 14:10
View user's profile Send private message Send e-mail Reply with quote
clamicun



Joined: 04 Dec 2013
Posts: 77
Location: Muenster NRW Germany
clamicun
Yes thank you!
Seems that, if I only want to change the color I can use the same WindowProc, but have to register a new class.

;
_childclass TCHAR 'chwin',0
wcch WNDCLASS ,WindowProc,0,0,NULL,NULL,NULL,hbrBackground,NULL,_childclass

invoke GetModuleHandle,0
mov [wcch.hInstance],eax
invoke CreateSolidBrush,BLUE
mov [wcch.hbrBackground],eax
invoke RegisterClass,wcch

invoke CreateWindowEx,WS_EX_CLIENTEDGE,_chclass,NULL,WS_CHILD+WS_VISIBLE,\
90,90,180,130,[wndhandle],NULL,[wcch.hInstance],NULL
Post 17 Feb 2014, 16:33
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
clamicun,

WNDCLASS.cbWndExtra can be used to allocate some per-window memory, accessible with Get/SetWindowLong(). You may use Get/SetProp() if you're not into offsets that much. This extra memory can be used to store brush handle for WM_ERASEBKGND handling.

Separate window class for each background color looks like overkill.
Post 17 Feb 2014, 20:24
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1413
Location: Toronto, Canada
AsmGuru62
@clamicun:
I have attached some working code.


Description: Frame + 3 child panels with separate colors.
Download
Filename: FrameApp.zip
Filesize: 8.38 KB
Downloaded: 81 Time(s)

Post 17 Feb 2014, 22:40
View user's profile Send private message Send e-mail 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 YouTube, Twitter.

Website powered by rwasa.