Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C GetWindowText()函数未从输入(“编辑”类型窗口)获取/输出任何文本_C_Winapi - Fatal编程技术网

C GetWindowText()函数未从输入(“编辑”类型窗口)获取/输出任何文本

C GetWindowText()函数未从输入(“编辑”类型窗口)获取/输出任何文本,c,winapi,C,Winapi,我一直在制作反馈表,需要将数据记录到文本文件中。为此,我在ANSI(C)编程中使用Win32(Windows .h),而不是用C++编译代码:使用GNU编译器编写代码: 我面临的问题是,我无法从任何“编辑”子窗口(第15行:HWND NAME、ROLLNO、CASE_REPORT)记录数据输入,因此每当用户按下“SAVETXT”按钮时,我都可以让消息框打印它们。 我不知道如何在这里有一段代码,所以我在问题中粘贴了整个有问题的代码 #if defined(UNICODE) &&a

我一直在制作反馈表,需要将数据记录到文本文件中。为此,我在ANSI(C)编程中使用Win32(Windows .h),而不是用C++编译代码:使用GNU编译器编写代码: 我面临的问题是,我无法从任何“编辑”子窗口(第15行:HWND NAME、ROLLNO、CASE_REPORT)记录数据输入,因此每当用户按下“SAVETXT”按钮时,我都可以让消息框打印它们。 我不知道如何在这里有一段代码,所以我在问题中粘贴了整个有问题的代码

     #if defined(UNICODE) && !defined(_UNICODE)
        #define _UNICODE
    #elif defined(_UNICODE) && !defined(UNICODE)
        #define UNICODE

#endif

#include <tchar.h>
#include <windows.h>

//Global Variables are declared here
#define ID_CANCEL 1
#define ID_SENDRPT 2
#define ID_SAVETXT 3
int WINWIDTH=460,WINHEIGHT=600;                                                                                 //Window Width and Window Height
HWND NAME,ROLLNO,CASE_REPORT,BTN_SEND,BTN_CANCEL,BTN_SAVE;                                                      //Declaring names of various elements
HWND NAME_LABEL,ROLLNO_LABEL,LABEL_WARNING,LABEL_CASE_REPORT,LABEL_EMAIL_INFO;                                  //for our application
int _inputy=20,_rollnoy=_inputy+21,_case_report_y=_rollnoy+21;                                                  //Position information for our elements

