BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) { HICON hIcon; WCHAR szText[260]; BOOL bLargeIcon; BOOL bHung = FALSE; typedef int (FAR __stdcall *IsHungAppWindowProc)(HWND); IsHungAppWindowProc IsHungAppWindow; /* Skip our window */ if (hWnd == hMainWnd) return TRUE; bLargeIcon = (TaskManagerSettings.ViewMode == ID_VIEW_LARGE); GetWindowTextW(hWnd, szText, 260); /* Get the window text */ /* Check and see if this is a top-level app window */ if ((wcslen(szText) <= 0) || !IsWindowVisible(hWnd) || (GetParent(hWnd) != NULL) || (GetWindow(hWnd, GW_OWNER) != NULL) || (GetWindowLongPtrW(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)) { return TRUE; /* Skip this window */ } noApps = FALSE; /* Get the icon for this window */ hIcon = NULL; SendMessageTimeoutW(hWnd, WM_GETICON, bLargeIcon ? ICON_BIG : ICON_SMALL, 0, 0, 1000, (PDWORD_PTR)&hIcon); if (!hIcon) { /* We failed, try to retrieve other icons... */ hIcon = (HICON)(LONG_PTR)GetClassLongPtrW(hWnd, bLargeIcon ? GCL_HICON : GCL_HICONSM); if (!hIcon) hIcon = (HICON)(LONG_PTR)GetClassLongPtrW(hWnd, bLargeIcon ? GCL_HICONSM : GCL_HICON); if (!hIcon) SendMessageTimeoutW(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (PDWORD_PTR)&hIcon); if (!hIcon) SendMessageTimeoutW(hWnd, WM_GETICON, bLargeIcon ? ICON_SMALL : ICON_BIG, 0, 0, 1000, (PDWORD_PTR)&hIcon); /* If we still do not have any icon, load the default one */ if (!hIcon) hIcon = LoadIconW(hInst, bLargeIcon ? MAKEINTRESOURCEW(IDI_WINDOW) : MAKEINTRESOURCEW(IDI_WINDOWSM)); } bHung = FALSE; IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandleW(L"USER32.DLL"), "IsHungAppWindow"); if (IsHungAppWindow) bHung = IsHungAppWindow(hWnd); AddOrUpdateHwnd(hWnd, szText, hIcon, bHung); return TRUE; }
static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) { HICON hIcon; WCHAR wszText[256]; BOOL bLargeIcon; BOOL bHung = FALSE; typedef int (__stdcall *IsHungAppWindowProc)(HWND); IsHungAppWindowProc IsHungAppWindow; /* Skip our window */ if (hWnd == hMainWnd) return TRUE; bLargeIcon = TaskManagerSettings.View_LargeIcons ? TRUE : FALSE; /* Check and see if this is a top-level app window */ if (!GetWindowTextW(hWnd, wszText, sizeof(wszText)/sizeof(WCHAR)) || !IsWindowVisible(hWnd) || (GetParent(hWnd) != NULL) || (GetWindow(hWnd, GW_OWNER) != NULL) || (GetWindowLongW(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)) { return TRUE; /* Skip this window */ } /* Get the icon for this window */ hIcon = NULL; SendMessageTimeoutW(hWnd, WM_GETICON, bLargeIcon ? ICON_BIG /*1*/ : ICON_SMALL /*0*/, 0, 0, 1000, (PDWORD_PTR)&hIcon); if (!hIcon) { hIcon = (HICON)GetClassLongPtrW(hWnd, bLargeIcon ? GCLP_HICON : GCLP_HICONSM); if (!hIcon) hIcon = (HICON)GetClassLongPtrW(hWnd, bLargeIcon ? GCLP_HICONSM : GCLP_HICON); if (!hIcon) SendMessageTimeoutW(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (PDWORD_PTR)&hIcon); if (!hIcon) SendMessageTimeoutW(hWnd, WM_GETICON, bLargeIcon ? ICON_SMALL /*0*/ : ICON_BIG /*1*/, 0, 0, 1000, (PDWORD_PTR)&hIcon); } if (!hIcon) hIcon = LoadIconW(hInst, bLargeIcon ? MAKEINTRESOURCEW(IDI_WINDOW) : MAKEINTRESOURCEW(IDI_WINDOWSM)); bHung = FALSE; IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandleW(wszUser32), "IsHungAppWindow"); if (IsHungAppWindow) bHung = IsHungAppWindow(hWnd); AddOrUpdateHwnd(hWnd, wszText, hIcon, bHung); return TRUE; }
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) { HICON hIcon; WCHAR szText[260]; BOOL bHung = FALSE; HICON* xhIcon = (HICON*)&hIcon; typedef int (FAR __stdcall *IsHungAppWindowProc)(HWND); IsHungAppWindowProc IsHungAppWindow; /* Skip our window */ if (hWnd == CurrenthWnd) return TRUE; GetWindowTextW(hWnd, szText, 260); /* Get the window text */ /* Check and see if this is a top-level app window */ if ((wcslen(szText) <= 0) || !IsWindowVisible(hWnd) || (GetParent(hWnd) != NULL) || (GetWindow(hWnd, GW_OWNER) != NULL) || (GetWindowLongPtrW(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)) { return TRUE; /* Skip this window */ } /* Get the icon for this window */ hIcon = NULL; SendMessageTimeoutW(hWnd, WM_GETICON, ICON_SMALL, 0, 0, 1000, (PDWORD_PTR)xhIcon); if (!hIcon) { hIcon = (HICON)(LONG_PTR)GetClassLongPtrW(hWnd, GCL_HICONSM); if (!hIcon) hIcon = (HICON)(LONG_PTR)GetClassLongPtrW(hWnd, GCL_HICON); if (!hIcon) SendMessageTimeoutW(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (PDWORD_PTR)xhIcon); } if (!hIcon) hIcon = LoadIconW(NULL, MAKEINTRESOURCEW(IDI_APPLICATION)); bHung = FALSE; IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandleW(L"USER32.DLL"), "IsHungAppWindow"); if (IsHungAppWindow) bHung = IsHungAppWindow(hWnd); AddOrUpdateHwnd(hWnd, szText, hIcon, bHung); return TRUE; }
/** * clutter_win32_get_stage_from_window: * @hwnd: a window handle * * Gets the stage for a particular window. * * Return value: The stage or NULL if a stage does not exist for the * window. * * Since: 0.8 */ ClutterStage * clutter_win32_get_stage_from_window (HWND hwnd) { /* Check whether the window handle is an instance of the stage window class */ if ((ATOM) GetClassLongPtrW (hwnd, GCW_ATOM) == clutter_stage_win32_get_window_class ()) /* If it is there should be a pointer to the stage in the window extra data */ return CLUTTER_STAGE_WIN32 (GetWindowLongPtrW (hwnd, 0))->wrapper; else { /* Otherwise it might be a foreign window so we should check the stage list */ ClutterStageManager *stage_manager; const GSList *stages, *l; stage_manager = clutter_stage_manager_get_default (); stages = clutter_stage_manager_peek_stages (stage_manager); for (l = stages; l != NULL; l = l->next) { ClutterStage *stage = l->data; ClutterStageWindow *impl; impl = _clutter_stage_get_window (stage); g_assert (CLUTTER_IS_STAGE_WIN32 (impl)); if (CLUTTER_STAGE_WIN32 (impl)->hwnd == hwnd) return stage; } } return NULL; }
VOID WepWriteClientData( __in HWND hwnd ) { WCHAR className[256]; LOGICAL isUnicode; memset(&WeServerSharedData->c, 0, sizeof(WeServerSharedData->c)); isUnicode = IsWindowUnicode(hwnd); if (isUnicode) { WeServerSharedData->c.WndProc = GetWindowLongPtrW(hwnd, GWLP_WNDPROC); WeServerSharedData->c.DlgProc = GetWindowLongPtrW(hwnd, DWLP_DLGPROC); } else { WeServerSharedData->c.WndProc = GetWindowLongPtrA(hwnd, GWLP_WNDPROC); WeServerSharedData->c.DlgProc = GetWindowLongPtrA(hwnd, DWLP_DLGPROC); } if (!GetClassName(hwnd, className, sizeof(className) / sizeof(WCHAR))) className[0] = 0; WeServerSharedData->c.ClassInfo.cbSize = sizeof(WNDCLASSEX); GetClassInfoEx(NULL, className, &WeServerSharedData->c.ClassInfo); if (isUnicode) WeServerSharedData->c.ClassInfo.lpfnWndProc = (PVOID)GetClassLongPtrW(hwnd, GCLP_WNDPROC); else WeServerSharedData->c.ClassInfo.lpfnWndProc = (PVOID)GetClassLongPtrA(hwnd, GCLP_WNDPROC); }
/*********************************************************************** * ICONTITLE_Paint */ static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive ) { RECT rect; HFONT hPrevFont; HBRUSH hBrush; COLORREF textColor = 0; if( bActive ) { hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION); textColor = GetSysColor(COLOR_CAPTIONTEXT); } else { if( GetWindowLongPtrA( hwnd, GWL_STYLE ) & WS_CHILD ) { hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND); if( hBrush ) { INT level; LOGBRUSH logBrush; GetObjectA( hBrush, sizeof(logBrush), &logBrush ); level = GetRValue(logBrush.lbColor) + GetGValue(logBrush.lbColor) + GetBValue(logBrush.lbColor); if( level < (0x7F * 3) ) textColor = RGB( 0xFF, 0xFF, 0xFF ); } else hBrush = GetStockObject( WHITE_BRUSH ); } else { hBrush = GetStockObject( BLACK_BRUSH ); textColor = RGB( 0xFF, 0xFF, 0xFF ); } } GetClientRect( hwnd, &rect ); DPtoLP( hDC, (LPPOINT)&rect, 2 ); FillRect( hDC, &rect, hBrush ); hPrevFont = SelectObject( hDC, hIconTitleFont ); if( hPrevFont ) { WCHAR buffer[80]; INT length = GetWindowTextW( owner, buffer, sizeof(buffer)/sizeof(buffer[0]) ); SetTextColor( hDC, textColor ); SetBkMode( hDC, TRANSPARENT ); DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX | DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) ); SelectObject( hDC, hPrevFont ); } return (hPrevFont != 0); }
/*------------------------------------------------ the windows is subclassified yet? --------------------------------------------------*/ BOOL IsSubclassed(HWND hwnd) { LONG_PTR wndproc1, wndproc2; wndproc1 = GetClassLongPtrW(hwnd, GCLP_WNDPROC); wndproc2 = GetWindowLongPtrW(hwnd, GWLP_WNDPROC); if(wndproc1 != wndproc2) return TRUE; return FALSE; }
/*********************************************************************** * PaintDesktop (USER32.@) * */ BOOL WINAPI PaintDesktop(HDC hdc) { HWND hwnd = GetDesktopWindow(); /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */ if (GetWindowThreadProcessId( hwnd, NULL )) { RECT rect; GetClientRect( hwnd, &rect ); /* Paint desktop pattern (only if wall paper does not cover everything) */ if (!hbitmapWallPaper || (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom)))) { HBRUSH brush = hbrushPattern; if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND ); /* Set colors in case pattern is a monochrome bitmap */ SetBkColor( hdc, RGB(0,0,0) ); SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) ); FillRect( hdc, &rect, brush ); } /* Paint wall paper */ if (hbitmapWallPaper) { INT x, y; HDC hMemDC = CreateCompatibleDC( hdc ); SelectObject( hMemDC, hbitmapWallPaper ); if (fTileWallPaper) { for (y = 0; y < rect.bottom; y += bitmapSize.cy) for (x = 0; x < rect.right; x += bitmapSize.cx) BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY ); } else { x = (rect.left + rect.right - bitmapSize.cx) / 2; y = (rect.top + rect.bottom - bitmapSize.cy) / 2; if (x < 0) x = 0; if (y < 0) y = 0; BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY ); } DeleteDC( hMemDC ); } } return TRUE; }
void _glfwPlatformSetWindowIcon(_GLFWwindow* window, int count, const GLFWimage* images) { HICON bigIcon = NULL, smallIcon = NULL; if (count) { const GLFWimage* bigImage = chooseImage(count, images, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); const GLFWimage* smallImage = chooseImage(count, images, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); bigIcon = createIcon(bigImage, 0, 0, GLFW_TRUE); smallIcon = createIcon(smallImage, 0, 0, GLFW_TRUE); } else { bigIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICON); smallIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICONSM); } SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) bigIcon); SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) smallIcon); if (window->win32.bigIcon) DestroyIcon(window->win32.bigIcon); if (window->win32.smallIcon) DestroyIcon(window->win32.smallIcon); if (count) { window->win32.bigIcon = bigIcon; window->win32.smallIcon = smallIcon; } }
BOOL CALLBACK EnumerateCallback(HWND window, LPARAM lParam) { HICON hIcon; HWND hwndIcon, hwndOwner; UNREFERENCED_PARAMETER(lParam); hwndOwner = GetWindow(window, GW_OWNER); hwndIcon = (hwndOwner ? hwndOwner : window); // First try to get the big icon assigned to the window hIcon = (HICON)SendMessageW(hwndIcon, WM_GETICON, ICON_BIG, 0); if (!hIcon) { // If no icon is assigned, try to get the icon assigned to the windows' class hIcon = (HICON)GetClassLongPtrW(hwndIcon, GCL_HICON); if (!hIcon) { // If we still don't have an icon, see if we can do with the small icon, // or a default application icon hIcon = (HICON)SendMessageW(hwndIcon, WM_GETICON, ICON_SMALL2, 0); if (!hIcon) { // using windows logo icon as default hIcon = gpsi->hIconWindows; if (!hIcon) { //if all attempts to get icon fails go to the next window return TRUE; } } } } windowList[windowCount] = window; iconList[windowCount] = CopyIcon(hIcon); windowCount++; // If we got to the max number of windows, // we won't be able to add any more if(windowCount >= MAX_WINDOWS) return FALSE; return TRUE; }
/*********************************************************************** * CC_PaintTriangle [internal] */ static void CC_PaintTriangle( HWND hDlg, int y) { HDC hDC; long temp; int w = LOWORD(GetDialogBaseUnits()) / 2; POINT points[3]; int height; int oben; RECT rect; HBRUSH hbr; HWND hwnd = GetDlgItem(hDlg, 0x2be); LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp ); if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6))) /* if full size */ { GetClientRect(hwnd, &rect); height = rect.bottom; hDC = GetDC(hDlg); points[0].y = rect.top; points[0].x = rect.right; /* | /| */ ClientToScreen(hwnd, points); /* | / | */ ScreenToClient(hDlg, points); /* |< | */ oben = points[0].y; /* | \ | */ /* | \| */ temp = (long)height * (long)y; points[0].x += 1; points[0].y = oben + height - temp / (long)MAXVERT; points[1].y = points[0].y + w; points[2].y = points[0].y - w; points[2].x = points[1].x = points[0].x + w; hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND); if (!hbr) hbr = GetSysColorBrush(COLOR_BTNFACE); FillRect(hDC, &lpp->old3angle, hbr); lpp->old3angle.left = points[0].x; lpp->old3angle.right = points[1].x + 1; lpp->old3angle.top = points[2].y - 1; lpp->old3angle.bottom= points[1].y + 1; hbr = SelectObject(hDC, GetStockObject(BLACK_BRUSH)); Polygon(hDC, points, 3); SelectObject(hDC, hbr); ReleaseDC(hDlg, hDC); } }
/*********************************************************************** * CC_PaintUserColorArray [internal] * Paint the 16 user-selected colors */ static void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, const COLORREF *lpcr ) { HWND hwnd = GetDlgItem(hDlg, 0x2d1); RECT rect, blockrect; HDC hdc; HBRUSH hBrush; int dx, dy, i, j, k; LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp ); GetClientRect(hwnd, &rect); dx = rect.right / cols; dy = rect.bottom / rows; k = rect.left; hdc = GetDC(hwnd); if (hdc) { hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND); if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE); FillRect( hdc, &rect, hBrush ); for (j = 0; j < rows; j++) { for (i = 0; i < cols; i++) { hBrush = CreateSolidBrush(lpcr[i+j*cols]); if (hBrush) { blockrect.left = rect.left; blockrect.top = rect.top; blockrect.right = rect.left + dx - DISTANCE; blockrect.bottom = rect.top + dy - DISTANCE; FillRect(hdc, &blockrect, hBrush); DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT); DeleteObject(hBrush); } rect.left += dx; } rect.top += dy; rect.left = k; } ReleaseDC(hwnd, hdc); } if (lpp->hwndFocus == hwnd) CC_DrawCurrentFocusRect(lpp); }
BOOL CALLBACK EnumerateCallback(HWND window, LPARAM lParam) { HICON hIcon; UNREFERENCED_PARAMETER(lParam); if (!IsWindowVisible(window)) return TRUE; GetClassNameW(window,windowText,4095); if ((wcscmp(L"Shell_TrayWnd",windowText)==0) || (wcscmp(L"Progman",windowText)==0) ) return TRUE; // First try to get the big icon assigned to the window hIcon = (HICON)SendMessageW(window, WM_GETICON, ICON_BIG, 0); if (!hIcon) { // If no icon is assigned, try to get the icon assigned to the windows' class hIcon = (HICON)GetClassLongPtrW(window, GCL_HICON); if (!hIcon) { // If we still don't have an icon, see if we can do with the small icon, // or a default application icon hIcon = (HICON)SendMessageW(window, WM_GETICON, ICON_SMALL2, 0); if (!hIcon) { // If all fails, give up and continue with the next window return TRUE; } } } windowList[windowCount] = window; iconList[windowCount] = CopyIcon(hIcon); windowCount++; // If we got to the max number of windows, // we won't be able to add any more if(windowCount == MAX_WINDOWS) return FALSE; return TRUE; }
void _clutter_stage_win32_update_cursor (ClutterStageWin32 *stage_win32) { HCURSOR cursor; if (stage_win32->is_cursor_visible) cursor = (HCURSOR) GetClassLongPtrW (stage_win32->hwnd, GCLP_HCURSOR); else { ClutterBackend *backend = clutter_get_default_backend (); /* The documentation implies that we can just use SetCursor(NULL) to get rid of the cursor but apparently this doesn't work very well so instead we create an invisible cursor */ cursor = _clutter_backend_win32_get_invisible_cursor (backend); } SetCursor (cursor); }
LRESULT DefWndNCCalcSize(HWND hWnd, BOOL CalcSizeStruct, RECT *Rect) { LRESULT Result = 0; DWORD Style = GetClassLongPtrW(hWnd, GCL_STYLE); DWORD ExStyle; SIZE WindowBorders; RECT OrigRect; if (Rect == NULL) { return Result; } OrigRect = *Rect; if (CalcSizeStruct) { if (Style & CS_VREDRAW) { Result |= WVR_VREDRAW; } if (Style & CS_HREDRAW) { Result |= WVR_HREDRAW; } Result |= WVR_VALIDRECTS; } Style = GetWindowLongPtrW(hWnd, GWL_STYLE); ExStyle = GetWindowLongPtrW(hWnd, GWL_EXSTYLE); if (!(Style & WS_MINIMIZE)) { HMENU menu = GetMenu(hWnd); if (UserHasWindowEdge(Style, ExStyle)) { UserGetWindowBorders(Style, ExStyle, &WindowBorders, FALSE); InflateRect(Rect, -WindowBorders.cx, -WindowBorders.cy); } else if ((ExStyle & WS_EX_STATICEDGE) || (Style & WS_BORDER)) { InflateRect(Rect, -1, -1); } if ((Style & WS_CAPTION) == WS_CAPTION) { if (ExStyle & WS_EX_TOOLWINDOW) Rect->top += GetSystemMetrics(SM_CYSMCAPTION); else Rect->top += GetSystemMetrics(SM_CYCAPTION); } if (menu && !(Style & WS_CHILD)) { HDC hDC = GetWindowDC(hWnd); if(hDC) { RECT CliRect = *Rect; CliRect.bottom -= OrigRect.top; CliRect.right -= OrigRect.left; CliRect.left -= OrigRect.left; CliRect.top -= OrigRect.top; Rect->top += MenuDrawMenuBar(hDC, &CliRect, hWnd, TRUE); ReleaseDC(hWnd, hDC); } } if (ExStyle & WS_EX_CLIENTEDGE) { InflateRect(Rect, -2 * GetSystemMetrics(SM_CXBORDER), -2 * GetSystemMetrics(SM_CYBORDER)); } if(Style & (WS_VSCROLL | WS_HSCROLL)) { SCROLLBARINFO sbi; SETSCROLLBARINFO ssbi; sbi.cbSize = sizeof(SCROLLBARINFO); if((Style & WS_VSCROLL) && NtUserGetScrollBarInfo(hWnd, OBJID_VSCROLL, &sbi)) { int i; LONG sx = Rect->right; sx -= GetSystemMetrics(SM_CXVSCROLL); for(i = 0; i <= CCHILDREN_SCROLLBAR; i++) ssbi.rgstate[i] = sbi.rgstate[i]; if(sx <= Rect->left) ssbi.rgstate[0] |= STATE_SYSTEM_OFFSCREEN; else ssbi.rgstate[0] &= ~STATE_SYSTEM_OFFSCREEN; NtUserSetScrollBarInfo(hWnd, OBJID_VSCROLL, &ssbi); if(ssbi.rgstate[0] & STATE_SYSTEM_OFFSCREEN) Style &= ~WS_VSCROLL; } else Style &= ~WS_VSCROLL; if((Style & WS_HSCROLL) && NtUserGetScrollBarInfo(hWnd, OBJID_HSCROLL, &sbi)) { int i; LONG sy = Rect->bottom; sy -= GetSystemMetrics(SM_CYHSCROLL); for(i = 0; i <= CCHILDREN_SCROLLBAR; i++) ssbi.rgstate[i] = sbi.rgstate[i]; if(sy <= Rect->top) ssbi.rgstate[0] |= STATE_SYSTEM_OFFSCREEN; else ssbi.rgstate[0] &= ~STATE_SYSTEM_OFFSCREEN; NtUserSetScrollBarInfo(hWnd, OBJID_HSCROLL, &ssbi); if(ssbi.rgstate[0] & STATE_SYSTEM_OFFSCREEN) Style &= ~WS_HSCROLL; } else Style &= ~WS_HSCROLL; } if ((Style & WS_VSCROLL) && (Style & WS_HSCROLL)) { if ((ExStyle & WS_EX_LEFTSCROLLBAR) != 0) Rect->left += GetSystemMetrics(SM_CXVSCROLL); else Rect->right -= GetSystemMetrics(SM_CXVSCROLL); Rect->bottom -= GetSystemMetrics(SM_CYHSCROLL); } else { if (Style & WS_VSCROLL) { if ((ExStyle & WS_EX_LEFTSCROLLBAR) != 0) Rect->left += GetSystemMetrics(SM_CXVSCROLL); else Rect->right -= GetSystemMetrics(SM_CXVSCROLL); } else if (Style & WS_HSCROLL) Rect->bottom -= GetSystemMetrics(SM_CYHSCROLL); } if (Rect->top > Rect->bottom) Rect->bottom = Rect->top; if (Rect->left > Rect->right) Rect->right = Rect->left; } else { Rect->right = Rect->left; Rect->bottom = Rect->top; } return Result; }
LRESULT WINAPI User32DefWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL bUnicode) { PWND pWnd = NULL; if (hWnd) { pWnd = ValidateHwnd(hWnd); if (!pWnd) return 0; } switch (Msg) { case WM_NCPAINT: { return DefWndNCPaint(hWnd, (HRGN)wParam, -1); } case WM_NCCALCSIZE: { return DefWndNCCalcSize(hWnd, (BOOL)wParam, (RECT*)lParam); } case WM_POPUPSYSTEMMENU: { /* This is an undocumented message used by the windows taskbar to display the system menu of windows that belong to other processes. */ HMENU menu = GetSystemMenu(hWnd, FALSE); if (menu) TrackPopupMenu(menu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON, LOWORD(lParam), HIWORD(lParam), 0, hWnd, NULL); return 0; } case WM_NCACTIVATE: { return DefWndNCActivate(hWnd, wParam, lParam); } case WM_NCHITTEST: { POINT Point; Point.x = GET_X_LPARAM(lParam); Point.y = GET_Y_LPARAM(lParam); return (DefWndNCHitTest(hWnd, Point)); } case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: iF10Key = iMenuSysKey = 0; break; case WM_NCLBUTTONDOWN: { return (DefWndNCLButtonDown(hWnd, wParam, lParam)); } case WM_LBUTTONDBLCLK: return (DefWndNCLButtonDblClk(hWnd, HTCLIENT, lParam)); case WM_NCLBUTTONDBLCLK: { return (DefWndNCLButtonDblClk(hWnd, wParam, lParam)); } case WM_NCRBUTTONDOWN: return NC_HandleNCRButtonDown( hWnd, wParam, lParam ); case WM_RBUTTONUP: { POINT Pt; Pt.x = GET_X_LPARAM(lParam); Pt.y = GET_Y_LPARAM(lParam); ClientToScreen(hWnd, &Pt); lParam = MAKELPARAM(Pt.x, Pt.y); if (bUnicode) { SendMessageW(hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, lParam); } else { SendMessageA(hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, lParam); } break; } case WM_NCRBUTTONUP: /* * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked * in Windows), but what _should_ we do? According to MSDN : * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND * message to the window". When is it appropriate? */ break; case WM_CONTEXTMENU: { if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CHILD) { if (bUnicode) { SendMessageW(GetParent(hWnd), Msg, wParam, lParam); } else { SendMessageA(GetParent(hWnd), WM_CONTEXTMENU, wParam, lParam); } } else { POINT Pt; LONG_PTR Style; LONG HitCode; Style = GetWindowLongPtrW(hWnd, GWL_STYLE); Pt.x = GET_X_LPARAM(lParam); Pt.y = GET_Y_LPARAM(lParam); if (Style & WS_CHILD) { ScreenToClient(GetParent(hWnd), &Pt); } HitCode = DefWndNCHitTest(hWnd, Pt); if (HitCode == HTCAPTION || HitCode == HTSYSMENU) { HMENU SystemMenu; UINT Flags; if((SystemMenu = GetSystemMenu(hWnd, FALSE))) { MenuInitSysMenuPopup(SystemMenu, GetWindowLongPtrW(hWnd, GWL_STYLE), GetClassLongPtrW(hWnd, GCL_STYLE), HitCode); if(HitCode == HTCAPTION) Flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON; else Flags = TPM_LEFTBUTTON; TrackPopupMenu(SystemMenu, Flags, Pt.x, Pt.y, 0, hWnd, NULL); } } } break; } case WM_PRINT: { DefWndPrint(hWnd, (HDC)wParam, lParam); return (0); } case WM_SYSCOLORCHANGE: { /* force to redraw non-client area */ DefWndNCPaint(hWnd, HRGN_WINDOW, -1); /* Use InvalidateRect to redraw client area, enable * erase to redraw all subcontrols otherwise send the * WM_SYSCOLORCHANGE to child windows/controls is required */ InvalidateRect(hWnd,NULL,TRUE); return (0); } case WM_PAINTICON: case WM_PAINT: { PAINTSTRUCT Ps; HDC hDC; /* If already in Paint and Client area is not empty just return. */ if (pWnd->state2 & WNDS2_STARTPAINT && !IsRectEmpty(&pWnd->rcClient)) { ERR("In Paint and Client area is not empty!\n"); return 0; } hDC = BeginPaint(hWnd, &Ps); if (hDC) { HICON hIcon; if (IsIconic(hWnd) && ((hIcon = (HICON)GetClassLongPtrW( hWnd, GCLP_HICON)))) { RECT ClientRect; INT x, y; GetClientRect(hWnd, &ClientRect); x = (ClientRect.right - ClientRect.left - GetSystemMetrics(SM_CXICON)) / 2; y = (ClientRect.bottom - ClientRect.top - GetSystemMetrics(SM_CYICON)) / 2; DrawIcon(hDC, x, y, hIcon); } EndPaint(hWnd, &Ps); } return (0); } case WM_CLOSE: DestroyWindow(hWnd); return (0); case WM_MOUSEACTIVATE: if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CHILD) { LONG Ret = SendMessageW(GetParent(hWnd), WM_MOUSEACTIVATE, wParam, lParam); if (Ret) return (Ret); } return ( (HIWORD(lParam) == WM_LBUTTONDOWN && LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE ); case WM_ACTIVATE: /* The default action in Windows is to set the keyboard focus to * the window, if it's being activated and not minimized */ if (LOWORD(wParam) != WA_INACTIVE && !(GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_MINIMIZE)) { //ERR("WM_ACTIVATE %p\n",hWnd); SetFocus(hWnd); } break; case WM_MOUSEWHEEL: if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CHILD) return SendMessageW( GetParent(hWnd), WM_MOUSEWHEEL, wParam, lParam); break; case WM_ERASEBKGND: case WM_ICONERASEBKGND: { RECT Rect; HBRUSH hBrush = (HBRUSH)GetClassLongPtrW(hWnd, GCL_HBRBACKGROUND); if (NULL == hBrush) { return 0; } if (GetClassLongPtrW(hWnd, GCL_STYLE) & CS_PARENTDC) { /* can't use GetClipBox with a parent DC or we fill the whole parent */ GetClientRect(hWnd, &Rect); DPtoLP((HDC)wParam, (LPPOINT)&Rect, 2); } else { GetClipBox((HDC)wParam, &Rect); } FillRect((HDC)wParam, &Rect, hBrush); return (1); } case WM_CTLCOLORMSGBOX: case WM_CTLCOLOREDIT: case WM_CTLCOLORLISTBOX: case WM_CTLCOLORBTN: case WM_CTLCOLORDLG: case WM_CTLCOLORSTATIC: case WM_CTLCOLORSCROLLBAR: return (LRESULT) DefWndControlColor((HDC)wParam, Msg - WM_CTLCOLORMSGBOX); case WM_CTLCOLOR: return (LRESULT) DefWndControlColor((HDC)wParam, HIWORD(lParam)); case WM_SETCURSOR: { LONG_PTR Style = GetWindowLongPtrW(hWnd, GWL_STYLE); if (Style & WS_CHILD) { /* with the exception of the border around a resizable wnd, * give the parent first chance to set the cursor */ if (LOWORD(lParam) < HTLEFT || LOWORD(lParam) > HTBOTTOMRIGHT) { HWND parent = GetParent( hWnd ); if (bUnicode) { if (parent != GetDesktopWindow() && SendMessageW( parent, WM_SETCURSOR, wParam, lParam)) return TRUE; } else { if (parent != GetDesktopWindow() && SendMessageA( parent, WM_SETCURSOR, wParam, lParam)) return TRUE; } } } return (DefWndHandleSetCursor(hWnd, wParam, lParam, Style)); } case WM_SYSCOMMAND: return (DefWndHandleSysCommand(hWnd, wParam, lParam)); case WM_KEYDOWN: if(wParam == VK_F10) iF10Key = VK_F10; break; case WM_SYSKEYDOWN: { if (HIWORD(lParam) & KF_ALTDOWN) { /* Previous state, if the key was down before this message, this is a cheap way to ignore autorepeat keys. */ if ( !(HIWORD(lParam) & KF_REPEAT) ) { if ( ( wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU ) && !iMenuSysKey ) iMenuSysKey = 1; else iMenuSysKey = 0; } iF10Key = 0; if (wParam == VK_F4) /* Try to close the window */ { HWND top = GetAncestor(hWnd, GA_ROOT); if (!(GetClassLongPtrW(top, GCL_STYLE) & CS_NOCLOSE)) PostMessageW(top, WM_SYSCOMMAND, SC_CLOSE, 0); } else if (wParam == VK_SNAPSHOT) // Alt-VK_SNAPSHOT? { HWND hwnd = hWnd; while (GetParent(hwnd) != NULL) { hwnd = GetParent(hwnd); } DefWndScreenshot(hwnd); } else if ( wParam == VK_ESCAPE || wParam == VK_TAB ) // Alt-Tab/ESC Alt-Shift-Tab/ESC { WPARAM wParamTmp; HWND Active = GetActiveWindow(); // Noticed MDI problem. if (!Active) { FIXME("WM_SYSKEYDOWN VK_ESCAPE no active\n"); break; } wParamTmp = GetKeyState(VK_SHIFT) & 0x8000 ? SC_PREVWINDOW : SC_NEXTWINDOW; SendMessageW( Active, WM_SYSCOMMAND, wParamTmp, wParam ); } } else if( wParam == VK_F10 ) { if (GetKeyState(VK_SHIFT) & 0x8000) SendMessageW( hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, MAKELPARAM(-1, -1) ); iF10Key = 1; } break; } case WM_KEYUP: case WM_SYSKEYUP: { /* Press and release F10 or ALT */ if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU) && iMenuSysKey) || ((wParam == VK_F10) && iF10Key)) SendMessageW( GetAncestor( hWnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L ); iMenuSysKey = iF10Key = 0; break; } case WM_SYSCHAR: { iMenuSysKey = 0; if (wParam == VK_RETURN && IsIconic(hWnd)) { PostMessageW( hWnd, WM_SYSCOMMAND, SC_RESTORE, 0L ); break; } if ((HIWORD(lParam) & KF_ALTDOWN) && wParam) { if (wParam == VK_TAB || wParam == VK_ESCAPE) break; if (wParam == VK_SPACE && (GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) SendMessageW( GetParent(hWnd), Msg, wParam, lParam ); else SendMessageW( hWnd, WM_SYSCOMMAND, SC_KEYMENU, wParam ); } else /* check for Ctrl-Esc */ if (wParam != VK_ESCAPE) MessageBeep(0); break; } case WM_CANCELMODE: { iMenuSysKey = 0; /* FIXME: Check for a desktop. */ //if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu(); MENU_EndMenu( hWnd ); if (GetCapture() == hWnd) { ReleaseCapture(); } break; } case WM_VKEYTOITEM: case WM_CHARTOITEM: return (-1); /* case WM_DROPOBJECT: return DRAG_FILE; */ case WM_QUERYDROPOBJECT: { if (GetWindowLongPtrW(hWnd, GWL_EXSTYLE) & WS_EX_ACCEPTFILES) { return(1); } break; } case WM_QUERYDRAGICON: { UINT Len; HICON hIcon; hIcon = (HICON)GetClassLongPtrW(hWnd, GCL_HICON); if (hIcon) { return ((LRESULT)hIcon); } for (Len = 1; Len < 64; Len++) { if ((hIcon = LoadIconW(NULL, MAKEINTRESOURCEW(Len))) != NULL) { return((LRESULT)hIcon); } } return ((LRESULT)LoadIconW(0, IDI_APPLICATION)); } case WM_ISACTIVEICON: { BOOL isai; isai = (pWnd->state & WNDS_ACTIVEFRAME) != 0; return isai; } case WM_NOTIFYFORMAT: { if (lParam == NF_QUERY) return IsWindowUnicode(hWnd) ? NFR_UNICODE : NFR_ANSI; break; } case WM_SETICON: { return DefWndSetIcon(pWnd, wParam, lParam); } case WM_GETICON: { return DefWndGetIcon(pWnd, wParam, lParam); } case WM_HELP: { if (bUnicode) { SendMessageW(GetParent(hWnd), Msg, wParam, lParam); } else { SendMessageA(GetParent(hWnd), Msg, wParam, lParam); } break; } case WM_SYSTIMER: { THRDCARETINFO CaretInfo; switch(wParam) { case 0xffff: /* Caret timer */ /* switch showing byte in win32k and get information about the caret */ if(NtUserxSwitchCaretShowing(&CaretInfo) && (CaretInfo.hWnd == hWnd)) { DrawCaret(hWnd, &CaretInfo); } break; } break; } case WM_QUERYOPEN: case WM_QUERYENDSESSION: { return (1); } case WM_INPUTLANGCHANGEREQUEST: { HKL NewHkl; if(wParam & INPUTLANGCHANGE_BACKWARD && wParam & INPUTLANGCHANGE_FORWARD) { return FALSE; } //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ? if(wParam & INPUTLANGCHANGE_BACKWARD) NewHkl = (HKL) HKL_PREV; else if(wParam & INPUTLANGCHANGE_FORWARD) NewHkl = (HKL) HKL_NEXT; else NewHkl = (HKL) lParam; NtUserActivateKeyboardLayout(NewHkl, 0); return TRUE; } case WM_INPUTLANGCHANGE: { int count = 0; HWND *win_array = WIN_ListChildren( hWnd ); if (!win_array) break; while (win_array[count]) SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam); HeapFree(GetProcessHeap(),0,win_array); break; } case WM_QUERYUISTATE: { LRESULT Ret = 0; PWND Wnd = ValidateHwnd(hWnd); if (Wnd != NULL) { if (Wnd->HideFocus) Ret |= UISF_HIDEFOCUS; if (Wnd->HideAccel) Ret |= UISF_HIDEACCEL; } return Ret; } case WM_CHANGEUISTATE: { BOOL AlwaysShowCues = FALSE; WORD Action = LOWORD(wParam); WORD Flags = HIWORD(wParam); PWND Wnd; SystemParametersInfoW(SPI_GETKEYBOARDCUES, 0, &AlwaysShowCues, 0); if (AlwaysShowCues) break; Wnd= ValidateHwnd(hWnd); if (!Wnd || lParam != 0) break; if (Flags & ~(UISF_HIDEFOCUS | UISF_HIDEACCEL | UISF_ACTIVE)) break; if (Flags & UISF_ACTIVE) { WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n"); } if (Action == UIS_INITIALIZE) { PDESKTOPINFO Desk = GetThreadDesktopInfo(); if (Desk == NULL) break; Action = Desk->LastInputWasKbd ? UIS_CLEAR : UIS_SET; Flags = UISF_HIDEFOCUS | UISF_HIDEACCEL; /* We need to update wParam in case we need to send out messages */ wParam = MAKEWPARAM(Action, Flags); } switch (Action) { case UIS_SET: /* See if we actually need to change something */ if ((Flags & UISF_HIDEFOCUS) && !Wnd->HideFocus) break; if ((Flags & UISF_HIDEACCEL) && !Wnd->HideAccel) break; /* Don't need to do anything... */ return 0; case UIS_CLEAR: /* See if we actually need to change something */ if ((Flags & UISF_HIDEFOCUS) && Wnd->HideFocus) break; if ((Flags & UISF_HIDEACCEL) && Wnd->HideAccel) break; /* Don't need to do anything... */ return 0; default: WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action); break; } if ((Wnd->style & WS_CHILD) && Wnd->spwndParent != NULL) { /* We're a child window and we need to pass this message down until we reach the root */ hWnd = UserHMGetHandle((PWND)DesktopPtrToUser(Wnd->spwndParent)); } else { /* We're a top level window, we need to change the UI state */ Msg = WM_UPDATEUISTATE; } if (bUnicode) return SendMessageW(hWnd, Msg, wParam, lParam); else return SendMessageA(hWnd, Msg, wParam, lParam); } case WM_UPDATEUISTATE: { BOOL Change = TRUE; BOOL AlwaysShowCues = FALSE; WORD Action = LOWORD(wParam); WORD Flags = HIWORD(wParam); PWND Wnd; SystemParametersInfoW(SPI_GETKEYBOARDCUES, 0, &AlwaysShowCues, 0); if (AlwaysShowCues) break; Wnd = ValidateHwnd(hWnd); if (!Wnd || lParam != 0) break; if (Flags & ~(UISF_HIDEFOCUS | UISF_HIDEACCEL | UISF_ACTIVE)) break; if (Flags & UISF_ACTIVE) { WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n"); } if (Action == UIS_INITIALIZE) { PDESKTOPINFO Desk = GetThreadDesktopInfo(); if (Desk == NULL) break; Action = Desk->LastInputWasKbd ? UIS_CLEAR : UIS_SET; Flags = UISF_HIDEFOCUS | UISF_HIDEACCEL; /* We need to update wParam for broadcasting the update */ wParam = MAKEWPARAM(Action, Flags); } switch (Action) { case UIS_SET: /* See if we actually need to change something */ if ((Flags & UISF_HIDEFOCUS) && !Wnd->HideFocus) break; if ((Flags & UISF_HIDEACCEL) && !Wnd->HideAccel) break; /* Don't need to do anything... */ Change = FALSE; break; case UIS_CLEAR: /* See if we actually need to change something */ if ((Flags & UISF_HIDEFOCUS) && Wnd->HideFocus) break; if ((Flags & UISF_HIDEACCEL) && Wnd->HideAccel) break; /* Don't need to do anything... */ Change = FALSE; break; default: WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action); return 0; } /* Pack the information and call win32k */ if (Change) { if (!NtUserxUpdateUiState(hWnd, Flags | ((DWORD)Action << 3))) break; } /* Always broadcast the update to all children */ EnumChildWindows(hWnd, UserSendUiUpdateMsg, (LPARAM)wParam); break; } /* Move to Win32k !*/ case WM_SHOWWINDOW: if (!lParam) break; // Call when it is necessary. case WM_SYNCPAINT: case WM_SETREDRAW: case WM_CLIENTSHUTDOWN: case WM_GETHOTKEY: case WM_SETHOTKEY: case WM_WINDOWPOSCHANGING: case WM_WINDOWPOSCHANGED: case WM_APPCOMMAND: { LRESULT lResult; NtUserMessageCall( hWnd, Msg, wParam, lParam, (ULONG_PTR)&lResult, FNID_DEFWINDOWPROC, !bUnicode); return lResult; } } return 0; }
LRESULT CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HBRUSH hbrBackground; int count; RECT rcItem; RECT rcClip; HDC hDC; int DcSave; switch (message) { case WM_ERASEBKGND: /* * The list control produces a nasty flicker * when the user is resizing the window because * it erases the background to white, then * paints the list items over it. * * We will clip the drawing so that it only * erases the parts of the list control that * show only the background. */ /* * Get the device context and save its state * to be restored after we're done */ hDC = (HDC) wParam; DcSave = SaveDC(hDC); /* * Get the background brush */ hbrBackground = (HBRUSH) GetClassLongPtrW(hWnd, GCLP_HBRBACKGROUND); /* * Calculate the clip rect by getting the RECT * of the first and last items and adding them up. * * We also have to get the item's icon RECT and * subtract it from our clip rect because we don't * use icons in this list control. */ rcClip.left = LVIR_BOUNDS; SendMessageW(hWnd, LVM_GETITEMRECT, 0, (LPARAM) &rcClip); rcItem.left = LVIR_BOUNDS; count = SendMessageW(hWnd, LVM_GETITEMCOUNT, 0, 0); SendMessageW(hWnd, LVM_GETITEMRECT, count - 1, (LPARAM) &rcItem); rcClip.bottom = rcItem.bottom; rcItem.left = LVIR_ICON; SendMessageW(hWnd, LVM_GETITEMRECT, 0, (LPARAM) &rcItem); rcClip.left = rcItem.right; /* * Now exclude the clip rect */ ExcludeClipRect(hDC, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); /* * Now erase the background * * * FIXME: Should I erase it myself or * pass down the updated HDC and let * the default handler do it? */ GetClientRect(hWnd, &rcItem); FillRect(hDC, &rcItem, hbrBackground); /* * Now restore the DC state that we * saved earlier */ RestoreDC(hDC, DcSave); return TRUE; } /* * We pass on all messages except WM_ERASEBKGND */ return CallWindowProcW(OldProcessListWndProc, hWnd, message, wParam, lParam); }
LRESULT DefWndHandleSetCursor(HWND hWnd, WPARAM wParam, LPARAM lParam, ULONG Style) { /* Not for child windows. */ if (hWnd != (HWND)wParam) { return(0); } switch((INT_PTR) LOWORD(lParam)) { case HTERROR: { WORD Msg = HIWORD(lParam); if (Msg == WM_LBUTTONDOWN || Msg == WM_MBUTTONDOWN || Msg == WM_RBUTTONDOWN || Msg == WM_XBUTTONDOWN) { MessageBeep(0); } break; } case HTCLIENT: { HICON hCursor = (HICON)GetClassLongPtrW(hWnd, GCL_HCURSOR); if (hCursor) { SetCursor(hCursor); return(TRUE); } return(FALSE); } case HTLEFT: case HTRIGHT: { if (Style & WS_MAXIMIZE) { break; } return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZEWE))); } case HTTOP: case HTBOTTOM: { if (Style & WS_MAXIMIZE) { break; } return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENS))); } case HTTOPLEFT: case HTBOTTOMRIGHT: { if (Style & WS_MAXIMIZE) { break; } return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENWSE))); } case HTBOTTOMLEFT: case HTTOPRIGHT: { if (GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_MAXIMIZE) { break; } return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENESW))); } } return((LRESULT)SetCursor(LoadCursorW(0, IDC_ARROW))); }
static LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { PMIXER_WINDOW MixerWindow; DWORD CtrlID, LineOffset; LRESULT Result = 0; SET_VOLUME_CONTEXT Context; switch (uMsg) { case WM_COMMAND: { MixerWindow = GetWindowData(hwnd, MIXER_WINDOW); switch (LOWORD(wParam)) { case IDC_PROPERTIES: { PREFERENCES_CONTEXT Pref; Pref.MixerWindow = MixerWindow; Pref.Mixer = NULL; Pref.SelectedLine = Preferences.SelectedLine; if (DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_PREFERENCES), hwnd, DlgPreferencesProc, (LPARAM)&Pref) == IDOK) { /* update window */ TCHAR szProduct[MAXPNAMELEN]; /* get mixer product name */ if (SndMixerGetProductName(MixerWindow->Mixer, szProduct, sizeof(szProduct) / sizeof(szProduct[0])) == -1) { /* failed to get name */ szProduct[0] = L'\0'; } else { /* copy product */ wcscpy(Preferences.DeviceName, szProduct); } /* destroy old status bar */ DestroyWindow(MixerWindow->hStatusBar); /* update details */ Preferences.SelectedLine = Pref.SelectedLine; /* destroy old mixer */ SndMixerDestroy(Preferences.MixerWindow->Mixer); /* use new selected mixer */ Preferences.MixerWindow->Mixer = Pref.Mixer; /* rebuild dialog controls */ RebuildMixerWindowControls(&Preferences); /* create status window */ MixerWindow->hStatusBar = CreateStatusWindow(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, NULL, hwnd, 0); /* set status bar */ if (MixerWindow->hStatusBar) { SendMessage(MixerWindow->hStatusBar, WM_SETTEXT, 0, (LPARAM)szProduct); } } break; } case IDC_EXIT: { PostQuitMessage(0); break; } case IDC_ABOUT: { HICON hAppIcon = (HICON)GetClassLongPtrW(hwnd, GCLP_HICON); ShellAbout(hwnd, lpAppTitle, NULL, hAppIcon); break; } default: { /* get button id */ CtrlID = LOWORD(wParam); /* check if the message is from the line switch */ if (HIWORD(wParam) == BN_CLICKED && (CtrlID % IDC_LINE_SWITCH == 0)) { /* compute line offset */ LineOffset = CtrlID / IDC_LINE_SWITCH; /* compute window id of line name static control */ CtrlID = LineOffset * IDC_LINE_NAME; /* get line name */ if (GetDlgItemTextW(hwnd, CtrlID, Context.LineName, MIXER_LONG_NAME_CHARS) != 0) { /* setup context */ Context.SliderPos = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0); Context.bVertical = FALSE; Context.bSwitch = TRUE; /* set volume */ SndMixerEnumConnections(Preferences.MixerWindow->Mixer, Preferences.SelectedLine, SetVolumeCallback, (LPVOID)&Context); } } } } break; } case MM_MIXM_LINE_CHANGE: { DPRINT("MM_MIXM_LINE_CHANGE\n"); break; } case MM_MIXM_CONTROL_CHANGE: { DPRINT("MM_MIXM_CONTROL_CHANGE\n"); /* get mixer window */ MixerWindow = GetWindowData(hwnd, MIXER_WINDOW); /* sanity checks */ assert(MixerWindow); assert(MixerWindow->Mixer->hmx == (HMIXER)wParam); SndMixerEnumConnections(MixerWindow->Mixer, Preferences.SelectedLine, MixerControlChangeCallback, (PVOID)lParam); break; } case WM_VSCROLL: { if (LOWORD(wParam) == TB_THUMBTRACK) { /* get dialog item ctrl */ CtrlID = GetDlgCtrlID((HWND)lParam); /* get line index */ LineOffset = CtrlID / IDC_LINE_SLIDER_VERT; /* compute window id of line name static control */ CtrlID = LineOffset * IDC_LINE_NAME; /* get line name */ if (GetDlgItemTextW(hwnd, CtrlID, Context.LineName, MIXER_LONG_NAME_CHARS) != 0) { /* setup context */ Context.SliderPos = HIWORD(wParam); Context.bVertical = TRUE; Context.bSwitch = FALSE; /* set volume */ SndMixerEnumConnections(Preferences.MixerWindow->Mixer, Preferences.SelectedLine, SetVolumeCallback, (LPVOID)&Context); } } break; } case WM_CREATE: { MixerWindow = ((LPCREATESTRUCT)lParam)->lpCreateParams; SetWindowLongPtr(hwnd, GWL_USERDATA, (LONG_PTR)MixerWindow); MixerWindow->hWnd = hwnd; MixerWindow->Mixer = SndMixerCreate(MixerWindow->hWnd); if (MixerWindow->Mixer != NULL) { TCHAR szProduct[MAXPNAMELEN]; /* get mixer product name */ if (SndMixerGetProductName(MixerWindow->Mixer, szProduct, sizeof(szProduct) / sizeof(szProduct[0])) == -1) { /* failed to get name */ szProduct[0] = L'\0'; } /* initialize perferences */ ZeroMemory(&Preferences, sizeof(Preferences)); /* store mixer */ Preferences.Mixer = MixerWindow->Mixer; /* store mixer window */ Preferences.MixerWindow = MixerWindow; /* first destination line id */ Preferences.SelectedLine = 0xFFFF0000; /* copy product */ wcscpy(Preferences.DeviceName, szProduct); if (!RebuildMixerWindowControls(&Preferences)) { DPRINT("Rebuilding mixer window controls failed!\n"); SndMixerDestroy(MixerWindow->Mixer); MixerWindow->Mixer = NULL; Result = -1; } /* create status window */ MixerWindow->hStatusBar = CreateStatusWindow(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, NULL, hwnd, 0); if (MixerWindow->hStatusBar) { SendMessage(MixerWindow->hStatusBar, WM_SETTEXT, 0, (LPARAM)szProduct); } } break; } case WM_DESTROY: { MixerWindow = GetWindowData(hwnd, MIXER_WINDOW); if (MixerWindow != NULL) { if (MixerWindow->Mixer != NULL) { SndMixerDestroy(MixerWindow->Mixer); } HeapFree(hAppHeap, 0, MixerWindow); } break; } case WM_CLOSE: { PostQuitMessage(0); break; } default: { Result = DefWindowProc(hwnd, uMsg, wParam, lParam); break; } } return Result; }
VOID DefWndDoButton(HWND hWnd, WPARAM wParam) { MSG Msg; HDC WindowDC; BOOL Pressed = TRUE, OldState; WPARAM SCMsg; HMENU hSysMenu; ULONG ButtonType; DWORD Style; UINT MenuState; Style = GetWindowLongPtrW(hWnd, GWL_STYLE); switch (wParam) { case HTCLOSE: hSysMenu = GetSystemMenu(hWnd, FALSE); MenuState = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND); /* in case of error MenuState==0xFFFFFFFF */ if (!(Style & WS_SYSMENU) || (MenuState & (MF_GRAYED|MF_DISABLED)) || (GetClassLongPtrW(hWnd, GCL_STYLE) & CS_NOCLOSE)) return; ButtonType = DFCS_CAPTIONCLOSE; SCMsg = SC_CLOSE; break; case HTMINBUTTON: if (!(Style & WS_MINIMIZEBOX)) return; ButtonType = DFCS_CAPTIONMIN; SCMsg = ((Style & WS_MINIMIZE) ? SC_RESTORE : SC_MINIMIZE); break; case HTMAXBUTTON: if (!(Style & WS_MAXIMIZEBOX)) return; ButtonType = DFCS_CAPTIONMAX; SCMsg = ((Style & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE); break; default: ASSERT(FALSE); return; } /* * FIXME: Not sure where to do this, but we must flush the pending * window updates when someone clicks on the close button and at * the same time the window is overlapped with another one. This * looks like a good place for now... */ UpdateWindow(hWnd); WindowDC = GetWindowDC(hWnd); UserDrawCaptionButtonWnd(hWnd, WindowDC, TRUE, ButtonType); SetCapture(hWnd); for (;;) { if (GetMessageW(&Msg, 0, WM_MOUSEFIRST, WM_MOUSELAST) <= 0) break; if (CallMsgFilterW( &Msg, MSGF_MAX )) continue; if (Msg.message == WM_LBUTTONUP) break; if (Msg.message != WM_MOUSEMOVE) continue; OldState = Pressed; Pressed = (DefWndNCHitTest(hWnd, Msg.pt) == wParam); if (Pressed != OldState) UserDrawCaptionButtonWnd(hWnd, WindowDC, Pressed, ButtonType); } if (Pressed) UserDrawCaptionButtonWnd(hWnd, WindowDC, FALSE, ButtonType); ReleaseCapture(); ReleaseDC(hWnd, WindowDC); if (Pressed) SendMessageW(hWnd, WM_SYSCOMMAND, SCMsg, MAKELONG(Msg.pt.x,Msg.pt.y)); }