#include "pch.h"
#include "framework.h"
#include "Ex_998p_FreeSpace.h"
#include<stdio.h>
#include<commctrl.h>
HWND hProg[24]{}, hStatic[24]{};
#define MEGA (1048576)
LPCTSTR MyClassName = TEXT("FreeSpace");
HINSTANCE g_hInst{};
HWND hWndMain{};
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
HWND hWnd{};
MSG msg{};
WNDCLASSEXW wndclassexw{};
g_hInst = hInstance;
wndclassexw.lpfnWndProc = WndProc;
wndclassexw.hInstance = hInstance;
wndclassexw.lpszClassName = MyClassName;
wndclassexw.hIconSm = NULL;
wndclassexw.cbSize = sizeof(WNDCLASSEXW);
wndclassexw.cbClsExtra = 0;
wndclassexw.cbWndExtra = 0;
wndclassexw.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclassexw.hIcon = LoadIconW(NULL, IDI_APPLICATION);
wndclassexw.hCursor = LoadCursorW(NULL, IDC_ARROW);
wndclassexw.lpszMenuName = NULL;
wndclassexw.style = CS_VREDRAW | CS_HREDRAW;
RegisterClassExW(&wndclassexw);
hWnd = CreateWindowExW(NULL, MyClassName, MyClassName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessageW(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return((int)msg.wParam);
}
void ReScan() {
int i{};
UINT Type{};
TCHAR Drive[MAX_PATH]{};
TCHAR Caption[MAX_PATH + 128]{};
TCHAR Volume[MAX_PATH]{};
ULARGE_INTEGER Avail{}, Total{};
double nTotal{}, nAvail{};
int Find = 0;
for (i = 0; i < 24; i++) {
if (hProg[i] != NULL) {
DestroyWindow(hProg[i]);
DestroyWindow(hStatic[i]);
hProg[i] = NULL;
hStatic[i] = NULL;
}
}
for (i = 'C'; i <= 'Z'; i++) {
wsprintf(Drive, TEXT("%c\\"), i);
Type = GetDriveType(Drive);
if (Type == DRIVE_FIXED) {
hProg[Find] = CreateWindow(PROGRESS_CLASS, NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER, 10,
Find * 40 + 50, 300, 25, hWndMain, NULL, g_hInst, NULL);
hStatic[Find] = CreateWindow(TEXT("static"), NULL,
WS_CHILD | WS_VISIBLE, 320, Find * 40 + 50, 500, 25, hWndMain, (HMENU)-1, g_hInst, NULL);
GetDiskFreeSpaceEx(Drive, &Avail, &Total, NULL);
nTotal = int(Total.QuadPart / MEGA) / 1024.0;
nAvail = int(Avail.QuadPart / MEGA) / 1024.0;
GetVolumeInformation(Drive, Volume, MAX_PATH, NULL, NULL, NULL, NULL, 0);
sprintf(Caption, "%c(%s): ÃÑ %.2fGÁß %.2fG»ç¿ë, %.2fG»ç¿ë°¡´É", i, Volume, nTotal, (nTotal - nAvail), nAvail);
SetWindowText(hStatic[Find], Caption);
SendMessage(hProg[Find], PBM_SETRANGE, 0, MAKELPARAM(0, 100));
SendMessage(hProg[Find], PBM_SETPOS, int((nTotal - nAvail) * 100 / nTotal), 0);
Find++;
}
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
switch (iMessage) {
case WM_CREATE:
hWndMain = hWnd;
InitCommonControls();
CreateWindow(TEXT("button"), TEXT("´Ù½Ã Á¶»ç"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
20, 15, 150, 25, hWnd, (HMENU)100, g_hInst, NULL);
ReScan();
return(0);
case WM_COMMAND:
switch (LOWORD(wParam)){
case 100:
ReScan();
break;
}
return(0);
case WM_DESTROY:
PostQuitMessage(0);
return(0);
}
return(DefWindowProcW(hWnd, iMessage, wParam, lParam));
}
-----------------------------------------------------------------------------------------------------------------------------------------
¹ØÁ٠ģ sprintf¿¡¼ ¿¡·¯°¡ °è¼Ó ¹ß»ýÇϴµ¥ ÇØ°áÃ¥ÀÌ ¹«¾ùÀÎÁö ±Ã±ÝÇÕ´Ï´Ù.
ÀÎÅÍ³Ý µÚÁö´Ù º¸´Ï TCHARÇü½ÄÀÇ º¯¼ö´Â sprintfÇÔ¼ö¿¡¼ »ç¿ë ¸ø ÇÑ´Ù°í ³ª¿ÍÀִµ¥ ¸Â´ÂÁö¿ä?
ÇØ°áÃ¥ÀÌ ÀÖ´Ù¸é ¾î¶»°Ô ¼öÁ¤ÇؾßÇÏ´ÂÁö ±Ã±ÝÇÕ´Ï´Ù.

±è¹Î¼ö
403 Forbidden403 Forbidden |
|