/*Declaration of User Defined Functions*/
void AGIMIX_MB_INFO(HWND hwnd,const char *_title,const char *_message);
void AGIMIX_MB_ERROR(HWND hend, const char *_title, const char *_message);
void AGIMIX_USR_INPUT(HWND hnd,HWND hwnd, const char *_default_text,int _xpos,int _ypos,int _length,int _ht);
void AGIMIX_PUT_TXT(HWND hnd,HWND hwnd, const char *_text,int _xpos,int _ypos,int _length,int _ht);
void AGIMIX_PUT_BUTTON(HWND hnd,HWND hwnd,HMENU _identify, const char *_text,int _xpos,int _ypos,int _length,int _ht);
void AGIMIX_USER_TXTFIELD(HWND hnd,HWND hwnd, const char *_text,int _xpos,int _ypos,int _length,int _ht);
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[ ] = _T("AGIMIX_WINDOWS_APP_FEEDBACK");
char *input_name;
int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */
 /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND+5;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilities for variation */
           szClassName,         /* Class name */
           _T("AGIMIX FEEDBACK FORM"),       /* Title Text */
           WS_OVERLAPPED|WS_SYSMENU, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           WINWIDTH,                 /* The programs width */
           WINHEIGHT,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
    case WM_CREATE:                                                                                                                                         //What to do when the application window is created
       AGIMIX_MB_INFO(hwnd,"AGIMIX [INFORMATION]","Welcome");                                                                                               //Welcome user with a Message Box
       AGIMIX_MB_ERROR(hwnd,"AGIMIX [WARNING: TRIAL VERSION]","This is a Educational / Trial version only, No functionality is supported!");                //Warn user about limited functionality
       AGIMIX_PUT_TXT(LABEL_WARNING,hwnd," All fields marked with \' * \' are compulsory",0,0,450,19);                                                      //STATIC type to Warn user about compulsory fields to be filled
       AGIMIX_PUT_TXT(NAME_LABEL,hwnd," NAME (FULL CAPS)*: ",0,_inputy,150,20);                                                                             //STATIC type to prompt user for his Name in Full Capital letters
       AGIMIX_USR_INPUT(NAME,hwnd,"",150,_inputy,300,20);                                                                                                   //EDIT type text-field to take input from user
       AGIMIX_PUT_TXT(ROLLNO_LABEL,hwnd," LICENCE NUMBER*: ",0,_rollnoy,150,20);                                                                            //STATIC type to prompt user for his Licence Number
       AGIMIX_USR_INPUT(ROLLNO,hwnd,"",150,_rollnoy,300,20);                                                                                                //EDIT type text-field to take input from user
       AGIMIX_PUT_TXT(LABEL_CASE_REPORT,hwnd," FEEDBACK / COMPLAINT*: ",0,_case_report_y,450,20);                                                           //STATIC type to prompt user for his complaint / feedback information
       AGIMIX_USER_TXTFIELD(CASE_REPORT,hwnd,"",0,_case_report_y+21,450,350);                                                                               //EDIT type text-field with added functionality of Multi-line input and Scrolling for inputting detail feedback / complaint
       AGIMIX_PUT_TXT(LABEL_EMAIL_INFO,hwnd,"     Feedback will be responded to Registered Email with Licence.",0,_case_report_y+380,450,21);               //STATIC type to warn user about preregistered email response to the complaint
       AGIMIX_PUT_BUTTON(BTN_SEND,hwnd,(HMENU)ID_SENDRPT,"SEND",50,_case_report_y+430,100,50);                                                              //BUTTON type input for Sending information to AGIMIX server
       AGIMIX_PUT_BUTTON(BTN_SAVE,hwnd,(HMENU)ID_SAVETXT,"SAVE TXT",170,_case_report_y+430,100,50);                                                         //BUTTON type input for Saving the information in a (.txt) file
       AGIMIX_PUT_BUTTON(BTN_CANCEL,hwnd,(HMENU)ID_CANCEL,"CANCEL && EXIT",290,_case_report_y+430,105,50);                                                  //BUTTON type input to Cancel the current complaint/feedback and exit the window/application
                                                                                                                                                            //3 GetWindowText(NAME,input_name,50);
    break;

    case WM_COMMAND:
        //TCHAR input_name[100];
        if(LOWORD(wParam) == ID_CANCEL)
        {
            AGIMIX_MB_ERROR(hwnd,"AGIMIX [WARNING: TRIAL VERSION]","This is a Educational / Trial version only, No functionality is supported!");           //Warn user about limited functionality
            AGIMIX_MB_INFO(hwnd,"AGIMIX [INFORMATION]","Exit Success! Bye.");                                                                               //Give user a parting Message
            PostQuitMessage (0);                                                                                                                            /* send a WM_QUIT to the message queue */
        }
        if(LOWORD(wParam) == ID_SENDRPT)
        {
            AGIMIX_MB_INFO(hwnd,"AGIMIX [FUNCTION SUPPORT]","Function is not supported as of now and will be available later!");
        }
        if(LOWORD(wParam) == ID_SAVETXT)
        {
            GetWindowText(NAME,input_name,50);
            AGIMIX_MB_INFO(hwnd,input_name,input_name);
            SetWindowText(hwnd,input_name);
            AGIMIX_MB_INFO(hwnd,"AGIMIX [ENTERED INFO]",input_name);
            AGIMIX_MB_INFO(hwnd,"AGIMIX [FUNCTION SUPPORT]","Function is not supported as of now and will be available later!");
        }
    break;

    case WM_DESTROY:                                                                                                                                        //What to do when the user exits the application
            AGIMIX_MB_ERROR(hwnd,"AGIMIX [WARNING: TRIAL VERSION]","This is a Educational / Trial version only, No functionality is supported!");           //Warn user about limited functionality
            AGIMIX_MB_INFO(hwnd,"AGIMIX [INFORMATION]","Exit Success! Bye.");                                                                               //Give user a parting Message
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
    break;

    default:                          /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}
