The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Stas_Rocketman on April 15, 2012, 02:13:00 PM

Title: How to create a hyperlink?
Post by: Stas_Rocketman on April 15, 2012, 02:13:00 PM
Hello guys... I want to make a simple app with a hyperlink and a button in its window.
Can anybody tell me, how to create a hyperlink in this application?

Here is a code of that program


.486                                      ; create 32 bit code
.model flat, stdcall                      ; 32 bit memory model
option casemap :none                      ; case sensitive

;     include files
;     ~~~~~~~~~~~~~
include \masm32\include\windows.inc       ; main windows include file
include \masm32\include\masm32.inc        ; masm32 library include

; -------------------------
; Windows API include files
; -------------------------
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\ole32.inc
include \masm32\include\msvcrt.inc

;     libraries
;     ~~~~~~~~~
includelib \masm32\lib\masm32.lib         ; masm32 static library

; ------------------------------------------
; import libraries for Windows API functions
; ------------------------------------------
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\msvcrt.lib

;__________________________________________________________________________________________

.const
hWnd1_Width = 256
hWnd1_Height = 179
hWnd1_button1_ID = 1
hWnd1_button1_Width = 75
hWnd1_button1_Height = 25
hWnd1_button1_X = hWnd1_Width-hWnd1_button1_Width - 16
hWnd1_button1_Y = hWnd1_Height-hWnd1_button1_Height - 32
.data?
hWnd1_Button1 HWND ?
hFontN HWND ?
hInstance HINSTANCE ?
.data
Textbutton1 db "Exit",0
TextHypLink1 db "www.masm32.com",0
FontName db "MS Sans Serif",0
lf LOGFONT <>
;_____________________________________________
BtnClName db "button",0
StarClName db "static",0
AppName db "Application 1",0
;_____________________________________________
sz_string_1 db "Couldn't register window class!", 0
sz_string_2 db "Couldn't create window!", 0
sz_string_3 db "Couldn't create button!", 0
;__________________________________________________________________________________________

.code

start:

Main proc
LOCAL msg :MSG
LOCAL hWnd :HWND
LOCAL wc :WNDCLASSEX
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_BYTEALIGNCLIENT
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
invoke GetModuleHandle, NULL
mov hInstance, eax
mov wc.hInstance, eax
mov wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszClassName, OFFSET AppName ;ClassName

invoke LoadIcon, hInstance, 500
mov wc.hIcon, eax
mov wc.hIconSm, eax

invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax

; Registering window class
invoke RegisterClassEx, addr wc
test eax, eax
jnz @F
invoke MessageBox, hWnd, \
addr sz_string_1, \
NULL, \
MB_OK or MB_ICONERROR
xor eax, eax
jmp @L_exit

@@:
; Centering window
invoke GetSystemMetrics, SM_CXSCREEN
sub eax, hWnd1_Width
shr eax, 1
mov ebx, eax
invoke GetSystemMetrics, SM_CYSCREEN
sub eax, hWnd1_Height
shr eax, 1

; Создаём окно
invoke CreateWindowEx, 0,\
ADDR AppName, \;ClassName,\
ADDR AppName,\
WS_SYSMENU,\ ; or WS_DLGFRAME
ebx, eax,\
hWnd1_Width, hWnd1_Height,\
NULL,\
NULL,\
hInstance,\
NULL
test eax, eax
jnz @F
invoke MessageBox, hWnd, \
addr sz_string_2, \
NULL, \
MB_OK or MB_ICONERROR
xor eax, eax
jmp @L_exit
@@:
mov hWnd, eax

; Getting font
invoke GetStockObject, DEFAULT_GUI_FONT

mov lf.lfHeight, -11
mov lf.lfWeight, 500
invoke CreateFontIndirect, addr lf
mov hFontN, eax

