如何创建和处理单选按钮消息C ++ windows.h [英] How to create and handle radio button messages C++ windows.h

查看:74
本文介绍了如何创建和处理单选按钮消息C ++ windows.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个单选按钮菜单,但不知道如何处理消息,我尝试的代码没有显示菜单。请帮帮我,提前谢谢



I want to create a radio button menu but don't know how to handle messages, the code that I tried isn't displaying the menu. Please help me out, thanks in advance

<pre lang="c++">
#include <windows.h>

 LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );

static char *title = TEXT("Check Box");

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
					LPSTR lpCmdLine, int nCmdShow )
{
  MSG  msg ;    
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "Check Box" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0, IDC_ARROW);

  
  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, title,
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                150, 150, 230, 150, 0, 0, hInstance, 0);  

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

 LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

 switch(msg)  
 {
  case WM_CREATE:
  {
    CreateWindow(TEXT("button"), TEXT("&Red"),
                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON|WS_GROUP ,
                20, 155, 100, 30, hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

CreateWindow(TEXT("button"), TEXT("&Red"),
                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
                20, 155, 100, 30,hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

CreateWindow(TEXT("button"), TEXT("&Red"),
                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
                20, 155, 100, 30, hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

    break;
  }
return DefWindowProc(hwnd, msg, wParam, lParam);
 }
}





我的尝试:



尝试向createwindow添加Group选项但是没有帮助



What I have tried:

Tried adding Group option to createwindow but that isn't helping

推荐答案

看起来你没有调用ShowWindow()和UpdateWindow()需要你获取创建的窗口的句柄(CreateWindow()的返回值),也许看看这个 [ ^ ]链接。
Looks like you're not calling ShowWindow() and UpdateWindow() which requires you to get a handle to the created window (the return value from CreateWindow()), maybe take a look at this[^] link.


这篇关于如何创建和处理单选按钮消息C ++ windows.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