• Курсы Академии Кодебай, стартующие в мае - июне, от команды The Codeby

    1. Цифровая криминалистика и реагирование на инциденты
    2. ОС Linux (DFIR) Старт: 16 мая
    3. Анализ фишинговых атак Старт: 16 мая Устройства для тестирования на проникновение Старт: 16 мая

    Скидки до 10%

    Полный список ближайших курсов ...

Ошибка компиляции в Dev C++

  • Автор темы alekssgor
  • Дата начала
A

alekssgor

При компиляция в среде Dev C++ выдаётся ошибка связанная с прозрачностью окна. Неизвестная функция. Хотя описана в winuser.h
В С++Builder6(стоит на том же компе) всё компилируется

Пример:
C++:
int Transparency=80;
long ExtStyle=GetWindowLong(hwnd,GWL_EXSTYLE);
SetWindowLong(hwnd ,GWL_EXSTYLE,ExtStyle|WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd,0,(255*Transparency)/100,LWA_ALPHA);//Ошибка неизвестая функция.
 
V

vital

2 Варианта решения.
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">1</div></div><div class="sp-body"><div class="sp-content">
you should load user32.dll to get the function:
Code:
C++:
hUser32=GetModuleHandle(TEXT("USER32.DLL"));

now prototype the function, get it from the module loaded and check it:
Code:
C++:
typedef int (WINAPI *lpfnSetLayeredWindowAttributes) (HWND , COLORREF , BYTE , DWORD );
lpfnSetLayeredWindowAttributes slwa_function;
if(!(slwa_function=(lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes")))
{/*error*/}

prepare the control or the window to be transparent:
Code:
C++:
SetWindowLong(hwnds,GWL_EXSTYLE,GetWindowLong(hwnd,GWL_EXSTYLE)|0x00080000);
/*
of course you can set a definition (if you haven't it in the used headers), to make a more readable code
#define WS_EX_LAYERED 0x00080000
*/

you've got it, just select a transparent color and apply:
Code:
C++:
COLORREF ctransparent=RGB(128,128,128);
slwa_function(hwnd,ctransparent,0,1);
Tha function gets 4 args: the handle to the target control, the color, the opacity (0->invisible, 255->visible), and an action. the action is LWA_COLORKEY or LWA_ALPHA, the first sets to transparent the specifyed color, and the second applies the alpha transparency to the color, just play a bit with them.


"...Also, has anyone ever got a semi-transparent window working in Dev-C++?..."
Yes, use the alpha semi transparency instead of use the hole color transparency
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">2</div></div><div class="sp-body"><div class="sp-content">
Here is the code that should work in any compiler and on every version of Windows:

Code:
C++:
#ifndef WS_EX_LAYERED
#define WS_EX_LAYERED 0x00080000
#endif

// Prototype for Win2000/XP API: SetLayeredWindowAttributes
typedef BOOL (WINAPI * SLWAProc)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);

#ifndef LWA_COLORKEY
#define LWA_COLORKEY			0x00000001
#define LWA_ALPHA			  0x00000002

#define ULW_COLORKEY			0x00000001
#define ULW_ALPHA			  0x00000002
#define ULW_OPAQUE			 0x00000004
#endif

static SLWAProc pSLWA = NULL;

BOOL SetWindowTransparency (HWND hwnd, int percent)
{
static short beenHere = FALSE;

HMODULE hUser32;

if (!pSLWA && !beenHere) {
beenHere = TRUE;
hUser32 = GetModuleHandle ("USER32.DLL");

pSLWA = (SLWAProc)GetProcAddress(hUser32, (char *)"SetLayeredWindowAttributes");

}

if (!pSLWA)
return (FALSE); // No support for translucent windows!

SetWindowLong (hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);

return (pSLWA(hwnd, 0, (BYTE)((255 * percent) / 100), LWA_ALPHA));  // percent% alpha
}

BOOL RemoveWindowTransparency (HWND hwnd)
{
SetWindowLong (hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);

RedrawWindow (hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);

return (TRUE);
}
 
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!