Positioning DOS window

Windows specific forum
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: Positioning DOS window

Post by fryquez »

You need the "_" prefix for x86.

Code: Select all

Import "kernel32.lib"
  CompilerIf#PB_Compiler_Processor = #PB_Processor_x86
    GetConsoleWindow_() As "_GetConsoleWindow"
  CompilerElse
    GetConsoleWindow_() As "GetConsoleWindow"
  CompilerEndIf
EndImport
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Positioning DOS window

Post by Kwai chang caine »

@Mijikai
Me too i have Polink error :|
W7 X86 / v5.61(X86)
Fryquez wrote:You need the "_" prefix for x86.
Even with your code FRYQUEZ, i have a polink error :|

Code: Select all

Import "kernel32.lib"
  CompilerIf#PB_Compiler_Processor = #PB_Processor_x86
    GetConsoleWindow_() As "_GetConsoleWindow"
  CompilerElse
    GetConsoleWindow_() As "GetConsoleWindow"
  CompilerEndIf
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
ImageThe happiness is a road...
Not a destination
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: Positioning DOS window

Post by fryquez »

Hmm, guess I don't have the default lib.
Can you try "_GetConsoleWindow@0"?
User avatar
Pierre Bellisle
User
User
Posts: 35
Joined: Wed Jun 27, 2018 5:12 am

Re: Positioning DOS window

Post by Pierre Bellisle »

Another way... Since it is newly created, the OS will put our console on foreground.
The GetForegroundWindow_() can then be used at the beginning of the code to get the appropriate handle.

Code: Select all

If OpenConsole()

  ;Set console position
  SetWindowPos_(GetForegroundWindow_(), #HWND_TOP, 150, 150, #Null, #Null, #SWP_NOZORDER|#SWP_NOSIZE|#SWP_SHOWWINDOW)
  PrintN("Console is at position 150, 150.")
  Sleep_(1500)  

  ;Center console
  Define.rect ConsoleRect : GetWindowRect_(GetForegroundWindow_(), ConsoleRect)
  SetWindowPos_(GetForegroundWindow_(), #HWND_TOP, 
  (GetSystemMetrics_(#SM_CXSCREEN) - (ConsoleRect\Right  - ConsoleRect\Left)) / 2, 
  (GetSystemMetrics_(#SM_CYSCREEN) - (ConsoleRect\Bottom - ConsoleRect\Top)) / 2, 
  #Null, #Null, #SWP_NOZORDER | #SWP_NOSIZE | #SWP_SHOWWINDOW)
  PrintN("Console is now centered on screen.")

  Input() : CloseConsole()

EndIf
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Positioning DOS window

Post by Kwai chang caine »

@Pierre Bellisle
That's works very well, thanks 8)
fryquez wrote:Hmm, guess I don't have the default lib.
Can you try "_GetConsoleWindow@0"?
You are too strong :shock:
That works now 8)
Thanks at MIJIKAI and you :wink:
ImageThe happiness is a road...
Not a destination
Post Reply