invoke CreateWindowEx, 0, \
ADDR BtnClName, \
ADDR Textbutton1, \
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON, \
hWnd1_button1_X, hWnd1_button1_Y, \
hWnd1_button1_Width, hWnd1_button1_Height, \
hWnd, \
hWnd1_button1_ID, \
hInstance, \
NULL
test eax, eax
jnz @F
invoke MessageBox, hWnd, \
addr sz_string_3, \
NULL, \
MB_OK or MB_ICONERROR
xor eax, eax
jmp @L_exit
@@:
mov hWnd1_Button1,eax
invoke SendMessage, hWnd1_Button1, WM_SETFONT, hFontN, 1

invoke ShowWindow, hWnd, SW_SHOWNORMAL
invoke UpdateWindow, hWnd
db 5 dup (90h) ; 5 nops
@L1:
invoke GetMessage, addr msg, 0, 0, 0
test eax, eax
jz @L_2
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp @L1
@L_2:
mov eax, msg.wParam
@L_exit:
invoke ExitProcess, eax
Main endp
;__________________________________________________________________________________________


;__________________________________________________________________________________________
align 16
;__________________________________________________________________________________________


;__________________________________________________________________________________________
WndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.IF uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg == WM_COMMAND
mov ecx, lParam
jcxz @L1
mov eax,wParam
.IF ax == BN_CLICKED*65536 + hWnd1_button1_ID
invoke ExitProcess, 0
.ENDIF
@L1:
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
;__________________________________________________________________________________________

end start


And sorry for my bad English  ::) I'm from Russia and I'm just 17
Title: Re: How to create a hyperlink?
Post by: dedndave on April 15, 2012, 03:08:04 PM
Faiseur had some nice code....
http://www.masm32.com/board/index.php?topic=1899.0
Title: Re: How to create a hyperlink?
Post by: jj2007 on April 15, 2012, 05:00:33 PM
First things first: Welcome to the Forum :thumbu

There are two options that come spontaneously to my mind:
1. Use a RichEdit control. It can handle hyperlinks
2. By hand:
    - Create a font that looks like a hyperlink (blue, underlined)
    - TextOut
    - create a region around the text and check in WM_MOUSEMOVE if the cursor is inside the region
    - if yes, change the cursor
    - if a button is pressed, open the link.
Title: Re: How to create a hyperlink?
Post by: avcaballero on April 19, 2012, 04:33:22 PM
http://www.abreojosensamblador.net/Productos/AOE/html/Pags_en/Chap20.html#HiperenlaceResExternos
Title: Re: How to create a hyperlink?
Post by: dedndave on April 19, 2012, 11:36:32 PM
i guess we could use the pre-defined "syslink" system class   :P

http://msdn.microsoft.com/en-us/library/bb760706%28VS.85%29.aspx

it requires common controls 6 or better, so you'll want a manifest
i may play with it, later

something like this...

IDW_HYPERLINK  EQU 2012

        .DATA

icc            INITCOMMONCONTROLSEX <sizeof INITCOMMONCONTROLSEX,ICC_LINK_CLASS>
szSyslinkClass db 'syslink',0
szHyperlink    db 'For more information, <A HREF=\"http://www.microsoft.com\">click here</A>',0

        .CODE

        INVOKE  InitCommonControlsEx,offset icc
        INVOKE  CreateWindowEx,NULL,offset szSyslinkClass,offset szHyperlink,
                WS_VISIBLE or WS_CHILD or WS_TABSTOP,
                rect.left,rect.top,rect.right,rect.bottom,
                hDlg,IDW_HYPERLINK,hInstance,NULL
Title: Re: How to create a hyperlink?
Post by: Stas_Rocketman on April 25, 2012, 03:31:23 PM
Thanks, dedndave, it works. But that hyperlink just appears in window with blue and underlined font and nothing more. It is not clickable. Ummm... so now there is another problem. How to make that hypellink work? :D Maybe through the WndProcess function... or something else?
Title: Re: How to create a hyperlink?
Post by: dedndave on April 25, 2012, 03:45:04 PM
CreateProcess is one way to go
but, i think ShellExecute is the way to fly, in this case...
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx

