From 1ed8f6b2e35e507f7357b978f1cd1dea58301dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E8=B5=AB?= <1160386205@qq.com> Date: Mon, 17 Dec 2018 21:58:26 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=AA=97=E4=BD=93=E9=98=B4=E5=BD=B1=20bug?= =?UTF-8?q?=E4=BF=AE=E4=BA=86=E5=8D=8A=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyWindow 4.0/EasyWindow.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/EasyWindow 4.0/EasyWindow.c b/EasyWindow 4.0/EasyWindow.c index c7bd22c..9e53d85 100644 --- a/EasyWindow 4.0/EasyWindow.c +++ b/EasyWindow 4.0/EasyWindow.c @@ -1247,8 +1247,10 @@ LRESULT CALLBACK EZParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM } } + Sleep(2000); switch (message) { + case WM_CREATE: { ezWnd = (EZWND)(((LPCREATESTRUCT)lParam)->lpCreateParams); @@ -1528,8 +1530,7 @@ LRESULT CALLBACK EZParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM int iRet = DefWindowProc(hwnd, message, wParam, lParam); EZSendMessage(ezWnd, EZWM_WINNCACTIVATE, wParam, lParam); - return iRet; - + return 1; } case WM_CLOSE: @@ -3819,6 +3820,7 @@ EZWNDPROC EZStyle_OverlappedWndProc(EZWND ezWnd, int message, WPARAM wParam, LPA case EZWM_WINNCDRAW: case EZWM_WINNCACTIVATE: + case EZWM_KILLFOCUS: { HDC hdc = GetDC(ezWnd->hParent); BitBlt(hdc, 0, 0, ezWnd->Width, ezWnd->Height, ezWnd->TopWndExtend->hdcTop, 0, 0, SRCCOPY); From ca740478c844254cec14a26e3c239201da707006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E8=B5=AB?= <1160386205@qq.com> Date: Wed, 19 Dec 2018 18:31:17 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=86=99=E4=BA=86=E5=8D=8A=E6=88=AA?= =?UTF-8?q?=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E9=98=B4=E5=BD=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyWindow 4.0/EasyWindow.c | 105 +++++++++--------------------------- 1 file changed, 24 insertions(+), 81 deletions(-) diff --git a/EasyWindow 4.0/EasyWindow.c b/EasyWindow 4.0/EasyWindow.c index 9e53d85..3901e93 100644 --- a/EasyWindow 4.0/EasyWindow.c +++ b/EasyWindow 4.0/EasyWindow.c @@ -302,24 +302,11 @@ EZWND CreateEZStyleParentWindow(TCHAR Title[], DWORD EZStyle, int x, int y, int } else { - //������ - //�Ӵ��� - DWORD WinStyle = WS_VISIBLE | WS_DLGFRAME | WS_POPUP | WS_THICKFRAME; - switch (EZStyle & MKDW(00000000, 00000000, 00000000, 11111111)) - { - - - case EZS_OVERLAPPEDWINDOW: - WinStyle |= WS_MINIMIZEBOX | WS_MAXIMIZEBOX; - case EZS_OVERLAPPED: - + + ezParent = CreateEZParentWindowEx(EZStyle, x, y, Width, bAdjust ? Height + EZWND_CAP_HEIGHT : Height, + WS_POPUP|WS_VISIBLE|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX, EZStyle_OverlappedWndProc, 0, 0); + ezParent->Extend->hExtend[0] = ezWnd = CreateEZWindow(ezParent, 0, EZWND_CAP_HEIGHT, Width, bAdjust ? Height : Height - EZWND_CAP_HEIGHT, ezWndProc); - ezParent = CreateEZParentWindowEx(EZStyle, x, y, Width, bAdjust ? Height + EZWND_CAP_HEIGHT : Height, - WinStyle, EZStyle_OverlappedWndProc, 0, 0); - ezParent->Extend->hExtend[0] = ezWnd = CreateEZWindow(ezParent, 0, EZWND_CAP_HEIGHT, Width, bAdjust ? Height : Height - EZWND_CAP_HEIGHT, ezWndProc); - - break; - } } @@ -1247,7 +1234,6 @@ LRESULT CALLBACK EZParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM } } - Sleep(2000); switch (message) { @@ -3818,23 +3804,26 @@ EZWNDPROC EZStyle_OverlappedWndProc(EZWND ezWnd, int message, WPARAM wParam, LPA } - case EZWM_WINNCDRAW: - case EZWM_WINNCACTIVATE: - case EZWM_KILLFOCUS: - { - HDC hdc = GetDC(ezWnd->hParent); - BitBlt(hdc, 0, 0, ezWnd->Width, ezWnd->Height, ezWnd->TopWndExtend->hdcTop, 0, 0, SRCCOPY); - ReleaseDC(ezWnd->hParent, hdc); - //������������������IJ����� - return 0; - } - // - //case EZWM_LBUTTONDOWN: - // SendMessage(ezWnd->hParent, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);//�϶����ڡ� - //// ���↑ʼ�������ijɴ���EZWM_NCHITTEST������EZWM_NCHITTEST�ĵݹ飿 - // return 0; + case EZWM_SIZE: + + if (ezWnd->Extend->hExtend[0]) + { + MoveEZWindow(ezWnd->Extend->hExtend[0], 0, EZWND_CAP_HEIGHT, ezWnd->Width, ezWnd->Height - EZWND_CAP_HEIGHT, 0); + } + + if ((ezWnd->EZStyle & MKDW(00000000, 00000000, 00000000, 11111111)) == EZS_OVERLAPPEDWINDOW) + { + int BtnLen = floor(EZWND_CAP_HEIGHT * 1.618); + + MoveEZWindow(ezWnd->Extend->hExtend[1], ezWnd->Width - BtnLen, 0, BtnLen, EZWND_CAP_HEIGHT, 0); + MoveEZWindow(ezWnd->Extend->hExtend[2], ezWnd->Width - (BtnLen << 1), 0, BtnLen, EZWND_CAP_HEIGHT, 0); + MoveEZWindow(ezWnd->Extend->hExtend[3], ezWnd->Width - BtnLen * 3, 0, BtnLen, EZWND_CAP_HEIGHT, 0); + + } + return 0; + case EZWM_WINNCHITTEST: { ////��ⷶΧ��������Ĭ�ϵ���������Ĭ��˵�ǿͻ��������ٿ��Dz��DZ����� @@ -3882,49 +3871,6 @@ EZWNDPROC EZStyle_OverlappedWndProc(EZWND ezWnd, int message, WPARAM wParam, LPA return 0; } - case EZWM_SIZE: - - if (ezWnd->Extend->hExtend[0]) - { - MoveEZWindow(ezWnd->Extend->hExtend[0], 0, EZWND_CAP_HEIGHT, ezWnd->Width, ezWnd->Height - EZWND_CAP_HEIGHT, 0); - } - - if ((ezWnd->EZStyle & MKDW(00000000, 00000000, 00000000, 11111111)) == EZS_OVERLAPPEDWINDOW) - { - int BtnLen = floor(EZWND_CAP_HEIGHT * 1.618); - - MoveEZWindow(ezWnd->Extend->hExtend[1], ezWnd->Width - BtnLen, 0, BtnLen, EZWND_CAP_HEIGHT, 0); - MoveEZWindow(ezWnd->Extend->hExtend[2], ezWnd->Width - (BtnLen << 1), 0, BtnLen, EZWND_CAP_HEIGHT, 0); - MoveEZWindow(ezWnd->Extend->hExtend[3], ezWnd->Width - BtnLen * 3, 0, BtnLen, EZWND_CAP_HEIGHT, 0); - - } - return 0; - case EZWM_GETMINMAXINFO: - { - PMINMAXINFO pMMInfo; - RECT rect; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); - - pMMInfo = lParam; - - - AdjustWindowRect(&rect, GetWindowLong(ezWnd->hParent, GWL_STYLE), 0); - - pMMInfo->ptMaxPosition.x = rect.left;// -(xborder << 1); - pMMInfo->ptMaxPosition.y = rect.top;// -(yborder << 1); - pMMInfo->ptMaxSize.x = rect.right - rect.left;// +(xborder << 2); - pMMInfo->ptMaxSize.y = rect.bottom - rect.top;// +(yborder << 2); - return 1; - } - - //case EZWM_SETFOCUS: - //case EZWM_KILLFOCUS: - // EZRepaint(ezWnd, 0); - //���������������Ӵ����յ����أ������϶����С��޸������EZWM_SETFOCUS EZWM_KILLFOCUS - - //return 0; - - case EZWM_WINNCCALCSIZE: { if (wParam) @@ -3944,11 +3890,7 @@ EZWNDPROC EZStyle_OverlappedWndProc(EZWND ezWnd, int message, WPARAM wParam, LPA AdjustWindowRect(&(NCCSParam->rgrc[0]), GetWindowLong(ezWnd->hParent, GWL_STYLE), 0); - NCCSParam->rgrc[0].left += 4; - NCCSParam->rgrc[0].top += 1;//�ڱ�������������һЩ���������ټ�һЩ - NCCSParam->rgrc[0].right -= 4; - NCCSParam->rgrc[0].bottom -= 4; - + return 0; } @@ -3957,6 +3899,7 @@ EZWNDPROC EZStyle_OverlappedWndProc(EZWND ezWnd, int message, WPARAM wParam, LPA return 1; } + case EZWM_CLOSE: return EZSendMessage(ezWnd->Extend->hExtend[0], EZWM_CLOSE, wParam, lParam); From c90b9e2d537da59d452d138dfbd65b3904b4755f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E8=B5=AB?= <1160386205@qq.com> Date: Wed, 19 Dec 2018 19:41:48 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyWindow 4.0/EasyWindow.c | 47 +++++++++++++++++-------------------- EasyWindow 4.0/EasyWindow.h | 2 +- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/EasyWindow 4.0/EasyWindow.c b/EasyWindow 4.0/EasyWindow.c index 3901e93..e683aaa 100644 --- a/EasyWindow 4.0/EasyWindow.c +++ b/EasyWindow 4.0/EasyWindow.c @@ -302,11 +302,19 @@ EZWND CreateEZStyleParentWindow(TCHAR Title[], DWORD EZStyle, int x, int y, int } else { - - ezParent = CreateEZParentWindowEx(EZStyle, x, y, Width, bAdjust ? Height + EZWND_CAP_HEIGHT : Height, - WS_POPUP|WS_VISIBLE|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX, EZStyle_OverlappedWndProc, 0, 0); - ezParent->Extend->hExtend[0] = ezWnd = CreateEZWindow(ezParent, 0, EZWND_CAP_HEIGHT, Width, bAdjust ? Height : Height - EZWND_CAP_HEIGHT, ezWndProc); + DWORD WinStyle = NULL; + switch (EZStyle & MKDW(00000000, 00000000, 00000000, 11111111)) + { + case EZS_OVERLAPPEDWINDOW: + WinStyle |= WS_MINIMIZEBOX | WS_MAXIMIZEBOX; + case EZS_OVERLAPPED: + WinStyle |= WS_THICKFRAME | WS_VISIBLE | WS_POPUP | WS_VISIBLE; + ezParent = CreateEZParentWindowEx(EZStyle, x, y, Width, bAdjust ? Height + EZWND_CAP_HEIGHT : Height, + WinStyle, EZStyle_OverlappedWndProc, 0, 0); + ezParent->Extend->hExtend[0] = ezWnd = CreateEZWindow(ezParent, 0, EZWND_CAP_HEIGHT, Width, bAdjust ? Height : Height - EZWND_CAP_HEIGHT, ezWndProc); + } + } @@ -1514,9 +1522,11 @@ LRESULT CALLBACK EZParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM //MSDN - The DefWindowProc function draws the title bar or icon title in its active colors when the wParam parameter is TRUE and in its inactive colors when wParam is FALSE. //�����ܹ����˼һ��ưɡ���������ֵ��Ҳ���봦�������Ǿ�д�������� - int iRet = DefWindowProc(hwnd, message, wParam, lParam); - EZSendMessage(ezWnd, EZWM_WINNCACTIVATE, wParam, lParam); - return 1; + if (EZSendMessage(ezWnd, EZWM_WINNCACTIVATE, wParam, lParam) == 1) + return 1; + + + return DefWindowProc(hwnd, message, wParam, lParam); } case WM_CLOSE: @@ -3803,9 +3813,6 @@ EZWNDPROC EZStyle_OverlappedWndProc(EZWND ezWnd, int message, WPARAM wParam, LPA return 0; } - - - case EZWM_SIZE: if (ezWnd->Extend->hExtend[0]) @@ -3850,24 +3857,8 @@ EZWNDPROC EZStyle_OverlappedWndProc(EZWND ezWnd, int message, WPARAM wParam, LPA ScreenToClient(ezWnd->hParent, &pt); if (PtInRect(&rect, pt)) { - if (!IsZoomed(ezWnd->hParent)) - { - if (pt.y <= 3) - { - if (pt.x <= 3) - { - return EZHTTOPLEFT; - } - return EZHTTOP; - } - } - return EZHTCAPTION; } - if ((ezWnd->EZStyle & 0xff) == EZS_OVERLAPPED) - { - return EZHTCLIENT; - } return 0; } @@ -3899,6 +3890,10 @@ EZWNDPROC EZStyle_OverlappedWndProc(EZWND ezWnd, int message, WPARAM wParam, LPA return 1; } + case EZWM_WINNCACTIVATE: + { + return 1; + } case EZWM_CLOSE: return EZSendMessage(ezWnd->Extend->hExtend[0], EZWM_CLOSE, wParam, lParam); diff --git a/EasyWindow 4.0/EasyWindow.h b/EasyWindow 4.0/EasyWindow.h index 27463bc..ff74a49 100644 --- a/EasyWindow 4.0/EasyWindow.h +++ b/EasyWindow 4.0/EasyWindow.h @@ -52,7 +52,7 @@ #define EZWM_ACTIVATE 9 #define EZWM_ACTIVATEAPP 10 -#define EZWM_WINNCACTIVATE 11//�������������ֵɶ�ö�û���������ˡ�ֻ�����Ǹ�֪ͨ��ע�⣬���յ�������Ϣ֮ǰ�Ѿ����ù�DefWndProc�� +#define EZWM_WINNCACTIVATE 11//����1����ֹ����DefWindowProc��DefWindowProc����Ĭ����ɫ�ڴ����ϻ���NC�� #define EZWM_CLOSE 12 From ca60c031ea604c26265c7e137bd879e30e6dbd46 Mon Sep 17 00:00:00 2001 From: yh-git Date: Thu, 20 Dec 2018 21:06:12 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=83=A1=E4=B9=B1=E5=B0=81=E8=A3=85?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=8B=E7=9A=84=E9=98=B4=E5=BD=B1=E3=80=82?= =?UTF-8?q?=20=E5=AD=98=E5=9C=A8bug=E4=BB=A5=E5=8F=8A=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyWindow 4.0/EasyWindow.c | 418 +++++++++++++++++++++++++++++++++++- EasyWindow 4.0/EasyWindow.h | 23 ++ EasyWindowDemo/Main.c | 28 ++- 3 files changed, 460 insertions(+), 9 deletions(-) diff --git a/EasyWindow 4.0/EasyWindow.c b/EasyWindow 4.0/EasyWindow.c index e683aaa..d567253 100644 --- a/EasyWindow 4.0/EasyWindow.c +++ b/EasyWindow 4.0/EasyWindow.c @@ -19,6 +19,17 @@ BOOL InitEZWindow() wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = EZWindowClass; + + if (!RegisterClass(&wndclass)) + { + return FALSE; + } + + //������Ӱ���ڵĴ����� + wndclass.lpfnWndProc = EZShadowWndProc; + wndclass.cbWndExtra = sizeof(EZWND);//ָ���Ӧ��EZ���� + wndclass.lpszClassName = EZWindowShadowClass; + if (!RegisterClass(&wndclass)) { return FALSE; @@ -544,7 +555,7 @@ BOOL MoveEZWindow(EZWND ezWnd, int x, int y, int Width, int Height, BOOL repaint fhdc = GetDC(ezWnd->hParent); AdjustMemDC(ezWnd->hdc, fhdc, Width, Height); // AdjustMemDC(ezWnd->hdcCopy, fhdc, Width, Height); - + AdjustMemDC(ezWnd->ShadowDC, fhdc, Width, Height); ReleaseDC(ezWnd->hParent, fhdc); //ReleaseDC(ezWnd->hParent, fhdc); @@ -581,6 +592,7 @@ BOOL MoveEZWindow(EZWND ezWnd, int x, int y, int Width, int Height, BOOL repaint EZRepaint(ezWnd, 0); return 0; } + BOOL EZResetChildPxPy(EZWND ezWnd) { if (IsEZWindow(ezWnd->FirstChild)) @@ -628,7 +640,6 @@ BOOL EZReleaseMouse(EZWND ezWnd) return TRUE; } - BOOL EZCaptureKeyboard(EZWND ezWnd) { ezWnd->ezRootParent->TopWndExtend->CptKbdWindow = ezWnd; @@ -641,8 +652,6 @@ BOOL EZReleaseKeyboard(EZWND ezWnd) return 0; } - - BOOL SetMouseMsgRecvMode(EZWND ezWnd, int Mode) { ezWnd->MouseMsgRecv = Mode; @@ -655,7 +664,36 @@ BOOL SetShowState(EZWND ezWnd, int State) return TRUE; } +BOOL EnableShadow(EZWND ezWnd, BOOL bEnable) +{ + if (bEnable && ezWnd->bShadow == FALSE) + { + ezWnd->ShadowDC = GetMemDC(ezWnd->hdc, ezWnd->Width, ezWnd->Height); + } + else if (bEnable == FALSE && ezWnd->bShadow) + { + DeleteMemDC(ezWnd->ShadowDC); + ezWnd->ShadowDC = NULL; + } + ezWnd->bShadow = bEnable; + + //TODO: ˢ���ϲ㴰�ڣ�ע�⴦�����㴰�ڣ� +} + +BOOL SetShadowStrength(EZWND ezWnd, float Strength) +{ + ezWnd->ShadowStrength = Strength; +} + +BOOL SetShadowColor(EZWND ezWnd,COLORREF Color) +{ + ezWnd->ShadowColor = Color; +} +BOOL SetShadowTransparent(EZWND ezWnd,int Trans) +{ + ezWnd->ShadowTransparent = Trans; +} @@ -749,7 +787,17 @@ BOOL RedrawBroadcast(EZWND ezWnd, WPARAM wp, LPARAM lp, int cx, int cy, RECT Rec /*OldRgn = SelectObject(LastChild->hdc, hRgn);*/ - + //��ʱ���� + + if (ezWnd->bShadow) + { + RepaintShadow(ezWnd); + BLENDFUNCTION bf = { 0 }; + bf.AlphaFormat = AC_SRC_ALPHA; + bf.SourceConstantAlpha = ezWnd->ShadowTransparent; + AlphaBlend(ezWnd->hdc, 0, 0, ezWnd->Width, ezWnd->Height, ezWnd->ShadowDC, 0, 0, ezWnd->Width, ezWnd->Height, bf); + } + RedrawBroadcast(LastChild, wp, lp, cx + LastChild->x + LastChild->ezParent->ScrollX, cy + LastChild->y + LastChild->ezParent->ScrollY, RectAns);//���Լ����Ӵ��ڷ��͸���Ϣ /* DeleteObject(SelectObject(LastChild->hdc, OldRgn));*/ @@ -878,7 +926,50 @@ BOOL EZRepaint(EZWND ezWnd, HDC hdc) return 0; } +BOOL RepaintShadow(EZWND ezWnd) +{ + if (!ezWnd->bShadow) + return 0; + + //��ɫ��� + HBRUSH OldBrush = SelectObject(ezWnd->ShadowDC, CreateSolidBrush(ezWnd->ShadowColor)); + PatBlt(ezWnd->ShadowDC, 0, 0, ezWnd->Width, ezWnd->Height, PATCOPY); + DeleteObject(SelectObject(ezWnd->ShadowDC, OldBrush)); + + RECT ParentRect = { 0,0,ezWnd->Width,ezWnd->Height }; + HBITMAP hBitmap = SelectObject(ezWnd->ShadowDC,CreateCompatibleBitmap(ezWnd->hdc, 1, 1)); + BITMAP bmp; + GetObject(hBitmap, sizeof(bmp), &bmp); + + PBYTE pByte = malloc(bmp.bmWidthBytes * bmp.bmHeight); + GetBitmapBits(hBitmap, bmp.bmWidthBytes * bmp.bmHeight, pByte); + for (int i = 3;i < bmp.bmWidthBytes * bmp.bmHeight; i += 4) + { + pByte[i] = 0; + } + for (EZWND ChildWnd = ezWnd->FirstChild; ChildWnd; ChildWnd = ChildWnd->NextEZWnd) + { + //ö�������Ӵ��ڣ����͸���� + RECT ChildRect = { ChildWnd->x,ChildWnd->y,ChildWnd->x +ChildWnd->Width,ChildWnd->y+ChildWnd->Height }; + RECT ResultRect; + IntersectRect(&ResultRect, &ParentRect, &ChildRect); + + for (int y = ResultRect.top; y < ResultRect.bottom; y++) + { + PBYTE Base = pByte + y*bmp.bmWidthBytes + ResultRect.left * 4 +3; + for (int x = 0; x < ResultRect.right - ResultRect.left; x++) + { + *Base = 255; + Base += 4; + } + } + } + GaussianBlurFilter(pByte, pByte, bmp.bmWidth, bmp.bmHeight, bmp.bmWidthBytes, ezWnd->ShadowStrength); + SetBitmapBits(hBitmap, bmp.bmWidthBytes * bmp.bmHeight, pByte); + free(pByte); + DeleteObject(SelectObject(ezWnd->ShadowDC, hBitmap)); +} //��ʱ������ @@ -1306,8 +1397,14 @@ LRESULT CALLBACK EZParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM //ReleaseDC(hwnd, hdc); hdc = GetDC(hwnd); AdjustMemDC(ezWnd->hdc, hdc, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); - // AdjustMemDC(ezWnd->hdcCopy, hdc, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + if(ezWnd->bShadow) + { + AdjustMemDC(ezWnd->ShadowDC, hdc, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + //TODO:ò����Ҫ�ػ� + } AdjustMemDC(ezWnd->TopWndExtend->hdcTop, hdc, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + + ReleaseDC(hwnd, hdc); EZSendMessage(ezWnd, EZWM_SIZE, wParam, lParam); @@ -1548,7 +1645,10 @@ LRESULT CALLBACK EZParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM //�����Լ������� EZSendMessage(ezWnd, EZWM_DESTROY, (WPARAM)NULL, (LPARAM)NULL);//����������Ϣ DeleteMemDC(ezWnd->hdc);//����DC - // DeleteMemDC(ezWnd->hdcCopy);//����DC + if (ezWnd->bShadow) + { + DeleteMemDC(ezWnd->ShadowDC);//����DC + } DeleteMemDC(ezWnd->TopWndExtend->hdcTop); free(ezWnd->TopWndExtend); @@ -1617,6 +1717,16 @@ LRESULT CALLBACK EZParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM } +LRESULT CALLBACK EZShadowWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case EZWM_CREATE: + return 0; + } + return DefWindowProc(hwnd, message, wParam, lParam); +} + VOID CALLBACK ezInsideTimerProc(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime) { @@ -1925,7 +2035,7 @@ HDC GetMemDC(HDC hdc, int cx, int cy) HBITMAP hBitmap = CreateCompatibleBitmap(hdc, cx, cy); HDC hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem, hBitmap); - DeleteObject(hBitmap); + //DeleteObject(hBitmap); return hdcMem; } @@ -1944,6 +2054,298 @@ BOOL AdjustMemDC(HDC hdc, HDC hdcCpb, int cx, int cy) DeleteObject(SelectObject(hdc, CreateCompatibleBitmap(hdcCpb, cx, cy))); } +void __inline CalGaussianCoeff(float sigma, float * a0, float * a1, float * a2, float * a3, float * b1, float * b2, float * cprev, float * cnext) { + float alpha, lamma, k; + + if (sigma < 0.5f) + sigma = 0.5f; + alpha = (float)exp((0.726) * (0.726)) / sigma; + lamma = (float)exp(-alpha); + *b2 = (float)exp(-2 * alpha); + k = (1 - lamma) * (1 - lamma) / (1 + 2 * alpha * lamma - (*b2)); + *a0 = k; *a1 = k * (alpha - 1) * lamma; + *a2 = k * (alpha + 1) * lamma; + *a3 = -k * (*b2); + *b1 = -2 * lamma; + *cprev = (*a0 + *a1) / (1 + *b1 + *b2); + *cnext = (*a2 + *a3) / (1 + *b1 + *b2); +} + +void __inline gaussianHorizontal(unsigned char * bufferPerLine, unsigned char * lpRowInitial, unsigned char * lpColumn, int width, int height, int Channels, int Nwidth, float a0a1, float a2a3, float b1b2, float cprev, float cnext) +{ + int HeightStep = Channels * height; + int WidthSubOne = width - 1; + if (Channels == 3) + { + float prevOut[3]; + prevOut[0] = (lpRowInitial[0] * cprev); + prevOut[1] = (lpRowInitial[1] * cprev); + prevOut[2] = (lpRowInitial[2] * cprev); + for (int x = 0; x < width; ++x) { + prevOut[0] = ((lpRowInitial[0] * (a0a1)) - (prevOut[0] * (b1b2))); + prevOut[1] = ((lpRowInitial[1] * (a0a1)) - (prevOut[1] * (b1b2))); + prevOut[2] = ((lpRowInitial[2] * (a0a1)) - (prevOut[2] * (b1b2))); + bufferPerLine[0] = prevOut[0]; + bufferPerLine[1] = prevOut[1]; + bufferPerLine[2] = prevOut[2]; + bufferPerLine += Channels; + lpRowInitial += Channels; + } + lpRowInitial -= Channels; + lpColumn += HeightStep * WidthSubOne; + bufferPerLine -= Channels; + prevOut[0] = (lpRowInitial[0] * cnext); + prevOut[1] = (lpRowInitial[1] * cnext); + prevOut[2] = (lpRowInitial[2] * cnext); + + for (int x = WidthSubOne; x >= 0; --x) { + prevOut[0] = ((lpRowInitial[0] * (a2a3)) - (prevOut[0] * (b1b2))); + prevOut[1] = ((lpRowInitial[1] * (a2a3)) - (prevOut[1] * (b1b2))); + prevOut[2] = ((lpRowInitial[2] * (a2a3)) - (prevOut[2] * (b1b2))); + bufferPerLine[0] += prevOut[0]; + bufferPerLine[1] += prevOut[1]; + bufferPerLine[2] += prevOut[2]; + lpColumn[0] = bufferPerLine[0]; + lpColumn[1] = bufferPerLine[1]; + lpColumn[2] = bufferPerLine[2]; + lpRowInitial -= Channels; + lpColumn -= HeightStep; + bufferPerLine -= Channels; + } + } + else if (Channels == 4) + { + float prevOut[4]; + + prevOut[0] = (lpRowInitial[0] * cprev); + prevOut[1] = (lpRowInitial[1] * cprev); + prevOut[2] = (lpRowInitial[2] * cprev); + prevOut[3] = (lpRowInitial[3] * cprev); + for (register int x = 0; x < width; ++x) { + prevOut[0] = ((lpRowInitial[0] * (a0a1)) - (prevOut[0] * (b1b2))); + prevOut[1] = ((lpRowInitial[1] * (a0a1)) - (prevOut[1] * (b1b2))); + prevOut[2] = ((lpRowInitial[2] * (a0a1)) - (prevOut[2] * (b1b2))); + prevOut[3] = ((lpRowInitial[3] * (a0a1)) - (prevOut[3] * (b1b2))); + + bufferPerLine[0] = prevOut[0]; + bufferPerLine[1] = prevOut[1]; + bufferPerLine[2] = prevOut[2]; + bufferPerLine[3] = prevOut[3]; + bufferPerLine += Channels; + lpRowInitial += Channels; + } + lpRowInitial -= Channels; + lpColumn += HeightStep * WidthSubOne; + bufferPerLine -= Channels; + + prevOut[0] = (lpRowInitial[0] * cnext); + prevOut[1] = (lpRowInitial[1] * cnext); + prevOut[2] = (lpRowInitial[2] * cnext); + prevOut[3] = (lpRowInitial[3] * cnext); + + for (register int x = WidthSubOne; x >= 0; --x) { + prevOut[0] = ((lpRowInitial[0] * a2a3) - (prevOut[0] * b1b2)); + prevOut[1] = ((lpRowInitial[1] * a2a3) - (prevOut[1] * b1b2)); + prevOut[2] = ((lpRowInitial[2] * a2a3) - (prevOut[2] * b1b2)); + prevOut[3] = ((lpRowInitial[3] * a2a3) - (prevOut[3] * b1b2)); + bufferPerLine[0] += prevOut[0]; + bufferPerLine[1] += prevOut[1]; + bufferPerLine[2] += prevOut[2]; + bufferPerLine[3] += prevOut[3]; + lpColumn[0] = bufferPerLine[0]; + lpColumn[1] = bufferPerLine[1]; + lpColumn[2] = bufferPerLine[2]; + lpColumn[3] = bufferPerLine[3]; + lpRowInitial -= Channels; + lpColumn -= HeightStep; + bufferPerLine -= Channels; + } + } + else if (Channels == 1) + { + float prevOut = (lpRowInitial[0] * cprev); + + for (int x = 0; x < width; ++x) { + prevOut = ((lpRowInitial[0] * (a0a1)) - (prevOut * (b1b2))); + bufferPerLine[0] = prevOut; + bufferPerLine += Channels; + lpRowInitial += Channels; + } + lpRowInitial -= Channels; + lpColumn += HeightStep * WidthSubOne; + bufferPerLine -= Channels; + + prevOut = (lpRowInitial[0] * cnext); + + for (int x = WidthSubOne; x >= 0; --x) { + prevOut = ((lpRowInitial[0] * a2a3) - (prevOut * b1b2)); + bufferPerLine[0] += prevOut; + lpColumn[0] = bufferPerLine[0]; + lpRowInitial -= Channels; + lpColumn -= HeightStep; + bufferPerLine -= Channels; + } + } + +} + +void __inline gaussianVertical(unsigned char * bufferPerLine, unsigned char * lpRowInitial, unsigned char * lpColInitial, int height, int width, int Channels, float a0a1, float a2a3, float b1b2, float cprev, float cnext) +{ + + int WidthStep = Channels * width; + int HeightSubOne = height - 1; + if (Channels == 3) + { + float prevOut[3]; + prevOut[0] = (lpRowInitial[0] * cprev); + prevOut[1] = (lpRowInitial[1] * cprev); + prevOut[2] = (lpRowInitial[2] * cprev); + + for (int y = 0; y < height; y++) { + prevOut[0] = ((lpRowInitial[0] * a0a1) - (prevOut[0] * b1b2)); + prevOut[1] = ((lpRowInitial[1] * a0a1) - (prevOut[1] * b1b2)); + prevOut[2] = ((lpRowInitial[2] * a0a1) - (prevOut[2] * b1b2)); + bufferPerLine[0] = prevOut[0]; + bufferPerLine[1] = prevOut[1]; + bufferPerLine[2] = prevOut[2]; + bufferPerLine += Channels; + lpRowInitial += Channels; + } + lpRowInitial -= Channels; + bufferPerLine -= Channels; + lpColInitial += WidthStep * HeightSubOne; + prevOut[0] = (lpRowInitial[0] * cnext); + prevOut[1] = (lpRowInitial[1] * cnext); + prevOut[2] = (lpRowInitial[2] * cnext); + for (int y = HeightSubOne; y >= 0; y--) { + prevOut[0] = ((lpRowInitial[0] * a2a3) - (prevOut[0] * b1b2)); + prevOut[1] = ((lpRowInitial[1] * a2a3) - (prevOut[1] * b1b2)); + prevOut[2] = ((lpRowInitial[2] * a2a3) - (prevOut[2] * b1b2)); + bufferPerLine[0] += prevOut[0]; + bufferPerLine[1] += prevOut[1]; + bufferPerLine[2] += prevOut[2]; + lpColInitial[0] = bufferPerLine[0]; + lpColInitial[1] = bufferPerLine[1]; + lpColInitial[2] = bufferPerLine[2]; + lpRowInitial -= Channels; + lpColInitial -= WidthStep; + bufferPerLine -= Channels; + } + } + else if (Channels == 4) + { + float prevOut[4]; + + prevOut[0] = (lpRowInitial[0] * cprev); + prevOut[1] = (lpRowInitial[1] * cprev); + prevOut[2] = (lpRowInitial[2] * cprev); + prevOut[3] = (lpRowInitial[3] * cprev); + + for (register int y = 0; y < height; y++) { + prevOut[0] = ((lpRowInitial[0] * a0a1) - (prevOut[0] * b1b2)); + prevOut[1] = ((lpRowInitial[1] * a0a1) - (prevOut[1] * b1b2)); + prevOut[2] = ((lpRowInitial[2] * a0a1) - (prevOut[2] * b1b2)); + prevOut[3] = ((lpRowInitial[3] * a0a1) - (prevOut[3] * b1b2)); + bufferPerLine[0] = prevOut[0]; + bufferPerLine[1] = prevOut[1]; + bufferPerLine[2] = prevOut[2]; + bufferPerLine[3] = prevOut[3]; + bufferPerLine += Channels; + lpRowInitial += Channels; + } + lpRowInitial -= Channels; + bufferPerLine -= Channels; + lpColInitial += WidthStep * HeightSubOne; + prevOut[0] = (lpRowInitial[0] * cnext); + prevOut[1] = (lpRowInitial[1] * cnext); + prevOut[2] = (lpRowInitial[2] * cnext); + prevOut[3] = (lpRowInitial[3] * cnext); + for (register int y = HeightSubOne; y >= 0; y--) { + prevOut[0] = ((lpRowInitial[0] * a2a3) - (prevOut[0] * b1b2)); + prevOut[1] = ((lpRowInitial[1] * a2a3) - (prevOut[1] * b1b2)); + prevOut[2] = ((lpRowInitial[2] * a2a3) - (prevOut[2] * b1b2)); + prevOut[3] = ((lpRowInitial[3] * a2a3) - (prevOut[3] * b1b2)); + bufferPerLine[0] += prevOut[0]; + bufferPerLine[1] += prevOut[1]; + bufferPerLine[2] += prevOut[2]; + bufferPerLine[3] += prevOut[3]; + lpColInitial[0] = bufferPerLine[0]; + lpColInitial[1] = bufferPerLine[1]; + lpColInitial[2] = bufferPerLine[2]; + lpColInitial[3] = bufferPerLine[3]; + lpRowInitial -= Channels; + lpColInitial -= WidthStep; + bufferPerLine -= Channels; + } + } + else if (Channels == 1) + { + float prevOut = 0; + prevOut = (lpRowInitial[0] * cprev); + for (int y = 0; y < height; y++) { + prevOut = ((lpRowInitial[0] * a0a1) - (prevOut * b1b2)); + bufferPerLine[0] = prevOut; + bufferPerLine += Channels; + lpRowInitial += Channels; + } + lpRowInitial -= Channels; + bufferPerLine -= Channels; + lpColInitial += WidthStep * HeightSubOne; + prevOut = (lpRowInitial[0] * cnext); + for (int y = HeightSubOne; y >= 0; y--) { + prevOut = ((lpRowInitial[0] * a2a3) - (prevOut * b1b2)); + bufferPerLine[0] += prevOut; + lpColInitial[0] = bufferPerLine[0]; + lpRowInitial -= Channels; + lpColInitial -= WidthStep; + bufferPerLine -= Channels; + } + } +} + +void GaussianBlurFilter(unsigned char * input, unsigned char * output, int Width, int Height, int Stride, float GaussianSigma) { + + int Channels = Stride / Width; + float a0, a1, a2, a3, b1, b2, cprev, cnext; + + CalGaussianCoeff(GaussianSigma, &a0, &a1, &a2, &a3, &b1, &b2, &cprev, &cnext); + + float a0a1 = (a0 + a1); + float a2a3 = (a2 + a3); + float b1b2 = (b1 + b2); + + int bufferSizePerThread = (Width > Height ? Width : Height) * Channels; + unsigned char * bufferPerLine = (unsigned char*)malloc(bufferSizePerThread); + unsigned char * tempData = (unsigned char*)malloc(Height * Stride); + if (bufferPerLine == NULL || tempData == NULL) + { + if (tempData) + { + free(tempData); + } + if (bufferPerLine) + { + free(bufferPerLine); + } + return; + } + for (register int y = 0; y < Height; ++y) { + unsigned char * lpRowInitial = input + Stride * y; + unsigned char * lpColInitial = tempData + y * Channels; + gaussianHorizontal(bufferPerLine, lpRowInitial, lpColInitial, Width, Height, Channels, Width, a0a1, a2a3, b1b2, cprev, cnext); + } + int HeightStep = Height * Channels; + for (register int x = 0; x < Width; ++x) { + unsigned char * lpColInitial = output + x * Channels; + unsigned char * lpRowInitial = tempData + HeightStep * x; + gaussianVertical(bufferPerLine, lpRowInitial, lpColInitial, Height, Width, Channels, a0a1, a2a3, b1b2, cprev, cnext); + } + + free(bufferPerLine); + free(tempData); +} + + //********************************************************************************************************* // EZWindow�����չͷ�ļ� �Լ��궨�� //********************************************************************************************************* diff --git a/EasyWindow 4.0/EasyWindow.h b/EasyWindow 4.0/EasyWindow.h index ff74a49..6d81ad7 100644 --- a/EasyWindow 4.0/EasyWindow.h +++ b/EasyWindow 4.0/EasyWindow.h @@ -291,6 +291,7 @@ #pragma region EasyWindowClassName #define EZWindowClass TEXT("EasyWindowClass") +#define EZWindowShadowClass TEXT("EasyWindowShadowClass") #pragma endregion @@ -349,6 +350,11 @@ typedef struct tagezTopWindowExtend HDC hdcTop;//���㴰�������ڴ�ʹ�ã��������ڶ��ԣ���ֻ��һ���յľ���� // int TimerNum;//��ǰʹ���˵ļ�ʱ������ + HWND ShadowWindow; + + BOOL bTobShadow;//���㴰����Ӱ�Ƿ��� + int TopShadowTransparent;//���㴰���Լ�����Ӱ͸���ȡ���ָ���Ӵ��ڵ��뿴EZWINDOW�ṹ�� + COLORREF TopShadowColor;//���㴰���Լ�����Ӱ��ɫ struct ezTimer { @@ -379,6 +385,16 @@ typedef struct tagEZWND int px;//x���꣨����������ڣ� int py;//y���꣨����������ڣ� + + + float ShadowStrength;//��Ӱǿ�� + + BOOL bShadow;//��Ӱ�Ƿ�������������Ӵ��ڶ����DZ����ڵ� + COLORREF ShadowColor;//��Ӱ��ɫ����������Ӵ��ڶ����DZ����ڵ� + BYTE ShadowTransparent;//��Ӱ͸���ȡ���������Ӵ��ڶ����DZ����ڵ� + HDC ShadowDC;//��Ӱ��DC�� + //TODO: �������Ӵ���������Ӱʱ�ſ��� + RECT VisibleRect;//�ɼ��ľ��Σ�����������ڣ� BOOL IsVsbRectNull; //�йػ���״̬**************************** @@ -531,6 +547,10 @@ BOOL EZCaptureKeyboard(EZWND ezWnd); BOOL EZReleaseKeyboard(EZWND ezWnd); BOOL SetMouseMsgRecvMode(EZWND ezWnd, int Mode); BOOL SetShowState(EZWND ezWnd, int State); +BOOL EnableShadow(EZWND ezWnd, BOOL bEnable); +BOOL SetShadowStrength(EZWND ezWnd, float Strength); +BOOL SetShadowColor(EZWND ezWnd, COLORREF Color); +BOOL SetShadowTransparent(EZWND ezWnd, int Trans); BOOL EZRedraw(EZWND ezWnd); BOOL EZUpdate(EZWND ezWnd, HDC hdc); BOOL EZRepaint(EZWND ezWnd, HDC hdc); @@ -548,6 +568,7 @@ BOOL EZEndDialog(EZWND ezWnd); EZWNDPROC EZDlgHookProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam); EZWNDPROC EZDialogBoxMask(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK EZParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK EZShadowWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); VOID CALLBACK ezInsideTimerProc(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime); int ezInsideWndProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam); BOOL PtInEZWnd(EZWND ezWnd, int x, int y); @@ -562,6 +583,8 @@ int EZWndMessageLoop(); +void GaussianBlurFilter(unsigned char * input, unsigned char * output, int Width, int Height, int Stride, float GaussianSigma); + //�ⲿ��ʽ EZWNDPROC EZStyle_ButtonProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam); EZWNDPROC EZStyle_StaticProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam); diff --git a/EasyWindowDemo/Main.c b/EasyWindowDemo/Main.c index d7af298..4b10de6 100644 --- a/EasyWindowDemo/Main.c +++ b/EasyWindowDemo/Main.c @@ -6,6 +6,7 @@ EZWND MainWnd; EZWNDPROC MainProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam); +EZWNDPROC ChildProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { @@ -17,11 +18,20 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine EZWNDPROC MainProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam) { + static EZWND ChildWnd; switch (message) { + case EZWM_CREATE: + { + ChildWnd = CreateEZWindow(ezWnd, ezWnd->Width / 2 + 30, 30, ezWnd->Width / 2 - 60, ezWnd->Height - 60, ChildProc); + EnableShadow(ezWnd, 1); + SetShadowTransparent(ezWnd, 128); + SetShadowStrength(ezWnd, 4); + return 0; + } case EZWM_DRAW: { - RECT rect = { 0,0,ezWnd->Width,ezWnd->Height }; + RECT rect = { 0,0,ezWnd->Width / 2,ezWnd->Height }; DrawText(wParam, TEXT("Hello, EasyWindow!!"), -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); return 0; } @@ -32,4 +42,20 @@ EZWNDPROC MainProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam) } } return 0; +} + + +EZWNDPROC ChildProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case EZWM_DRAW: + { + RECT rect = { 0,0,ezWnd->Width,ezWnd->Height }; + + DrawText(wParam, TEXT("ChildWindow"), -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); + return 0; + } + } + return 0; } \ No newline at end of file From 2557c123caa9ac022cc8a66d23d7696c338ec193 Mon Sep 17 00:00:00 2001 From: yh-git Date: Wed, 2 Jan 2019 21:36:44 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyWindow 4.0/EasyWindow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EasyWindow 4.0/EasyWindow.c b/EasyWindow 4.0/EasyWindow.c index d567253..04777f5 100644 --- a/EasyWindow 4.0/EasyWindow.c +++ b/EasyWindow 4.0/EasyWindow.c @@ -930,7 +930,7 @@ BOOL RepaintShadow(EZWND ezWnd) { if (!ezWnd->bShadow) return 0; - + ������޸ģ������Ӵ��ڷֿ��������ơ� //��ɫ��� HBRUSH OldBrush = SelectObject(ezWnd->ShadowDC, CreateSolidBrush(ezWnd->ShadowColor)); PatBlt(ezWnd->ShadowDC, 0, 0, ezWnd->Width, ezWnd->Height, PATCOPY);