I am using plain C ,and here is the code :
Creating the button:
HWND hBTN = CreateWindow(_T("button"), _T("AAasfasdfdsa"), WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 10, 10, 100, 100, hWnd, NULL, hInst, NULL);
Call DWM function:
DWM_BLURBEHIND bb = { 0 };
bb.dwFlags = DWM_BB_ENABLE;
bb.fEnable = true;
bb.hRgnBlur = NULL;
MARGINS margins = { -1, -1, -1, -1 };
DwmExtendFrameIntoClientArea(hWnd, &margins);
image demonstrates:
The text becomes transparent because the black colour is treated as the transparency key.
Therefore, you just need to set another transparency key for the window:
SetWindowLong(hWnd,GWL_EXSTYLE,WS_EX_LAYERED);
SetLayeredWindowAttributes(hWnd,RGB(200,201,202),0,LWA_COLORKEY);
Related
I am using the Win32 API. I have this code that creates an edit control:
CreateWindowW(L"Edit", L"", WS_VISIBLE | WS_CHILD, 100, 100, 200, 20, hand, NULL, NULL, NULL);
How do I put placeholder text inside of this edit box?
You can use SendMessage with EM_SETCUEBANNER:
HWND editCtlHandle = CreateWindowW(L"Edit", L"", WS_VISIBLE | WS_CHILD | WS_BORDER, 100, 100, 200, 20, hWnd, NULL, hInstance, NULL);
WCHAR placeholderText[] = L"Enter here";
SendMessage(editCtlHandle, EM_SETCUEBANNER, FALSE, (LPARAM)placeholderText);
Or use Edit_SetCueBannerText macro:
Edit_SetCueBannerText(editCtlHandle, placeholderText);
The result will like this:
How can I add some elements(window) in my tab?
Use these:
INITCOMMONCONTROLSEX icex;
TCITEMW tie;
WM_CREATE:
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icex);
Tab = CreateWindowW(WC_TABCONTROLW, NULL, WS_CHILD | WS_VISIBLE,
0, 0, 200, 150, hwnd, (HMENU)ID_TABCTRL, NULL, NULL);
CreateWindowW(WC_BUTTONW, L"Add", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
250, 50, 100, 25, hwnd, (HMENU)BTN_ADD, NULL, NULL);
In BTN_ADD I make two tabs.
case BTN_ADD: {
tie.mask = TCIF_TEXT;
tie.pszText = (LPWSTR)L"TAB1";
SendMessageW(Tab, TCM_GETITEMCOUNT, 0, 0);
SendMessageW(Tab, TCM_INSERTITEMW, 1, (LPARAM)(LPTCITEM)&tie);
tie.mask = TCIF_TEXT;
tie.pszText = (LPWSTR)L"TAB2";
SendMessageW(Tab, TCM_GETITEMCOUNT, 0, 0);
SendMessageW(Tab, TCM_INSERTITEMW, 2, (LPARAM)(LPTCITEM)&tie);
SendMessageW(Tab, TCM_GETITEMCOUNT, 0, 0);
//Add item in tab
CreateWindowW(WC_BUTTONW, L"BTN", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
50, 50, 30, 30, Tab, NULL, NULL, NULL);
break;
}
But this button added in hwnd (main), and when I open other tab, I continue to see this button. I need add content in a certain tab.
First tab
Second tab
I solved a problem. Understand, that need use a MoveWindow function. These tabs isn't content, but content attachment to window (Tab). I just created Tab via:
Tab = CreateWindowW(WC_TABCONTROLW, NULL, WS_CHILD | WS_VISIBLE,
0, 0, TAB_WEIGHT, TAB_HEIGHT,
hwnd, (HMENU)ID_TABCTRL, NULL, NULL);
Then I put down a few window (ListBox) on the Tab (which window).
ListBoxProcesses = CreateWindowEx(WS_EX_CLIENTEDGE, L"ListBox", NULL,
WS_CHILD | WS_VISIBLE | LBS_STANDARD | LBS_WANTKEYBOARDINPUT,
0, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100,
Tab, (HMENU)ID_LIST, NULL, NULL);
ListBoxModules = CreateWindowEx(WS_EX_CLIENTEDGE, L"ListBox", NULL,
WS_CHILD | WS_VISIBLE | LBS_STANDARD | LBS_WANTKEYBOARDINPUT,
TAB_WEIGHT, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100,
Tab, (HMENU)ID_LIST, NULL, NULL);
But there is one feature. First window (ListBoxProcesses) has a horizontal position 0. But second window (ListBoxModules) has TAB_WEIGHT. After I choose other tab, I call a MoveWindow function and its shifts my content.
Btw, yes, I understand that need use WM_NOTIFY message which contains this:
switch (wParam)
{
case ID_TABCTRL: {
switch (SendMessageW(Tab, TCM_GETCURFOCUS, 0, 0))
{
case FIRST_PAGE: {
MoveWindow(ListBoxProcesses, 0, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100, TRUE);
MoveWindow(ListBoxModules, TAB_WEIGHT, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100, TRUE);
break;
}
case SECOND_PAGE: {
MoveWindow(ListBoxProcesses, -TAB_WEIGHT, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100, TRUE);
MoveWindow(ListBoxModules, 0, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100, TRUE);
break;
}
default:
break;
}
break;
}
default:
break;
}
First tab
Second tab
I am attempting to get a tooltip to appear over a Static control. I've followed the MSDN example almost word for word but the tooltip doesn't appear. Maybe I need to initialise a specific common control prior to creating a tooltip? Right now I initialise ICC_STANDARD_CLASSES and ICC_COOL_CLASSES.
Any idea why the tooltip doesn't appear?
case WM_CREATE:
{
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC = ICC_STANDARD_CLASSES | ICC_COOL_CLASSES;
InitCommonControlsEx(&iccx);
HWND hwndTool = CreateWindowEx(0, _T("Static"), _T("Abc"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
10, 10, 100, 100, hWnd, (HMENU)50001, hInst, NULL);
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hWnd, NULL,
hInst, NULL);
// Associate the tooltip with the tool.
LPTSTR pszText = _T("Def");
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hWnd;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText = pszText;
output(_T("Is null: %d\n"), hwndTip == NULL); // output = Is null: 0
output(_T("Send res: %d\n"), SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo)); // output = Send res: 0
}
break;
I'm trying to create a scrollable child-window within a window. The child-window is supposed to have scrollbars; the scrollbars appear but are totally unresponsive. Window creation code:
// "mainwindow" is the handle of the main application window.
HWND wnd = CreateWindow(WC_STATIC, NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL,
10, 100, 300, 300, mainwindow, NULL, GetModuleHandle(0), 0);
SCROLLINFO si = { 0 };
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nMax = 800;
SetScrollInfo(g_wnd, SB_VERT, &si, true);
I've set a custom WNDPROC for the new child-window, but no scrolling-messages arrive. I've found numerous examples on the internet, but none of them either work or are about using scrollbars in child-windows.
As Hans Passant pointed out, a scrollable child-window needs its own windows class.
Example code:
HWND create_scroll_window(HWND parent)
{
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.hInstance = GetModuleHandle(0);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszClassName = TEXT("MyScrollWinClass");
if (!RegisterClassEx(&wcex)) return 0;
HWND hWnd = CreateWindow(_T("MyScrollWinClass"), _T(""), WS_CHILD | WS_BORDER | WS_VISIBLE | WS_VSCROLL, 20, 20,
300, 300, parent, NULL, wcex.hInstance, NULL);
return hWnd;
}
I'm using C - (NO MFC or GDI+) :-)
What I want is to set the opacity of my child window to let say 100 (my child window is a STATIC control). I was wondering if this is even possible and if so can someone please point me to the right direction on how to do it.
Here is my setup:
I create my Parent window as follow:
HWND hWnd;
WNDCLASS wndCls_s;
wndCls_s.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndCls_s.lpfnWndProc = MainWndProc;
wndCls_s.cbClsExtra = 0;
wndCls_s.cbWndExtra = 0;
wndCls_s.hInstance = hInstance;
wndCls_s.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BSN_64));
wndCls_s.hCursor = LoadCursor(NULL, IDC_ARROW);
wndCls_s.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
wndCls_s.lpszMenuName = NULL;
wndCls_s.lpszClassName = pszCName;
if (RegisterClass(&wndCls_s) == 0)
return EXIT_FAILURE;
/* Creating Window */
hWnd = CreateWindow(
pszCName, pszCName,
WS_VISIBLE | WS_POPUP | WS_SYSMENU | WS_CLIPCHILDREN,
0, 0, WND_WIDTH, WND_HEIGHT,
NULL, NULL, hInstance, NULL);
In my MainWndProc:
case WM_CREATE:
{
HWND hWndChild = CreateWindow(
L"STATIC", (LPCTSTR) NULL,
WS_CHILD | WS_VISIBLE,
10, 10, 110, 110,
hWnd, (HMENU) (int) 10000,
g_hInst, NULL);
}
break;
case WM_CTLCOLORSTATIC:
{
COLORREF dwColor;
dwColor = RGB(255, 0, 0);
hDC = (HDC) wParam;
//SetBkColor(hDC, dwColor);
SetBkMode(hDC, TRANSPARENT);
/*
This is not going to work for child window
SetWindowLong(
hWnd, GWL_EXSTYLE,
GetWindowLong((HWND)lParam, GWL_EXSTYLE) & ~WS_EX_LAYERED);
SetLayeredWindowAttributes(
(HWND)lParam, 0, 100, LWA_ALPHA);
RedrawWindow((HWND)lParam, NULL, NULL, RDW_ERASE | RDW_INVALIDATE);
*/
if (g_hBrushRed == NULL)
g_hBrushRed = CreateSolidBrush(dwColor);
}
return (INT_PTR)g_hBrushRed;
Why do you enable transparency with TRANSPARENT if you are going to return a valid brush for the background? You don't need SetBkMode and your red brush will be used by the control then.