回 帖 发 新 帖 刷新版面

主题:如何获取文本框的信息.

win32api中如何获取文本编辑框的信息呀?[em18]

回复列表 (共13个回复)

沙发

UINT GetDlgItemText(
  HWND hDlg,       // handle of dialog box
  int nIDDlgItem,  // identifier of control
  LPTSTR lpString, // address of buffer for text
  int nMaxCount    // maximum size of string
);
int GetWindowText(
  HWND hWnd,        // handle to window or control with text
  LPTSTR lpString,  // address of buffer for text
  int nMaxCount     // maximum number of characters to copy
);

板凳

可以更详细吗?

3 楼

#include <windows.h>

#define ID_TEXT 101   //text ID


LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

TCHAR    szAppName[]=TEXT("my text");

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
{    
    HWND        hwnd;
    MSG            msg;
    WNDCLASS    wndclass;

    wndclass.style            =CS_HREDRAW|CS_VREDRAW;
    wndclass.lpfnWndProc    =WndProc;
    wndclass.cbClsExtra        =0;
    wndclass.cbWndExtra        =0;
    wndclass.hInstance        =hInstance;
    wndclass.hIcon            =LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hCursor        =LoadCursor(NULL,IDC_ARROW);
    wndclass.hbrBackground    =(HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName    =NULL;
    wndclass.lpszClassName    =szAppName;

    if (!RegisterClass(&wndclass))
    {
        MessageBox(NULL,TEXT("This program requires Windows NT!"),szAppName,MB_ICONERROR);
        return 0;
    }
     
    hwnd=CreateWindow(szAppName,                 
                    szAppName,
                    WS_OVERLAPPEDWINDOW,       
                    CW_USEDEFAULT,CW_USEDEFAULT,             
                    CW_USEDEFAULT,CW_USEDEFAULT,            
                    NULL,                      
                    NULL,                     
                    hInstance,                 
                    NULL);                   
     
    ShowWindow(hwnd,iCmdShow);
    UpdateWindow(hwnd);
     
    while (GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
    LPCREATESTRUCT    lpcs;
    static HWND        hwndtext;
    static TCHAR    text[200];
    switch (message)
    {
    case WM_CREATE:
        lpcs = (LPCREATESTRUCT)lParam;
        hwndtext = CreateWindow(TEXT("EDIT"),               
                    TEXT("text"),
                    ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER,       
                    10,10,200,20,            
                    hwnd,                      
                    (HMENU)ID_TEXT,                     
                    lpcs->hInstance,                 
                    NULL);
        return 0;
    case WM_LBUTTONDOWN:
        GetWindowText(hwndtext,text,sizeof(text));//获取编辑框文本
        return 0;
    case WM_LBUTTONUP:
        SetWindowText(hwnd,text);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd,message,wParam,lParam);
}

4 楼

还有复选框,单选框,例表框,都要怎么响应呀。
请帮忙。谢了

5 楼

对于类似的问题不能一一举例说明了,我建议买本Windows编程的书籍看看,推荐“Windows 程序设计(第5版)”。我这有电子版的,要得话我发给你。

6 楼

好啊。
你给我发一份吧,
我看过,我这边也没有什么关于API的书,
那你就给我发份吧,
我的电邮:digital05@sina.com

7 楼

我也想要,能发下吗? lantk@126.com

8 楼

请查收~

9 楼

我也要!谢谢!
tiankong219@sina.com

10 楼

楼9这里面不是有吗?
都有在呀,
不用发了吧

我来回复

您尚未登录,请登录后再回复。点此登录或注册