473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Problem in disabling close button(X) of window.

88 64KB
Hi,
I am trying to work on an application that disables the close button (X) on the upper right hand corner of a window. In order to do that I need to use calls to API methods like GetSystemMenu, EnableMenuItem and RemoveMenu. I can figure out how these methods work but there are certain parameters that these methods have whose values that need to be passed to them as argument is unknown to me. How can I know them.

E.G.- for EnableMenuItem, the parameters are- hMenu (handle to the menu), uIDEnableItem (The menu item to be enabled, disabled, or grayed), uEnable (This parameter must be a combination of at least two of the following:
MF_BYCOMMAND or MF_BYPOSITION
MF_ENABLED, MF_DISABLED, or MF_GRAYED)

Now when I call this method from my application I supply the current window handle as the first argument, the item no. to be disabled/enabled as the second argument but I CAN'T UNDERSTAND WHAT TO SEND AS THE THIRD ARGUMENT. What exactly are the possible values for those parameters- MF_BYCOMMAND or MF_DISABLED. I checked certain examples where they are supplying hexadecimal values like &HF060, &H1, 0x400, 0x1000, 0x2 etc. or integer values like 1024, 2 etc. But how would I know what exactly these values are and when to use which value. The same problem arises in case of calling RemoveMenu method. If you know about any chart or tutorial that lists the values of these parameters then plz refer. Waiting for your help. Thanks.
Apr 15 '09 #1
3 2977
tlhintoq
3,525 Expert 2GB
Aweful lot of work.

Easier to just handle the form closing event, check the reason or some parameter you setup and override the close if you want.

Expand|Select|Wrap|Line Numbers
  1.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  2.         {
  3.  
  4.             MainLog.AddEntry("Main window closing");
  5.             if (LoggedInUserName.Contains("tlhintoq"))
  6.             {
  7.                 Application.Exit();
  8.                 return;
  9.                 // Check if it is me so I don't have to log in every time just to exit
  10.             }
  11.  
  12.             // Check if user logged into this application has permission to exit
  13.             if (Program.myPrivs.ExitApp)
  14.             {
  15.                 DialogResult dlgResult = DialogResult.Yes;
  16.                 if (!Program.myPrivs.DisableWarnings)
  17.                 {
  18.                     dlgResult = SmartDialog(30, "Are you sure you want to close?", "Please confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
  19.                     // A timed out dialog returns with 'ok' thus changing the dlgresult
  20.                 }
  21.                 if (dlgResult == DialogResult.Yes)
  22.                 {
  23.                     notifyIcon1.Visible = false;
  24.                     // No need to do more as we are already closing.
  25.                     // We 'fall through' to exiting at this point.
  26.                 }
  27.             }
  28.             else
  29.             {
  30.                 LackPrivs();
  31.                 e.Cancel = true;// Cancel the close;
  32.             }
  33.  
  34.  
  35.             #region If I want to 'close' to notify icon instead
  36.             //        if (e.CloseReason == CloseReason.UserClosing || e.CloseReason == CloseReason.TaskManagerClosing)
  37.             //{
  38.             //    MainLog.AddEntry(string.Format("Hiding. ({0})",e.CloseReason));
  39.             //    e.Cancel = true; // true that we are canceling the close event
  40.             //    this.Hide(); // same as saying this.visible = false;
  41.             //    //this.WindowState = FormWindowState.Minimized;
  42.             //    //this.ShowInTaskbar = false;
  43.             //    notifyIcon1.Visible = true;
  44.             //}
  45.             //else MainLog.AddEntry(string.Format("Closing. ({0})", e.CloseReason));
  46.             //notifyIcon1.Visible = false;
  47.  
  48.             #endregion        
  49.         }
  50.  
Apr 15 '09 #2
Plater
7,872 Expert 4TB
I believe they wanted to affect some OTHER programs window?
Apr 15 '09 #3
priyamtheone
88 64KB
@tlhintoq
Thanks for your work but I can manage this part by myself. But I want to disable the Close button and the Close option from the window menu. For that u need to call the functions that i mentioned. I couldn't figure out the argument values that need to be passed to them. I'm exactle looking for those values somewhere. Thanks again for your help.
Apr 16 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Shaun Fleming | last post by:
I've been trying to make this simple script compatible across various browsers. It works for IE 6.0 and NS 7 but doesnt work with Opera (I have version 7.11). This is what is supposed to happen:...
4
by: Mohit Gupta | last post by:
Hi all, Lately I have been working on an application in VB .net CF for Pocket PC device. I have a small question about Context Menu. When I try to close the window after context menu is poped...
6
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the...
1
by: dibyendu_k | last post by:
Hi, There is a problem i cant solve regarding Internet Explorer 5.5. It is regarding the Print Dialog Box. From a webpage if I open a popup window (window.open()) containing buttons Print and...
6
by: Joe | last post by:
Hi, I have a form with Submit and cancel button. When Cancel button is clicked I want to close the browser window. Here is my sample form. To make things simple I have removed the submit button....
13
by: lightzizo | last post by:
All, How can I disable or remove the close button in the screen. thanks
9
by: cor-travel | last post by:
Hi Folk Is there a way to disable the close button for an application? Thank you - Nicolaas
37
by: Jan Tovgaard | last post by:
Hey everyone:) We have a critical problem, which I can see that other people also has ran into. In Internet Explorer 7 it is no longer possible to do a window.close after opening a window,...
7
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.