Win32 Advanced Path: Add a hyperlink button to the screen lock Software

Source: Internet
Author: User
Tags textout

Preface:

Everything in windows is a window. The hyperlink we see is also a window, as shown below:

Place the cursor on the home page of the blog Garden of Zhao Eldest Brother and on the software button. The font on the button changes from green to red, and the mouse pointer changes to the hand shape, click the left mouse button to open the configured webpage in the default browser.

PS: To be completely consistent with our common hyperlinks, you also need some button self-painting knowledge to integrate the buttons with the background.

Implementation Analysis:

1. Create a button window. The button window class is customized in windows. You can specify the category and style when creating the window.

2. Capture and process messages that get and lose the mouse. If the mouse is successful, you can move the mouse over the button to change the color and shape of the button.

3. Click the processing button and click the next button to call the browser to open the specified page.

Detailed process:

1. the button creation button provided by windows is better. You can call this class and specify the window style to create a button similar to the button in MFC. Here, I want to make a button without obvious pressure marks, the BS_OWNDRAW style is used.

M_hInfoButton = createjavaswex (WS_EX_NOACTIVATE,
TEXT ("button "),
TEXT ("infobutton "),
WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
30,
50,
100,
50,
HWnd,
(HMENU) SUBWND_INFO_BUTTON,
(LPCREATESTRUCT) lParam)-> hInstance,
NULL );
If (! M_hInfoButton)
{
MessageBox (NULL, TEXT ("create Info Button fail"), TEXT ("policy"), MB_ICONEXCLAMATION );
}

The two key parameters have been marked with red, and other style of the button class can be viewed by F12 + F1. Anyone who has used VS can understand them.

2. the message obtained and lost mouse are processed by the main thread window. When there is a multi-layer subwindow relationship, the message will still be sent to the main thread window, this message is captured to change the button text color and Mouse shape.

Case WM_SETCURSOR:
If (HWND) wParam = m_hADHandle)
{
SetCursor (LoadCursor (NULL, IDC_HAND ));
HDC hSubdc = GetDC (HWND) wParam );
SetTextColor (hSubdc, RGB (255, 0, 0 ));
TextOut (hSubdc, 0, 0, TEXT (""), sizeof (TEXT (" ")));
ReleaseDC (m_hADHandle, hSubdc );
Return TRUE;
}
// All messages that receive or lose the mouse are processed by the main window of the thread.
Else if (HWND) wParam = m_hCopyRightButton)
{
SetCursor (LoadCursor (NULL, IDC_HAND ));
HDC hSubdc = GetDC (HWND) wParam );
SetTextColor (hSubdc, RGB (255, 0, 0 ));
TextOut (hSubdc, 0, 0, TEXT ("about software"), sizeof (TEXT ("about software ")));
ReleaseDC (m_hCopyRightButton, hSubdc );
Return TRUE;
}
Else
{
HDC hSubdc = GetDC (m_hADHandle );
SetTextColor (hSubdc, RGB (0,255, 0 ));
TextOut (hSubdc, 0, 0, TEXT (""), sizeof (TEXT (" ")));
ReleaseDC (m_hADHandle, hSubdc );
HDC hCopyRightdc = GetDC (m_hCopyRightButton );
SetTextColor (hCopyRightdc, RGB (0,255, 0 ));
TextOut (hCopyRightdc, 0, 0, TEXT ("about software"), sizeof (TEXT ("about software ")));
}
Break;

If you want to change the shape of the mouse, manually shield the DefWindowProc. Otherwise, the mouse flickering hand type will be changed back, And the DefWindowProc method will be blocked, such as code. You can return TRUE after setting the Mouse shape.

3. click the button to call the browser and open the specified page. This is easy to handle. Click the left-click message and call the API to open the page.

Case WM_COMMAND:
Switch (LOWORD (wParam ))
{
Case SUBWND_COPYRIGHT_BUTTON:
Switch (HIWORD (wParam ))
{
Case BN_CLICKED:
ShellExecute (hWnd, TEXT ("open"), TEXT ("http://www.cnblogs.com/learn-my-life/"), TEXT (""), TEXT (""), SW_SHOWNORMAL );
Break;
Default:
Break;
}
}
Break;

The message clicked by the button is processed by the parent window corresponding to the button, instead of the main thread window. You can call API-ShellExecute to open the specified page in the browser. The code is very detailed.

Now, the screen lock software has added a function to configure the interface thread to implement hyperlinks. In the future, typical windows controls and xml file parsing will be added. If you are interested, please add them to your attention or fans.

The complete code will be uploaded and pasted later, so stay tuned.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.