Раздел посвящен программированию с использованием Power Basic.
-
SLUTER
-
- Новичок
-
-
- Сообщения: 49
- Зарегистрирован: 06.06.2010 (Вс) 18:26
SLUTER » 02.01.2011 (Вс) 16:15
имеется следующий код. при деактивации и активации окна фокус с активной кнопки уходит в никуда.
- Код: Выделить всё
#DIM ALL
#COMPILE EXE
#INCLUDE "WIN32API.INC"
GLOBAL ghInstance AS DWORD
FUNCTION WINMAIN (BYVAL hInstance AS LONG, BYVAL hPrevInstance AS LONG, BYVAL pszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
LOCAL szClassName AS ASCIIZ * %MAX_PATH
LOCAL twcx AS WNDCLASSEX
LOCAL tmsg AS tagMsg
LOCAL hWnd AS DWORD
ghInstance = hInstance
szClassName = "TestTest"
twcx.cbSize = SIZEOF(twcx)
twcx.style = %CS_DBLCLKS
twcx.lpfnWndProc = CODEPTR(Form1_WndProc)
twcx.cbClsExtra = 0
twcx.cbWndExtra = 0
twcx.hInstance = ghInstance
twcx.hIcon = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)
twcx.hCursor = LoadCursor(%NULL, BYVAL %IDC_ARROW)
twcx.hbrBackground = %COLOR_APPWORKSPACE
twcx.lpszMenuName = %NULL
twcx.lpszClassName = VARPTR(szClassName)
twcx.hIconSm = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)
IF ISFALSE RegisterClassEx(twcx) THEN
FUNCTION = %FALSE
EXIT FUNCTION
END IF
hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _
szClassName, _
"Testing", _
%WS_POPUP OR %WS_CAPTION OR _
%WS_MINIMIZEBOX OR %WS_SYSMENU, _
0, 0, _
375, 333, _
%NULL, %NULL, _
ghInstance, BYVAL %NULL)
IF ISFALSE hWnd THEN
FUNCTION = %FALSE
EXIT FUNCTION
END IF
CALL CenterWindow(GetDesktopWindow, hWnd)
ShowWindow hWnd, %SW_SHOW
UpdateWindow hWnd
WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
TranslateMessage tmsg
DispatchMessage tmsg
END IF
WEND
FUNCTION = tmsg.wParam
END FUNCTION
FUNCTION Form1_WndProc (BYVAL hWnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG
LOCAL hWndChild AS DWORD
LOCAL hFont AS DWORD
SELECT CASE uMsg
CASE %WM_COMMAND
SELECT CASE LOWRD(wParam)
CASE 1
IF HIWRD(wParam) = %BN_CLICKED THEN
'PostMessage hWnd, %WM_CLOSE, 0, 0
MSGBOX "A"
END IF
END SELECT
CASE %WM_DESTROY
PostQuitMessage 0
FUNCTION = %FALSE
EXIT FUNCTION
CASE %WM_CREATE
hFont = GetStockObject(%DEFAULT_GUI_FONT)
SendMessage hWndChild, %WM_SETREDRAW, %FALSE, 0
hWndChild = CreateWindowEx(%NULL, _
"Button", _
"OK", _
%WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
%BS_DEFPUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, _
145, 150, _
63, 23, _
hWnd, 1, _
ghInstance, BYVAL %NULL)
SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE
hWndChild = CreateWindowEx(%NULL, _
"Button", _
"ASS", _
%WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
%BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER, _
245, 150, _
63, 23, _
hWnd, 3, _
ghInstance, BYVAL %NULL)
SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE
SetFocus GetNextDlgTabItem(hWnd, %NULL, %FALSE)
FUNCTION = %FALSE
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)
END FUNCTION
FUNCTION CenterWindow(hndl1 AS DWORD, hndl2 AS DWORD) AS LONG
LOCAL x AS LONG, y AS LONG
LOCAL rc1 AS RECT
LOCAL rc2 AS RECT
LOCAL rc3 AS RECT
GetWindowRect hndl1, rc1
GetWindowRect hndl2, rc2
CALL GetWindowRect(hndl1, rc1)
CALL GetWindowRect(hndl2, rc2)
IF hndl1 = GetDesktopWindow THEN CALL SystemParametersInfo(%SPI_GETWORKAREA, 0, rc3, 0)
x = (rc1.nRight / 2) - ((rc2.nRight - rc2.nLeft) / 2) - ((rc1.nRight - rc3.nRight) / 2) + (rc3.nLeft / 2)
y = (rc1.nBottom / 2) - ((rc2.nBottom - rc2.nTop) / 2) - ((rc1.nBottom - rc3.nBottom) / 2) + (rc3.nTop / 2)
CALL SetWindowPos(hndl2, 0, x,y, 0, 0, %SWP_NOSIZE OR %SWP_NOACTIVATE OR %SWP_NOZORDER)
END FUNCTION
Вернуться в Power Basic
Кто сейчас на конференции
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 23