1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-06-29 11:40:38 +00:00
QB64-PE/internal/help/_WINDOWHANDLE.txt
SteveMcNeill 33adc04fc4 Add temp folder to repo. It's necessary as well!
Just more initial setting on... nothing much to see here.
2022-04-28 13:39:56 -04:00

98 lines
5 KiB
Plaintext

{{DISPLAYTITLE:_WINDOWHANDLE}}
The [[_WINDOWHANDLE]] function returns the window handle assigned to the current program by the OS. Windows-only.
{{PageSyntax}}
: {{Parameter|hwnd&&}} = [[_WINDOWHANDLE]]
{{PageDescription}}
* The result is an [[_INTEGER64]] number assigned by Windows to your running program.
* Use it to make [[Windows Libraries|API calls]] that require a window handle to be passed.
* [[Keywords_currently_not_supported_by_QB64#Keywords_Not_Supported_in_Linux_or_MAC_OSX_versions|Not available in Linux or macOS]].
==Availability==
* '''Build 20170924/68'''.
{{PageExamples}}
''Example:'' Showing the system-default message box in Windows.
{{CodeStart}} '' ''
'Message Box Constant values as defined by Microsoft (MBType)
{{Cl|CONST}} MB_OK& = 0 'OK button only
{{Cl|CONST}} MB_OKCANCEL& = 1 'OK & Cancel
{{Cl|CONST}} MB_ABORTRETRYIGNORE& = 2 'Abort, Retry & Ignore
{{Cl|CONST}} MB_YESNOCANCEL& = 3 'Yes, No & Cancel
{{Cl|CONST}} MB_YESNO& = 4 'Yes & No
{{Cl|CONST}} MB_RETRYCANCEL& = 5 'Retry & Cancel
{{Cl|CONST}} MB_CANCELTRYCONTINUE& = 6 'Cancel, Try Again & Continue
{{Cl|CONST}} MB_ICONSTOP& = 16 'Error stop sign icon
{{Cl|CONST}} MB_ICONQUESTION& = 32 'Question-mark icon
{{Cl|CONST}} MB_ICONEXCLAMATION& = 48 'Exclamation-point icon
{{Cl|CONST}} MB_ICONINFORMATION& = 64 'Letter i in a circle icon
{{Cl|CONST}} MB_DEFBUTTON1& = 0 '1st button default(left)
{{Cl|CONST}} MB_DEFBUTTON2& = 256 '2nd button default
{{Cl|CONST}} MB_DEFBUTTON3& = 512 '3rd button default(right)
{{Cl|CONST}} MB_APPLMODAL& = 0 'Message box applies to application only
{{Cl|CONST}} MB_SYSTEMMODAL& = 4096 'Message box on top of all other windows
{{Cl|CONST}} MB_SETFOCUS& = 65536 'Set message box as focus
{{Cl|CONST}} IDOK& = 1 'OK button pressed
{{Cl|CONST}} IDCANCEL& = 2 'Cancel button pressed
{{Cl|CONST}} IDABORT& = 3 'Abort button pressed
{{Cl|CONST}} IDRETRY& = 4 'Retry button pressed
{{Cl|CONST}} IDIGNORE& = 5 'Ignore button pressed
{{Cl|CONST}} IDYES& = 6 'Yes button pressed
{{Cl|CONST}} IDNO& = 7 'No button pressed
{{Cl|CONST}} IDTRYAGAIN& = 10 'Try again button pressed
{{Cl|CONST}} IDCONTINUE& = 1 'Continue button pressed
'----------------------------------------------------------------------------------------
{{Cl|DECLARE LIBRARY|DECLARE DYNAMIC LIBRARY}} "user32"
{{Cl|FUNCTION}} MessageBoxA& ({{Cl|BYVAL}} hwnd {{Cl|AS}} {{Cl|LONG}}, Message {{Cl|AS}} {{Cl|STRING}}, Title {{Cl|AS}} {{Cl|STRING}}, {{Cl|BYVAL}} MBType {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|LONG}})
{{Cl|DECLARE LIBRARY|END DECLARE}}
DO
msg& = 0: icon& = 0: DB& = 0
{{Cl|INPUT}} "Enter Message Box type(0 to 6 other Quits): ", BOX&
{{Cl|IF...THEN|IF}} BOX& < 0 {{Cl|OR (boolean)|OR}} BOX& > 6 {{Cl|THEN}} {{Cl|EXIT DO}}
{{Cl|INPUT}} "Enter Icon&(0=none, 1=stop, 2=?, 3=!, 4=info): ", Icon&
{{Cl|IF...THEN|IF}} BOX& {{Cl|THEN}} {{Cl|INPUT (file mode)|INPUT}} "Enter Default Button(1st, 2nd or 3rd): ", DB&
{{Cl|IF...THEN|IF}} DB& {{Cl|THEN}} DB& = DB& - 1 'adjust value to 0, 1, or 2
msg& = MsgBox&("Box Title", "Box text message", BOX&, Icon&, DB&, 4096) 'on top of all windows
{{Cl|PRINT}} "Button ="; msg&
{{Cl|LOOP}}
{{Cl|END}}
{{Cl|FUNCTION}} MsgBox& (Title$, Message$, BoxType&, Icon&, DBtn&, Mode&)
{{Cl|SELECT CASE}} Icon&
{{Cl|CASE}} 1: Icon& = MB_ICONSTOP& 'warning X-sign icon
{{Cl|CASE}} 2: Icon& = MB_ICONQUESTION& 'question-mark icon
{{Cl|CASE}} 3: Icon& = MB_ICONEXCLAMATION& 'exclamation-point icon
{{Cl|CASE}} 4: Icon& = MB_ICONINFORMATION& 'lowercase letter i in circle
{{Cl|CASE ELSE}}: Icon& = 0 'no icon
{{Cl|END SELECT}}
{{Cl|IF...THEN|IF}} BoxType& > 0 {{Cl|AND (boolean)|AND}} DBtn& > 0 {{Cl|THEN}} 'set default button as 2nd(256) or 3rd(512)
{{Cl|SELECT CASE}} BoxType&
{{Cl|CASE}} 2, 3, 6
{{Cl|IF...THEN|IF}} DBtn& = 2 {{Cl|THEN}} Icon& = Icon& + MB_DEFBUTTON3& {{Cl|ELSE}} Icon& = Icon& + MB_DEFBUTTON2& '3 button
{{Cl|CASE ELSE}}: Icon& = Icon& + MB_DEFBUTTON2& '2nd button default
{{Cl|END SELECT}}
{{Cl|END IF}}
Focus& = MB_SetFocus&
MsgBox& = MessageBoxA&({{Cl|_WINDOWHANDLE}}, Message$, Title$, BoxType& + Icon& + Mode& + Focus&) 'focus on button
{{Cl|END FUNCTION}} '' ''
{{CodeEnd}}
:''Explanation:'' Notice how the call to the external dynamic library function MessageBoxA& passes _WINDOWHANDLE to the API and how the message box shown is created as a child of your program's window, not allowing the main window to be manipulated while the message box is open.
{{PageSeeAlso}}
* [[_WINDOWHASFOCUS]]
* [[Windows Libraries]]
{{PageNavigation}}
<