PowerBASIC語言可移動的無標題欄窗體程式碼
阿新 • • 發佈:2018-11-01
#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 CASE100 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,"dalai" 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拖動,窗體位置會移動。