flat assembler
Message board for the users of flat assembler.

Index > Windows > SetSysColors problem

Author
Thread Post new topic Reply to topic
jochenvnltn



Joined: 15 Jul 2011
Posts: 83
jochenvnltn
Hello everyone Smile

Im trying to use SetSysColors to set the color of the window in FASM, but SetSysColors function returns 0

Anyone knows more about this function ?

Code:

; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include 'win32w.inc'

section '.text' code readable executable

macro RGB red, green, blue
{
     xor     eax,eax
     mov     ah,blue
     shl     eax,8
     mov     ah,green
     mov     al,red
}

  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  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,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_DESTROY
        je      .wmdestroy
        cmp    [wmsg], WM_CREATE
        je    .wmcreate

  .defwndproc:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .finish
  .wmcreate:

         RGB 080h, 080h, 080h


         invoke SetSysColors, 1, COLOR_WINDOW, eax  ; <--- returns 0
         jmp     .finish

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

section '.data' data readable writeable

  _class TCHAR 'FASMWIN32',0
  _title TCHAR 'Win32 program template',0
  _error TCHAR 'Startup failed.',0

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

  msg MSG 
    
Post 19 Feb 2020, 13:57
View user's profile Send private message MSN Messenger Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 773
Location: Belarus
DimonSoft
jochenvnltn wrote:
Im trying to use SetSysColors to set the color of the window in FASM, but SetSysColors function returns 0


MSDN wrote:
BOOL WINAPI SetSysColors(
__in int cElements,
__in const INT* lpaElements,
__in const COLORREF* lpaRgbValues
);

Parameters
cElements
The number of display elements in the lpaElements array.

lpaElements
A pointer to an array of integers that specify the display elements to be changed. For a list of display elements, see GetSysColor.

lpaRgbValues
A pointer to an array of COLORREF values that contain the new red, green, blue (RGB) color values for the display elements in the array pointed to by the lpaElements parameter.

To generate a COLORREF, use the RGB macro.


The most obvious guess is that there’s parameter validation that checks the pointers for being out of valid address range (first 64K are not accessible for applications). GetLastError would give a clue but you didn’t give us this information, so just guessing for now.

Are you sure changing global settings (even if for the session duration) to solve a local problem is a good idea?

Also
Code:
macro RGB red, green, blue
{
  mov     eax, ((red and $FF) shl 16) or ((green and $FF) shl 8) or (blue and $FF)
}    

might be a better idea if you’re going to use constants. In fact $bbggrr is not even worth making a macro, IMHO.
Post 19 Feb 2020, 15:40
View user's profile Send private message Visit poster's website Reply with quote
jochenvnltn



Joined: 15 Jul 2011
Posts: 83
jochenvnltn
Hi DimonSoft ! Smile

The function returns "Invalid access to memory location"
thank you for the nice macro ! Ill be using that from now on Smile It looks more FASM like Very Happy Can you explain more about " In fact $bbggrr is not even worth making a macro" I find it interesting. Thank you for your reply Wink
Post 19 Feb 2020, 21:05
View user's profile Send private message MSN Messenger Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 773
Location: Belarus
DimonSoft
jochenvnltn wrote:
Hi DimonSoft ! Smile

The function returns "Invalid access to memory location"
thank you for the nice macro ! Ill be using that from now on Smile It looks more FASM like Very Happy Can you explain more about " In fact $bbggrr is not even worth making a macro" I find it interesting. Thank you for your reply Wink

Have you ever used HTML/CSS notation for colors? #FFCCDD?
Post 20 Feb 2020, 08:12
View user's profile Send private message Visit poster's website Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 17
Location: Czech republic
Hrstka
The second and third arguments are pointers, so you cannot pass these values to SetSysColors directly.
Post 21 Feb 2020, 09:15
View user's profile Send private message Reply with quote
jochenvnltn



Joined: 15 Jul 2011
Posts: 83
jochenvnltn
Hrstka wrote:
The second and third arguments are pointers, so you cannot pass these values to SetSysColors directly.


Yes you were right ! I have it running now, but the colors never change ..
Ill get back to this later
Post 21 Feb 2020, 15:14
View user's profile Send private message MSN Messenger 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.