Windows Calculator

Hi.

I am writing a program in VB.2003 that needs to use the windows calculator. I know how to open it, but is there a way to tell the calc exactly where to be located on the screen.

Thanks

Rocco

[731 byte] By [RoccoSmit] at [2007-12-23]
# 1

Hi RoccoSmit,

I don't think you can accomplish the task by just using parameters at the start of 'calc.exe'. However, you can get the handle of the new process, and send the 'move to new position' message to it.

gqlu at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
RoccoSmit wrote:

Hi.

I am writing a program in VB.2003 that needs to use the windows calculator. I know how to open it, but is there a way to tell the calc exactly where to be located on the screen.

Thanks

Rocco

No you can't tell where to display the calculator from outside, this is to respect the application on where it want to display itself. But you can move it after it is shown, by using set of APIs and the process's MainWindowHandle. Here's a sample code to launch calc.exe, and move it to coordinate 0,0 of primary screen:



[DllImport("user32.dll")]
private static extern int GetWindowRect(
IntPtr hwnd,
ref RECT lpRect);

[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
internal int Left;
internal int Top;
internal int Right;
internal int Bottom;
}

[DllImport("user32.dll")]
private static extern int MoveWindow(
IntPtr hwnd,
int x,
int y,
int nWidth,
int nHeight,
bool bRepaint);

public void OpenCalc()
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "calc.exe";
Process p = Process.Start(psi);

RECT rect = new RECT();
GetWindowRect(p.MainWindowHandle, ref rect);

MoveWindow(p.MainWindowHandle, 0, 0, rect.Right - rect.Left, rect.Bottom - rect.Top, true);
}



Hope this sample helps,

-chris

ChrisVega at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
How did you open it?
LeoFi at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...