⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 怎样使窗口保持在屏幕的中央.txt

📁 VB技巧问答10000例 VB技巧问答10000例
💻 TXT
字号:
你 可 以 设 置 窗 体 的 StartUpPosition属 性 为 2, 这 样 窗 口 一 开 始 就 出 现 在 屏 幕 中 央 。 VB缺 乏 一 个 事 件 来 检 测 用 户 是 否 移 动 窗 口 , 你 可 以 参 考 “在msgblst中如何处理指向结构变量的地址”所 介 绍 的 方 法 来 禁 止 用 户 移 动 窗 口 。 
<END>
禁 止 窗 口 移 动 可 以 使 用 : 
    Form1.Moveable=false 
<END>   
VOID 
    CenterWindow( 
     HWND hwnd 
     ) 
    { 
     RECT rect; 
     LONG dx, dy; 
     LONG dxParent, dyParent; 
     LONG Style; 
     
     // Get window rect 
     GetWindowRect(hwnd, &rect); 
     
     dx = rect.right - rect.left; 
     dy = rect.bottom - rect.top; 
     
     // Get parent rect 
     Style = GetWindowLong(hwnd, GWL_STYLE); 
     if ((Style & WS_CHILD) == 0) { 
     
     // Return the desktop windows size (size of main screen) 
     dxParent = GetSystemMetrics(SM_CXSCREEN); 
     dyParent = GetSystemMetrics(SM_CYSCREEN); 
     } else { 
     HWND hwndParent; 
     RECT rectParent; 
     
     hwndParent = GetParent(hwnd); 
     if (hwndParent == NULL) { 
     hwndParent = GetDesktopWindow(); 
     } 
     
     GetWindowRect(hwndParent, &rectParent); 
     
     dxParent = rectParent.right - rectParent.left; 
     dyParent = rectParent.bottom - rectParent.top; 
     } 
     
     // Centre the child in the parent 
     rect.left = (dxParent - dx) / 2; 
     rect.top = (dyParent - dy) / 3; 
     
     // Move the child into position 
     SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, 0, 0, SWP_NOSIZE); 
     
     SetForegroundWindow(hwnd); 
<END>    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -