PowerBASIC语言可移动的无标题栏窗体代码

#COMPILE EXE
#DIM ALL
#INCLUDE "Win32API.inc"
GLOBAL hDlg, hContextListView AS DWORD
%IDMC_ListViewOne = 920  : %IDMC_ListViewTwo = 921
GLOBAL flag AS LONG
GLOBAL xx,yy AS LONG
GLOBAL ipt AS POINT
GLOBAL xpt AS POINT
  
FUNCTION PBMAIN() AS LONG
  DIALOG NEW PIXELS, 0, "Label Test",,,100,30, %WS_POPUP TO hDlg
  CONTROL ADD LABEL, hDlg, 100,"右键点击", 0,0,100,30,%SS_NOTIFY OR %WS_BORDER
   ‘上下文菜单
    MENU NEW POPUP TO hContextListView
    MENU ADD STRING, hContextListView, "打开",  %IDMC_ListViewOne,  %MF_ENABLED
    MENU ADD STRING, hContextListView, "退出",  %IDMC_ListViewTwo,  %MF_ENABLED
    DIALOG SHOW MODAL hDlg CALL DlgProc
END FUNCTION

CALLBACK FUNCTION DlgProc() AS LONG

  LOCAL x, y, iReturn AS LONG
    SELECT CASE CB.MSG
        CASE %WM_INITDIALOG
            SetWindowPos(hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE)  on Top
        CASE %WM_ContextMenu
            x = LO(WORD,CB.LPARAM) : y = HI(WORD, CB.LPARAM)
            iReturn = GetDlgCtrlID (CB.WPARAM)             get control ID
            SELECT CASE iReturn
               CASE 100
                  TrackPopupMenu hContextListView, %TPM_LEFTALIGN, x, y, 0, CB.HNDL, BYVAL 0
            END SELECT
        CASE %WM_COMMAND
             SELECT CASE CB.CTL
                CASE %IDMC_ListViewOne
                    CONTROL SET TEXT CBHNDL,100,"*"
                CASE %IDMC_ListViewTwo
                    DIALOG END CBHNDL
              END SELECT
         CASE %WM_SetCursor
            SELECT CASE HI(WORD, CB.LPARAM)
               CASE %WM_LBUTTONDOWN
                    flag=1
                    GetCursorPos ipt
                    DIALOG GET LOC hDlg TO xx, yy
               CASE %WM_MOUSEMOVE
                 IF flag=1 THEN
                     GetCursorPos xpt
                     CONTROL SET TEXT CBHNDL,100,"move:"+STR$(xpt.x)+","+STR$(xpt.y)
                     DIALOG SET LOC CBHNDL, xx+xpt.x-ipt.x,yy+xpt.y-ipt.y
                 END IF
              CASE %WM_LBUTTONUP
                  flag=0
            END SELECT
      END SELECT
END FUNCTION

以上程序代码完整复制下来,即可创建一个程序,程序是一个小窗口,窗口上只有一个label控件,右键点击label,可弹出菜单,左键按住label拖动,窗体位置会移动。

PowerBASIC语言可移动的无标题栏窗体代码

上一篇:std::ios::sync_with_stdio和tie()——给cin加速


下一篇:3.Appnium的安装