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

    gaurav.bhorkar

    gaurav.bhorkar

    @gauravbhorkar-Pf9kZD
    Updated: Oct 25, 2024
    Views: 987
    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?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • gaurav.bhorkar

    MemberJan 12, 2010

    Can anyone answer my question?
    Are you sure? This action cannot be undone.
    Cancel
  • Prasad Ajinkya

    MemberJan 12, 2010

    Hey Gaurav,
    Why not use a simple VB application to do this?
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberJan 12, 2010

    I don't know VB.

    I am creating a simple window program in C.
    Are you sure? This action cannot be undone.
    Cancel
  • Prasad Ajinkya

    MemberJan 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?
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorJan 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? 😕
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJan 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
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJan 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
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberJan 13, 2010

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberJan 13, 2010

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberJan 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.
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJan 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..
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberJan 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]
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register