ShellExecute(NULL, "open", "http://www.microsoft.com", NULL, NULL, SW_SHOWNORMAL)
you can get the link text from the syslink control (prefered - so it supports more than one syslink)
this will open in the user's default browser - you might use SW_SHOWDEFAULT, instead

as for detecting the click...
the parent window receives a WM_NOTIFY message when the link is clicked
lParam is a pointer to a NMHDR structure
the NMHDR.hwndFrom member will have a handle to the syslink control
the NMHDR.idFrom member will have the syslink control ID
the NMHDR.code member will be NM_CLICK

http://msdn.microsoft.com/en-us/library/bb760714%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/bb775583%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/bb775514%28v=vs.85%29.aspx
Title: Re: How to create a hyperlink?
Post by: dedndave on April 25, 2012, 04:04:11 PM
this will give you a starting place
        .DATA

szOpen  dw 'o','p','e','n',0

        .CODE
;
;
;
        LOCAL   sli:LITEM

    .if uMsg==WM_NOTIFY
        mov     edx,lParam
        .if [edx].NMHDR.code==NM_CLICK
            INVOKE  SendMessage,[edx].NMHDR.hwndFrom,LM_GETITEM,NULL,addr sli
            INVOKE  ShellExecuteW,NULL,offset szOpen,addr sli.szUrl,NULL,NULL,SW_SHOWDEFAULT
        .endif
    .elseif......

the string in the LITEM structure is unicode, supposedly
you can use it directly by using ShellExecuteW, or maybe convert it to ansi and use ShellExecute
for the ansi version, szOpen should be...
szOpen  db 'open',0

EDIT - oops, added ".endif"
Title: Re: How to create a hyperlink?
Post by: dedndave on April 25, 2012, 05:06:26 PM
a little better code
i added a test to make sure the message came from the syslink by checking the control ID
        .DATA

szOpen  dw 'o','p','e','n',0

        .CODE
;
;
;
        LOCAL   sli:LITEM

    .if uMsg==WM_NOTIFY
        mov     edx,lParam
        .if [edx].NMHDR.code==NM_CLICK
            .if [edx].NMHDR.idFrom==IDL_SYSLINK1
                INVOKE  SendMessage,[edx].NMHDR.hwndFrom,LM_GETITEM,NULL,addr sli
                INVOKE  ShellExecuteW,NULL,offset szOpen,addr sli.szUrl,NULL,NULL,SW_SHOWDEFAULT
            .endif
        .endif
    .elseif......
Title: Re: How to create a hyperlink?
Post by: Stas_Rocketman on May 14, 2012, 02:52:30 PM
Sorry, didn't understood, what does this line of code?
Quote from: dedndave on April 25, 2012, 05:06:26 PM

                INVOKE  SendMessage,[edx].NMHDR.hwndFrom,LM_GETITEM,NULL,addr sli

Is it extracting URL from the syslink text?
But thanks... I've modified this code a bit, but it also works properly.

.data
syslink1_Text db '<A HREF="">MASM forum</A>',0
syslink1_SiteAddr db 'www.masm32.com/board/index.php', 0
SyslinkClName db 'syslink', 0
...
invoke CreateWindowEx, 0, \
ADDR SyslinkClName, \
ADDR syslink1_Text, \
WS_VISIBLE or WS_CHILD or WS_TABSTOP, \
...
.ELSEIF uMsg == WM_NOTIFY
mov     eax,lParam
.IF [eax].NMHDR.code == NM_CLICK
.IF [eax].NMHDR.idFrom == hWnd1_syslink1_ID
push 0
push 0
push 0
push offset syslink1_SiteAddr
push offset sz_Open
push hWnd
call ShellExecute
.ENDIF
.ENDIF
.ELSEIF
Title: Re: How to create a hyperlink?
Post by: dedndave on May 14, 2012, 04:54:43 PM
yes - it gets the URL from the hyperlink

the method you are using will work fine if you have only one link

