一派护法 十九级 |
【程序核心代码】 #include <tchar.h> #include <Windows.h> #include <CommCtrl.h> #include "resource.h"
// 必须启用XP风格 // 否则窗口显示后需要等待几秒钟动画才开始播放 #pragma comment(lib, "comctl32.lib") #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
HWND hwndAnimate; BOOL bPaused = FALSE; int nStep = 0;
void CALLBACK TimerProc(HWND hDlg, UINT uMsg, UINT iTimerID, DWORD dwTime) { static int nPos[] = {25, 50, 75, 90, 100}; static int nMoney[] = {1500, 1000, 500, 200, 0}; TCHAR str[20]; if (bPaused) return; _stprintf_s(str, TEXT("剩余%d块"), nMoney[nStep]); SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETPOS, nPos[nStep], NULL); SetDlgItemText(hDlg, IDC_TEXT2, str); if (nStep == 3) { bPaused = TRUE; if (MessageBox(hDlg, TEXT("确定要上缴所有钱钱, 不留零花钱吗?"), TEXT("工资上缴"), MB_ICONQUESTION | MB_YESNO) == IDYES) { nStep = 4; bPaused = FALSE; } else EndDialog(hDlg, IDNO); } else if (nStep == 4) { SetDlgItemText(hDlg, IDC_TEXT1, TEXT("上缴完毕! 你是世上最诚实的男人!")); SetDlgItemText(hDlg, IDCANCEL, TEXT("完成")); KillTimer(hDlg, IDT_TIMER1); } else nStep++; }
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HICON hIcon; int wmId; switch (uMsg) { case WM_COMMAND: wmId = LOWORD(wParam); switch (wmId) { case IDOK: case IDCANCEL: KillTimer(hDlg, IDT_TIMER1); EndDialog(hDlg, wmId); break; } break; case WM_INITDIALOG: hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)); SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETPOS, 4, NULL); hwndAnimate = GetDlgItem(hDlg, IDC_ANIMATE1); Animate_Open(hwndAnimate, MAKEINTRESOURCE(IDR_AVI1)); SetTimer(hDlg, IDT_TIMER1, 1000, TimerProc); break; } return FALSE; }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { InitCommonControls(); DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc); return 0; }
|