It is currently Tue Aug 21, 2018 10:35 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Mon Mar 14, 2005 4:09 pm 
Offline
Addict
Addict

Joined: Mon Jun 07, 2004 7:10 pm
Posts: 841
Location: Bergen, Norway
Quote:
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 14, 2005 4:09 pm 
Offline
Addict
Addict

Joined: Fri Apr 25, 2003 11:13 pm
Posts: 1073
Location: Netherlands
Forgot to embed a thread id check.
I pass GetCurrentThreadId_() but i do nnot compare the hWnd being created in this thread.

It's easier to set a truly odd title and abandon my thread id stuff.

_________________
Hellobasic website


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 14, 2005 4:24 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Apr 26, 2003 5:08 pm
Posts: 404
Location: Denmark
chippy73
Sometimes debuging your values will help you alot
Code:
hDosWin = FindWindow_(#Null, "edit.com")
Debug hDosWin

hDosWin returns 0 on wim98

But
Code:
hDosWin = FindWindow_(#Null, "MS-DOS Editor")
Debug hDosWin

is valid

Use Freaks
Code:
SendMessage_(hDosWin, #WM_CLOSE, 0, 0)

to close the window

This workes on win98
Code:
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


Henrik


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 14, 2005 4:31 pm 
Offline
User
User

Joined: Wed Feb 16, 2005 6:11 pm
Posts: 59
Location: S.W.Wales
El_Choni,

Many thanks for solution. It works OK. Now on to my next problem !!

Alan

_________________
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 14, 2005 5:27 pm 
Offline
Addict
Addict

Joined: Fri Apr 25, 2003 11:13 pm
Posts: 1073
Location: Netherlands
Why do i have the feeling you totally skipped my version?
Looking for a non-unique string as above is not the best way.

_________________
Hellobasic website


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 14, 2005 7:11 pm 
Offline
User
User

Joined: Wed Feb 16, 2005 6:11 pm
Posts: 59
Location: S.W.Wales
Thanks everyone,

That's a lot of useful info and have saved it for future reference.

Thanks again.

Alan

_________________
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Sun May 06, 2018 4:14 am 
Offline
User
User

Joined: Sun Apr 30, 2017 12:27 pm
Posts: 16
Code updated For 5.62

Code:
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Sun May 06, 2018 8:04 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1481
Poplar wrote:
Code updated For 5.62

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).


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Wed Jun 27, 2018 5:15 am 
Offline
New User
New User
User avatar

Joined: Wed Jun 27, 2018 5:12 am
Posts: 4
What if you try those APIs...
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Wed Jun 27, 2018 9:29 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4229
Location: Lyon - France
Works great here with W7 X86 / v5.61 X86
Thanks 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Wed Jun 27, 2018 11:55 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 227
Here is my version :)

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Wed Jun 27, 2018 12:55 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1481
Mijikai, your version doesn't work for me with Win 7:

Code:
---------------------------
PureBasic - Linker error
---------------------------
POLINK: error: Unresolved external symbol 'GetConsoleWindow'.
POLINK: fatal error: 1 unresolved external(s).
---------------------------
OK   
---------------------------


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Wed Jun 27, 2018 1:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 227
Dude wrote:
Mijikai, your version doesn't work for me with Win 7...


Should work, thats the OS im currently using.
Mby some silly AV is blocking?


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Wed Jun 27, 2018 1:30 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Apr 26, 2003 2:15 pm
Posts: 732
Location: Cuernavaca, Mexico
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.

_________________
- It was too lonely at the top.


Top
 Profile  
Reply with quote  
 Post subject: Re: Positioning DOS window
PostPosted: Wed Jun 27, 2018 1:55 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 227
blueb 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.


I also did some testing
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye