2014-12-02 17 views
1

我的問題很簡單,但我還沒有找到解決方法。我目前正在製作單文檔MFC應用程序,我需要用戶輸入任何可能的方式。我已經探索CDialog,但還沒有想出如何使其工作。我需要窗口中用戶的基本整數輸入。這是我第一次開發使用MFC,我到處都試過,但還沒有找到解決方案。如果任何人都可以幫助,我會非常感激。
編輯: 我使用CPaintDC繪製不同的形狀就像在我的應用程序橢圓形和方形:MFC單文檔應用程序用戶輸入

CPaintDC dc(this); // device context for painting 
    dc.Ellipse(200, 200, 400, 400); 

所有我需要做的是讓用戶的輸入爲橢圓形的點,使用上面的函數繪製形狀。

dc.Ellipse(x1,y1,x2,y2); 
// where x1,y1 and x2,y2 are user inputs. any way to get the user input will do.. thanks 

以下是我已經探討了鏈接:

Interactive Service - Display Dialog Box & Get Input from user

http://www.codeproject.com/Articles/13330/Using-Dialog-Templates-to-create-an-InputBox-in-C

沒什麼變化。這是我的代碼:::

void AddCircle::OnBnClickedOk() 
{ 

    CDialogEx::OnOK(); 

    CString abc; 
    x1ctrl.GetWindowText(abc); 
    int x1; 
    _stscanf(abc, _T("%d"), &x1); //convert CString to integer value 

    y1ctrl.GetWindowText(abc); 
    int y1; 
    _stscanf(abc, _T("%d"), &y1); //convert CString to integer value 

    x2ctrl.GetWindowText(abc); 
    int x2; 
    _stscanf(abc, _T("%d"), &x2); 
    y2ctrl.GetWindowText(abc); 
    int y2; 
    _stscanf(abc, _T("%d"), &y2); 
    Invalidate(); 
    CPaintDC dc(this); 
    dc.Ellipse(x1, y1, x2, y2); 
} 
+0

我也試過這個:http://stackoverflow.com/questions/3507085/input-box-in-an-mfc-cwinapp-prgram – Hammadzafar 2014-12-02 07:10:35

+0

你的評論中的鏈接似乎很好地涵蓋了你的要求 - 什麼你有沒有嘗試過,究竟**是什麼**是你的問題? [請編輯您的問題與細節] – 2014-12-02 08:05:10

回答

0

從工具箱中取一個EditControl。右鍵單擊編輯控制 - >添加變量,給變量名稱說m_myedit

在點擊按鈕編寫代碼

CString abc; //Take CString variable 
m_myedit.GetWindowText(abc); //read value from textbox 
int x1; 
_stscanf(abc, _T("%d"), &x1); //convert CString to integer value 

使用不同editbox得到X2,Y1和Y2值。

相關問題