Sunday, June 29, 2014

Console Application doubt

Hello zyyqzyyra,


1. You can use the GetConsoleWindow() and SetWindowPos() APIs.


2. Here is a sample code for you to begin with :



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CSConsoleApp01
{
class Program
{
const Int32 SW_MINIMIZE = 6;

const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOZORDER = 0x0004;
const UInt32 SWP_NOREDRAW = 0x0008;
const UInt32 SWP_NOACTIVATE = 0x0010;
const UInt32 SWP_FRAMECHANGED = 0x0020; /* The frame changed: send WM_NCCALCSIZE */
const UInt32 SWP_SHOWWINDOW = 0x0040;
const UInt32 SWP_HIDEWINDOW = 0x0080;
const UInt32 SWP_NOCOPYBITS = 0x0100;
const UInt32 SWP_NOOWNERZORDER = 0x0200; /* Don't do owner Z ordering */
const UInt32 SWP_NOSENDCHANGING = 0x0400; /* Don't send WM_WINDOWPOSCHANGING */

const UInt32 SWP_DRAWFRAME = SWP_FRAMECHANGED;
const UInt32 SWP_NOREPOSITION = SWP_NOOWNERZORDER;

const Int32 HWND_TOP = 0;
const Int32 HWND_BOTTOM = 1;
const Int32 HWND_TOPMOST = -1;
const Int32 HWND_NOTOPMOST = -2;

[DllImport("Kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
private static extern IntPtr GetConsoleWindow();

[DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow([In] IntPtr hWnd, [In] Int32 nCmdShow);

[DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos
(
[In] IntPtr hWnd,
[In] IntPtr hWndInsertAfter,
[In] Int32 X,
[In] Int32 Y,
[In] Int32 cx,
[In] Int32 cy,
[In] UInt32 uFlags
);

private static void MinimizeConsoleWindow()
{
IntPtr hWndConsole = GetConsoleWindow();
ShowWindow(hWndConsole, SW_MINIMIZE);
}

private static void PositionWindow(Int32 X, Int32 Y, Int32 cx, Int32 cy)
{
IntPtr hWndConsole = GetConsoleWindow();
SetWindowPos(hWndConsole, (IntPtr)HWND_TOP, X, Y, cx, cy, SWP_SHOWWINDOW);
}

static void Main(string[] args)
{
PositionWindow(0, 0, 300, 300);
Console.ReadKey();
}
}
}

- Bio.



Please visit my blog : http://ift.tt/1r6KxsJ


No comments:

Post a Comment