Page 3 of 3

Re: Positioning DOS window

Posted: Wed Jun 27, 2018 2:13 pm
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

Re: Positioning DOS window

Posted: Wed Jun 27, 2018 3:32 pm
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

Re: Positioning DOS window

Posted: Wed Jun 27, 2018 3:45 pm
by fryquez
Hmm, guess I don't have the default lib.
Can you try "_GetConsoleWindow@0"?

Re: Positioning DOS window

Posted: Thu Jun 28, 2018 1:34 am
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

Re: Positioning DOS window

Posted: Thu Jun 28, 2018 2:24 pm
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: