flat assembler
Message board for the users of flat assembler.

Index > Windows > How to change label text color at runtime?

Author
Thread Post new topic Reply to topic
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
how to change label text color at runtime? Embarassed

[edit by moderator]Please give your threads descriptive names, names like "easy question" is not considered descriptive. - topic name changed-[/edit]

_________________
[not enough memory]
Post 25 Oct 2004, 12:39
View user's profile Send private message Reply with quote
metalfishx



Joined: 30 Sep 2004
Posts: 65
Location: Florida, Uruguay
metalfishx
Hello Vasilev.
Well, if you take the Handle of the device content (HDC) you can use the api SetTextColor to do that.

WinApi Help In C:
--------------------------------------------------------------------------------
LIB: GDI32

COLORREF SetTextColor(

HDC hdc, // handle of device context
COLORREF crColor // text color
);

Parameters

hdc: Identifies the device context.

crColor: Specifies the color of the text.


Return Values

If the function succeeds, the return value is a color reference for the previous text color.
If the function fails, the return value is CLR_INVALID. To get extended error information, call GetLastError.

Remarks

The text color is used to draw the face of each character written by the TextOut and ExtTextOut functions. The text color is also used in converting bitmaps from color to monochrome and vice versa.

--------------------------------------------------------------------------------

Even, i think you can use GetDC to obtain the HDC...

LIB: USER32

HDC GetWindowDC(
HWND hWnd // handle of window
);

--------------------------------------------------------------------------------

I hope this can help you. Also, i know theres in the icelion tutorials you can find the way to do this, but im at the office now and i dont have these material here, mave later (if some one dont let you something more) i look at these code.
Smile

Cheers.

_________________
---------------------------------------
Roberto A. Berrospe Machin
Ruta Internet, Florida Uruguay
---------------------------------------
Post 25 Oct 2004, 13:54
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
thanks for answer

i'll try it

_________________
[not enough memory]
Post 25 Oct 2004, 14:20
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
please,
give a more specific thread topic
posting rules are just about finished, its kinda shame to write this in to the posting rules, but ...
this thread should have had a name like:
"how to change label text color at runtime?"
Post 25 Oct 2004, 14:59
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
metalfishx, your method wont works Confused

i think the best method is SS_OWNERDRAW and super-subclassing, i was played around it - works perfect, who knows other methods?

_________________
[not enough memory]
Post 26 Oct 2004, 05:47
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable

  _title db 'Win32 program template',0
  _class db 'FASMWIN32',0

  _title2 db 'Label',0
  _class2 db 'STATIC',0

  mainhwnd dd ?
  hinstance dd ?
  hlabel dd ?

  color dd ?

  msg MSG
  wc WNDCLASS

section '.code' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [hinstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        mov     [wc.style],0
        mov     [wc.lpfnWndProc],WindowProc
        mov     [wc.cbClsExtra],0
        mov     [wc.cbWndExtra],0
        mov     eax,[hinstance]
        mov     [wc.hInstance],eax
        mov     [wc.hbrBackground],COLOR_BTNFACE+1
        mov     [wc.lpszMenuName],0
        mov     [wc.lpszClassName],_class
        invoke  RegisterClass,wc

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,\
          128,128,150,70,NULL,NULL,[hinstance],NULL
        mov     [mainhwnd],eax

        invoke  CreateWindowEx,0,_class2,_title2,WS_VISIBLE+WS_CHILD+SS_CENTER,\
          5,5,135,35,eax,NULL,[hinstance],NULL
        mov     [hlabel],eax

        invoke  SetTimer,[mainhwnd],123,50,NULL

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  end_loop:
        invoke  KillTimer,[mainhwnd],123
        invoke  ExitProcess,[msg.wParam]

proc WindowProc, hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_TIMER
        je      wmtimer
        cmp     [wmsg],WM_CTLCOLORSTATIC
        je      wmctlcolorstatic
        cmp     [wmsg],WM_DESTROY
        je      wmdestroy
  defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     finish
  wmtimer:
        invoke  InvalidateRect,[hlabel],NULL,FALSE
        jmp     finish
  wmctlcolorstatic:
        invoke  SetBkColor,[wparam],$00000000
        invoke  SetTextColor,[wparam],[color]
        add     [color],1234567890
        and     [color],$00FFFFFF
        invoke  GetStockObject,BLACK_BRUSH
        jmp     finish
  wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  finish:
        pop     edi esi ebx
        return
endp

section '.idata' import data readable writeable

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

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

  import user,\
         RegisterClass,'RegisterClassA',\
         CreateWindowEx,'CreateWindowExA',\
         DefWindowProc,'DefWindowProcA',\
         GetMessage,'GetMessageA',\
         TranslateMessage,'TranslateMessage',\
         DispatchMessage,'DispatchMessageA',\
         LoadCursor,'LoadCursorA',\
         LoadIcon,'LoadIconA',\
         PostQuitMessage,'PostQuitMessage',\
         SetTimer,'SetTimer',\
         KillTimer,'KillTimer',\
         InvalidateRect,'InvalidateRect'

  import gdi,\
         SetBkColor,'SetBkColor',\
         SetTextColor,'SetTextColor',\
         GetStockObject,'GetStockObject'    
Post 26 Oct 2004, 10:42
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
metalfishx



Joined: 30 Sep 2004
Posts: 65
Location: Florida, Uruguay
metalfishx
Yep, this works Wink
GetDC or GetWindowDC works only with the whole window Wink

Smile
Post 26 Oct 2004, 14:03
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
mike.dld, your method like my method, but i use whole WM_PAINT for paint color, thanks

_________________
[not enough memory]
Post 27 Oct 2004, 06:21
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.

Powered by rwasa.