如何 创建按钮 添加到窗口中去??????

解决方案 »

  1.   

    Copy my Oldthing:定义成员 CButton m_button ,在Resource.h定义IDC_BUTTON1,ID号自定义m_button.Create(_T("按钮"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,50), this, IDC_BUTTON1 );然后用IDC_BUTTON1 作消息影射
      

  2.   

    CButton::Create 
    BOOL Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );pParentWnd设为你的窗口就行了
      

  3.   

    我问下这个代码是 win32 api 中的吗 ?不用注册按钮类吗 ?不要mfc的代码
      

  4.   

    // Login.cpp : Defines the entry point for the application.
    //#include "stdafx.h"
    #include "resource.h"#define MAX_LOADSTRING 100// Global Variables:
    HINSTANCE hInst;
    CButton button1;
    // Foward declarations of functions included in this code module:
    ATOM MyRegisterClass(HINSTANCE hInstance);
    BOOL InitInstance(HINSTANCE, int);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
      // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable; MyRegisterClass(hInstance); // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow)) 
    {
    return FALSE;
    } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_LOGIN); // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0)) 
    {
    if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    } return msg.wParam;
    }//
    //  FUNCTION: MyRegisterClass()
    //
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX);  wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = (WNDPROC)WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = NULL;
    wcex.hCursor = NULL;
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "Login";
    wcex.hIconSm = NULL; return RegisterClassEx(&wcex);
    }ATOM MyButtonClass(HINSTANCE hInstance) {
    WNDCLASSEX wcex; wcex.style = BS_PUSHBUTTON;
    wcex.lpfnWndProc = (WNDPROC)WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = NULL;
    wcex.hCursor = NULL;
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "Button";
    wcex.hIconSm = NULL;
    }
    //
    //   FUNCTION: InitInstance(HANDLE, int)
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;   hInst = hInstance; // Store instance handle in our global variable   hWnd = CreateWindow("Login", "登录窗口", WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME ,
          300, 300, 450, 250, NULL, NULL, hInstance, NULL);   if (!hWnd)
       {
          return FALSE;
       }   ShowWindow(hWnd, nCmdShow);
       UpdateWindow(hWnd);   return TRUE;
    }//
    //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    HWND hButton; switch (message) 
    {
    case WM_CREATE:

    case WM_COMMAND:
    wmId    = LOWORD(wParam); 
    wmEvent = HIWORD(wParam); 
    // Parse the menu selections:
    break;
    case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // TODO: Add any drawing code here...
    RECT rt;
    GetClientRect(hWnd, &rt);
    EndPaint(hWnd, &ps);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
    }
    我要在这段代码上 添加按钮怎么做啊
      

  5.   

    不用注册按钮类的,button这个类是系统内定的类,像edit这个类是编辑控件的窗口类一样,可以直接用,如果你自己定义一个button类的话也行,不过它的所有的东西都要你自己写
      

  6.   

    我知道你说的什么意思了,你首先首先双击窗口资源,然后选定你的窗口,再然后窗口旁边就会出来一个叫controls的小窗口,然后选中button,直接托上去就ok了!如果你没有controls这个窗口,你就需要在最上面叫什么菜单栏右键单击一下,在controls前面打勾就行了!
    希望你问的是这个!