How to create a link to a website in a window?

gaurav.bhorkar
@gauravbhorkar-Pf9kZD โ€ข Oct 25, 2024

How to create a link to a website in a window?

Example Window:
[โ€‹IMG]
When we click the link, the webpage should open in the default web browser.

Is there any Windows API function to do this?

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Jan 12, 2010

    Can anyone answer my question?

  • Prasad Ajinkya

    @prasad-aSUfhP Jan 12, 2010

    Hey Gaurav,
    Why not use a simple VB application to do this?

  • gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Jan 12, 2010

    I don't know VB.

    I am creating a simple window program in C.

  • Prasad Ajinkya

    @prasad-aSUfhP Jan 13, 2010

    I am not so strong in C (perhaps others can help you). But suffice to say you have to create event handlers and events.

    What say folks?

  • Kaustubh Katdare

    @thebigk Jan 13, 2010

    What programming language are you using? If its simple HTML:

    [url=https://www.CrazyEngineers.com/]CrazyEngineers[/url] 

    The target attribute will tell the browser to open the page in a new window.

    Is that what you are looking for? ๐Ÿ˜•

  • Manish Goyal

    @manish-r2Hoep Jan 13, 2010

    Gaurav This is very interesting question that today you ask...i don't know much about it..but what my mind gives me this ..

    First of all you have to include <stdlib.h> file.in your code..Now use something like this

    Create a button on window ..when button will be clicked then this code will be executed
    {
    system("browser.bat");
    }
    here browser.bat will contain this name firefox.exe
    now when ever you click button then browser will open
    Now Question arises how to open a desired link..I will try this..
    I hope this will help you

  • Manish Goyal

    @manish-r2Hoep Jan 13, 2010

    Gaurav just add this line to .bat file
    @echo off.
    start "link which you want to open"

    Just give it a try i am sure you will achieve what you want..and Please post your code here

  • gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Jan 13, 2010

    The_Big_KWhat programming language are you using? If its simple HTML:

    [url=https://www.CrazyEngineers.com/]CrazyEngineers[/url] 
    The target attribute will tell the browser to open the page in a new window.

    Is that what you are looking for? ๐Ÿ˜•

    Ya, this works in HTML but I am creating a simple window in C, which should link to a webpage.

  • gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Jan 13, 2010

    goyal420Gaurav just add this line to .bat file
    @echo off.
    start "link which you want to open"

    Just give it a try i am sure you will achieve what you want..and Please post your code here

    I'll try your method and get back on this thread.

  • gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Jan 13, 2010

    @ Goyal
    The solution you suggested is not working. I think it works only for console applications.


    But a very intense Google search got this solution :-

    ShellExecute(hwnd, "open",
                    "https://www.example.com",
                           NULL, NULL, SW_SHOWNORMAL);

    Its a windows API function and it is working perfectly.

    Thank you guys for your suggestions.

  • Manish Goyal

    @manish-r2Hoep Jan 13, 2010

    The solution you suggested is not working. I think it works only for console applications.

    Gaurav can you please post your code?
    Actually i have tried this ..and this is working fine..

  • gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Jan 13, 2010

    Here is the code snippet. I hope you know the contents of WinMain () function.

    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                 
        {
            case WM_DESTROY:
                PostQuitMessage (0);       
                break;
            case WM_PAINT:
                 OnPaint (hwnd);
                 break;
            case [B]WM_LBUTTONDOWN:[/B]       /*To deal with the mouse click*/
                 OnClick (hwnd, LOWORD(lParam), HIWORD(lParam));
                 break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    
    void OnPaint (HWND hwnd)
    {
         HDC hdc;
         PAINTSTRUCT ps;
         HFONT hfont;
         LOGFONT f = {0};
         HGDIOBJ holdfont;
         
         hdc = BeginPaint (hwnd, &ps);
         
         f.lfUnderline = 1;
         
         hfont = CreateFontIndirect (&f);
         holdfont = SelectObject (hdc, hfont);
         
         SetTextColor (hdc, RGB (0, 0, 255));
         
         TextOut (hdc, 0, 0, "Go to Google", 12);
         
         SelectObject (hdc, holdfont);
         DeleteObject (hfont);
         
         EndPaint( hwnd, &ps);
         
    }
    
    void OnClick (HWND hwnd, int x, int y)
    {
         if ((x>0) && (x<85) && (y>0) && (y<15))
         {
                   [B]ShellExecute(hwnd, "open",
                   "https://www.google.com",
                   NULL, NULL, SW_SHOWNORMAL);[/B]
         }
    }
    

    This is the output.

    [โ€‹IMG]