The MASM Forum

General => The Campus => Topic started by: Don57 on December 04, 2012, 04:00:53 AM

Title: Setting color for hyperlink
Post by: Don57 on December 04, 2012, 04:00:53 AM
I used an example from the old forum to create a hyperlink, I was wondering how to change the color. After reading on the microsoft website the only way I can see is to CreatePen then SelectObject. I was looking for an easier example.

      .IF uMsg==WM_CREATE

          CALL Check_Admin                                                       ; check if program is being run as administrator

          invoke CreateWindowEx,NULL, ADDR sz_Button,ADDR sz_ButtonText,\        ; create button
                                WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
                                130,110,140,25,hWnd,BUTTON_ID,hInstance,NULL
       mov  hwndButton,eax                                                    ; save button handle


;==================== HyperLink ==============================

           invoke SendMessage, hWnd, WM_SETTEXT,0, ADDR sz_AppName

           invoke CreateWindowEx, NULL, addr sz_AppLink, 0, WS_CHILD or WS_VISIBLE or SS_NOTIFY,\
                               10, 147, 115, 20, hWnd,0, hInstance, NULL

           mov hStatic, eax

        invoke CreateFont, -12, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0
        invoke SendMessage, hStatic, WM_SETFONT, eax, 1   
           invoke LoadCursor, 0, IDC_HAND
           invoke SetClassLong, hStatic, GCL_HCURSOR,eax
           invoke SetWindowText,hStatic,addr sz_Url
   



;====================
Title: Re: Setting color for hyperlink
Post by: dedndave on December 04, 2012, 04:50:54 AM
WM_CTLCOLORSTATIC

http://msdn.microsoft.com/en-us/library/windows/desktop/bb787524%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/bb787524%28v=vs.85%29.aspx)
Title: Re: Setting color for hyperlink
Post by: Don57 on December 04, 2012, 04:57:15 AM
Thank You. :eusa_clap:
Title: Re: Setting color for hyperlink
Post by: hfheatherfox07 on December 04, 2012, 06:25:58 AM
Dunno if you still need it but this is how I do it  :biggrin:
Title: Re: Setting color for hyperlink
Post by: dedndave on December 04, 2012, 06:36:55 AM
that doesn't look good, Heather

you create new solid brushes everytime a message comes in without deleting them
if you want to create solid brushes for that...
1) create the brush once in WM_CREATE and store the handle
2) delete the brush object(s) in WM_CLOSE

depending on the color, you may be able to use stock brushes - in which case, you don't have to delete
Title: Re: Setting color for hyperlink
Post by: hfheatherfox07 on December 04, 2012, 06:47:27 AM
Thanks dedndave you are right I forgot to delete the brush
I added :

.ELSEIF eax == WM_CLOSE
    INVOKE  DeleteObject,hBrush1
    INVOKE  DeleteObject,hBrush2
    INVOKE EndDialog, hWnd, 0
   .ENDIF


But the reason that I create new solid brushes every time a message comes and not once in WM_CREATE
Is So you can have more than one link with more than one colour and background too ....
Also the flexibility of a colour you pick with a colour picker  :biggrin:

How does this look ?
Title: Re: Setting color for hyperlink
Post by: dedndave on December 04, 2012, 07:04:38 AM
still plagued with the same issue, i am afraid
it may create several brushes, but only deletes the last one created

i sometimes use a method that you may find useful
i create a small function for deleting GDI objects, like so...
DelGdiObj PROTO :LPVOID

;**************************************************************************

        OPTION  PROLOGUE:None
        OPTION  EPILOGUE:None

DelGdiObj PROC  lphGdiObject:LPVOID

        mov     edx,[esp+4]
        mov     eax,[edx]
        or      eax,eax
        jz      DelObj

        and dword ptr [edx],0
        INVOKE  DeleteObject,eax

DelObj: ret     4

DelGdiObj ENDP

        OPTION  PROLOGUE:PrologueDef
        OPTION  EPILOGUE:EpilogueDef

;**************************************************************************


notice that you pass a pointer to the handle - not the handle, itself
now, you can delete the previous handle...
if it is 0, nothing happens
if it is not 0, the GDI object is deleteted and the stored handle is set to 0
Title: Re: Setting color for hyperlink
Post by: hfheatherfox07 on December 04, 2012, 07:11:13 AM
That is very nice ....dedndave
That will help me a lot with the animated region project (once I return to it LOL)
and other projects

So some thing like this will work now

.ELSEIF eax == WM_CLOSE
    INVOKE  DelGdiObj,hBrush1
    INVOKE  DelGdiObj,hBrush2
    INVOKE EndDialog, hWnd, 0
   .ENDIF
Title: Re: Setting color for hyperlink
Post by: dedndave on December 04, 2012, 07:19:05 AM
well - not quite
you can use the function in WM_CLOSE, of course

however, the intention was that you use it just before creating a new brush
.elseif eax==WM_CTLCOLORSTATIC
invoke GetWindowLong,lParam,GWL_ID
.if eax==IDC_ID_WWW 

invoke SetBkMode,wParam,TRANSPARENT
invoke SetTextColor,wParam,00FF0000h
invoke DelGdiObj,offset hBrush1
invoke CreateSolidBrush,00D8E9ECh
mov hBrush1,eax
ret
.endif


also - your code does not pass a pointer - it passes the handle   :P