【问题标题】:Using a button c++ winapi [duplicate]使用按钮c ++ winapi [重复]
【发布时间】:2021-08-31 07:59:37
【问题描述】:

我想在我的窗口中添加一个按钮,这是它的代码:

HWND hwndButton = CreateWindow(
        L"BUTTON",  // Predefined class; Unicode assumed 
        L"Check for update",      // Button text 
        WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles 
        10,         // x position 
        30,         // y position 
        150,        // Button width
        30,        // Button height
        hWnd,     // Parent window
        NULL,     // No menu.<----------
        (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
        NULL);      // Pointer not needed.

现在,我想让窗口做点什么,如果按钮被按下,所以我找到了方法:

UINT IsDlgButtonChecked( HWND hDlg, int nIDButton );

  HWND hDlg,
  int  nIDFirstButton,
  int  nIDLastButton,
  int  nIDCheckButton
);

问题:在这两种方法中都有一个 ID,但我找不到任何关于从哪里获取 ID、lastbuttonid、firstbuttonid 和按钮 ID 本身的信息。另外,我知道在上面代码中的箭头处,注释“No menu.

【问题讨论】:

  • 您自己为ID_RADIOBTN1(和其他ID)定义“替换”令牌。通常,这些定义将在头文件中,看起来像#define ID_MYBUTTON1 123。然后将这些值作为hMenu 参数传递。您可以为按钮使用(几乎)从(大约)10 到 0x7FFF (32767) 范围内的任何值。 (系统对“OK”和“Cancel”等标准按钮使用低值。)
  • ... 或者,对于“更纯粹”的 C++ 系统,您可以使用 constexpr unsigned int ID_MYBUTTON1 = 123;

标签: c++ winapi button window


【解决方案1】:

没关系,找到了一些东西。有时 youtube 比网站更明确。

你必须定义一个常量,例如: define ID_Button1 100

然后只使用那个 id,所以写 (HMENU)ID_Button1 作为你提到的参数(在你的“no menu

【讨论】:

  • 不,youtube 不像官方文档那样明确。
  • @user2120666 您应该阅读网站的定义...网站不是文档。
  • 你在说什么???
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多