Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disable "x" button?
#1
How can I disable the "x" close button from a window? This will be on a window that is already created! Is it possible? Anyway to disable the "x"?

Tried finding a style to set in msdn and use SetWinStyle but can't seem to find anything.
Found this C++ code, can you convert?

Macro Macro2
Code:
Copy      Help
HMENU hMenuHandle;
long lngItemCount;
int c, style;

hMenuHandle = GetSystemMenu(hWnd, false);
lngItemCount = GetMenuItemCount(hMenuHandle);

style = GetWindowLong(hWnd, GWL_STYLE);
style &= ~WS_MAXIMIZEBOX;
SetWindowLong(hWnd, GWL_STYLE, style);

c = lngItemCount;
while(c > lngItemCount - 4)
RemoveMenu(hMenuHandle, c--, MF_BYPOSITION | MF_DISABLED);

DrawMenuBar(hWnd);;As you can see this code will go in your window procedure under WM_CREATE. Just as a reminder, some systems have things added to the "standard" system menu so you will need to find a way of allowing for that.
#2
It removes system menu items, not X button.

This code removes all system buttons.
Macro Macro1563
Code:
Copy      Help
int w=win("Untitled - Notepad" "Notepad")
SetWinStyle w WS_SYSMENU 2|8

Cannot disable or remove just X.
#3
Thank you Gint, will work from that!
#4
sorry, it works

Macro Macro1563
Code:
Copy      Help
int hWnd=win("Untitled - Notepad" "Notepad")

int hMenuHandle;
int lngItemCount;
int c, style;

hMenuHandle = GetSystemMenu(hWnd, 0);
lngItemCount = GetMenuItemCount(hMenuHandle);

SetWinStyle hWnd WS_MAXIMIZEBOX 2

for c lngItemCount-1 3 -1
,RemoveMenu(hMenuHandle, c, MF_BYPOSITION);

DrawMenuBar(hWnd)
#5
Thank you, this does exactly what I need...using this plus a menu with trigger as "x" button will open a menu making sure you want to close the window.
Original disabled maximize button got rid of setwinstyle to remove max button and changed the 3 to 4 int he for statement.

Macro Macro4
Code:
Copy      Help
int hWnd=win("Untitled - Notepad" "Notepad")
int hMenuHandle lngItemCount c style
hMenuHandle = GetSystemMenu(hWnd, 0);
lngItemCount = GetMenuItemCount(hMenuHandle);
for c lngItemCount-1 4 -1
,RemoveMenu(hMenuHandle, c, MF_BYPOSITION);
DrawMenuBar(hWnd)

Thank you
#6
Gintaras,

Ran into a little problem, some of the windows have minimize, maximize and close and others have only minimize and close.

The code I posted above works fine when all three are there but when it only has minimize and close it will not work. I tried adjusting the for statement but can not get the correct combination. Any idea?

Thank you
#7
Macro Macro1564
Code:
Copy      Help
int hWnd=win("Untitled - Notepad" "Notepad")

RemoveMenu GetSystemMenu(hWnd 0) 0xF060 0
DrawMenuBar(hWnd)
#8
Still does not change it at all
#9
Here is what it looks like incase confusion.


Attached Files Image(s)
   
#10
Run this macro. What is ID of menu item "Close"?

Macro Macro1565
Code:
Copy      Help
int hWnd=win("Untitled - Notepad" "Notepad")

int i hMenuHandle = GetSystemMenu(hWnd, 0);

for i 0 GetMenuItemCount(hMenuHandle)
,GetMenuString hMenuHandle i _s.all(300) 300 MF_BYPOSITION
,out "0x%X %s" GetMenuItemID(hMenuHandle i) _s
#11
QM_Expert Wrote:Here is what it looks like incase confusion.

With this window probably will not work.
#12
0xF120 &Restore
0xF010 &Move
0xF000 &Size
0xF020 Mi&nimize
0xF030 Ma&ximize
0x0
0xF060 &Close Alt+F4

Which would tell me that the previous posted code would work correctly since 0xF060 is the Close id, wonder why it does not work?
#13
Gintaras Wrote:
QM_Expert Wrote:Here is what it looks like incase confusion.

With this window probably will not work.

How come?
#14
Looks like it is not a standard title bar.
#15
Thank you Gintaras I guess will need to find a different way


Forum Jump:


Users browsing this thread: 1 Guest(s)