but, i was trying to make a more "generic" routine that could be used where you have more than one hyperlink
rather than looking up which link sent the message in some kind of table - just get it from the link, itself
Title: Re: How to create a hyperlink?
Post by: Force on May 14, 2012, 08:12:58 PM
Simple HyperLink

Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 16, 2012, 01:09:38 AM
Quote from: Force on May 14, 2012, 08:12:58 PM
Simple HyperLink



Hi there Force ...nice to meet you !
You link leads us to a page were you have Call Listview From Menu
"AniMultipleWindows.zip"   

I noticed that you still have the black corners appearing .... we solved that if you are interested here : http://www.masm32.com/board/index.php?topic=17255.msg144527#msg144527

Download:

http://www.masm32.com/board/index.php?action=dlattach;topic=17255.0;id=9628

just 2 extra lines in the code
Title: Re: How to create a hyperlink?
Post by: dedndave on May 16, 2012, 01:31:08 AM
yah - that's not a great solution to the black corners issue   :P
i got rid of them by moving the CreateWindowEx call from WM_CREATE
but - i have also managed to create child windows without black corners in WM_CREATE
i haven't found the magic style flag that is causing this, yet - lol
it may be WS_CLIPCHILDREN

as for the link to the attachment - i downloaded it fine, here
maybe you have a virus, Heather   :eek
Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 16, 2012, 01:32:44 AM
Quote from: dedndave on May 16, 2012, 01:31:08 AM

as for the link to the attachment - i downloaded it fine, here
maybe you have a virus, Heather   :eek

???? what do you mean? I never said it did not download fine
Title: Re: How to create a hyperlink?
Post by: dedndave on May 16, 2012, 01:33:56 AM
sorry - i misunderstood...
QuoteHi there Force ...nice to meet you !
You link leads us to a page were you have Call Listview From Menu
"AniMultipleWindows.zip"
Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 16, 2012, 01:35:04 AM
LOL

the link in his hyperlink example
Title: Re: How to create a hyperlink?
Post by: Gunner on May 16, 2012, 01:44:23 AM
Here is one way to make a hyperlink
http://www.dreamincode.net/forums/topic/241669-masm-creating-a-hyperlink/
Title: Re: How to create a hyperlink?
Post by: dedndave on May 16, 2012, 02:25:04 AM
Quote from: hfheatherfox07 on May 16, 2012, 01:35:04 AM
LOL

the link in his hyperlink example
ohhhhhhhhhh   :P

Rob - nice example
i suspect you could also do it by displaying it as an HTML with an "a" tag
Title: Re: How to create a hyperlink?
Post by: Force on May 16, 2012, 08:38:54 AM
Hi hfheatherfox07
nice 2 meet u too
At the begining i just wanted to call listview from menu later i changed idea
closing menu.... opening child window like when we were programing on DOS times
I got ur example its nice I may use it in coming projects

in fact my plan is small window will get bigger slowly while its opening
and it will get smaller while its closing I did it in java b4
but i couldnt do it in assembly yet
do you have any idea for it ?
Title: Re: How to create a hyperlink?
Post by: dedndave on May 16, 2012, 02:30:01 PM
neat idea   :P

in WM_CREATE, you could use SetTimer
then handle WM_TIMER messages to set the window size

the same could be done in reverse when you receive WM_DESTROY
Title: Re: How to create a hyperlink?
Post by: Force on May 16, 2012, 03:24:11 PM
Thanks Dave i will try it soon  :U
Title: Re: How to create a hyperlink?
Post by: guga on May 17, 2012, 02:46:50 AM
excelent code gunner....many tks.
Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 17, 2012, 07:29:39 PM
Quote from: Force on May 16, 2012, 08:38:54 AM
Hi hfheatherfox07
nice 2 meet u too
At the begining i just wanted to call listview from menu later i changed idea
closing menu.... opening child window like when we were programing on DOS times
I got ur example its nice I may use it in coming projects

in fact my plan is small window will get bigger slowly while its opening
and it will get smaller while its closing I did it in java b4
but i couldnt do it in assembly yet
do you have any idea for it ?

