# Disable Close Button in TP Application

**URL:** https://tech-community.robotics.abb.com/t/disable-close-button-in-tp-application/1359
**Category:** RobotStudio
**Created:** [July 26, 2007, 10:55pm UTC](https://tech-community.robotics.abb.com/t/disable-close-button-in-tp-application/1359 "2007-07-26T22:55:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jhweppler](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jhweppler](https://tech-community.robotics.abb.com/u/jhweppler)
#### Post date: [July 26, 2007, 10:55pm UTC](https://tech-community.robotics.abb.com/t/disable-close-button-in-tp-application/1359/1 "2007-07-26T22:55:25Z")

</div>

Hey all,

I’m trying to disable the close button on my robot application and add my own close button within the application itself. I want to do this so i am able to ask the operator with a gtpumessagebox if he/she really wants to close the application (because doing so results in the robot system going into a controlled shutdown state and subsequently shutting down).

The trouble i am having is not knowing how to disable the close button.

Can anyone please help.

---

<div class="post-metadata">

### Author: ![apox](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/apox/32/2392_2.png) [@apox](https://tech-community.robotics.abb.com/u/apox)
#### Post date: [July 30, 2007, 9:57am UTC](https://tech-community.robotics.abb.com/t/disable-close-button-in-tp-application/1359/2 "2007-07-30T09:57:08Z")

</div>

Hi,

here is a VSTA macro that could solve your problem:

using System.Runtime.InteropServices;

[DllImport(“user32.dll”, EntryPoint = “GetSystemMenu”)]  
private static extern IntPtr GetSystemMenu(IntPtr hwnd, int revert);

[DllImport(“user32.dll”, EntryPoint = “GetMenuItemCount”)]  
private static extern int GetMenuItemCount(IntPtr hmenu);

[DllImport(“user32.dll”, EntryPoint = “RemoveMenu”)]  
private static extern int RemoveMenu(IntPtr hmenu, int npos, int wflags);

[DllImport(“user32.dll”, EntryPoint = “DrawMenuBar”)]  
private static extern int DrawMenuBar(IntPtr hwnd);

public void Macro\_DisableCloseButton()  
{  
const int MF\_BYPOSITION = 0x0400;  
const int MF\_DISABLED = 0x0002;

IntPtr win = ABB.Robotics.RobotStudio.Environment.UIEnvironment.MainWindo w.Handle;  
IntPtr hmenu = GetSystemMenu(win, 0);  
int cnt = GetMenuItemCount(hmenu);

// remove close action and extra menu line  
RemoveMenu(hmenu, cnt-1, MF\_DISABLED | MF\_BYPOSITION);  
RemoveMenu(hmenu, cnt-2, MF\_DISABLED | MF\_BYPOSITION);  
}

Don’t forget to add the refernce System.Windows.Forms.

---

<div class="post-metadata">

### Author: ![jhweppler](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jhweppler](https://tech-community.robotics.abb.com/u/jhweppler)
#### Post date: [July 30, 2007, 8:39pm UTC](https://tech-community.robotics.abb.com/t/disable-close-button-in-tp-application/1359/3 "2007-07-30T20:39:13Z")

</div>

Thanks for your help!
