c - 在文本框和程序源代码之间传递信息

标签 c textbox

所以我自己有一个项目,其中有两个文件,AT.c 和 main.c(我使用 DEV-C++)。 AT.c 包含我需要的所有计算内容,使用命令行进行 I/O,并且本身工作得相对良好。但是,由于我需要该程序的 GUI,因此我还获得了 main.c 文件,该文件基本上创建了一个带有文本框的窗口,供我输入数字。

无论如何,现在我有点卡住了,因为我不知道如何让 AT.c 从这些文本框中读取值而不是使用 scanf 方法。我想我应该在两个代码之间做一些声明或链接,但我还没有找到任何可以帮助的东西。

代码是 main.c 是在 Dev-C++ 中创建新的 Windows 应用程序项目时获得的起始代码。我只更改了 LRESULTCALLBACK 部分。

#define ID_BUTTON 1
#define ID_TEXTBOX 2

static HWND hwndA;
static HWND hwndB;
/*  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:{
         CreateWindow(TEXT("Button"), TEXT("Generate"),
             WS_CHILD | WS_VISIBLE,
             10, 160, 80, 20,
             hwnd, (HMENU) ID_BUTTON, NULL, NULL
             );
         hwndA = CreateWindow(TEXT("EDIT"), TEXT(""),
             WS_VISIBLE | WS_CHILD | WS_BORDER,
             190, 130, 70, 15,
             hwnd, (HMENU) ID_TEXTBOX, NULL, NULL
             );    
         hwndB = CreateWindow(TEXT("EDIT"), TEXT(""),
             WS_VISIBLE | WS_CHILD | WS_BORDER,
             260, 130, 70, 15,
             hwnd, (HMENU) ID_TEXTBOX, NULL, NULL
             );
         break;
         }
    case WM_COMMAND:{

         if (LOWORD(wParam) == ID_BUTTON) {
            char wot[256];

            GetWindowText(hwndA, wot, 4);
            SetWindowText(hwndB, wot);
            }
         }

         break;
         }
    case WM_DESTROY:
        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;
}

AT.c虽然很大,但计算程序非常简单。 喜欢

#include<stdio.h>
#include<stdlib.h>
#include<math.h> 

int a, b, c;

main(){
   scanf("%d", &a);
   scanf("%d", &b);
   printf("\n%d", a+b);
   system("pause");
}

只是一堆 if 和循环。

最佳答案

我假设您已将 AT.CMAIN.C 添加到您的项目中。你可以很容易地交流,它们写在不同的文件中并不重要,除非我不明白这个问题。

在文件1.C中:

#include "headers.h"
//..
char Input_Text[256]; 
void Function_in_file1(const char *buf)
{
   //..
}
//..

在文件2.C中:

#include "headers.h"
//..
extern char Input_Text[256]; 
void Function_in_file1(const char *buf);//let the compiler know this is a valid function and you wrote it somewhere else
//...
case WM_COMMAND:{
    if (LOWORD(wParam) == ID_BUTTON) {
        char temp[50];
        GetWindowText(hwndA, temp, 4);
        Function_in_file1(temp); //call Function_in_file1() in file1.C
        //or
        GetWindowText(hwndA, Input_Text, 4);//Input_Text is available in file1.C
    }
}

关于c - 在文本框和程序源代码之间传递信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29336093/

相关文章:

c - 正确地将多维 C 数组传递给 fortran,以便 size 函数(在 fortran 中)在每个维度中获得正确的大小?

c - 如何在for循环中获取3次数组?

c - 如何从输入文件中读取并保存每行的某些部分并将其输出到命令行?

excel - 如何在选择中的每个单元格周围添加文本框/形状?

html - Blazor 中的 “The attribute names could not be inferred from bind attribute ' 绑定(bind)值 '” 异常

asp.net - ASP :TextBox ReadOnly=true or Enabled=false?

c - 如何按降序对这个链表进行排序?

c++ - 在链表中删除

wpf - 在 TextBox/RichTextBox 中 block 选择

Javascript RegExp 仅允许某些位置出现某些字符