Jump to content

Recommended Posts

Posted

Hi all,

I am creating a GUI library in Nim with win32 API functions. Even though the syntax is similar to Python, coding is almost similar to C in Nim. 

I can change the back color of the button in NM_CUSTOMDRAW. But I can't change the button text color. here is my pseudo code.  

proc setBtnBackColor*(me : Button, lp: LPNMCUSTOMDRAW )  = 

    if lp.uItemState and CDIS_SELECTED : #------------------ btn clicked  
       # Here i am changing the button color with SelectObject & FillRect.

    elif lp.uItemState and CDIS_HOT : # ----------------Mouse over       
                
        # Here i am changing the button's mouse hover color with SelectObject &  FillRect.

    else: # -------------------------Default color set       
        # Here i am changing the button's default color with SelectObject & FillRect.
        # Here i tried--->
        SetTextColor(lp.hdc, RGB(102, 255, 51) ) #------- But no luck.
      
#-------------------------------------------------------------------------

Please guide me. What i am doing wrong here ?  I am returning "CDRF_SKIPDEFAULT" after calling this function.

Note : I am using subclassed button. So when the parent window receives WM_NOTIFY message, it sends that to my button's WndProc. There i am handling the message.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Posted

I have found the answer myself. In order to change the fore color of a button, we need to use three functions.

SetBkMode    // set bk mode transparent
SetTextColor 
DrawText

After this return CDRF_NOTIFYPOSTPAINT from your function. Otherwise, color won't change.

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...