📄 main.c
字号:
DeleteObject(Font);
}
void showUninstaller() {
int Split_Vertical = 200;
RECT Rect;
GetClientRect(hwnd,&Rect);
ShowWindow(hUninstallButton,SW_SHOW);
MoveWindow(hDownloadButton,(Split_Vertical+Rect.right-Rect.left)/2,Rect.bottom-Rect.top-45,140,35,TRUE);;
}
void hideUninstaller() {
int Split_Vertical = 200;
RECT Rect;
GetClientRect(hwnd,&Rect);
ShowWindow(hUninstallButton,SW_HIDE);
MoveWindow(hDownloadButton,(Split_Vertical+Rect.right-Rect.left)/2-70,Rect.bottom-Rect.top-45,140,35,TRUE);
}
void startUninstaller(WCHAR* Uninstaller) {
STARTUPINFOW si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
CreateProcessW(NULL,Uninstaller,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
CloseHandle(pi.hThread);
// WaitForSingleObject(pi.hProcess, INFINITE); // If you want to wait for the Unistaller
CloseHandle(pi.hProcess);
hideUninstaller();
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
static RECT DescriptionRect;
switch (Message)
{
case WM_CREATE:
{
if(!SetupControls(hwnd))
return -1;
ShowMessage(Strings[IDS_WELCOME_TITLE], Strings[IDS_WELCOME]);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC BackbufferHdc = CreateCompatibleDC(hdc);
HBITMAP BackbufferBmp = CreateCompatibleBitmap(hdc, ps.rcPaint.right, ps.rcPaint.bottom);
SelectObject(BackbufferHdc, BackbufferBmp);
FillRect(BackbufferHdc, &ps.rcPaint, CreateSolidBrush(RGB(235,235,235)));
DrawBitmap(BackbufferHdc, 10, 12, hLogo);
DrawDescription(BackbufferHdc, DescriptionRect);
BitBlt(hdc, 0, 0, ps.rcPaint.right, ps.rcPaint.bottom, BackbufferHdc, 0, 0, SRCCOPY);
DeleteObject(BackbufferBmp);
DeleteDC(BackbufferHdc);
EndPaint(hwnd, &ps);
}
break;
case WM_COMMAND:
{
if(HIWORD(wParam) == BN_CLICKED)
{
if (lParam == (LPARAM)hDownloadButton)
{
if(SelectedApplication)
DialogBoxW(GetModuleHandle(NULL), MAKEINTRESOURCEW(IDD_DOWNLOAD), 0, DownloadProc);
else
ShowMessage(Strings[IDS_NO_APP_TITLE], Strings[IDS_NO_APP]);
}
else if (lParam == (LPARAM)hUninstallButton)
{
if(SelectedApplication)
{
WCHAR Uninstaller[200];
if(StrCmpW(SelectedApplication->RegName, L"")) {
if(getUninstaller(SelectedApplication->RegName, Uninstaller))
startUninstaller(Uninstaller);
}
}
}
else if (lParam == (LPARAM)hUpdateButton)
{
ShowMessage(Strings[IDS_UPDATE_TITLE], Strings[IDS_UPDATE]);
}
else if (lParam == (LPARAM)hHelpButton)
{
ShowMessage(Strings[IDS_HELP_TITLE], Strings[IDS_HELP]);
}
}
}
break;
case WM_NOTIFY:
{
LPNMHDR data = (LPNMHDR)lParam;
if(data->code == TVN_SELCHANGED)
{
BOOL bShowUninstaller = FALSE;
if(data->hwndFrom == hCategories)
{
struct Category* Category = (struct Category*) ((LPNMTREEVIEW)lParam)->itemNew.lParam;
CategoryChoosen (hApps, Category);
}
else if(data->hwndFrom == hApps)
{
SelectedApplication = (struct Application*) ((LPNMTREEVIEW)lParam)->itemNew.lParam;
if(SelectedApplication)
{
ApplicationText[0]=L'\0';
if(StrCmpW(SelectedApplication->Version, L"")) {
StrCatW(ApplicationText, Strings[IDS_VERSION]);
StrCatW(ApplicationText, SelectedApplication->Version);
StrCatW(ApplicationText, L"\n");
}
if(StrCmpW(SelectedApplication->Licence, L"")) {
StrCatW(ApplicationText, Strings[IDS_LICENCE]);
StrCatW(ApplicationText, SelectedApplication->Licence);
StrCatW(ApplicationText, L"\n");
}
if(StrCmpW(SelectedApplication->Maintainer, L"")) {
StrCatW(ApplicationText, Strings[IDS_MAINTAINER]);
StrCatW(ApplicationText, SelectedApplication->Maintainer);
StrCatW(ApplicationText, L"\n");
}
if(StrCmpW(SelectedApplication->Licence, L"") || StrCmpW(SelectedApplication->Version, L"") || StrCmpW(SelectedApplication->Maintainer, L""))
StrCatW(ApplicationText, L"\n");
StrCatW(ApplicationText, SelectedApplication->Description);
ShowMessage(SelectedApplication->Name, ApplicationText);
WCHAR Uninstaller[200];
if(StrCmpW(SelectedApplication->RegName, L"")) {
if(getUninstaller(SelectedApplication->RegName, Uninstaller)) {
bShowUninstaller = TRUE;
}
}
}
}
if (bShowUninstaller)
showUninstaller();
else
hideUninstaller();
}
}
break;
case WM_SIZING:
{
LPRECT pRect = (LPRECT)lParam;
if (pRect->right-pRect->left < 520)
pRect->right = pRect->left + 520;
if (pRect->bottom-pRect->top < 300)
pRect->bottom = pRect->top + 300;
}
break;
case WM_SIZE:
{
int Split_Hozizontal = (HIWORD(lParam)-(45+60))/2 + 60;
int Split_Vertical = 200;
ResizeControl(hCategories, 10, 60, Split_Vertical, HIWORD(lParam)-10);
ResizeControl(hApps, Split_Vertical+5, 60, LOWORD(lParam)-10, Split_Hozizontal);
RECT Rect = {Split_Vertical+5, Split_Hozizontal+5, LOWORD(lParam)-10, HIWORD(lParam)-50};
DescriptionRect = Rect;
MoveWindow(hHelpButton, LOWORD(lParam)-50, 10, 40, 40, TRUE);
MoveWindow(hUpdateButton, LOWORD(lParam)-100, 10, 40, 40, TRUE);
if(IsWindowVisible(hUninstallButton))
MoveWindow(hDownloadButton, (Split_Vertical+LOWORD(lParam))/2, HIWORD(lParam)-45, 140, 35, TRUE);
else
MoveWindow(hDownloadButton, (Split_Vertical+LOWORD(lParam))/2-70, HIWORD(lParam)-45, 140, 35, TRUE);
MoveWindow(hUninstallButton, (Split_Vertical+LOWORD(lParam))/2-140, HIWORD(lParam)-45, 140, 35, TRUE);
}
break;
case WM_DESTROY:
{
DeleteObject(hLogo);
if(Root.Children)
FreeTree(Root.Children);
PostQuitMessage(0);
return 0;
}
break;
}
return DefWindowProc (hwnd, Message, wParam, lParam);
}
INT WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInst,
LPTSTR lpCmdLine, INT nCmdShow)
{
int i;
WNDCLASSEXW WndClass = {0};
MSG msg;
InitCommonControls();
// Load strings
for(i=0; i<STRING_COUNT; i++)
LoadStringW(hInstance, i, Strings[i], MAX_STRING_LENGHT); // if you know a better method please tell me.
// Create the window
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.lpszClassName = L"Downloader";
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN));
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClassExW(&WndClass);
hwnd = CreateWindowW(L"Downloader",
Strings[IDS_WINDOW_TITLE],
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
CW_USEDEFAULT,
CW_USEDEFAULT,
600, 550,
NULL, NULL,
hInstance,
NULL);
// Show it
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
// Message Loop
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -