+
+ /* in order for the delegation below to also work for
+ WM_CREATE, we need to assign our window pointers *before* the
+ CreateWindow returns, because that's when the WM_CREATE event
+ is sent */
+ if(message == WM_CREATE) {
+ CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
+ if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "params")) {
+ wnd_params = hwnd;
+ }
+ if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "progress")) {
+ wnd_progress = hwnd;
+ }
+ }
+
+ if(hwnd == 0) {
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ } else if(hwnd == wnd_progress) {
+ static struct progress_data data;
+
+ switch(message)
+ {
+ case USER_SETMESSAGE:
+ data.text3 = (char*)wParam;
+ SendMessage(data.wnd_text3, WM_SETTEXT, 0, data.text3);
+ return 0;
+ case WM_CREATE: {
+ memset(&data, 0, sizeof(data));
+ data.text1 = "Installing SWFTools";
+ data.text2 = (char*)malloc(strlen(install_path)+250);
+ sprintf(data.text2, "to %s", install_path);
+ data.pos = 0;
+ data.step = 1;
+
+ CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
+ RECT rc;
+ GetClientRect (hwnd, &rc);
+ data.width = rc.right - rc.left;
+ data.height = rc.bottom - rc.top;
+ data.bar_width = cs->cx - 17;
+ data.bar_height= 16;
+ data.bar_posx = (data.width -data.bar_width)/2;
+ data.bar_posy = 56;
+ data.range = 50;
+ data.hwndButton = CreateWindow (
+ PROGRESS_CLASS,
+ "Progress",
+ WS_CHILD | WS_VISIBLE,
+ data.bar_posx,
+ data.bar_posy,
+ data.bar_width,
+ data.bar_height,
+ hwnd, /* Parent */
+ (HMENU)1,
+ cs->hInstance,
+ NULL
+ );
+
+ data.wnd_text3 = CreateWindow (
+ WC_EDIT,
+ "text3",
+ WS_CHILD | WS_VISIBLE | ES_READONLY | ES_CENTER,
+ data.bar_posx,
+ 72,
+ (rc.right - rc.left - data.bar_posx*2),
+ 20,
+ hwnd, /* Parent */
+ (HMENU)1,
+ cs->hInstance,
+ NULL
+ );
+ SendMessage(data.hwndButton, PBM_SETRANGE, 0, (LPARAM) MAKELONG(0,data.range));
+ SendMessage(data.hwndButton, PBM_SETSTEP, (WPARAM) data.step, 0);
+ //ShowWindow(hwndButton, SW_SHOW);
+ return 0;
+ }
+ case PBM_STEPIT: {
+ if(data.pos+data.step < data.range) {
+ data.pos += data.step;
+ SendMessage(data.hwndButton, PBM_STEPIT, wParam, lParam);
+ }
+ }
+ case WM_PAINT: {
+ TEXTMETRIC tm;
+ HDC hdc; /* A device context used for drawing */
+ PAINTSTRUCT ps; /* Also used during window drawing */
+ RECT rc; /* A rectangle used during drawing */
+
+ hdc = GetDC(hwnd);
+ SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
+ GetTextMetrics(hdc, &tm);
+ ReleaseDC(hwnd, hdc);
+
+ hdc = BeginPaint (hwnd, &ps);
+
+ rc.top = 8; rc.left= 0; rc.right = data.width; rc.bottom = 24;
+ DrawText(hdc, data.text1, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
+
+ /*if(data.text3) {
+ rc.top = 112; rc.left= 0; rc.right = data.width; rc.bottom = 128;
+ InvalidateRect(hwnd,&rc,1);
+ DrawText(hdc, data.text3, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
+ }*/
+
+ char buf[256];
+ char*text = data.text2;
+ if(tm.tmAveCharWidth * strlen(text) > data.width) {
+ int chars = (data.width / tm.tmAveCharWidth)-8;
+ if(chars>240) chars=240;
+ strncpy(buf, text, chars);
+ strcpy(&buf[chars],"...");
+ text = buf;
+ }
+
+ rc.top = 32; rc.left= 0; rc.right = data.width; rc.bottom = 48;
+ DrawText(hdc, text, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
+
+ EndPaint (hwnd, &ps);
+ return 0;
+ }
+ case WM_DESTROY:
+ wnd_progress = 0;
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ default:
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+ } else if(hwnd == wnd_params) {
+ static struct params_data data;
+ switch(message)
+ {
+ case WM_CREATE: {
+ memset(&data, 0, sizeof(data));
+ CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
+ RECT rc;
+ GetClientRect (hwnd, &rc);
+ data.width = rc.right - rc.left;
+ data.height = rc.bottom - rc.top;
+
+ //EDITTEXT IDD_EDIT,68,8,72,12, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP
+ HWND text = CreateWindow(
+ WC_STATIC,
+ "Select Installation Directory:",
+ WS_CHILD | WS_VISIBLE,
+ 32,
+ 0,
+ data.width-32*2,
+ 20,
+ hwnd, /* Parent */
+ (HMENU)1,
+ cs->hInstance,
+ NULL
+ );
+
+ SendMessage(text, WM_SETTEXT, "test1", "test2");
+
+ data.edit = CreateWindow (
+ WC_EDIT,
+ "EditPath",
+ WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL,
+ 32,
+ 32,
+ data.width-32*2,
+ 20,
+ hwnd, /* Parent */
+ (HMENU)1,
+ cs->hInstance,
+ NULL
+ );
+
+ data.installButton = CreateWindow (
+ WC_BUTTON,
+ "Install",
+ WS_CHILD | WS_VISIBLE | WS_TABSTOP,
+ (data.width - 80)/2,
+ data.height - 32*2,
+ 80,
+ 32,
+ hwnd, /* Parent */
+ (HMENU)1,
+ cs->hInstance,
+ NULL
+ );
+ return 0;
+ }
+ case WM_PAINT: {
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+ case WM_COMMAND: {
+ data.ok = 1;
+ DestroyWindow(wnd_params);
+ return;
+ }
+ case WM_KEYDOWN: {
+ if(wParam == 0x49) {
+ DestroyWindow(wnd_params);
+ }
+ return 0;
+ }
+ case WM_DESTROY:
+ if(!data.ok)
+ PostQuitMessage (0);
+ wnd_params = 0;
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ default:
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+ }
+ return DefWindowProc(hwnd, message, wParam, lParam);
+}
+
+void processMessages()
+{
+ MSG msg;
+ while(PeekMessage(&msg,NULL,0,0,0))