I think I just might .... I have an example that lets you animate the window  by using 2 destination rects ...I have an example were I can make the window animate to open from the corner of the screen to open and close there too .... but you can do what ever you want it to do with different co-ordinates in the rect definition
I made a note for my self and bring it on my flash drive tomorrow and upload it for you
....in any case Dave was right..... you are going to have to use a timer to slow down the animation
Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 18, 2012, 11:09:25 PM
Quote from: Force on May 16, 2012, 08:38:54 AM
Hi hfheatherfox07
nice 2 meet u too
At the begining i just wanted to call listview from menu later i changed idea
closing menu.... opening child window like when we were programing on DOS times
I got ur example its nice I may use it in coming projects

in fact my plan is small window will get bigger slowly while its opening
and it will get smaller while its closing I did it in java b4
but i couldnt do it in assembly yet
do you have any idea for it ?

Disregard what I said before ... I had another Brain fart day .... LOL..... in the invoke animatewindow API call  the 500 is your timer ...there is no need to add timer
switch all your 500 to 2500 (it is in milliseconds) also you can make the window open like in DOS and close to here is your source modified to do that ...at least this is what I think you want  :U

Let me know if this is the effect you wanted when you open and close child window
For the heck of it since I promised that other source I brought it ....SO I will post it
Title: Re: How to create a hyperlink?
Post by: Force on May 19, 2012, 04:51:22 PM
heather what i mean is ... opening window  from the smallest to bigger *by changing size*
i got ur ani window example b4 its nice
Title: Re: How to create a hyperlink?
Post by: dedndave on May 19, 2012, 06:01:50 PM
i think it does change size - lol
it's hard to tell because it's also moving
Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 19, 2012, 07:51:01 PM
Quote from: Force on May 19, 2012, 04:51:22 PM
heather what i mean is ... opening window  from the smallest to bigger *by changing size*
i got ur ani window example b4 its nice

That is doable ... I found a bunch of hex value commands that are not included in the windows.inc .... instead of just AW_CENTER etc.....
can you please post a small video or a gif of video ..... SO I know what you want exactly ?
Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 19, 2012, 08:22:18 PM
Quote from: dedndave on May 19, 2012, 06:01:50 PM
i think it does change size - lol
it's hard to tell because it's also moving

The window opening from one corner slowly in diagonal to open that I can do  .....

In theory we should be able to make the window move across the screen  with a timer proc
invoke MoveWindow,hwnd,0,0,rec.right,rec.bottom,TRUE   to     invoke MoveWindow,hwnd,50,50,rec.right,rec.bottom,TRUE
we we'd need system metrics in there some were too  LOL

Wat do you think dedndave ?
Title: Re: How to create a hyperlink?
Post by: dedndave on May 20, 2012, 12:32:57 AM
welllll
i think you start with....
where and how big you want the window to be when you are done
find the center of that window
make smaller windows centered on the same spot, gradually larger and larger
it would take a little experimentation to see how many steps and how fast
it might flicker and not be as cool as it sounds

although that would be kind of a cool effect...
i like my shit to SNAP onto the screen - lol
i want it to appear to be done, just BEFORE i hit enter   :bg

i was thinking of drawing the window while it is invisible - then BANG - snap it onto the screen
back in the days of DOS, we used to go to great lengths to achieve that effect

a good example is one i am working on now
it displays a bitmap, which is pretty large
just before it does, it finds the average color value of that bitmap to use as the background color
i played some tricks and got that average calculation to be pretty fast, but there is still a slight delay
i could make the app window and everything invisible - then snap it on when done   :8)
Title: Re: How to create a hyperlink?
Post by: Force on May 20, 2012, 09:28:27 PM
Heather

I mention about that program I wrote it in Java B4

I will try to make it in assembly too but I m lil bit bussy lately :bg
Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 21, 2012, 12:13:37 AM
I have something Close .... but your does all 4 sides
I will see If I can edit mine to do that some how
Title: Re: How to create a hyperlink?
Post by: hfheatherfox07 on May 21, 2012, 07:14:02 PM
I was not able to duplicate that .....I do have some once that you might like ....just change the time on them to make slower or faster