Platform SDK: DLLs, Processes, and Threads
GetConsoleWindow
The GetConsoleWindow function retrieves the window handle used by the console associated with the calling process.
HWND GetConsoleWindow(void);
Parameters
This function has no parameters.
Return Values
The return value is a handle to the window used by the console associated with the calling process or NULL if there is no such associated console.
Remarks
To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0500 or later. For more information, see Using the Windows Headers.
Requirements
Client Requires Windows XP or Windows 2000 Professional.
Server Requires Windows Server 2003 or Windows 2000 Server.
Header
Declared in Wincon.h; include Windows.h.
Library
Link to Kernel32.lib.
DLL Requires Kernel32.dll.
See Also
Character-Mode Applications Overview, Console Functions
Positioning DOS window
-
- Addict
- Posts: 841
- Joined: Mon Jun 07, 2004 7:10 pm
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
chippy73
Sometimes debuging your values will help you alot
hDosWin returns 0 on wim98
But
is valid
Use Freaks
to close the window
This workes on win98
Henrik
Sometimes debuging your values will help you alot
Code: Select all
hDosWin = FindWindow_(#Null, "edit.com")
Debug hDosWin
But
Code: Select all
hDosWin = FindWindow_(#Null, "MS-DOS Editor")
Debug hDosWin
Use Freaks
Code: Select all
SendMessage_(hDosWin, #WM_CLOSE, 0, 0)
This workes on win98
Code: Select all
If OpenWindow(0, 580, 0, 250, 100, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Test") And CreateGadgetList(WindowID(0))
;--> Just to keep our window on top
SetWindowPos_(WindowID(0), #HWND_TOPMOST, -1, -1, -1, -1, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_SHOWWINDOW)
ButtonGadget(1, 75, 10, 100, 20, "close Dos Window")
RunProgram("edit.com")
Repeat
event = WaitWindowEvent()
If event = #PB_EventGadget And EventGadgetID() = 1
; hDosWin = FindWindow_(#Null, "edit.com")
;Edit's name under win98 is "MS-DOS Editor"
hDosWin = FindWindow_(#Null, "MS-DOS Editor")
Debug hDosWin
SendMessage_(hDosWin, #WM_CLOSE, 0, 0)
; DestroyWindow_(hDosWin)
EndIf
Until event = #PB_Event_CloseWindow
EndIf
End
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
Re: Positioning DOS window
Code updated For 5.62
[/color]
Code: Select all
RunProgram("edit.com")
DosWindowTitle$ = "C:\Windows\system32\edit.com"
Delay(2000)
hDosWin = FindWindow_("ConsoleWindowClass", DosWindowTitle$)
Debug hDosWin
SetWindowPos_(hDosWin, 0, 10, 100, 600,400, #SWP_SHOWWINDOW)
Delay(2000)
SendMessage_(hDosWin, #WM_CLOSE, 0, 0)
Re: Positioning DOS window
Hmm, it doesn't close the DOS window on Win XP; and doesn't even work on Vista and later at all (no DOS window gets opened because "edit.com" doesn't exist).Poplar wrote:Code updated For 5.62
- Pierre Bellisle
- User
- Posts: 35
- Joined: Wed Jun 27, 2018 5:12 am
Re: Positioning DOS window
What if you try those APIs...
Code: Select all
EnableExplicit
#SM_CXSCREEN = 0
#SM_CYSCREEN = 1
Import "kernel32.lib"
GetConsoleWindow()
EndImport
Define.rect ConsoleRect
Define.l WindowWidth
Define.l WindowHeight
Define.l hConsole
Define.Size ConsoleSize
OpenConsole()
ConsoleTitle ("PureBasic - Center console on screen")
RunProgram("Cmd.exe")
hConsole = GetConsoleWindow() ;Get console handle
GetWindowRect_(hConsole, ConsoleRect) ;Get console rectangle
ConsoleSize\cx = ConsoleRect\Right - ConsoleRect\Left ;Compute console width
ConsoleSize\cy = ConsoleRect\Bottom - ConsoleRect\Top ;Compute console height
SetWindowPos_(hConsole, #HWND_TOP, ;Console handle. top zOrder
(GetSystemMetrics_(#SM_CXSCREEN) - ConsoleSize\cx) / 2, ;Compute console x center, GetSystemMetrics_() retreive screen size
(GetSystemMetrics_(#SM_CYSCREEN) - ConsoleSize\cy) / 2, ;Compute console y center, GetSystemMetrics_() retreive screen size
ConsoleSize\cx, ConsoleSize\cy, #SWP_SHOWWINDOW) ;SizeX, SizeY, Show the window
CloseConsole()
End
- Kwai chang caine
- Always Here
- Posts: 5357
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Positioning DOS window
Works great here with W7 X86 / v5.61 X86
Thanks
Thanks
The happiness is a road...
Not a destination
Not a destination
Re: Positioning DOS window
Here is my version
Code: Select all
Import "kernel32.lib"
GetConsoleWindow_() As "GetConsoleWindow"
EndImport
Procedure.i SetConsolePosition(X.i,Y.i)
ProcedureReturn SetWindowPos_(GetConsoleWindow_(),#Null,X,Y,#Null,#Null,#SWP_NOZORDER|#SWP_NOSIZE|#SWP_SHOWWINDOW)
EndProcedure
Procedure.i SetConsolePosition_XP(X.i,Y.i)
Protected WindowHandle.i
Protected Buffer.s = Space(1024)
If GetConsoleTitle_(@Buffer,1024)
WindowHandle = FindWindow_(#Null,Buffer)
If WindowHandle
ProcedureReturn SetWindowPos_(WindowHandle,#Null,X,Y,#Null,#Null,#SWP_NOZORDER|#SWP_NOSIZE|#SWP_SHOWWINDOW)
EndIf
EndIf
EndProcedure
If OpenConsole()
SetConsolePosition(10,10)
;SetConsolePosition_XP(10,10)
Input()
EndIf
Re: Positioning DOS window
Mijikai, your version doesn't work for me with Win 7:
Code: Select all
---------------------------
PureBasic - Linker error
---------------------------
POLINK: error: Unresolved external symbol 'GetConsoleWindow'.
POLINK: fatal error: 1 unresolved external(s).
---------------------------
OK
---------------------------
Re: Positioning DOS window
Should work, thats the OS im currently using.Dude wrote:Mijikai, your version doesn't work for me with Win 7...
Mby some silly AV is blocking?
Re: Positioning DOS window
Mijikai....
Tested on Windows 10 Pro:
5.46 LTS (x86)
5.62 (x86)
5.62 (x64)
5.70 b1 (x86)
Polink errors on all versions... except 5.62 (x64)
It worked.
Tested on Windows 10 Pro:
5.46 LTS (x86)
5.62 (x86)
5.62 (x64)
5.70 b1 (x86)
Polink errors on all versions... except 5.62 (x64)
It worked.
- It was too lonely at the top.
System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Re: Positioning DOS window
I also did some testingblueb wrote:Mijikai....
Tested on Windows 10 Pro:
5.46 LTS (x86)
5.62 (x86)
5.62 (x64)
5.70 b1 (x86)
Polink errors on all versions... except 5.62 (x64)
It worked.
the PB version i used on my old PC is 5.60
-> x64 is working and x86 is not
so clearly PB has a Bug.