News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Setting color for hyperlink

Started by Don57, December 04, 2012, 04:00:53 AM

Previous topic - Next topic

Don57

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
   



;====================



hfheatherfox07

Dunno if you still need it but this is how I do it  :biggrin:
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

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

hfheatherfox07

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 ?
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

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

hfheatherfox07

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
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

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