WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
 
Forum
Pages (6) [1] 2 3 4 5 6   ( Go to first unread post )

Changing static ctrl color

ly47
Quote Post


Member
**

Group: Members
Posts: 21
Member No.: 24924
Joined: 29-July 09


Hi
How to change static ctrl's color,by command(btn click) ?
(any color)
attached asm file.
Thanks
ly


CODE

; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include '%fasminc%\win32ax.inc'

section '.text' code readable executable

 start:

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

invoke GetSystemMetrics, SM_CXSCREEN; SM_CXSCREEN = 0
sub eax,256
shr eax,1

mov [wX],eax
invoke GetSystemMetrics, SM_CYSCREEN; SM_CYSCREEN = 1
sub eax,192
shr eax,1

mov [wY],eax
invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,\
         [wX],[wY],256,192,NULL,NULL,[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 uses ebx esi edi, hwnd,wmsg,wparam,lparam
 cmp [wmsg],WM_CREATE
 je .wmcreate
 cmp [wmsg],WM_INITDIALOG
 je .wminitdialog
 cmp     [wmsg],WM_CTLCOLORSTATIC
 je      .wmctlcolorstatic
 cmp [wmsg],WM_COMMAND
 je .wmcommand
 cmp [wmsg],WM_DESTROY
 je .wmdestroy
.defwndproc:
 invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
 jmp .finish
.wmcreate:
 invoke CreateWindowEx,0,'STATIC','ID_ST_TEST',WS_VISIBLE+WS_CHILD+SS_SUNKEN+SS_NOTIFY,\
          20,20,100,100,[hwnd],ID_ST_TEST,[wc.hInstance],NULL
 mov [hwndstatic1],eax
 invoke CreateWindowEx,0,'BUTTON',' EXIT',WS_VISIBLE+WS_CHILD,\
          185,125,55,25,[hwnd],ID_BT_EXIT,[wc.hInstance],NULL
 invoke CreateWindowEx,0,'BUTTON',' COLOR',WS_VISIBLE+WS_CHILD,\
          130,55,65,25,[hwnd],ID_BT_COLOR,[wc.hInstance],NULL
 mov [hwndbtn1],eax
 xor eax,eax
 jmp .finish

.wminitdialog:
 ;
 ;
 xor eax,eax
 jmp .finish
.wmctlcolorstatic:

  invoke  SetTextColor,[wparam],0x00666666
  invoke  SetBkColor,[wparam],0x00CCCCCC
  invoke  CreateSolidBrush,0x00CCCCCC

 jmp .finish
.wmcommand:
 cmp [wparam],BN_CLICKED shl 16 + ID_BT_EXIT
 jne @F
 jmp .wmdestroy
 @@:
 cmp [wparam],BN_CLICKED shl 16 + ID_BT_COLOR
 jne @F
; xxxxxxxxxxxxxxxxxxxxxxxxxxxx  code  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 invoke MessageBox ,0,'???',"Code for changing 'ID_ST_TEST' color needed !",0
;    Code ???

; xxxxxxxxxxxxxxxxxxxxxxxxxxxx  code  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 xor eax,eax
 jmp .finish
 @@:

 xor eax,eax
 jmp .finish
.wmdestroy:
 invoke PostQuitMessage,0
 xor eax,eax
.finish:
 ret
endp

section '.data' data readable writeable

_class db 'FASMWIN32',0
_title  db 'Win32 TMPL',0
_error db 'Startup failed.',0

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

msg MSG

hwndstatic1 dd ?
hwndbtn1 dd ?
wX dd ?
wY dd ?

section '.idata' import data readable writeable

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

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

ID_BT_EXIT = 1000
ID_ST_TEST = 1001
ID_BT_COLOR = 1002



Sponsored Links
PMEmail Poster
Top
huntingspace
Quote Post


Active Member
***

Group: Members
Posts: 49
Member No.: 49504
Joined: 11-February 12


perhaps you need so
CODE

...
.wmctlcolorstatic:
mov eax,[lparam]
cmp eax,[hwndstatic1]
jne .finish
invoke SetTextColor,[wparam],[dwColorText]
invoke SetBkColor,[wparam],[dwColorBkg]
invoke CreateSolidBrush,[dwColorBkg]
jmp .finish
.wmcommand:
xor eax,eax
cmp [wparam],BN_CLICKED shl 16 + ID_BT_EXIT
je .wmdestroy
cmp [wparam],BN_CLICKED shl 16 + ID_BT_COLOR
jne .finish
invoke MessageBox,0,'???',"Code for changing 'ID_ST_TEST' color needed !",0
mov [dwColorText],0x0000ff    ;red
mov [dwColorBkg],0xff0000    ;blue
invoke InvalidateRect,[hwndstatic1],NULL,TRUE
invoke UpdateWindow,[hwndstatic1]
xor eax,eax
jmp .finish
...
section '.data' data readable writeable
dwColorText dd 0x00666666
dwColorBkg dd 0x00CCCCCC
...
PMEmail Poster
Top
ly47
Quote Post


Member
**

Group: Members
Posts: 21
Member No.: 24924
Joined: 29-July 09


Hi huntingspace

Thanks a lot, it works !!!
ly
PMEmail Poster
Top
Jupiter
Quote Post


Extremely Active Member
******

Group: Moderators
Posts: 738
Member No.: 773
Joined: 10-November 04


ly47,
please, use a "code" tag for huge listings, or better attach sources as asm files
PMEmail Poster
Top
ly47
Quote Post


Member
**

Group: Members
Posts: 21
Member No.: 24924
Joined: 29-July 09


Hi
I use 3 statics and change their color to diff. colors(btn click)
But if I minimize and then restore the window all lables color changed
to the last color.
Attached code file in fasm.
Please help
thanks
ly
CODE


; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include '%fasminc%\win32ax.inc'

section '.text' code readable executable

 start:

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

invoke GetSystemMetrics, SM_CXSCREEN; SM_CXSCREEN = 0
sub eax,256
shr eax,1

mov [wX],eax
invoke GetSystemMetrics, SM_CYSCREEN; SM_CYSCREEN = 1
sub eax,192
shr eax,1

mov [wY],eax
invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU+WS_MINIMIZEBOX,
\
         [wX],[wY],256,392,NULL,NULL,[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 uses ebx esi edi, hwnd,wmsg,wparam,lparam
 cmp [wmsg],WM_CREATE
 je .wmcreate
 cmp [wmsg],WM_INITDIALOG
 je .wminitdialog
 cmp     [wmsg],WM_CTLCOLORSTATIC
 je      .wmctlcolorstatic
 cmp [wmsg],WM_COMMAND
 je .wmcommand
 cmp [wmsg],WM_DESTROY
 je .wmdestroy
.defwndproc:
 invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
 jmp .finish
.wmcreate:
 invoke CreateWindowEx,0,'STATIC','ID_ST_TEST',WS_VISIBLE+WS_CHILD+SS_SUNKEN+SS_NOTIFY,\
          20,20,100,100,[hwnd],ID_ST_TEST_1,[wc.hInstance],NULL
 mov [hwndstatic1],eax
 invoke CreateWindowEx,0,'STATIC','ID_ST_TEST',WS_VISIBLE+WS_CHILD+SS_SUNKEN+SS_NOTIFY,\
          20,130,100,100,[hwnd],ID_ST_TEST_2,[wc.hInstance],NULL
 mov [hwndstatic2],eax
 invoke CreateWindowEx,0,'STATIC','ID_ST_TEST',WS_VISIBLE+WS_CHILD+SS_SUNKEN+SS_NOTIFY,\
          20,240,100,100,[hwnd],ID_ST_TEST_3,[wc.hInstance],NULL
 mov [hwndstatic3],eax
 invoke CreateWindowEx,0,'BUTTON','EXIT',WS_VISIBLE+WS_CHILD,\
          185,325,55,25,[hwnd],ID_BT_EXIT,[wc.hInstance],NULL
 invoke CreateWindowEx,0,'BUTTON','COLOR',WS_VISIBLE+WS_CHILD,\
          130,55,65,25,[hwnd],ID_BT_COLOR,[wc.hInstance],NULL
 mov [hwndbtn1],eax
 xor eax,eax
 jmp .finish

.wminitdialog:
 ;
 ;
 xor eax,eax
 jmp .finish
.wmctlcolorstatic:
 mov eax,[lparam]

 cmp eax,[hwndstatic1]
 jne @F
 invoke SetTextColor,[wparam],[dwColorText]
 invoke SetBkColor,[wparam],[dwColorBkg]
 invoke CreateSolidBrush,[dwColorBkg]

 @@:
 cmp eax,[hwndstatic2]
 jne @F
 invoke SetTextColor,[wparam],[dwColorText]
 invoke SetBkColor,[wparam],[dwColorBkg]
 invoke CreateSolidBrush,[dwColorBkg]
 @@:
 cmp eax,[hwndstatic3]
 jne @F
 invoke SetTextColor,[wparam],[dwColorText]
 invoke SetBkColor,[wparam],[dwColorBkg]
 invoke CreateSolidBrush,[dwColorBkg]
 @@:
 jmp .finish
.wmcommand:
; xor eax,eax
 cmp [wparam],BN_CLICKED shl 16 + ID_BT_EXIT
 je .wmdestroy
 cmp [wparam],BN_CLICKED shl 16 + ID_BT_COLOR
 jne .finish

; invoke MessageBox,0,'???',"Code for changing 'ID_ST_TEST' color needed !",0

 mov [dwColorText],0x0000ff   ;red
 mov [dwColorBkg],0xff0000   ;blue
 invoke InvalidateRect,[hwndstatic1],NULL,TRUE
 invoke UpdateWindow,[hwndstatic1]

 mov [dwColorText],0x0000ff   ;red
 mov [dwColorBkg],0x00ff00   ;green
 invoke InvalidateRect,[hwndstatic2],NULL,TRUE
 invoke UpdateWindow,[hwndstatic2]

 mov [dwColorText],0x0000ff   ;red
 mov [dwColorBkg],0x0000ff    ;red
 invoke InvalidateRect,[hwndstatic3],NULL,TRUE
 invoke UpdateWindow,[hwndstatic3]

 xor eax,eax
 jmp .finish
 @@:

 xor eax,eax
 jmp .finish
.wmdestroy:
 invoke PostQuitMessage,0
 xor eax,eax
.finish:

 ret
endp

section '.data' data readable writeable

_class db 'FASMWIN32',0
_title  db 'Color Test',0
_error db 'Startup failed.',0

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

msg MSG

hwndstatic1 dd ?
hwndstatic2 dd ?
hwndstatic3 dd ?
hwndbtn1 dd ?
wX dd ?
wY dd ?

hBrush dd ?

dwColorText dd 0x00666666
dwColorBkg  dd 0x00CCCCCC

section '.idata' import data readable writeable

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

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

ID_BT_EXIT = 1000
ID_ST_TEST_1 = 1001
ID_ST_TEST_2 = 1002
ID_ST_TEST_3 = 1003
ID_BT_COLOR = 1010


Attached File ( Number of downloads: 9 )
 Login or Register to download
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages (6) [1] 2 3 4 5 6  Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian