Code for Small C++ Class to Transform Any Static Control
into a Hyperlink Control?
Answer / Rahul Chandra
To transform any static control into a hyperlink in C++, you can use the `SetWindowLongPtr()` function to set a custom window procedure and handle the `WM_LBUTTONDOWN` message:n```cppn#include <windows.h>n#include <shlobj.h>nnclass HyperlinkStatic : public CWindow {npublic:n HyperlinkStatic(HWND parent) : CWindow(parent, WC_STATIC) {n SetLongPtr(GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));n RegisterClass();n }nprivate:n static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {n auto hWndUserData = GetWindowLongPtr(hwnd, GWLP_USERDATA);n if (hWndUserData == reinterpret_cast<LONG_PTR>(this)) {n if (message == WM_LBUTTONDOWN) {n POINT pt;n GetCursorPos(&pt);n ScreenToClient(hwnd, &pt);n const auto range = GetTextRange();n SendMessage(hwnd, EM_EXSETSEL, 0, MAKELPARAM(range.cpMin, range.cpMax));n OpenURL(this);n }n }n return DefWindowProc(hwnd, message, wParam, lParam);n }n void RegisterClass() {n WNDCLASSEXW wcex;n ZeroMemory(&wcex, sizeof(wcex));n wcex.cbSize = sizeof(wcex);n wcex.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;n wcex.lpfnWndProc = WndProc;n wcex.hInstance = GetModuleHandle(nullptr);n wcex.lpszClassName = TEXT("HyperlinkStatic");n RegisterClassEx(wcex);n }n void OpenURL(HWND hwnd) const {n const auto textRange = GetTextRange();n if (textRange.cpMin <= textRange.cpMax) {n IShellLink* psl;n CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));n PWSTR url = nullptr;n if (SUCCEEDED(psl->SetPath(textRange.chrg.cpMin, &url))) {n IFACEMETHODCALLMACRO(psl, SetAttributes, DWORD(LNK_INVISIBLE | LNK_NOREPRESENTATION), 0);n CoTaskMemFree(url);n }n psl->Release();n }n }n TEXTMETRICW textMetrics;n CHARRANGE textRange = {0};n void GetTextRange() {n if (GetTextLength(&textRange.cpMax) > 0) {n GetText(textRange.chrg, &textMetrics, CFM_TEXT);n textRange.cpMax += textRange.cpMin + textMetrics.tmAveCharWidth;n }n }n};n``
| Is This Answer Correct ? | 0 Yes | 0 No |
Coin Problem You are given 9 gold coins that look identical. One is counterfeit and weighs a bit greater than the others, but the difference is very small that only a balance scale can tell it from the real one. You have a balance scale that costs 25 USD per weighing. Give an algorithm that finds the counterfeit coin with as little weighting as possible. Of primary importance is that your algorithm is correct; of secondary importance is that your algorithm truly uses the minimum number of weightings possible. HINT: THE BEST ALGORITHM USES ONLY 2 WEIGHINGS!!!
1 Answers Motorola, Qatar University,
Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.
3 Answers TCS, Vimukti Technologies, Wipro,
find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L
Given 1 to n random number, find top 10 maximum numbers and explain the time complexity of the algorithm.
how to take time as input in the format (12:02:13) from user so that controls remains between these columns?
Display Pattern: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 …
Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).
Min-Max Write an algorithm that finds both the smallest and largest numbers in a list of n numbers and with complexity T(n) is at most about (1.5)n comparisons.
10 Answers ABC, College School Exams Tests, ITC Infotech, Kyambogo University, Qatar University,
write a program to perform generic sort in arrays?
Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.
5 Answers ADP, Amazon, HCL, IBM, Infosys, Satyam, TCS, Vimukti Technologies,
How can I Draw an ellipse in 3d space and color it by using graph3d?
Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?