powerbasic 通过鼠标控制窗口大小
时间: 2023-07-18 10:32:26 浏览: 154
是的,PowerBASIC 可以通过鼠标控制窗口大小。您可以使用内置的控件或 API 函数来实现此功能。下面是一个使用 API 函数的示例代码:
```
#COMPILE EXE
#DIM ALL
%IDC_BUTTON = 100
DECLARE FUNCTION WindowProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
DECLARE FUNCTION SetWindowLongPtr LIB "USER32.DLL" ALIAS "SetWindowLongPtrA" (BYVAL hWnd AS DWORD, BYVAL nIndex AS LONG, BYVAL dwNewLong AS DWORD) AS DWORD
DECLARE FUNCTION GetWindowLongPtr LIB "USER32.DLL" ALIAS "GetWindowLongPtrA" (BYVAL hWnd AS DWORD, BYVAL nIndex AS LONG) AS DWORD
GLOBAL hDlg AS DWORD
FUNCTION PBMAIN () AS LONG
DIALOG NEW 0, "Test", , , 200, 200, %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX, %WS_EX_CONTROLPARENT TO hDlg
CONTROL ADD BUTTON, hDlg, %IDC_BUTTON, "Click me", 50, 50, 100, 25
DIALOG SHOW MODAL hDlg CALL WindowProc
END FUNCTION
FUNCTION WindowProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
SELECT CASE wMsg
CASE %WM_NCHITTEST
' Allow resizing of the window
LOCAL x AS LONG, y AS LONG
x = LOWRD(lParam)
y = HIWRD(lParam)
IF x < 5 AND y < 5 THEN
FUNCTION = %HTTOPLEFT
ELSEIF x > (GETCLIENTWIDTH(hWnd) - 5) AND y < 5 THEN
FUNCTION = %HTTOPRIGHT
ELSEIF x < 5 AND y > (GETCLIENTHEIGHT(hWnd) - 5) THEN
FUNCTION = %HTBOTTOMLEFT
ELSEIF x > (GETCLIENTWIDTH(hWnd) - 5) AND y > (GETCLIENTHEIGHT(hWnd) - 5) THEN
FUNCTION = %HTBOTTOMRIGHT
ELSEIF x < 5 THEN
FUNCTION = %HTLEFT
ELSEIF x > (GETCLIENTWIDTH(hWnd) - 5) THEN
FUNCTION = %HTRIGHT
ELSEIF y < 5 THEN
FUNCTION = %HTTOP
ELSEIF y > (GETCLIENTHEIGHT(hWnd) - 5) THEN
FUNCTION = %HTBOTTOM
ELSE
FUNCTION = %HTCLIENT
END IF
CASE %WM_COMMAND
SELECT CASE LOWRD(wParam)
CASE %IDC_BUTTON
MSGBOX "Button clicked"
END SELECT
CASE %WM_DESTROY
POSTQUITMESSAGE 0
END SELECT
FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
END FUNCTION
```
此代码创建一个具有可调整大小的窗口和一个按钮的对话框。您可以通过拖动窗口边框来调整大小。在 `WindowProc` 函数中,`%WM_NCHITTEST` 消息用于确定鼠标指针位于窗口的哪个部分。如果指针位于窗口的边框上,则返回相应的 `HT*` 值,表示允许调整大小。
阅读全文