我不知道如何使用代码块win32 gui

问题描述 投票:0回答:2

我使用了win32 GUI,并在经过谷歌搜索后设法建立了某种界面,但我不知道如何使按钮做某事或使GUI文本框中的值成为整数。

这是主要

#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"

HINSTANCE hInst;

BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
    case WM_INITDIALOG:
    {
    }
    return TRUE;

    case WM_CLOSE:
    {
        EndDialog(hwndDlg, 0);
    }
    return TRUE;

    case WM_COMMAND:
    {
        switch(LOWORD(wParam))
        {
        }
    }
    return TRUE;
    }
    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst=hInstance;
    InitCommonControls();
    return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}

这是resource.rc


#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"




//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 125, 64
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Numar Factorial"
FONT 8, "Ms Shell Dlg"
{
    EDITTEXT        0, 82, 10, 23, 16, ES_AUTOHSCROLL, WS_EX_LEFT
    LTEXT           "Introdu numarul\r\n", 0, 20, 13, 50, 17, SS_LEFT, WS_EX_LEFT
    PUSHBUTTON      "Confirma\r\n", 0, 40, 34, 45, 14, 0, WS_EX_LEFT
}



//
// Manifest resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1                  RT_MANIFEST    ".\\manifest.xml"

Resource.h

#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define DLG_MAIN                                100

manifest.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
    </dependentAssembly>
  </dependency>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

这是主要的GUI它说阶乘数,插入一个数字并确认,我希望程序通过该文本框输入一个数字,然后单击确认,它返回那个数的阶乘。我需要弄清楚如何使按钮能够完成我是新手的工作,并且我的项目应在2天内到期。请帮助。

c++ c user-interface winapi win32gui
2个回答
0
投票

您的PUSHBUTTON需要一个控件ID。代替这个:

PUSHBUTTON      "Confirma\r\n", 0, 40, 34, 45, 14, 0, WS_EX_LEFT

此:

PUSHBUTTON      "Confirma\r\n", IDC_BUTTON1, 40, 34, 45, 14, 0, WS_EX_LEFT

IDC_BUTTON1是resource.h文件中的ID。 (例如#define IDC_BUTTON1 101

给您的编辑框类似的处理。

EDITTEXT        IDC_EDIT1, 82, 10, 23, 16, ES_AUTOHSCROLL, WS_EX_LEFT

以便您使用GetDlgItemText来获取该控件中的字符串:

然后,您可以在对话框处理程序中按如下方式处理单击事件:

case WM_COMMAND:
{
    switch(LOWORD(wParam))
    {
        case IDC_BUTTON1:
        {
             wchar_t str[200];
             GetDlgItemText(hwndDlg, IDC_EDIT1, str, 200);
             HandleClick(str);
             return TRUE;
        }
    }
}

-2
投票

我有同样的问题。有人可以提供帮助吗?

© www.soinside.com 2019 - 2024. All rights reserved.