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

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

  • gaurav.bhorkar
    gaurav.bhorkar
    Can anyone answer my question?
  • Prasad Ajinkya
    Prasad Ajinkya
    Hey Gaurav,
    Why not use a simple VB application to do this?
  • gaurav.bhorkar
    gaurav.bhorkar
    I don't know VB.

    I am creating a simple window program in C.
  • Prasad Ajinkya
    Prasad Ajinkya
    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
    Kaustubh Katdare
    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 Goyal
    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 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 Goyal
    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
    gaurav.bhorkar
    The_Big_K
    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? 😕
    Ya, this works in HTML but I am creating a simple window in C, which should link to a webpage.
  • gaurav.bhorkar
    gaurav.bhorkar
    goyal420
    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
    I'll try your method and get back on this thread.
  • gaurav.bhorkar
    gaurav.bhorkar
    @ 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 Goyal
    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
    gaurav.bhorkar
    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]

You are reading an archived discussion.

Related Posts

Hello all, I have a project in Enhancing images and Remote sensing. My task is to make a software controling a specified unit (Car, Boat, ...). I tried to use...
With immense pleasure we, on behalf of Department of Computer Engineering, IT-BHU, invite you to participate in Codefest, a completely Online technical festival, which is being organized by our department...
I want to do summer internship this year.but cannot find a good company.i am a computer science 3rd year student doing b.tech from u.p.t.u.,noida.can any one help??
i am a 3rd year b.tech student.i want to know how to get a new miniproject?
how do i interface java with matlab?? I need to call Matlab functions in Java.I have no idea how to do it.Can anyone help me out for the same? 😕