I want to get the results of the console window into the dialog.

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

I want to configure the screen that appears when I press the Windows Driver Properties window using MFC. Somehow I succeeded in getting information about the type and capacity of the driver I'm at a loss to put this result in the dialog. What should I do at times like this? The version is Visual Studio 2017.

#include <stdio.h>
#include <direct.h>  //_getdrive, _chdrive
#include <windows.h> //GetDiskFreeSpaceEx

#define CALCUL_MB (1)
//#define CALCUL_MB (1024 * 1024)
#define CALCUL_GB (1024 * 1024 * 1024)

typedef struct _drive_info
    unsigned __int64 freeBytesToCaller;
    unsigned __int64 totoalFreeBytes;
    unsigned __int64 freeBytes;

int driveInfo(char *dirve, DRIVE_INFO &info)
    BOOL  r;
    unsigned __int64 freeBytesToCaller;
    unsigned __int64 totoalFreeBytes;
    unsigned __int64 freeBytes;

    r = GetDiskFreeSpaceEx(dirve,

    if (r==0)
        return -1;

    info.freeBytesToCaller = freeBytesToCaller;
    info.totoalFreeBytes = totoalFreeBytes;
    info.freeBytes = freeBytes;

    return 0;

int main(void)
    char dirveArrary[30] = "";
    int driveCount = 0, i = 0, driveBackup = 0;
    unsigned __int64 usedBytes = 0;
    DRIVE_INFO info;
    char buf[50] = "";

    driveBackup = _getdrive();
    printf("\n >> List of Available Drives: \n");

    //Search sequentially from A(1) to Z(26)
    for (i = 1; i <= 26; i++)
        if (_chdrive(i) == 0)
            printf("  >> %c: \n", i + 'A' - 1);
            dirveArrary[driveCount] = i + 'A' - 1;

    printf(" >> There are a total of %d available drives.\n\n", driveCount);

    for (i = 0; i < driveCount; i++)
        printf(" >> ------------------------------------------\n");
        printf(" >> #%d: [%C:] View drive capacity information:\n", i+1, dirveArrary[i]);
        printf(" >> ------------------------------------------\n");
        sprintf_s(buf, "%C:", dirveArrary[i]);
        if (driveInfo(buf, info) == 0)
            usedBytes = info.totoalFreeBytes - info.freeBytes;
            printf(" >> Space in Use: %10I64u bytes (%6.0fGB)\n",
                usedBytes / CALCUL_MB, (double)usedBytes / CALCUL_GB);
            printf(" >> Free space: %10I64u bytes (%6.0fGB)\n",
                info.freeBytes / CALCUL_MB, (double)info.freeBytes / CALCUL_GB);
            printf(" >> Full capacity: %10I64u bytes (%6.0fGB)\n\n",
                info.totoalFreeBytes / CALCUL_MB, (double)info.totoalFreeBytes / CALCUL_GB);

    return 0;

If you run it, the results will appear as shown in the picture below.

The UI I organized is the picture above. in the end

I want to make it like this, but how can I get the output value from the console window to STATIC TAXT?

visual-studio console dialog c++

2022-09-20 11:15

1 Answers

I think I can do it by myself if I made the UI by myself like that much.

By default:

You printed it out as printf in the console program. There's a function called printf that writes it to the string buffer, not the console.

printf("hello %s", who); // output to console

Sprintf(str_buf, "hello %s", who); // string formatted as str_buf is stored.

In mfc, we'll probably use CString, in this case we have the format method.

CString str;

str.format(_T ("drive letter is %C", drive_chr);

I'm not sure if this is right.

2022-09-20 11:15

If you have any answers or tips

© 2022 pinfo. All rights reserved.