// User Defined Functions for easy functionality
void AGIMIX_MB_INFO(HWND hwnd,const char *_title,const char *_message)
{
    MessageBox(hwnd,_message,_title,MB_ICONINFORMATION|MB_OK);
}

void AGIMIX_MB_ERROR(HWND hwnd, const char *_title, const char *_message)
{
    MessageBox(hwnd,_message,_title,MB_ICONERROR|MB_OK);
}

void AGIMIX_USR_INPUT(HWND hnd,HWND hwnd, const char *_default_text,int _xpos,int _ypos,int _length,int _ht)
{
    hnd = CreateWindow("EDIT",_default_text,WS_VISIBLE|WS_CHILD|WS_BORDER,_xpos,_ypos,_length,_ht,hwnd,NULL,NULL,NULL);
}

void AGIMIX_PUT_TXT(HWND hnd,HWND hwnd, const char *_text,int _xpos,int _ypos,int _length,int _ht)
{
    hnd = CreateWindow("STATIC",_text,WS_VISIBLE|WS_CHILD,_xpos,_ypos,_length,_ht,hwnd,NULL,NULL,NULL);
}
void AGIMIX_USER_TXTFIELD(HWND hnd,HWND hwnd, const char *_text,int _xpos,int _ypos,int _length,int _ht)
{
    hnd = CreateWindow("EDIT",_text,WS_VISIBLE|WS_CHILD|WS_BORDER|ES_MULTILINE|ES_AUTOVSCROLL|WS_VSCROLL,_xpos,_ypos,_length,_ht,hwnd,NULL,NULL,NULL);
}
void AGIMIX_PUT_BUTTON(HWND hnd,HWND hwnd,HMENU _identify, const char *_text,int _xpos,int _ypos,int _length,int _ht)
{
    hnd = CreateWindow("BUTTON",_text,WS_VISIBLE|WS_CHILD|WS_BORDER,_xpos,_ypos,_length,_ht,hwnd,_identify,NULL,NULL);
}
#如果已定义(UNICODE)&&!已定义(_UNICODE)
#定义UNICODE
#elif定义(_UNICODE)&&!已定义(UNICODE)
#定义UNICODE
#恩迪夫
#包括
#包括
//全局变量在这里声明
#定义ID\u取消1
#定义ID_SENDRPT 2
#定义ID_SAVETXT 3
int WINWIDTH=460,WINHEIGHT=600//窗宽窗高
硬件名称、卷号、案例报告、发送、取消、保存//声明各种元素的名称
HWND名称标签、ROLLNO标签、标签警告、标签案例报告、标签电子邮件信息//供我们申请
输入=20,输入=21,案例=21//我们元素的位置信息
/*用户定义函数的声明*/
无效AGIMIX_MB_信息(HWND HWND,常量字符*_标题,常量字符*_消息);
无效AGIMIX\u MB\u错误(HWND hend、常量字符*标题、常量字符*消息);
void AGIMIX_USR_输入(HWND hnd、HWND HWND、const char*_default_text、int-xpos、int-ypos、int-length、int-ht);
void AGIMIX_PUT_TXT(HWND hnd,HWND HWND,const char*_text,int-xpos,int-ypos,int-length,int-ht);
无效AGIMIX PUT按钮(HWND hnd、HWND HWND、HMENU标识、常量字符*文本、int xpos、int YPO、int长度、int ht);
void AGIMIX_USER_TXTFIELD(HWND hnd,HWND HWND,const char*_text,int-xpos,int-ypos,int-length,int-ht);
/*声明Windows过程*/
LRESULT回调窗口过程(HWND、UINT、WPARAM、LPARAM);
/*将类名设置为全局变量*/
TCHAR szClassName[]=“AGIMIX_WINDOWS_应用程序_反馈”);
字符*输入_名称;
int WINAPI WinMain(HINSTANCE Hthis实例,
HINSTANCE HPPrevenstance,
LPSTR LPSZ参数,
国际展览(nCmdShow)
{
这是我们窗口的手柄*/
MSG messages;/*此处保存应用程序的消息*/
windowclass的WNDCLASSEX wincl;/*数据结构*/
/*窗口结构*/
wincl.hInstance=hthis实例;
wincl.lpszClassName=szClassName;
wincl.lpfnWndProc=WindowProcedure;/*此函数由windows调用*/
wincl.style=CS_DBLCLKS;/*捕捉双击*/
wincl.cbSize=sizeof(WNDCLASSEX);
/*使用默认图标和鼠标指针*/
wincl.hIcon=加载图标(空,IDI_应用程序);
wincl.hIconSm=加载图标(空,IDI_应用程序);
wincl.hCursor=LoadCursor(空,IDC_箭头);
wincl.lpszMenuName=NULL;/*无菜单*/
wincl.cbClsExtra=0;/*窗口类后没有额外字节*/
wincl.cbWndExtra=0;/*结构或窗口实例*/
/*使用Windows的默认颜色作为窗口的背景*/
wincl.hbrBackground=(HBRUSH)颜色背景+5;
/*注册窗口类,如果失败,退出程序*/
if(!RegisterClass(&wincl))
返回0;
/*类已注册,让我们创建程序*/
hwnd=CreateWindowEx(
0,/*扩展的变化可能性*/
szClassName,/*类名*/
_T(“AGIMIX反馈表”),/*标题文本*/
WS_重叠| WS_系统菜单,/*默认窗口*/
CW_USEDEFAULT,/*Windows决定位置*/
CW_USEDEFAULT,/*窗口在屏幕上结束*/
WINWIDTH,/*程序宽度*/
WINHEIGHT、/*和高度(以像素为单位)*/
HWND_DESKTOP,/*该窗口是桌面的子窗口*/
空,/*无菜单*/
hThisInstance,/*程序实例处理程序*/
NULL/*无窗口创建数据*/
);
/*使窗口在屏幕上可见*/
显示窗口(hwnd、nCmdShow);
/*运行消息循环。它将一直运行,直到GetMessage()返回0*/
while(GetMessage(&messages,NULL,0,0))
{
/*将虚拟密钥消息转换为字符消息*/
翻译消息(和消息);
/*向WindowProcedure发送消息*/
DispatchMessage(&messages);
}
/*程序返回值为0—PostQuitMessage()给出的值*/
返回messages.wParam;
}
/*此函数由Windows函数DispatchMessage()调用*/
LRESULT回调窗口过程(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM)
{
开关(消息)/*处理消息*/
{
case WM_CREATE://创建应用程序窗口时要做什么
AGIMIX_MB_INFO(hwnd,“AGIMIX[INFORMATION],“Welcome”);//使用消息框欢迎用户
AGIMIX_MB_错误(hwnd,“AGIMIX[警告:试用版]”,“这只是一个教育/试用版,不支持任何功能!”;//警告用户功能有限
AGIMIX_PUT_TXT(标签警告,hwnd,“
HWND AGIMIX_USR_INPUT(HWND hwnd, const char *_default_text, int _xpos, int _ypos, int _length, int _ht)
{
  return CreateWindow("EDIT", _default_text, WS_VISIBLE | WS_CHILD | WS_BORDER, _xpos, _ypos, _length, _ht, hwnd, NULL, NULL, NULL);
}
NAME = AGIMIX_USR_INPUT(hwnd, "", 150, _inputy, 300, 20);
GetWindowText(NAME, input_name, _countof(input_name));