简体   繁体   English

如何禁用C中的关闭按钮?

[英]How to disable the close button in C?

有没有人知道如何禁用Windows控制台窗口上的关闭按钮与从C程序创建的.exe可执行文件?

From here: 这里:

#define _WIN32_WINNT 0x0500
#include <stdio.h>
#include <windows.h>

int main(int argc, _TCHAR* argv[]){
  HWND h;   
  HMENU sm;
  int i, j, c; 
  LPTSTR buf;  
  // get the handle to the console
  h = GetConsoleWindow(); 
  // get handle to the System Menu
  sm = GetSystemMenu(h, 0);  
  // how many items are there?  
  c = GetMenuItemCount(sm);   
  j = -1;  
  buf = (TCHAR*) malloc (256 *sizeof(TCHAR));  
  for (i=0; i<c; i++) {
    // find the one we want   
    GetMenuString(sm, i, buf, 255, MF_BYPOSITION);   
    if (!strcmp(buf, "&Close")) {        
      j = i;        
      break;      
    }
  }
  // if found, remove that menu item  
  if (j >= 0)
    RemoveMenu(sm, j, MF_BYPOSITION); 
  return 0;
}

If you want to disable a button in a running program there are methods to do this. 如果要在正在运行的程序中禁用按钮,则有方法可以执行此操作。

The principle is to find the window, then find the button inside the window and then send a WM_DISABLE message to the button. 原理是找到窗口,然后找到窗口内的按钮,然后向按钮发送WM_DISABLE消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM