// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); ::TextOut(hdc, 10, 10, L"Arrow keys to turn.", 19); ::SetTextColor(hdc, RGB(200,0,0)); ::TextOut(hdc, 10, 25, L"Red = Original;", 15); ::SetTextColor(hdc, RGB(0,0,255)); ::TextOut(hdc, 120, 25, L"Blue = Extrapolated", 19); ::SetTextColor(hdc, RGB(0,0,0)); { wchar_t buf[100]; _snwprintf(buf, 100, L"Latency %d ms Jitter %d ms Droprate %d%%", (int)(LATENCY*1000), (int)(JITTER*1000), (int)(DROPRATE*100)); buf[99] = 0; ::TextOut(hdc, 10, 40, buf, (INT)wcslen(buf)); } ::TextOut(hdc, 10, 55, L"F2: change draw mode", 20); ::TextOut(hdc, 10, 70, L"F3: pause/go", 12); ::TextOut(hdc, 10, 85, L"F4: single step", 15); if (gPaused) { ::SetTextColor(hdc, RGB(255,0,0)); ::TextOut(hdc, 300, 10, L"PAUSED", 6); ::SetTextColor(hdc, RGB(0,0,0)); } if (gPointDisplay) { ::TextOut(hdc, 300, 25, L"POINTS", 6); } else { ::TextOut(hdc, 300, 25, L"LINES", 5); } DrawWindow(hWnd, hdc); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); gRunning = false; break; case WM_SYSKEYDOWN: case WM_KEYDOWN: keyDown[wParam&0xff] = true; break; case WM_SYSKEYUP: case WM_KEYUP: keyDown[wParam&0xff] = false; break; case WM_ACTIVATEAPP: gActive = (wParam != 0); memset(keyDown, 0, sizeof(keyDown)); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK WndPauseProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; TEXTMETRIC tm; LPPW lppw; int cxChar, cyChar, middle; lppw = (LPPW)GetWindowLongPtr(hwnd, 0); switch(message) { case WM_KEYDOWN: if (wParam == VK_RETURN) SendMessage(hwnd, WM_COMMAND, lppw->bDefOK ? IDOK : IDCANCEL, 0L); else if (wParam == VK_ESCAPE) SendMessage(hwnd, WM_COMMAND, IDCANCEL, 0L); return 0; case WM_COMMAND: if ((LOWORD(wParam) == IDCANCEL) || (LOWORD(wParam) == IDOK)) { lppw->bPauseCancel = LOWORD(wParam); lppw->bPause = FALSE; break; } return 0; case WM_SETFOCUS: SetFocus(lppw->bDefOK ? lppw->hOK : lppw->hCancel); return 0; case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); SelectObject(hdc, GetStockObject(SYSTEM_FONT)); SetTextAlign(hdc, TA_CENTER); GetClientRect(hwnd, &rect); SetBkMode(hdc,TRANSPARENT); TextOut(hdc, (rect.right + rect.left) / 2, (rect.bottom + rect.top) / 6, lppw->Message, strlen(lppw->Message)); EndPaint(hwnd, &ps); return 0; } case WM_CREATE: { int ws_opts = WS_CHILD | WS_TABSTOP; #ifdef USE_MOUSE if (!paused_for_mouse) /* don't show buttons during pausing for mouse or key */ ws_opts |= WS_VISIBLE; #endif lppw = (LPPW) ((CREATESTRUCT *)lParam)->lpCreateParams; SetWindowLongPtr(hwnd, 0, (LONG_PTR)lppw); lppw->hWndPause = hwnd; hdc = GetDC(hwnd); SelectObject(hdc, GetStockObject(SYSTEM_FONT)); GetTextMetrics(hdc, &tm); cxChar = tm.tmAveCharWidth; cyChar = tm.tmHeight + tm.tmExternalLeading; ReleaseDC(hwnd, hdc); middle = ((LPCREATESTRUCT) lParam)->cx / 2; lppw->hOK = CreateWindow((LPSTR)"button", (LPSTR)"OK", ws_opts | BS_DEFPUSHBUTTON, middle - 10 * cxChar, 3 * cyChar, 8 * cxChar, 7 * cyChar / 4, hwnd, (HMENU)IDOK, ((LPCREATESTRUCT) lParam)->hInstance, NULL); lppw->bDefOK = TRUE; lppw->hCancel = CreateWindow((LPSTR)"button", (LPSTR)"Cancel", ws_opts | BS_PUSHBUTTON, middle + 2 * cxChar, 3 * cyChar, 8 * cxChar, 7 * cyChar / 4, hwnd, (HMENU)IDCANCEL, ((LPCREATESTRUCT) lParam)->hInstance, NULL); lppw->lpfnOK = (WNDPROC) GetWindowLongPtr(lppw->hOK, GWLP_WNDPROC); SetWindowLongPtr(lppw->hOK, GWLP_WNDPROC, (LONG_PTR)PauseButtonProc); lppw->lpfnCancel = (WNDPROC) GetWindowLongPtr(lppw->hCancel, GWLP_WNDPROC); SetWindowLongPtr(lppw->hCancel, GWLP_WNDPROC, (LONG_PTR)PauseButtonProc); if (GetParent(hwnd)) EnableWindow(GetParent(hwnd), FALSE); return 0; } case WM_DESTROY: GetWindowRect(hwnd, &rect); lppw->Origin.x = (rect.right + rect.left) / 2; lppw->Origin.y = (rect.bottom + rect.top) / 2; lppw->bPause = FALSE; if (GetParent(hwnd)) EnableWindow(GetParent(hwnd), TRUE); break; } return DefWindowProc(hwnd, message, wParam, lParam); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; //RECT rect; int num=0; switch (message) { case WM_CREATE: StartUp(); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_FILE_NEW: StartUp(); WinCheck(); if(wongame==true) StartUp(); InvalidateRect(hWnd,NULL,FALSE); break; case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); //GetClientRect(hWnd,&rect); for(int i=0;i<4;i++) for(int j=0;j<4;j++) OnPaint(hdc,j*64,i*64,Pole[i][j]); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_LBUTTONDOWN: POINT pt; GetCursorPos(&pt); ScreenToClient(hWnd,&pt); SwapNum((int)pt.x/64,(int)pt.y/64); InvalidateRect(hWnd,NULL,FALSE); if(wongame == true) MessageBox(hWnd,"You Won The Game!","Congradulations !",NULL); break; case WM_WINDOWPOSCHANGED: //case WM_MOVE: InvalidateRect(hWnd,NULL,FALSE); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
//Yeah this truly turned into a mess with the latest additions.. but it sure looks nice ;) void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam) { struct branch { int src,dst,srcAddr; }; branch branches[256]; int numBranches=0; GetClientRect(wnd, &rect); PAINTSTRUCT ps; HDC hdc; hdc = BeginPaint(wnd, &ps); // TODO: Add any drawing code here... int width = rect.right; int numRows=(rect.bottom/rowHeight)/2+1; //numRows=(numRows&(~1)) + 1; SetBkMode(hdc, TRANSPARENT); DWORD bgColor = 0xffffff; HPEN nullPen=CreatePen(0,0,bgColor); HPEN currentPen=CreatePen(0,0,0); HPEN selPen=CreatePen(0,0,0x808080); LOGBRUSH lbr; lbr.lbHatch=0; lbr.lbStyle=0; lbr.lbColor=bgColor; HBRUSH nullBrush=CreateBrushIndirect(&lbr); lbr.lbColor=0xFFEfE8; HBRUSH currentBrush=CreateBrushIndirect(&lbr); lbr.lbColor=0x70FF70; HBRUSH pcBrush=CreateBrushIndirect(&lbr); HPEN oldPen=(HPEN)SelectObject(hdc,nullPen); HBRUSH oldBrush=(HBRUSH)SelectObject(hdc,nullBrush); HFONT oldFont = (HFONT)SelectObject(hdc,(HGDIOBJ)font); HICON breakPoint = (HICON)LoadIcon(hMod,(LPCWSTR)IDI_BRKPT); HICON breakPointDisable = (HICON)LoadIcon(hMod,(LPCWSTR)IDI_BRKPTDIS); int i; for (i=-numRows; i<=numRows; i++) { unsigned int address=curAddress + i*align; int rowY1 = rect.bottom/2 + rowHeight*i - rowHeight/2; int rowY2 = rect.bottom/2 + rowHeight*i + rowHeight/2; wchar temp[256]; swprintf(temp,L"%08X",address); TCHAR desc[256]=L""; wcscpy(desc,debugger->getDescription(address)); // do this before getColor() lbr.lbColor=debugger->getColor(address); //SelectObject(hdc,currentBrush); SelectObject(hdc,nullPen); Rectangle(hdc,0,rowY1,16,rowY2); if (selecting && address == (u32)selection) SelectObject(hdc,selPen); else SelectObject(hdc,i==0 ? currentPen : nullPen); HBRUSH mojsBrush=CreateBrushIndirect(&lbr); SelectObject(hdc,mojsBrush); if (address == debugger->getPC()) SelectObject(hdc,pcBrush); //else // SelectObject(hdc,i==0 ? currentBrush : nullBrush); Rectangle(hdc,16,rowY1,width,rowY2); SelectObject(hdc,currentBrush); DeleteObject(mojsBrush); SetTextColor(hdc,0x600000); TextOut(hdc,17,rowY1,temp,(int)wcslen(temp)); SetTextColor(hdc,0x000000); TCHAR *dis = debugger->disasm(address); TCHAR *dis2=_tcschr(dis,'\t'); if (dis2) { *dis2=0; dis2++; wchar *mojs=wcsstr(dis2,L"0x8"); if (mojs) for (int i=0; i<8; i++) { bool found=false; for (int j=0; j<22; j++) { if (mojs[i+2]==L"0123456789ABCDEFabcdef"[j]) found=true; } if (!found) { mojs=0; break; } } if (mojs) { int offs; swscanf(mojs+2,L"%08X",&offs); branches[numBranches].src=rowY1 + rowHeight/2; branches[numBranches].srcAddr=address/align; branches[numBranches++].dst=(int)(rowY1+((__int64)offs-(__int64)address)*rowHeight/align + rowHeight/2); // sprintf(desc,"-->%s", debugger->getDescription(offs)); SetTextColor(hdc,0x600060); } else SetTextColor(hdc,0x000000); TextOut(hdc,198,rowY1,dis2,(int)wcslen(dis2)); } SetTextColor(hdc,0x007000); TextOut(hdc,90,rowY1,dis,(int)wcslen(dis)); SetTextColor(hdc,0x0000FF); //char temp[256]; //UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE); if (wcslen(desc)) TextOut(hdc,320,rowY1,desc,(int)wcslen(desc)); if (debugger->isBreakpoint(address)) { DrawIconEx(hdc,2,rowY1,breakPoint,32,32,0,0,DI_NORMAL); } } SelectObject(hdc,currentPen); for (i=0; i<numBranches; i++) { int x=250+(branches[i].srcAddr%9)*8; MoveToEx(hdc,x-2,branches[i].src,0); if (branches[i].dst<rect.bottom+200 && branches[i].dst>-200) { LineTo(hdc,x+2,branches[i].src); LineTo(hdc,x+2,branches[i].dst); LineTo(hdc,x-4,branches[i].dst); MoveToEx(hdc,x,branches[i].dst-4,0); LineTo(hdc,x-4,branches[i].dst); LineTo(hdc,x+1,branches[i].dst+5); } else { LineTo(hdc,x+4,branches[i].src); //MoveToEx(hdc,x+2,branches[i].dst-4,0); //LineTo(hdc,x+6,branches[i].dst); //LineTo(hdc,x+1,branches[i].dst+5); } //LineTo(hdc,x,branches[i].dst+4); //LineTo(hdc,x-2,branches[i].dst); } SelectObject(hdc,oldFont); SelectObject(hdc,oldPen); SelectObject(hdc,oldBrush); DeleteObject(nullPen); DeleteObject(currentPen); DeleteObject(selPen); DeleteObject(nullBrush); DeleteObject(pcBrush); DeleteObject(currentBrush); DestroyIcon(breakPoint); DestroyIcon(breakPointDisable); EndPaint(wnd, &ps); }
static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { MButtonCtrl *bct = (MButtonCtrl *) GetWindowLongPtr(hwndDlg, 0); switch (msg) { case WM_NCCREATE: { SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLong(hwndDlg, GWL_STYLE) | BS_OWNERDRAW); bct = reinterpret_cast<MButtonCtrl *>(malloc(sizeof(MButtonCtrl))); if (bct == NULL) return FALSE; bct->hwnd = hwndDlg; bct->stateId = PBS_NORMAL; bct->focus = 0; bct->hFont = reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)); bct->arrow = NULL; bct->defbutton = 0; bct->hIcon = bct->hIconPrivate = 0; bct->iIcon = 0; bct->hIml = 0; bct->hBitmap = NULL; bct->pushBtn = 0; bct->pbState = 0; bct->hThemeButton = NULL; bct->hThemeToolbar = NULL; bct->cHot = 0; bct->flatBtn = 0; bct->bThemed = FALSE; bct->bSkinned = bct->bSendOnDown = 0; bct->buttonItem = NULL; LoadTheme(bct); SetWindowLongPtr(hwndDlg, 0, (LONG_PTR) bct); if (((CREATESTRUCTA *) lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *) lParam)->lpszName); return TRUE; } case WM_DESTROY: { if (bct) { if (hwndToolTips) { TOOLINFO ti; ZeroMemory(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR) bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM) &ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM) &ti); } if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM) &ti) == 0) { DestroyWindow(hwndToolTips); hwndToolTips = NULL; } } if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); DestroyTheme(bct); free(bct); } SetWindowLongPtr(hwndDlg, 0, 0); break; // DONT! fall thru } case WM_SETTEXT: { bct->cHot = 0; if ((char*) lParam) { char *tmp = (char *) lParam; while (*tmp) { if (*tmp == '&' && *(tmp + 1)) { bct->cHot = tolower(*(tmp + 1)); break; } tmp++; } InvalidateRect(bct->hwnd, NULL, TRUE); lstrcpyn(bct->szText, (TCHAR *)lParam, 127); bct->szText[127] = 0; } break; } case WM_SYSKEYUP: if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == tolower((int) wParam)) { if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; InvalidateRect(bct->hwnd, NULL, TRUE); } if(!bct->bSendOnDown) SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); return 0; } break; case WM_THEMECHANGED: { if (bct->bThemed) LoadTheme(bct); InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it break; } case WM_SETFONT: // remember the font so we can use it later { bct->hFont = (HFONT) wParam; // maybe we should redraw? break; } case WM_NCPAINT: case WM_PAINT: { PAINTSTRUCT ps; HDC hdcPaint; hdcPaint = BeginPaint(hwndDlg, &ps); if (hdcPaint) { PaintWorker(bct, hdcPaint); EndPaint(hwndDlg, &ps); } break; } case BM_GETIMAGE: if(wParam == IMAGE_ICON) return (LRESULT)(bct->hIconPrivate ? bct->hIconPrivate : bct->hIcon); break; case BM_SETIMAGE: if(!lParam) break; bct->hIml = 0; bct->iIcon = 0; if (wParam == IMAGE_ICON) { ICONINFO ii = {0}; BITMAP bm = {0}; if (bct->hIconPrivate) { DestroyIcon(bct->hIconPrivate); bct->hIconPrivate = 0; } GetIconInfo((HICON) lParam, &ii); GetObject(ii.hbmColor, sizeof(bm), &bm); if (bm.bmWidth > g_cxsmIcon || bm.bmHeight > g_cysmIcon) { HIMAGELIST hImageList; hImageList = ImageList_Create(g_cxsmIcon, g_cysmIcon, IsWinVerXPPlus() ? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0); ImageList_AddIcon(hImageList, (HICON) lParam); bct->hIconPrivate = ImageList_GetIcon(hImageList, 0, ILD_NORMAL); ImageList_RemoveAll(hImageList); ImageList_Destroy(hImageList); bct->hIcon = 0; } else { bct->hIcon = (HICON) lParam; bct->hIconPrivate = 0; } DeleteObject(ii.hbmMask); DeleteObject(ii.hbmColor); bct->hBitmap = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } else if (wParam == IMAGE_BITMAP) { bct->hBitmap = (HBITMAP) lParam; if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIcon = bct->hIconPrivate = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; case BM_SETPRIVATEICON: bct->hIml = 0; bct->iIcon = 0; { if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIconPrivate = DuplicateIcon(g_hInst, (HICON) lParam); bct->hIcon = 0; break; } case BM_SETIMLICON: { if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIml = (HIMAGELIST) wParam; bct->iIcon = (int) lParam; bct->hIcon = bct->hIconPrivate = 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; } case BM_SETSKINNED: bct->bSkinned = (DWORD)lParam; bct->bThemed = bct->bSkinned ? FALSE : bct->bThemed; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BM_SETBTNITEM: bct->buttonItem = (ButtonItem *)lParam; break; case BM_SETASMENUACTION: bct->bSendOnDown = wParam ? TRUE : FALSE; return 0; case BM_SETCHECK: if (!bct->pushBtn) break; if (wParam == BST_CHECKED) { bct->pbState = 1; bct->stateId = PBS_PRESSED; } else if (wParam == BST_UNCHECKED) { bct->pbState = 0; bct->stateId = PBS_NORMAL; } InvalidateRect(bct->hwnd, NULL, TRUE); break; case BM_GETCHECK: if (bct->pushBtn) { return bct->pbState ? BST_CHECKED : BST_UNCHECKED; } return 0; case BUTTONSETARROW: // turn arrow on/off if (wParam) { if (!bct->arrow) bct->arrow = (HICON) LoadImage(g_hInst, MAKEINTRESOURCE(IDI_MINIMIZE), IMAGE_ICON, g_cxsmIcon, g_cysmIcon, 0); } else { if (bct->arrow) { DestroyIcon(bct->arrow); bct->arrow = NULL; } } InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETDEFAULT: bct->defbutton = wParam ? 1 : 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASPUSHBTN: bct->pushBtn = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASFLATBTN: bct->flatBtn = lParam == 0 ? 1 : 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASFLATBTN + 10: bct->bThemed = lParam ? TRUE : FALSE; bct->bSkinned = bct->bThemed ? 0 : bct->bSkinned; break; case BUTTONADDTOOLTIP: { TOOLINFO ti; if (!(char*) wParam) break; if (!hwndToolTips) { hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); SetWindowPos(hwndToolTips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); } ZeroMemory(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR) bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM) &ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM) &ti); } ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.uId = (UINT_PTR) bct->hwnd; ti.lpszText = (TCHAR *) wParam; SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM) &ti); break; } case WM_SETFOCUS: // set keybord focus and redraw bct->focus = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_KILLFOCUS: // kill focus and redraw bct->focus = 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_WINDOWPOSCHANGED: InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_ENABLE: // windows tells us to enable/disable { bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED; InvalidateRect(bct->hwnd, NULL, TRUE); break; } case WM_MOUSELEAVE: // faked by the WM_TIMER { if (bct->stateId != PBS_DISABLED) { // don't change states if disabled bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; } case WM_LBUTTONDOWN: { if (bct->stateId != PBS_DISABLED && bct->stateId != PBS_PRESSED) { bct->stateId = PBS_PRESSED; InvalidateRect(bct->hwnd, NULL, TRUE); if(bct->bSendOnDown) { SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } } break; } case WM_LBUTTONUP: { if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; } if (bct->stateId != PBS_DISABLED) { // don't change states if disabled if (msg == WM_LBUTTONUP) bct->stateId = PBS_HOT; else bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } if(!bct->bSendOnDown) SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); break; } case WM_MOUSEMOVE: if (bct->stateId == PBS_NORMAL) { bct->stateId = PBS_HOT; InvalidateRect(bct->hwnd, NULL, TRUE); } // Call timer, used to start cheesy TrackMouseEvent faker SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL); break; case WM_NCHITTEST: { LRESULT lr = SendMessage(GetParent(hwndDlg), WM_NCHITTEST, wParam, lParam); if(lr == HTLEFT || lr == HTRIGHT || lr == HTBOTTOM || lr == HTTOP || lr == HTTOPLEFT || lr == HTTOPRIGHT || lr == HTBOTTOMLEFT || lr == HTBOTTOMRIGHT) return HTTRANSPARENT; break; } case WM_TIMER: // use a timer to check if they have did a mouseout { if (wParam == BUTTON_POLLID) { RECT rc; POINT pt; GetWindowRect(hwndDlg, &rc); GetCursorPos(&pt); if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave PostMessage(hwndDlg, WM_MOUSELEAVE, 0, 0L); KillTimer(hwndDlg, BUTTON_POLLID); } } break; } case WM_ERASEBKGND: return 1; } return DefWindowProc(hwndDlg, msg, wParam, lParam); }
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; static HPEN hpen,hpen1,hpen2; static HBRUSH hbrush,hbrush1,hbrush2; int x,y; switch (message) /* handle the messages */ { case WM_KEYDOWN: switch (wParam) { case VK_F5: Init(hwnd); Rectangle(hdc,0,0,xw,yw); for(x=0;x<MAX;x++) for(y=0;y<MAX;y++) { Rectangle(hdc,x*xw/MAX,y*yw/MAX,(x+1)*xw/MAX,(y+1)*yw/MAX) ; iGame[x][y]=Default; } SetTimer(hwnd,Time1,times,NULL); leng=1; plays=Play; break; case VK_F1: break; case VK_F2: SetTimer(hwnd,Time1,times,NULL); leng=1; plays=Play; break; case VK_F3: if(plays==Play) { KillTimer(hwnd,Time1); plays=Paush; } else if(plays==Paush) { SetTimer(hwnd,Time1,times,NULL); plays=Play; } break; } break; case WM_TIMER: switch (wParam) { case Time1: timechage(hwnd); break; } break; case WM_CREATE: plays=Stop; play=Player1; break; case WM_SIZE: xw=LOWORD(lParam); yw=HIWORD(lParam); xw-=TextWidth; InvalidateRect(hwnd,NULL,TRUE); break; case WM_LBUTTONDOWN: //获取但前鼠标坐标 point.x=LOWORD(lParam); point.y=HIWORD(lParam); //初始化设备DC Init(hwnd); //鼠标坐标换为数组坐标 x=(point.x)/(xw/MAX); y=(point.y)/(yw/MAX); if(plays==Stop)break; if(x<MAX&&y<MAX) { if(iGame[x][y]==Default&&plays==Play)//判断但前位置是否有棋子覆盖 { leng=1; paint(play,x,y); if(Look(x,y,play)) over(hwnd,play); chagePlayer(); } } break; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); Init(hwnd); Rectangle(hdc,0,0,xw,yw); for(x=0;x<MAX;x++) for(y=0;y<MAX;y++) { Rectangle(hdc,x*xw/MAX,y*yw/MAX,(x+1)*xw/MAX,(y+1)*yw/MAX) ; paint(iGame[x][y],x,y); } EndPaint(hwnd,&ps); break; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; int wmId, wmEvent; PAINTSTRUCT ps; unsigned short* str[100]; RECT rt; int i; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_HELP_ABOUT: DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDOK: SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd); SendMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_TOOLS_EXIT: ILibStopChain(TheChain); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: g_hwndCB = CreateRpCommandBar(hWnd); // Initialize the shell activate info structure // Clear up all of the active transfers. for (i=0;i<10;i++) {g_DownloadStatsMapping[i] = -1;} // Load all of the icon resources we will need to draw the UI. HICON_MEDIASERVER = LoadIcon(g_hInst, (LPCTSTR)IDI_MEDIASERVER); HICON_MEDIASERVER2 = LoadIcon(g_hInst, (LPCTSTR)IDI_MEDIASERVER2); HICON_RIGHTARROW = LoadIcon(g_hInst, (LPCTSTR)IDI_RIGHTARROW); HICON_LEFTARROW = LoadIcon(g_hInst, (LPCTSTR)IDI_LEFTARROW); // Create the Micro Media Server thread. This thread will exist for // the duration of the application and will be owned by the media // server library. CreateThread(NULL, 0, &UPnPMain, 0, 0, NULL ); memset (&s_sai, 0, sizeof (s_sai)); s_sai.cbSize = sizeof (s_sai); break; case WM_PAINT: // Paint the complete screen here. Quite workout to get the UI looking // event half decent using Win32 directly. GetClientRect(hWndMainWindow, &rt); hdc = BeginPaint(hWnd, &ps); // Paint the top portion of the screen RECT r; r.left = 1; r.right = rt.right-1; r.top = 0; r.bottom = 40; FillRect(hdc,&r,GetSysColorBrush(COLOR_SCROLLBAR)); DrawEdge(hdc,&r,EDGE_RAISED,BF_RECT); DrawIcon(hdc,8,5,HICON_MEDIASERVER2); SetBkColor(hdc,GetSysColor(COLOR_SCROLLBAR)); // Paint the title r.left = 50; r.right = rt.right-1; r.top = 4; r.bottom = 50; DrawText(hdc,TEXT("Intel Micro Media Server"),-1,&r,0); // Paint the transfer count stat label & value r.left = 50; r.right = rt.right-1; r.top = 20; r.bottom = 50; if (MmsCurrentTransfersCount == 0) { DrawText(hdc,TEXT("No File Transfers "),-1,&r,0); } if (MmsCurrentTransfersCount == 1) { DrawText(hdc,TEXT("1 File Transfer "),-1,&r,0); } if (MmsCurrentTransfersCount > 1) { wsprintf((unsigned short*)str,TEXT("%d File Transfers "),MmsCurrentTransfersCount); DrawText(hdc,(unsigned short*)str,-1,&r,0); } // Paint the main portion of the screen r.left = 1; r.right = rt.right-1; r.top = 42; r.bottom = 267; FillRect(hdc,&r,GetSysColorBrush(COLOR_SCROLLBAR)); // Paint global media server stats labels r.left = 8; r.right = 150; r.top = 50; r.bottom = 70; DrawText(hdc,TEXT("Browse Requests"),-1,&r,0); r.left = 8; r.right = 150; r.top = 70; r.bottom = 90; DrawText(hdc,TEXT("HTTP Requests"),-1,&r,0); // Paint global media server stats values wsprintf((unsigned short*)str,TEXT("%d"),MmsBrowseCount); r.left = 180; r.right = rt.right-5; r.top = 50; r.bottom = 70; DrawText(hdc,(unsigned short*)str,-1,&r,DT_RIGHT); wsprintf((unsigned short*)str,TEXT("%d"),MmsHttpRequestCount); r.left = 180; r.right = rt.right-5; r.top = 70; r.bottom = 90; DrawText(hdc,(unsigned short*)str,-1,&r,DT_RIGHT); // Paint the transfer window edge r.left = 2; r.right = rt.right-1; r.top = 94; r.bottom = 264; DrawEdge(hdc,&r,EDGE_SUNKEN,BF_RECT); // Paint the white transfer window r.left = 4; r.right = rt.right-5; r.top = 96; r.bottom = 262; FillRect(hdc,&r,GetSysColorBrush(COLOR_MENU)); // Draw all of the active transfers on the screen (up to 5) for (i=0;i<5;i++) { DrawTransferInfo(hdc,i,g_DownloadStatsMapping[i]); } EndPaint(hWnd, &ps); break; case WM_CLOSE: ILibStopChain(TheChain); break; case WM_DESTROY: DestroyIcon(HICON_MEDIASERVER); DestroyIcon(HICON_MEDIASERVER2); DestroyIcon(HICON_RIGHTARROW); DestroyIcon(HICON_LEFTARROW); CommandBar_Destroy(g_hwndCB); PostQuitMessage(0); break; case WM_ACTIVATE: // Notify shell of our activate message SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE); break; case WM_SETTINGCHANGE: SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK FilterboxDlgHandler( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { int t; // ,z; char newname[25],sztemp[30]; static int acttype; static int dinit=FALSE; static FidFilter * tempf=NULL,* newf=NULL; FILTEROBJ * st; st = (FILTEROBJ *) actobject; if ((st==NULL)||(st->type!=OB_FILTER)) return(FALSE); switch( message ) { case WM_INITDIALOG: dinit=TRUE; SendMessage(GetDlgItem(hDlg, IDC_FILTERTYPECOMBO), CB_RESETCONTENT,0,0); for (t = 0; t < FILTERTYPES; t++) SendMessage( GetDlgItem(hDlg, IDC_FILTERTYPECOMBO), CB_ADDSTRING, 0, (LPARAM) (LPSTR) FILTERTYPE[t].tname) ; SetDlgItemText(hDlg,IDC_FILTERTYPECOMBO, FILTERTYPE[st->filtertype].tname); SetDlgItemText(hDlg,IDC_FILTERNEWNAME, st->name); SetDlgItemInt(hDlg,IDC_FROMFREQ, st->dispfrom,0); SetDlgItemInt(hDlg,IDC_TOFREQ, st->dispto,0); SetDlgItemInt(hDlg,IDC_FILTERPAR0, st->par0,0); sprintf(sztemp,"%.5f",st->par1); SetDlgItemText(hDlg,IDC_FILTERPAR1, sztemp); sprintf(sztemp,"%.5f",st->par2); SetDlgItemText(hDlg,IDC_FILTERPAR2, sztemp); acttype=st->filtertype; dinit=FALSE; newf=do_filt_design(hDlg,acttype); if (newf) tempf=newf; update_filterdialog(hDlg,st->filtertype); return TRUE; case WM_CLOSE: EndDialog(hDlg, LOWORD(wParam)); return TRUE; break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_FILTERTYPECOMBO: acttype=SendMessage( GetDlgItem(hDlg, IDC_FILTERTYPECOMBO), CB_GETCURSEL, 0, 0 ) ; update_filterdialog(hDlg,acttype); case IDC_FILTERPAR0: case IDC_FILTERPAR1: case IDC_FILTERPAR2: case IDC_FROMFREQ: case IDC_TOFREQ: if (!dinit) { newf=do_filt_design(hDlg,acttype); if (newf) tempf=newf; InvalidateRect(hDlg,NULL,TRUE); } break; case IDC_FILTERSTORE: if (newf) { GetDlgItemText(hDlg, IDC_FILTERNEWNAME,newname,sizeof(newname)); st->filtertype=acttype; st->par0=GetDlgItemInt(hDlg,IDC_FILTERPAR0, NULL, 0); GetDlgItemText(hDlg,IDC_FILTERPAR1,sztemp,sizeof(sztemp)); sscanf(sztemp,"%f",&st->par1); GetDlgItemText(hDlg,IDC_FILTERPAR2,sztemp,sizeof(sztemp)); st->dispfrom=GetDlgItemInt(hDlg, IDC_FROMFREQ, NULL, 0); st->dispto=GetDlgItemInt(hDlg, IDC_TOFREQ, NULL, 0); sscanf(sztemp,"%f",&st->par2); strcpy(st->name,newname); st->filt=do_filt_design(hDlg, acttype); st->run= fid_run_new(st->filt, &(st->funcp)); if (st->fbuf!=NULL) { fid_run_freebuf(st->fbuf); st->fbuf=fid_run_newbuf(st->run); } } break; } return(TRUE); case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; RECT rect; HPEN tpen; HBRUSH tbrush; int height; int f1,f2; float fstep,val,x; hdc = BeginPaint (hDlg, &ps); GetClientRect(hDlg, &rect); tpen = CreatePen (PS_SOLID,1,0); SelectObject (hdc, tpen); tbrush = CreateSolidBrush(RGB(240,240,240)); SelectObject(hdc,tbrush); rect.top+=80; rect.bottom -= 18; height= rect.bottom-rect.top; Rectangle(hdc,rect.left,rect.top-1,rect.right,rect.bottom+20); Rectangle(hdc,rect.left,rect.top-1,rect.right,rect.bottom); Rectangle(hdc,rect.left,rect.bottom-(int)(height/1.3),rect.right,rect.bottom); DeleteObject(tbrush); DeleteObject(tpen); tpen = CreatePen (PS_SOLID,1,RGB(0,100,0)); SelectObject (hdc, tpen); f1=GetDlgItemInt(hDlg, IDC_FROMFREQ, NULL, 0); f2=GetDlgItemInt(hDlg, IDC_TOFREQ, NULL, 0); fstep=(float)(f2-f1)/(rect.right-rect.left); MoveToEx(hdc,rect.left+1,rect.bottom-(int)(height*fid_response(tempf, (float)f1/256.0)/1.3),NULL); for (t=rect.left; t<rect.right; t++) { MoveToEx(hdc,1+t,rect.bottom,NULL); LineTo(hdc,1+t,rect.bottom-(int)(height*fid_response(tempf, (((float)f1+fstep*(t-rect.left))/PACKETSPERSECOND))/1.3)); } SelectObject(hdc, DRAW.scaleFont); wsprintf(sztemp,"1.0"); ExtTextOut( hdc, rect.left+2,rect.top+(int)(height*0.2308), 0, &rect,sztemp, strlen(sztemp), NULL ) ; val=(f2-f1)/10.0f; fstep=((rect.right-25)-rect.left)/10.0f; for (t=0; t<=10; t++) { x=f1+val*t; wsprintf(sztemp,"%d.%d",(int)x,(int)(x*10)%10); ExtTextOut( hdc, rect.left+2+(int)(fstep*t),rect.bottom+2, 0, &rect,sztemp, strlen(sztemp), NULL ) ; } DeleteObject(tpen); EndPaint(hDlg, &ps ); } break; case WM_SIZE: case WM_MOVE: update_toolbox_position(hDlg); break; return(TRUE); } return FALSE; }
LRESULT CALLBACK waoWC_button0Proc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { static TRACKMOUSEEVENT tME; switch( msg ) { case WM_CREATE: { tME.cbSize = sizeof( TRACKMOUSEEVENT ); //tME.dwFlags = TME_HOVER; tME.dwHoverTime = 0; SendMessage( GetParent (hwnd), WAOM_TBBTNCREATED, MAKEWPARAM( WAOM_TBBTNCREATED_LW, GetWindowLong( hwnd, GWL_ID ) ), ( LPARAM ) hwnd ); return FALSE; } case WM_ENABLE: if( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CHECKED ) SetWindowLong( hwnd, GWL_USERDATA, wParam ? ( WAO_TBBS_NORMAL | WAO_TBBS_CHECKED ) : ( WAO_TBBS_DISABLED | WAO_TBBS_CHECKED ) ); else SetWindowLong( hwnd, GWL_USERDATA, wParam ? WAO_TBBS_NORMAL : WAO_TBBS_DISABLED ); RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE ); return FALSE; case WM_MOUSEMOVE: if( GetWindowLong( hwnd, GWL_USERDATA ) != WAO_TBBS_NORMAL ) return FALSE; SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_HOVERED ); RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE ); tME.dwFlags = TME_LEAVE; tME.hwndTrack = hwnd; TrackMouseEvent( &tME ); return FALSE; case WM_MOUSELEAVE: SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_NORMAL ); RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE ); return FALSE; case WM_RBUTTONDOWN: if( GetWindowLong( hwnd, GWL_STYLE ) & BS_RIGHTBUTTON ) { long btnStt = GetWindowLong( hwnd, GWL_USERDATA ); SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_CLICKED | ( btnStt & WAO_TBBS_CHECKED ) ); } return FALSE; case WM_LBUTTONDOWN: { long btnStt = GetWindowLong( hwnd, GWL_USERDATA ); SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_CLICKED | ( btnStt & WAO_TBBS_CHECKED ) ); RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE ); if( GetWindowLong( hwnd, GWL_STYLE ) & BS_NOTIFY ) SetTimer( hwnd, WAO_TMR_TBRPW, WAO_TBBN_RPWTIME, NULL ); return FALSE; } case WM_LBUTTONUP: // should be clicked first: if( !( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CLICKED ) ) return FALSE; case WM_CLEAR: // tweak to check with one internal message { SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_NORMAL ); RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE ); DLGPROC parProc = ( DLGPROC ) GetWindowLong ( GetParent( hwnd ), DWL_DLGPROC ); if( msg != WM_CLEAR ) // what about making this a seperate thread? parProc( GetParent ( hwnd ), WM_COMMAND, MAKEWPARAM( GetWindowLong( hwnd, GWL_ID ), WAO_TBBN_LCLCKED ), ( LPARAM ) hwnd ); if( GetWindowLong( hwnd, GWL_STYLE ) & BS_NOTIFY ) { KillTimer( hwnd, WAO_TMR_TBRPW ); KillTimer( hwnd, WAO_TMR_TBRPT ); } return FALSE; } case WM_RBUTTONUP: // should be clicked first: if( !( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CLICKED ) ) return FALSE; if( GetWindowLong( hwnd, GWL_STYLE ) & BS_RIGHTBUTTON ) { DLGPROC parProc = ( DLGPROC ) GetWindowLong( GetParent( hwnd ), DWL_DLGPROC ); parProc( GetParent( hwnd ), WM_COMMAND, MAKEWPARAM( GetWindowLong ( hwnd, GWL_ID ), WAO_TBBN_RCLCKED ), ( LPARAM ) hwnd ); } return FALSE; case WM_TIMER: { if( wParam == WAO_TMR_TBRPW ) // repeat wait { KillTimer( hwnd, WAO_TMR_TBRPW ); SetTimer( hwnd, WAO_TMR_TBRPT, WAO_TBBN_RPTTIME, NULL ); } DLGPROC parProc = ( DLGPROC ) GetWindowLong( GetParent( hwnd ), DWL_DLGPROC ); parProc( GetParent( hwnd ), WM_COMMAND, MAKEWPARAM( GetWindowLong( hwnd, GWL_ID ), WAO_TBBN_LCLCKED ), ( LPARAM ) hwnd ); return FALSE; } case WM_PAINT: { PAINTSTRUCT paintStruct; BeginPaint( hwnd, &paintStruct ); RECT rcWnd; GetClientRect( hwnd, &rcWnd ); // should this be calculated every time? int btnStt = GetWindowLong( hwnd, GWL_USERDATA ); if( btnStt & WAO_TBBS_CHECKED ) { FillRect( paintStruct.hdc, &rcWnd, CreateSolidBrush( 0x99ffff ) ); DrawEdge( paintStruct.hdc, &rcWnd, BDR_SUNKENOUTER, BF_RECT ); } else if( btnStt == WAO_TBBS_CLICKED ) { DrawEdge( paintStruct.hdc, &rcWnd, BDR_SUNKENOUTER, BF_RECT ); } else if( btnStt == WAO_TBBS_HOVERED ) { DrawEdge( paintStruct.hdc, &rcWnd, BDR_RAISEDINNER, BF_RECT ); } // drawing icon if( GetWindowLong( hwnd, GWL_STYLE ) & BS_ICON ) // maybe later bitmap too { HICON hIco = LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( GetWindowLong( hwnd, GWL_ID ) ) ); DrawIconEx( paintStruct.hdc, ( rcWnd.right - rcWnd.left - 16 ) / 2, ( rcWnd.bottom - rcWnd.top - 16 ) / 2, hIco, 16, 16, 0, NULL, DI_NORMAL ); } // drawing text else { int tmpLen = GetWindowTextLength( hwnd ); wchar_t buffer[ tmpLen + 1 ]; SIZE tmpSze; GetWindowText( hwnd, buffer, tmpLen + 1 ); SetBkMode( paintStruct.hdc, TRANSPARENT ); SelectObject( paintStruct.hdc, GetStockObject( DEFAULT_GUI_FONT ) ); GetTextExtentPoint32( paintStruct.hdc, buffer, tmpLen, &tmpSze ); DrawState( paintStruct.hdc, NULL, NULL, ( LPARAM ) buffer, tmpLen, ( rcWnd.right-rcWnd.left-tmpSze.cx ) / 2, ( rcWnd.bottom-rcWnd.top-tmpSze.cy ) / 2, tmpSze.cx, tmpSze.cy, DST_TEXT|( ( btnStt & WAO_TBBS_DISABLED ) ? DSS_DISABLED : 0 ) ); } EndPaint( hwnd, &paintStruct ); return FALSE; } default: return DefWindowProc( hwnd, msg, wParam, lParam ); } }
LRESULT CALLBACK ChatView::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; HDC hdc; ChatView *p=(ChatView *) GetWindowLong(hWnd, GWL_USERDATA); switch (message) { case WM_CREATE: { p=(ChatView *) (((CREATESTRUCT *)lParam)->lpCreateParams); SetWindowLong(hWnd, GWL_USERDATA, (LONG) p ); p->msgList=VirtualListView::ref(new VirtualListView(hWnd, std::string("Chat"))); p->msgList->setParent(hWnd); p->msgList->showWindow(true); p->msgList->wrapList=false; p->msgList->colorInterleaving=true; p->editWnd=DoCreateEditControl(hWnd); p->calcEditHeight(); p->msgList->bindODRList(p->contact->messageList); break; } case WM_PAINT: hdc = BeginPaint(hWnd, &ps); { //p->contact->nUnread=0; RECT rc = {0, 0, 200, tabHeight}; SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, p->contact->getColor()); p->contact->draw(hdc, rc); int iconwidth= skin->getElementWidth(); skin->drawElement(hdc, icons::ICON_CLOSE, p->width-2-iconwidth, 0); skin->drawElement(hdc, icons::ICON_TRASHCAN_INDEX, p->width-2-iconwidth*2, 0); /*SetBkMode(hdc, TRANSPARENT); LPCTSTR t=p->title.c_str(); DrawText(hdc, t, -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP); DrawText(hdc, t, -1, &rc, DT_LEFT | DT_TOP);*/ } EndPaint(hWnd, &ps); break; //case WM_KILLFOCUS: // p->contact->nUnread=0; // break; case WM_SIZE: { HDWP hdwp; RECT rc; int height=GET_Y_LPARAM(lParam); p->width=GET_X_LPARAM(lParam); int ySplit=height-p->editHeight; p->calcEditHeight(); // Calculate the display rectangle, assuming the // tab control is the size of the client area. SetRect(&rc, 0, 0, GET_X_LPARAM(lParam), ySplit ); // Size the tab control to fit the client area. hdwp = BeginDeferWindowPos(2); /*DeferWindowPos(hdwp, dropdownWnd, HWND_TOP, 0, 0, GET_X_LPARAM(lParam), 20, SWP_NOZORDER ); */ DeferWindowPos(hdwp, p->msgList->getHWnd(), HWND_TOP, 0, tabHeight, GET_X_LPARAM(lParam), ySplit-tabHeight, SWP_NOZORDER ); /*DeferWindowPos(hdwp, rosterWnd, HWND_TOP, 0, tabHeight, GET_X_LPARAM(lParam), height-tabHeight, SWP_NOZORDER );*/ DeferWindowPos(hdwp, p->editWnd, NULL, 0, ySplit+1, GET_X_LPARAM(lParam), height-ySplit-1, SWP_NOZORDER ); EndDeferWindowPos(hdwp); break; } case WM_COMMAND: { if (wParam==IDS_SEND) { p->sendJabberMessage(); } if (wParam==IDC_COMPLETE) { p->mucNickComplete(); } if (wParam==IDC_COMPOSING) { p->setComposingState(lParam!=0); } break; } /*case WM_CTLCOLORSTATIC: case WM_CTLCOLORLISTBOX: case WM_CTLCOLOREDIT: { //HGDIOBJ brush= GetStockObject(GRAY_BRUSH); //HGDIOBJ pen= GetStockObject(WHITE_PEN); SetBkColor(hdc, 0x808080); SetTextColor(hdc, 0xffffff); //SelectObject((HDC)wParam, brush); //SelectObject((HDC)wParam, pen); return (BOOL) GetStockObject(GRAY_BRUSH); break; }*/ case WM_LBUTTONDOWN: SetFocus(hWnd); if ((GET_Y_LPARAM(lParam))>tabHeight) break; if (GET_X_LPARAM(lParam) > (p->width)-2-(skin->getElementWidth()) ) { PostMessage(GetParent(hWnd), WM_COMMAND, TabsCtrl::CLOSETAB, 0); break; } if (GET_X_LPARAM(lParam) > (p->width)-2-(skin->getElementWidth())*2) { int result=MessageBox( p->getHWnd(), L"Are You sure want to clear this chat session?", L"Clear chat", MB_YESNO | MB_ICONWARNING); if (result==IDYES) { p->contact->messageList->clear(); p->msgList->moveCursorEnd(); } break; } break; case WM_DESTROY: //TODO: Destroy all child data associated eith this window return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM uParam,LPARAM lParam) { TEXTMETRIC tm; PAINTSTRUCT ps; HDC hdc; int i,j,k,t; static int cxChar,cyChar; static int outRow,outCol; CHAR c; CHAR lnBuffer[128]; CHAR *lnPtr; int lnLen; int outColFlag; switch (message) { case WM_CREATE: hdc = GetDC(hwnd); SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT)); GetTextMetrics(hdc,&tm); cxChar = tm.tmAveCharWidth; cyChar = tm.tmHeight; ReleaseDC(hwnd,hdc); outRow = 0; outCol = 0; break; case WM_SIZE: break; case WM_SETFOCUS: CreateCaret(hwnd,(HBITMAP)1,cxChar,cyChar); ShowCaret(hwnd); break; case WM_KILLFOCUS: HideCaret(hwnd); DestroyCaret(); break; case WM_PAINT: hdc = BeginPaint(hwnd,&ps); SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT)); outRow=0; outCol=0; outColFlag = 0; lnPtr = lnBuffer; lnLen = 0; for (i=1; i <= gCurrStr; i++) { k = strlen(&gPutStr[i][0]); for (j=0; j < k; j++) { c = gPutStr[i][j]; switch (c) { case '\n': if (lnLen) TextOut(hdc,(outCol*cxChar),(outRow*cyChar),lnBuffer,lnLen); lnPtr = lnBuffer; lnLen = 0; outCol = 0; outRow++; break; case '\r': outColFlag = 1; break; case '\x0C': // form-feed (rest of gPutStr[] line ignored) // cls gCurrStr=0; InvalidateRect(gHwnd,NULL,TRUE); break; default: if (c >= 32) { *lnPtr++ = c; lnLen++; } } } if (lnLen) { TextOut(hdc,(outCol*cxChar),(outRow*cyChar),lnBuffer,lnLen); outCol = outCol + lnLen; lnPtr = lnBuffer; lnLen = 0; } if (outColFlag) { outCol = 0; outColFlag = 0; } } SetCaretPos(outCol*cxChar,outRow*cyChar); EndPaint(hwnd,&ps); break; case WM_CHAR: HideCaret(hwnd); for (i=0; i < (int)LOWORD(lParam); i++) { switch(LOWORD(uParam)) { case '\r': outRow++; outCol=0; gGetStr[gCurrChar] = '\x0'; gInputReady = 1; // used in GetMsg() in bd_main.c break; case '\n': break; case '\b': if (gCurrChar > 0) { gCurrChar--; gGetStr[gCurrChar] = '\x0'; t = strlen(&gPutStr[gCurrStr][0]); if (t > 0) gPutStr[gCurrStr][t-1] = 0; if (outCol > 0) outCol--; // play it safe hdc = GetDC(hwnd); SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT)); TextOut(hdc,(outCol*cxChar),(outRow*cyChar)," ",1); ReleaseDC(hwnd, hdc); } break; default: if (gCurrChar < sizeof(gGetStr)-1) { c = (CHAR)LOWORD(uParam); if ((c >= 32) & (c < 127)) { gGetStr[gCurrChar] = c; t = strlen(&gPutStr[gCurrStr][0]); gPutStr[gCurrStr][t] = c; gPutStr[gCurrStr][t+1] = '\x0'; hdc = GetDC(hwnd); SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT)); TextOut(hdc,(outCol*cxChar),(outRow*cyChar),&c,1); ReleaseDC(hwnd, hdc); gCurrChar++; outCol++; } } else { gGetStr[gCurrChar] = '\x0'; gInputReady = 1; } break; } } SetCaretPos(outCol*cxChar,outRow*cyChar); ShowCaret(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return (DefWindowProc(hwnd, message, uParam, lParam)); } return 0; }
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { LONG lRet = 0; PAINTSTRUCT ps; switch (uMsg) { case WM_SIZE: // If the window is resized if(!g_bFullScreen) // Do this only if we are NOT in full screen { SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height GetClientRect(hWnd, &g_rRect); // Get the window rectangle } break; case WM_PAINT: // If we need to repaint the scene BeginPaint(hWnd, &ps); // Init the paint struct EndPaint(hWnd, &ps); // EndPaint, Clean up break; /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Below we check what the user types in. If they use the arrow keys // then we want to move the sphere around (LEFT RIGHT UP and DOWN keys, plus F3/F4) // To rotate the camera around the line segment, use the F1 and F2 keys. case WM_KEYDOWN: switch(wParam) { case VK_ESCAPE: // Check if we hit the ESCAPE key. PostQuitMessage(0); // Tell windows we want to quit break; case VK_UP: // Check if we hit the UP ARROW key. g_vPosition.y += 0.01f; // Move the sphere up break; case VK_DOWN: // Check if we hit the DOWN ARROW key. g_vPosition.y -= 0.01f; // Move the sphere down break; case VK_LEFT: // Check if we hit the LEFT ARROW key. g_vPosition.x -= 0.01f; // Move the sphere left along it's plane break; case VK_RIGHT: // Check if we hit the RIGHT ARROW key. g_vPosition.x += 0.01f; // Move the sphere right along it's plane break; case VK_F3: // Check if we hit F3 g_vPosition.z -= 0.01f; // Move the sphere in front of the line break; case VK_F4: // Check if we hit F4 g_vPosition.z += 0.01f; // Move the sphere in front of the line break; case VK_F1: // Check if we hit F1 g_rotateY -= 2; // Rotate the camera left break; case VK_F2: // Check if we hit F2 g_rotateY += 2; // Rotate the camera right break; } /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * break; case WM_CLOSE: // If the window is closed PostQuitMessage(0); // Tell windows we want to quit break; default: // Return by default lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); break; } return lRet; // Return by default }
LRESULT CALLBACK MainWndProc ( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { HDC hDC; PAINTSTRUCT ps; DLGPROC dlgProcAbout; int i; int j; short y; switch ( message ) { case WM_CREATE: hDC = GetDC ( hWnd ); GetTextMetrics ( hDC, &tm ); cxChar = tm.tmAveCharWidth; cyChar = tm.tmHeight + tm.tmExternalLeading; ReleaseDC ( hWnd, hDC ); lpDdeProc = MakeProcInstance ( (FARPROC) DDECallback, hInst ); if ( DdeInitialize ( (LPDWORD)&idInst, (PFNCALLBACK)lpDdeProc, APPCMD_CLIENTONLY, 0L ) ) { HandleOutput ( "Client DDE initialization failure." ); return ( FALSE ); } hszService = DdeCreateStringHandle ( idInst, "Borland", CP_WINANSI ); hszTopic = DdeCreateStringHandle ( idInst, "DDEExample", CP_WINANSI ); hszItem = DdeCreateStringHandle ( idInst, "DDEData", CP_WINANSI ); cCurrentLine = 0; cTotalLines = 0; strcpy ( szDDEString, "Client application message number: " ); break; case WM_COMMAND: switch ( wParam ) { case IDM_EXIT: DestroyWindow ( hWnd ); break; case IDM_CONNECT_SERVER: if ( hConv == NULL ) { hConv = DdeConnect ( idInst, hszService, hszTopic, (PCONVCONTEXT) NULL ); if ( hConv == NULL ) { HandleError ( DdeGetLastError ( idInst ) ); HandleOutput ( "Unsuccessful connection." ); } else HandleOutput ( "Successful connection." ); } else HandleOutput ( "Already connected to DDE Server." ); break; case IDM_DISCONNECT_SERVER: if ( hConv != NULL ) { DdeDisconnect ( hConv ); hConv = NULL; HandleOutput ( "Disconnected from server." ); } else HandleOutput ( "Must be connected before disconnecting." ); break; case IDM_MSG_TO_SERVER: if ( hConv != NULL ) { iClientCount ++; sprintf ( tbuf, "%3d.", iClientCount ); strncpy ( &szDDEString[36], tbuf, 5 ); hData = DdeCreateDataHandle ( idInst, &szDDEString, sizeof ( szDDEString ), 0L, hszItem, wFmt, 0 ); if ( hData != NULL ) hData = DdeClientTransaction ( (LPBYTE)hData, -1, hConv, hszItem, wFmt, XTYP_POKE, 1000, &dwResult ); else HandleOutput ( "Could not create data handle." ); } else HandleOutput ( "A connection to a DDE Server has not been established." ); break; case IDM_MSG_FROM_SERVER: if ( hConv != NULL ) { hData = DdeClientTransaction ( NULL, 0, hConv, hszItem, wFmt, XTYP_REQUEST, 1000, &dwResult ); if ( dwResult == DDE_FNOTPROCESSED ) HandleOutput ( "Data not available from server." ); else { DdeGetData ( hData, (LPBYTE) szDDEData, 80L, 0L ); if ( szDDEData != NULL ) HandleOutput ( szDDEData ); else HandleOutput ( "Message from server is null." ); } } else HandleOutput ( "A connection to a DDE Server has not been established." ); break; case IDM_ABOUT: dlgProcAbout = (DLGPROC) MakeProcInstance ( (FARPROC)About, hInst ); DialogBox ( hInst, "AboutBox", hWnd, dlgProcAbout ); FreeProcInstance ( (FARPROC) dlgProcAbout ); break; default: return ( DefWindowProc ( hWnd, message, wParam, lParam ) ); } break; case WM_PAINT: hDC = BeginPaint ( hWnd, &ps ); y = 0; for ( i = 0; i < cTotalLines; i ++ ) { if ( cTotalLines == 8 ) j = ( (cCurrentLine + 1 + i) % 9 ); else j = i; // can't do this if we clear window and start in middle of array TextOut ( hDC, 0, y, (LPSTR)(szScreenText[j]), lstrlen ( szScreenText[j] ) ); y = y + cyChar; } EndPaint ( hWnd, &ps ); break; case WM_DESTROY: if ( hConv != NULL ) { DdeDisconnect ( hConv ); hConv = NULL; } DdeFreeStringHandle ( idInst, hszService ); DdeFreeStringHandle ( idInst, hszTopic ); DdeFreeStringHandle ( idInst, hszItem ); FreeProcInstance ( lpDdeProc ); PostQuitMessage ( 0 ); break; default: return ( DefWindowProc ( hWnd, message, wParam, lParam ) ); } return ( FALSE ); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; RECT rc; TCHAR WndText[MAX_PATH]; DWORD Index; NONCLIENTMETRICS ncm; HFONT hFont; switch (message) { case WM_CREATE: hEditWnd = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_AUTOHSCROLL|ES_LEFT|ES_MULTILINE, 0, 0, 0, 0, hWnd, NULL, hInst, NULL); hDisplayWnd = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE, 0, 0, 0, 0, hWnd, NULL, hInst, NULL); memset(&ncm, 0, sizeof(NONCLIENTMETRICS)); ncm.cbSize = sizeof(NONCLIENTMETRICS); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0); hFont = CreateFontIndirect(&ncm.lfMessageFont); SendMessage(hEditWnd, WM_SETFONT, (WPARAM)hFont, TRUE); SendMessage(hDisplayWnd, WM_SETFONT, (WPARAM)hFont, TRUE); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); if (lParam == (LPARAM)hEditWnd && wmEvent == EN_CHANGE) { GetWindowText(hEditWnd, WndText, MAX_PATH); if (_tcslen(WndText) > 0) { SetWindowText(hEditWnd, TEXT("")); if (!bConnected) { MessageBox(hWnd, TEXT("You are not currently connected!"), TEXT("Error"), MB_OK|MB_ICONSTOP); break; } for (Index=0; Index<_tcslen(WndText); Index++) { if (dwThreadId != 0) { PostThreadMessage(dwThreadId, WM_CHAR, (WPARAM)WndText[Index], (LPARAM)0); } } } } // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case IDM_FILE_CLEARDISPLAY: SetWindowText(hDisplayWnd, TEXT("")); break; case IDM_FILE_CONNECT: if (bConnected) { MessageBox(hWnd, TEXT("You are already connected!"), TEXT("Error"), MB_OK|MB_ICONSTOP); } else { if (DialogBox(hInst, (LPCTSTR)IDD_CONNECTION, hWnd, (DLGPROC)ConnectionDialogProc) == IDOK) { bConnected = TRUE; EnableFileMenuItemByID(IDM_FILE_DISCONNECT, TRUE); EnableFileMenuItemByID(IDM_FILE_CONNECT, FALSE); _beginthread(Rs232Thread, 0, NULL); } } break; case IDM_FILE_DISCONNECT: if (bConnected) { bConnected = FALSE; EnableFileMenuItemByID(IDM_FILE_DISCONNECT, FALSE); EnableFileMenuItemByID(IDM_FILE_CONNECT, TRUE); } else { MessageBox(hWnd, TEXT("You are not currently connected!"), TEXT("Error"), MB_OK|MB_ICONSTOP); } break; case IDM_FILE_STARTCAPTURE: if (DialogBox(hInst, (LPCTSTR)IDD_CAPTURE, hWnd, (DLGPROC)CaptureDialogProc) == IDOK) { bCapturing = TRUE; EnableFileMenuItemByID(IDM_FILE_STOPCAPTURE, TRUE); EnableFileMenuItemByID(IDM_FILE_STARTCAPTURE, FALSE); hCaptureFile = CreateFile(strCaptureFileName, FILE_APPEND_DATA, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); } break; case IDM_FILE_STOPCAPTURE: if (bCapturing) { bCapturing = FALSE; EnableFileMenuItemByID(IDM_FILE_STOPCAPTURE, FALSE); EnableFileMenuItemByID(IDM_FILE_STARTCAPTURE, TRUE); CloseHandle(hCaptureFile); hCaptureFile = NULL; } break; case IDM_FILE_LOCALECHO: if (bLocalEcho) { bLocalEcho = FALSE; CheckLocalEchoMenuItem(bLocalEcho); } else { bLocalEcho = TRUE; CheckLocalEchoMenuItem(bLocalEcho); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); (void)hdc; // FIXME EndPaint(hWnd, &ps); break; case WM_SIZE: GetClientRect(hWnd, &rc); MoveWindow(hDisplayWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top - 20, TRUE); MoveWindow(hEditWnd, rc.left, rc.bottom - 20, rc.right - rc.left, 20, TRUE); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK InternalWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; // Structure for the paint message POINT p = {0, 0}; // Translation point for the window's client region HRESULT hRet; switch (iMsg) { case WM_MOVE: // Make sure we're not moving to be minimized - because otherwise // our ratio varialbes (g_dwXRatio and g_dwYRatio) will end up // being 0, and once we hit CheckBoundries it divides by 0. if (!IsIconic(hwnd)) { g_rcSrc.left = 0; g_rcSrc.right = g_sizex; g_rcSrc.top = 0; g_rcSrc.bottom = g_sizey; GetClientRect(hwnd, &g_rcDst); g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 / (g_rcSrc.right - g_rcSrc.left); g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 / (g_rcSrc.bottom - g_rcSrc.top); ClientToScreen(hwnd, &p); g_rcDst.left = p.x; g_rcDst.top = p.y; g_rcDst.bottom += p.y; g_rcDst.right += p.x; CheckBoundries(); } else // Else, hide the overlay... just in case we can't do // destination color keying, this will pull the overlay // off of the screen for the user. if (g_pDDSOverlay && g_pDDSPrimary) g_pDDSOverlay->UpdateOverlay(NULL, g_pDDSPrimary, NULL, DDOVER_HIDE, NULL); // Check to make sure our window exists before we tell it to // repaint. This will fail the first time (while the window is being created). if (hwnd) { InvalidateRect(hwnd, NULL, FALSE); UpdateWindow(hwnd); } return 0L; case WM_SIZE: // Another check for the minimization action. This check is // quicker though... if (wParam != SIZE_MINIMIZED) { GetClientRect(hwnd, &g_rcDst); ClientToScreen(hwnd, &p); g_rcDst.left = p.x; g_rcDst.top = p.y; g_rcDst.bottom += p.y; g_rcDst.right += p.x; g_rcSrc.left = 0; g_rcSrc.right = g_sizex; g_rcSrc.top = 0; g_rcSrc.bottom = g_sizey; // Here we multiply by 1000 to preserve 3 decimal places in the // division opperation (we picked 1000 to be on the same order // of magnitude as the stretch factor for easier comparisons) g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 / (g_rcSrc.right - g_rcSrc.left); g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 / (g_rcSrc.bottom - g_rcSrc.top); CheckBoundries(); } return 0L; case WM_PAINT: BeginPaint(hwnd, &ps); // Check the primary surface to see if it's lost - if so you can // pretty much bet that the other surfaces are also lost - thus // restore EVERYTHING! If we got our surfaces stolen by a full // screen app - then we'll destroy our primary - and won't be able // to initialize it again. When we get our next paint message (the // full screen app closed for example) we'll want to try to reinit // the surfaces again - that's why there is a check for // g_pDDSPrimary == NULL. The other option, is that our program // went through this process, could init the primary again, but it // couldn't init the overlay, that's why there's a third check for // g_pDDSOverlay == NULL. Make sure that the check for // !g_pDDSPrimary is BEFORE the IsLost call - that way if the // pointer is NULL (ie. !g_pDDSPrimary is TRUE) - the compiler // won't try to evaluate the IsLost function (which, since the // g_pDDSPrimary surface is NULL, would be bad...). if (!g_pDDSPrimary || (g_pDDSPrimary->IsLost() != DD_OK) || (g_pDDSOverlay == NULL)) { DestroyOverlay(); DestroyPrimary(); if (DDPrimaryInit()) if (DDOverlayInit()) if (!DrawOverlay()) DestroyOverlay(); } // UpdateOverlay is how we put the overlay on the screen. if (g_pDDSOverlay && g_pDDSPrimary && g_video->updating) { hRet = g_pDDSOverlay->UpdateOverlay(&g_rcSrc, g_pDDSPrimary, &g_rcDst, g_OverlayFlags, &g_OverlayFX); #ifdef _DEBUG if(hRet != DD_OK) DisplayError("Can't update overlay", hRet); #endif } EndPaint(hwnd, &ps); return 0L; // process mouse and keyboard events case WM_LBUTTONDOWN: mouse(1, lParam); break; case WM_LBUTTONUP: mouse(-1, lParam); break; case WM_RBUTTONDOWN: mouse(2, lParam); break; case WM_RBUTTONUP: mouse(-2, lParam); break; case WM_MBUTTONDOWN: mouse(3, lParam); break; case WM_MBUTTONUP: mouse(-3, lParam); break; case WM_CHAR: g_video->on_key(wParam); break; case WM_DISPLAYCHANGE: return 0L; case WM_DESTROY: // Now, shut down the window... PostQuitMessage(0); return 0L; } return g_pUserProc? g_pUserProc(hwnd, iMsg, wParam, lParam) : DefWindowProc(hwnd, iMsg, wParam, lParam); }
static LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static int penDown = JAVACALL_FALSE; int x, y; int i; PAINTSTRUCT ps; HDC hdc; HANDLE *mutex; int key; //check if udp or tcp int level = SOL_SOCKET; int opttarget; int optname; int optsize = sizeof(optname); switch(iMsg) { #ifdef SKINS_MENU_SUPPORTED case WM_COMMAND: switch(wParam & 0xFFFF) { case EXMENU_ITEM_SHUTDOWN: printf("EXMENU_ITEM_SHUTDOWN ... \n"); javanotify_shutdown(); break; case EXMENU_ITEM_PAUSE: javanotify_pause(); break; case EXMENU_ITEM_RESUME: javanotify_resume(); break; default: return DefWindowProc (hwnd, iMsg, wParam, lParam); } /* end of switch */ return 0; #endif case WM_CREATE: hdc = GetDC(hwnd); CHECK_RETURN(SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT))); GetTextMetrics(hdc, &fixed_tm); CHECK_RETURN(SelectObject(hdc, GetStockObject(SYSTEM_FONT))); GetTextMetrics(hdc, &tm); ReleaseDC(hwnd, hdc); return 0; case WM_PAINT: mutex = (HANDLE*) TlsGetValue(tlsId); WaitForSingleObject(*mutex, INFINITE); hdc = BeginPaint(hwnd, &ps); /* * There are 3 bitmap buffers, putpixel screen buffer, the phone * bitmap and the actual window buffer. Paint the phone bitmap on the * window. LCDUIrefresh has already painted the putpixel buffer on the * LCD screen area of the phone bitmap. * * On a real win32 (or high level window API) device the phone bitmap * would not be needed the code below would just paint the putpixel * buffer the window. */ DrawBitmap(hdc, hPhoneBitmap, 0, 0, SRCCOPY); EndPaint(hwnd, &ps); ReleaseMutex(*mutex); return 0; case WM_CLOSE: /* * Handle the "X" (close window) button by sending the AMS a shutdown * event. */ #ifdef SKINS_MENU_SUPPORTED destroySkinsMenu(); #endif javanotify_shutdown(); PostQuitMessage(0); return 0; case WM_SYSKEYDOWN: case WM_SYSKEYUP: /* The only event of this type that we want MIDP * to handle is the F10 key which for some reason is not * sent in the WM_KEY messages. * if we receive any other key in this message, break. */ if(wParam != VK_F10) { break; } // patch for VK_F10 if (WM_SYSKEYUP == iMsg) { iMsg = WM_KEYUP; } else if (WM_SYSKEYDOWN == iMsg) { iMsg = WM_KEYDOWN; } /* fall through */ case WM_KEYDOWN: { /* Impl note: to send pause and resume notifications */ static int isPaused; if(VK_F5 == wParam) { if(!isPaused) { javanotify_pause(); } else { javanotify_resume(); } isPaused =!isPaused; break; } else if(VK_HOME == wParam) { javanotify_switch_to_ams(); break; } else if(VK_F4 == wParam) { javanotify_select_foreground_app(); break; /* F3 key used for rotation. */ } else if(VK_F3 == wParam) { javanotify_rotation(); } } case WM_KEYUP: key = mapKey(wParam, lParam); switch(key) { case /* MIDP_KEY_INVALID */ 0: return 0; /* case MD_KEY_HOME: if (iMsg == WM_KEYDOWN) { return 0; } pMidpEventResult->type = SELECT_FOREGROUND_EVENT; pSignalResult->waitingFor = AMS_SIGNAL; return 0; */ default: break; } if(iMsg == WM_KEYUP) { javanotify_key_event((javacall_key)key, JAVACALL_KEYRELEASED); } else if(iMsg == WM_KEYDOWN) { if (lParam & 0xf0000000) { javanotify_key_event((javacall_key)key, JAVACALL_KEYREPEATED); } else { javanotify_key_event((javacall_key)key, JAVACALL_KEYPRESSED); } } return 0; case WM_TIMER: // Stop the timer from repeating the WM_TIMER message. KillTimer(hwnd, wParam); return 0; case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONUP: /* Cast lParam to "short" to preserve sign */ x = (short)LOWORD(lParam); y = (short)HIWORD(lParam); /** please uncomment following line if you want to test pen input in win32 emulator. ** with ENABLE_PEN_EVENT_NOTIFICATION defined, you should also modify constants.xml ** in midp workspace in order to pass related tck cases. **/ #define ENABLE_PEN_EVENT_NOTIFICATION 1 #ifdef ENABLE_PEN_EVENT_NOTIFICATION midpScreen_bounds.x = x_offset; midpScreen_bounds.y = y_offset; midpScreen_bounds.width = VRAM.width; midpScreen_bounds.height = (inFullScreenMode? VRAM.height: VRAM.height - TOP_BAR_HEIGHT); if(iMsg == WM_LBUTTONDOWN && INSIDE(x, y, midpScreen_bounds) ) { penAreDragging = JAVACALL_TRUE; SetCapture(hwnd); if (reverse_orientation) { javanotify_pen_event(javacall_lcd_get_screen_width() - y + y_offset, x - x_offset, JAVACALL_PENPRESSED); } else { javanotify_pen_event(x-x_offset, y-y_offset, JAVACALL_PENPRESSED); } return 0; } if(iMsg == WM_LBUTTONUP && (INSIDE(x, y, midpScreen_bounds) || penAreDragging == JAVACALL_TRUE)) { if(penAreDragging == JAVACALL_TRUE) { penAreDragging = JAVACALL_FALSE; ReleaseCapture(); } if (reverse_orientation) { javanotify_pen_event(javacall_lcd_get_screen_width() - y + y_offset, x - x_offset, JAVACALL_PENRELEASED); } else { javanotify_pen_event(x-x_offset, y-y_offset, JAVACALL_PENRELEASED); } return 0; } if(iMsg == WM_MOUSEMOVE) { if(penAreDragging == JAVACALL_TRUE) { if (reverse_orientation) { javanotify_pen_event(javacall_lcd_get_screen_width() - y + y_offset, x - x_offset, JAVACALL_PENDRAGGED); } else { javanotify_pen_event(x-x_offset, y-y_offset, JAVACALL_PENDRAGGED); } } return 0; } #else if(iMsg == WM_MOUSEMOVE) { /* * Don't process mouse move messages that are not over the LCD * screen of the skin. */ return 0; } #endif for(i = 0; i < NUMBEROF(Keys); ++i) { if(!(INSIDE(x, y, Keys[i].bounds))) { continue; } /* Chameleon processes keys on the way down. */ #ifdef SOUND_SUPPORTED if(iMsg == WM_LBUTTONDOWN) { MessageBeep(MB_OK); } #endif switch(Keys[i].button) { case KEY_POWER: if(iMsg == WM_LBUTTONUP) { return 0; } javanotify_shutdown(); return 0; case KEY_END: if(iMsg == WM_LBUTTONUP) { return 0; } /* NEED REVISIT: destroy midlet instead of shutdown? */ javanotify_shutdown(); return 0; default: /* Handle the simulated key events. */ switch(iMsg) { case WM_LBUTTONDOWN: javanotify_key_event((javacall_key)Keys[i].button, JAVACALL_KEYPRESSED); return 0; case WM_LBUTTONUP: javanotify_key_event((javacall_key)Keys[i].button, JAVACALL_KEYRELEASED); return 0; default: break; } /* switch iMsg */ } /* switch key */ } /* for */ return 0; case WM_NETWORK: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "Got WM_NETWORK("); fprintf(stderr, "descriptor = %d, ", (int)wParam); fprintf(stderr, "status = %d, ", WSAGETSELECTERROR(lParam)); #endif optname = SO_TYPE; if(0 != getsockopt((SOCKET)wParam, SOL_SOCKET, optname,(char*)&opttarget, &optsize)) { #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "getsocketopt error)\n"); #endif } if(opttarget == SOCK_STREAM) { // TCP socket return handleNetworkStreamEvents(wParam,lParam); } else { return handleNetworkDatagramEvents(wParam,lParam); }; break; case WM_HOST_RESOLVED: #ifdef ENABLE_TRACE_NETWORKING fprintf(stderr, "Got Windows event WM_HOST_RESOLVED \n"); #endif javanotify_socket_event( JAVACALL_EVENT_NETWORK_GETHOSTBYNAME_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); return 0; #if 0 /* media */ case WM_DEBUGGER: pSignalResult->waitingFor = VM_DEBUG_SIGNAL; return 0; case WM_MEDIA: pSignalResult->waitingFor = MEDIA_EVENT_SIGNAL; pSignalResult->descriptor = (int)wParam; pSignalResult->pResult = (void*)lParam; return 0; #endif /* media */ default: break; } /* end of external switch */ return DefWindowProc (hwnd, iMsg, wParam, lParam); } /* end of WndProc */
/*------------------------------------------------ subclass procedure of TrayNotifyWnd --------------------------------------------------*/ LRESULT CALLBACK WndProcTrayNotify(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_ERASEBKGND: { RECT rc; if(bNoClock) break; GetClientRect(hwnd, &rc); FillClock(hwnd, (HDC)wParam, &rc, 0); return 1; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; RECT rc; if(bNoClock) break; hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rc); FillClock(hwnd, hdc, &rc, 0); #ifdef TEST_505 Rectangle(hdc, 1, 1, rc.right, rc.bottom); #endif //TEST_505 EndPaint(hwnd, &ps); return 0; } #ifdef TEST_505 case WM_MOVE: return 0; case WM_SIZE: if(bNoClock) break; SendMessage(s_hwndClock, WM_SIZE, 0, 0); // return 0; break; #else //TEST_505 case WM_SIZE: if(bNoClock) break; SendMessage(s_hwndClock, WM_SIZE, 0, 0); break; #endif //TEST_505 case WM_NOTIFY: { LPNMHDR pnmh; if(bNoClock) break; pnmh = (LPNMHDR)lParam; if (pnmh->code == NM_CUSTOMDRAW && pnmh->idFrom == 0) { LPNMCUSTOMDRAW pnmcd; pnmcd = (LPNMCUSTOMDRAW)lParam; if (pnmcd->dwDrawStage == CDDS_ITEMPREPAINT && hdcClock != NULL) { POINT ptTray, ptToolbar; int x, y; ptTray.x = ptTray.y = 0; ClientToScreen(hwnd, &ptTray); ptToolbar.x = ptToolbar.y = 0; ClientToScreen(pnmh->hwndFrom, &ptToolbar); x = ptToolbar.x - ptTray.x; y = ptToolbar.y - ptTray.y; BitBlt(pnmcd->hdc, pnmcd->rc.left, pnmcd->rc.top, pnmcd->rc.right - pnmcd->rc.left, pnmcd->rc.bottom - pnmcd->rc.top, hdcClock, x + pnmcd->rc.left, y + pnmcd->rc.top, SRCCOPY); } } break; } } return CallWindowProc(oldWndProcTrayNotify, hwnd, message, wParam, lParam); }
//--------------------------------------------------------------------------- // ViewportWndProc // // This is the window procedure for the ViewPort window. It doesn't have to // do all that much, as is obvious... // // RETURNS: Per Windows convention //--------------------------------------------------------------------------- LONG APIENTRY ViewportWndProc (HWND hwnd, WORD msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; switch (msg) { case WM_CREATE: { RECT r; HMENU hSysMenu; HANDLE hScreen; // Here, we have to allocate memory for the "screen" memory and // clear it, and also set the "cursor" location and window size // and position monitors. All this stuff is stored in the extra // bytes list of this viewport window. //--------------------------------------------------------------- hScreen = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, MAXLINES * (MAXLINELEN+1)); if (!hScreen) return (-1); SetWindowLong (hwnd, GWW_MEMHANDLE, (UINT)hScreen); SetWindowLong (hwnd, GWW_CURSOR, (UINT)0); SetWindowLong (hwnd, GWW_COMECHO, (UINT)0); GetClientRect (hwnd, &r); SetWindowLong (hwnd, GWW_WINDOWY, (UINT)r.bottom); hSysMenu = GetSystemMenu (hwnd, 0); AppendMenu (hSysMenu, MF_SEPARATOR, 0, NULL); AppendMenu (hSysMenu, MF_STRING, IDM_CLEARVP, "C&lear"); break; } case WM_SIZE: // Reset the WinY client-area variable to the new size //--------------------------------------------------------------- SetWindowLong (hwnd, GWW_WINDOWY, (DWORD)HIWORD(lParam)); break; case WM_GETMINMAXINFO: { POINT FAR *rgpt = (LPPOINT)lParam; TEXTMETRIC tm; HDC hDC; RECT r; HFONT hOldFont; INT maxx, maxy, t; // This is where we tell windows how large/small the window can // be grown/shrunk/maximized, etc. //--------------------------------------------------------------- hDC = GetDC (hwnd); hOldFont = SelectObject (hDC, GetStockObject (ANSI_FIXED_FONT)); GetTextMetrics (hDC, &tm); SelectObject (hDC, hOldFont); ReleaseDC (hwnd, hDC); GetWindowRect (hwnd, &r); maxx = MAXLINELEN * (tm.tmMaxCharWidth); maxy = MAXLINES * (tm.tmHeight + tm.tmExternalLeading); rgpt[1].x = min((GetSystemMetrics(SM_CXFRAME)*2) + maxx, rgpt[1].x); rgpt[1].y = min((GetSystemMetrics(SM_CYFRAME)*2) + GetSystemMetrics(SM_CYCAPTION) + maxy, rgpt[1].y); rgpt[2].x = min(r.left, GetSystemMetrics(SM_CXSCREEN)-rgpt[1].x); t = -GetSystemMetrics(SM_CXFRAME); if (rgpt[2].x < t) rgpt[2].x = t; rgpt[2].y = min(r.top, GetSystemMetrics(SM_CYSCREEN)-rgpt[1].y); t = -GetSystemMetrics(SM_CYFRAME); if (rgpt[2].y < t) rgpt[2].y = t; rgpt[4] = rgpt[1]; break; } case WM_CLOSE: ShowWindow (hwnd, SW_HIDE); break; case WM_SYSCOMMAND: // Closing the viewport by the system menu is actually a "hide" //--------------------------------------------------------------- if (wParam == SC_CLOSE) ShowWindow (hwnd, SW_HIDE); else if (wParam == IDM_CLEARVP) ClearViewport (hwnd); else return (DefWindowProc (hwnd, msg, wParam, lParam)); break; case WM_DESTROY: // Deallocate the screen memory before we die! //--------------------------------------------------------------- GlobalFree ((HANDLE)GetWindowLong (hwnd, GWW_MEMHANDLE)); break; case WM_PAINT: { HFONT hOldFont; // Refresh the client area ONLY IF not minimized //--------------------------------------------------------------- if (IsIconic(hwnd)) break; BeginPaint (hwnd, &ps); hOldFont = SelectObject(ps.hdc, GetStockObject(ANSI_FIXED_FONT)); if (GetWindowLong (hwnd, GWW_WINDOWY) == CW_USEDEFAULT) { RECT r; GetClientRect (hwnd, &r); SetWindowLong (hwnd, GWW_WINDOWY, (UINT)r.bottom); } PaintViewport (hwnd, &ps); SelectObject (ps.hdc, hOldFont); EndPaint (hwnd, &ps); break; } default: return (DefWindowProc (hwnd, msg, wParam, lParam)); } return FALSE; }
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HPALETTE hPalette ; static int cxClient, cyClient ; HBRUSH hBrush ; HDC hdc ; int i ; LOGPALETTE * plp ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case WM_CREATE: // Set up a LOGPALETTE structure and create a palette plp = malloc (sizeof (LOGPALETTE) + 64 * sizeof (PALETTEENTRY)) ; plp->palVersion = 0x0300 ; plp->palNumEntries = 65 ; for (i = 0 ; i < 65 ; i++) { plp->palPalEntry[i].peRed = (BYTE) min (255, 4 * i) ; plp->palPalEntry[i].peGreen = (BYTE) min (255, 4 * i) ; plp->palPalEntry[i].peBlue = (BYTE) min (255, 4 * i) ; plp->palPalEntry[i].peFlags = 0 ; } hPalette = CreatePalette (plp) ; free (plp) ; return 0 ; case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; // Select and realize the palette in the device context SelectPalette (hdc, hPalette, FALSE) ; RealizePalette (hdc) ; // Draw the fountain of grays for (i = 0 ; i < 65 ; i++) { rect.left = i * cxClient / 64 ; rect.top = 0 ; rect.right = (i + 1) * cxClient / 64 ; rect.bottom = cyClient ; hBrush = CreateSolidBrush (PALETTERGB (min (255, 4 * i), min (255, 4 * i), min (255, 4 * i))) ; FillRect (hdc, &rect, hBrush) ; DeleteObject (hBrush) ; } EndPaint (hwnd, &ps) ; return 0 ; case WM_QUERYNEWPALETTE: if (!hPalette) return FALSE ; hdc = GetDC (hwnd) ; SelectPalette (hdc, hPalette, FALSE) ; RealizePalette (hdc) ; InvalidateRect (hwnd, NULL, TRUE) ; ReleaseDC (hwnd, hdc) ; return TRUE ; case WM_PALETTECHANGED: if (!hPalette || (HWND) wParam == hwnd) break ; hdc = GetDC (hwnd) ; SelectPalette (hdc, hPalette, FALSE) ; RealizePalette (hdc) ; UpdateColors (hdc) ; ReleaseDC (hwnd, hdc) ; break ; case WM_DESTROY: DeleteObject (hPalette) ; PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
LRESULT CALLBACK CardImageWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { PCARDBACK pCardBack = (PCARDBACK)GetWindowLongPtr(hwnd, GWL_USERDATA); static WNDPROC hOldProc = NULL; if (!hOldProc && pCardBack) hOldProc = pCardBack->hOldProc; switch (msg) { case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; HPEN hPen, hOldPen; HBRUSH hBrush, hOldBrush; RECT rc; hdc = BeginPaint(hwnd, &ps); if (pCardBack->bSelected) { hPen = CreatePen(PS_SOLID, 2, RGB(0,0,0)); } else { DWORD Face = GetSysColor(COLOR_3DFACE); hPen = CreatePen(PS_SOLID, 2, Face); } GetClientRect(hwnd, &rc); hBrush = (HBRUSH)GetStockObject(NULL_BRUSH); hOldPen = (HPEN)SelectObject(hdc, hPen); hOldBrush = (HBRUSH)SelectObject(hdc, hBrush); Rectangle(hdc, rc.left+1, rc.top+1, rc.right, rc.bottom); StretchBlt(hdc, 2, 2, CARDBACK_OPTIONS_WIDTH, CARDBACK_OPTIONS_HEIGHT, __hdcCardBitmaps, pCardBack->hdcNum * __cardwidth, 0, __cardwidth, __cardheight, SRCCOPY); SelectObject(hdc, hOldPen); SelectObject(hdc, hOldBrush); EndPaint(hwnd, &ps); break; } case WM_LBUTTONDOWN: pCardBack->bSelected = pCardBack->bSelected ? FALSE : TRUE; break; } return CallWindowProc(hOldProc, hwnd, msg, wParam, lParam); }
/* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND checks[10]; static int IDs[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int x = 400,y = 500; static HDC hdcCat1, hdcCat2; static BITMAP bitmapCat1, bitmapCat2; static HBITMAP hbmpImg1 = NULL ; static HBITMAP hbmpImg2 = NULL; static HFONT font_forte, text_font, font_forte1, text_font1;; static RECT area = {400, 80, 707, 470}; static RECT write = {45, 501, 282, 522}; PAINTSTRUCT Ps; HDC hdc = GetDC(hwnd); HBRUSH hbrush; static RECT diff[30]; char* current_img = Images[random]; char* current_story = Story[random]; char str[15]; if(toRender) { sprintf(str,"%s1.bmp",current_img); // load bitmaps hbmpImg1 = (HBITMAP)LoadImage(hInst, str, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); GetObject(hbmpImg1, sizeof(bitmapCat1), &bitmapCat1); sprintf(str,"%s2.bmp",current_img); hbmpImg2 = (HBITMAP)LoadImage(hInst, str, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); GetObject(hbmpImg2, sizeof(bitmapCat2), &bitmapCat2); toRender = false; } //Static variables for mouse Coordinates static int xMouse, yMouse; xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); //Coordinates of the differences diff[0] = {508,122,569,165}; diff[1] = {511,161,568,180}; //sprincene diff[2] = {540, 197, 560, 217 };//ochi diff[3] = {583, 228, 614, 245};//mustata dreapta diff[4] = {645, 328, 685, 348};//coada diff[5] = {586, 292, 630, 327};//fluture diff[6] = {498, 359, 526, 388};//hand diff[7] = {520, 289, 557, 305};//piept diff[8] = {540, 390, 550, 400 };//flowerbottom diff[9] = {450, 310, 470, 330};//left diff[10] = {467, 155 , 489, 190 }; //acc diff[11] = {503, 175,522, 192 } ;// paplivoc diff[12] = {521,123, 558, 155};// circioc diff[13] = {578, 140, 600, 163 }; //circioc dreapta diff[14] = {630,290, 653, 312}; //mina diff[15] = {471, 444,495, 464 };//ass diff[16] = {429, 292, 468, 325};//mp3 diff[17] = {464, 265,481, 279 };//sunnglass diff[18] = {478, 305,494, 316 };//bunghi linga mp3 diff[19] = {585, 400, 608, 419}; //bumb picior dreapta diff[20] ={416, 100, 494, 128};//nour stinga diff[21] ={619, 124, 638, 137}; //nour dreapta diff[22] ={678, 109, 700, 124 }; //sun diff[23] ={534, 207, 565, 245}; //wolf hands diff[24] ={637, 202,655, 215}; //barba diff[25] ={595, 405, 615, 417}; //picior Wolf diff[26] ={514,399,531,409 };//picior fetita diff[27] ={511,344, 526, 360 }; //fata jacketa diff[28] ={400,325,455,353};//deal diff[29] ={425,351,446,368};//floare switch (message) /* handle the messages */ { case WM_GETMINMAXINFO: { LPMINMAXINFO pInfo = (LPMINMAXINFO)lParam; pInfo -> ptMaxTrackSize.x = 750; pInfo -> ptMaxTrackSize.y = 700; pInfo -> ptMinTrackSize.x= 750; pInfo -> ptMinTrackSize.y = 700; } break; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDI_EXIT: //Exit Coammand { PostQuitMessage (0); break; } case IDI_NEW: { toRender = true; InvalidateRect(hwnd, &area, FALSE); InvalidateRect(hwnd, &area, TRUE); InvalidateRect(hwnd, &write, FALSE); InvalidateRect(hwnd, &write, TRUE); random = GetRandom(3); for (int i=0; i<11; i++) { CheckDlgButton(hwnd, IDs[i], BST_UNCHECKED); } break; } case IDI_ABOUT: { DialogBox(hInst, MAKEINTRESOURCE(IDI_DIALOG), hwnd, AboutDlgProc); break; } case IDI_RULE: { DialogBox(hInst, MAKEINTRESOURCE(IDI_DIALOG_RULE), hwnd, AboutDlgProc); break; } } break; } break; case WM_CREATE: { for(int i=0; i<sizeof(checks)/sizeof(HWND); i++) { checks[i] = CreateWindow(TEXT("button"), TEXT(""), WS_VISIBLE | WS_CHILD | BS_CHECKBOX, x, 500, 12, 12, hwnd, (HMENU) IDs[i], hInst, NULL); x+=33; } break; } //Work with LButton case WM_LBUTTONDOWN: { if(random == 0) { coeficient = 3 ; } if(random == 1) coeficient = 1.5; if(random == 2) coeficient = 1; for (int i = 0+ random * 10; i < (sizeof(diff)/sizeof(diff[0]))/coeficient ; i++) { if(diff[i].left < xMouse && xMouse < diff[i].right && diff[i].top < yMouse && yMouse < diff[i].bottom ) { if(coeficient == 3) PlaySound("Meow.wav", NULL, SND_ASYNC); if(coeficient == 1.5) PlaySound("goofy.wav", NULL, SND_ASYNC); if(coeficient == 1) PlaySound("Wolf.wav", NULL, SND_ASYNC); DrawEdge(hdc, &diff[i], BDR_RAISEDOUTER | BDR_SUNKENINNER, BF_RECT); CheckDlgButton(hwnd, IDs[i], BST_CHECKED); nr_differences ++; CheckDlgButton(hwnd, IDs[i - + (random * 10)], BST_CHECKED); // MessageBoxA(NULL,"You found it! Good Job", "Congrats", MB_OK | MB_ICONINFORMATION); if (nr_differences == 10) { PlaySound("Level.wav", NULL, SND_ASYNC); MessageBoxA(NULL,"You won! Go to File->New game", "Congrats", MB_OK | MB_ICONINFORMATION); } notFound = false; } } if(notFound) PlaySound("FailSound.wav", NULL, SND_ASYNC); notFound = true; } break; case WM_LBUTTONDBLCLK: { char str [256]; POINT pt; pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); wsprintf(str, "Co-ordinates are \nX=%i and Y=%i", pt.x, pt.y); MessageBoxA(NULL,str, "Message", MB_OK | MB_ICONINFORMATION); } break; case WM_PAINT: { BeginPaint(hwnd, &Ps); hdcCat1 = CreateCompatibleDC(hdc); SelectObject(hdcCat1, hbmpImg1); BitBlt(hdc, 37, 80, bitmapCat1.bmWidth, bitmapCat1.bmHeight, hdcCat1, 0, 0, SRCCOPY); DeleteObject(hdcCat1); hdcCat2 = CreateCompatibleDC(hdc); SelectObject(hdcCat2, hbmpImg2); BitBlt(hdc, 400, 80, bitmapCat2.bmWidth, bitmapCat2.bmHeight, hdcCat2, 0, 0, SRCCOPY); DeleteObject(hdcCat2); // create the title font_forte = CreateFont(30, 27.5, 0, 0, FW_DONTCARE, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Forte"); font_forte1 = CreateFont(0, 0, 0, 0, FW_DONTCARE, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Forte"); text_font = (HFONT)SelectObject(hdc, font_forte); // setting new font for text SetTextColor(hdc, TITLE_COLOR); // setting new text color TextOut( hdc, 115, 20, "Find the difference", 19); text_font1 = (HFONT)SelectObject(hdc, font_forte1); TextOut(hdc, 45, 501, current_story, 42); TextOut(hdc, 45, 520, "And have changed, it needs your ", 32); TextOut(hdc, 45, 539, "help to find differences!", 25); DeleteObject(font_forte); DeleteObject(text_font); DeleteObject(font_forte1); DeleteObject(text_font1); EndPaint(hwnd, &Ps); } break; case WM_CTLCOLORSTATIC: { SetBkMode((HDC)wParam,TRANSPARENT); // transparent background hbrush=(HBRUSH)GetStockObject(NULL_BRUSH); // handle to brush, no background color return(LRESULT) hbrush; } break; case WM_DESTROY: { DeleteFont(font_forte); DeleteFont(text_font); PostQuitMessage (0); /* send a WM_QUIT to the message queue */ } break; // InvalidateRect(hwnd, &all_area, FALSE); default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK VolumeControlProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { VolumeControlData *control; switch(message) { case WM_NCCREATE: { CREATESTRUCT *pCreateData = (CREATESTRUCT*)lParam; control = (VolumeControlData*)malloc(sizeof(VolumeControlData)); zero(control, sizeof(VolumeControlData)); SetWindowLongPtr(hwnd, 0, (LONG_PTR)control); control->curVolume = 1.0f; control->bDisabled = ((pCreateData->style & WS_DISABLED) != 0); control->cx = pCreateData->cx; control->cy = pCreateData->cy; return TRUE; } case WM_DESTROY: { control = GetVolumeControlData(hwnd); if(control) free(control); break; } case WM_PAINT: { control = GetVolumeControlData(hwnd); PAINTSTRUCT ps; HDC hDC = BeginPaint(hwnd, &ps); control->DrawVolumeControl(hDC); EndPaint(hwnd, &ps); break; } case WM_LBUTTONDOWN: case WM_LBUTTONUP: { control = GetVolumeControlData(hwnd); short x = short(LOWORD(lParam)); short y = short(HIWORD(lParam)); UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID); if(message == WM_LBUTTONDOWN && !control->bDisabled) { if(control->cy == 32 && x >= (control->cx-32)) { if(control->curVolume < 0.05f) { if(control->lastUnmutedVol < 0.05f) control->lastUnmutedVol = 1.0f; control->curVolume = control->lastUnmutedVol; } else { control->lastUnmutedVol = control->curVolume; control->curVolume = 0.0f; } SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_FINALVALUE), (LPARAM)hwnd); } else { SetCapture(hwnd); control->bHasCapture = true; if(control->curVolume > 0.05f) control->lastUnmutedVol = control->curVolume; int cxAdjust = control->cx; if(control->bDrawIcon) cxAdjust -= 32; control->curVolume = float(x) / cxAdjust; SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd); } HDC hDC = GetDC(hwnd); control->DrawVolumeControl(hDC); ReleaseDC(hwnd, hDC); } else if(control->bHasCapture) { UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID); SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_FINALVALUE), (LPARAM)hwnd); ReleaseCapture(); control->bHasCapture = false; } break; } case WM_MOUSEMOVE: { control = GetVolumeControlData(hwnd); if(control->bHasCapture) { int cxAdjust = control->cx; if(control->bDrawIcon) cxAdjust -= 32; control->curVolume = float(short(LOWORD(lParam))) / cxAdjust; if(control->curVolume < 0.0f) control->curVolume = 0.0f; else if(control->curVolume > 1.0f) control->curVolume = 1.0f; HDC hDC = GetDC(hwnd); control->DrawVolumeControl(hDC); ReleaseDC(hwnd, hDC); UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID); SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd); } break; } case WM_ENABLE: { UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID); control = GetVolumeControlData(hwnd); if(control->bDisabled == !wParam) break; control->bDisabled = !control->bDisabled; if(control->bDisabled) { if(control->curVolume > 0.05f) { control->lastUnmutedVol = control->curVolume; control->curVolume = 0.0f; SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd); } } else { if(control->curVolume < 0.05f) { control->curVolume = control->lastUnmutedVol; SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd); } } HDC hDC = GetDC(hwnd); control->DrawVolumeControl(hDC); ReleaseDC(hwnd, hDC); break; } case WM_SIZE: { control = GetVolumeControlData(hwnd); control->cx = LOWORD(lParam); control->cy = HIWORD(lParam); control->bDrawIcon = (control->cy == 32) && control->hiconPlay; HDC hDC = GetDC(hwnd); control->DrawVolumeControl(hDC); ReleaseDC(hwnd, hDC); break; } default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam) { PINFO pInfo; /* Get the window context */ pInfo = (PINFO)GetWindowLongPtrW(hDlg, GWLP_USERDATA); if (pInfo == NULL && Message != WM_INITDIALOG) { goto HandleDefaultMessage; } switch(Message) { case WM_INITDIALOG: OnMainCreate(hDlg, (PRDPSETTINGS)lParam); break; case WM_COMMAND: { if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { if (LOWORD(wParam) == IDOK ) { SaveAllSettings(pInfo); SaveRdpSettingsToFile(NULL, pInfo->pRdpSettings); } Cleanup(pInfo); EndDialog(hDlg, LOWORD(wParam)); } break; } case WM_NOTIFY: { INT idctrl; LPNMHDR pnmh; idctrl = (int)wParam; pnmh = (LPNMHDR)lParam; if (//(pnmh->hwndFrom == pInfo->hSelf) && (pnmh->idFrom == IDC_TAB) && (pnmh->code == TCN_SELCHANGE)) { OnTabWndSelChange(pInfo); } break; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; hdc = BeginPaint(hDlg, &ps); if (hdc != NULL) { HDC hdcMem = CreateCompatibleDC(hdc); if (hdcMem) { WCHAR szBuffer[32]; RECT bmpRc, txtRc; LOGFONTW lf; HFONT hFont, hFontOld; HBITMAP hBmpOld; GetClientRect(pInfo->hSelf, &bmpRc); hBmpOld = SelectObject(hdcMem, pInfo->hHeader); StretchBlt(hdc, 0, 0, bmpRc.right, pInfo->headerbitmap.bmHeight, hdcMem, 0, 0, pInfo->headerbitmap.bmWidth, pInfo->headerbitmap.bmHeight, SRCCOPY); SelectObject(hdcMem, hBmpOld); txtRc.left = bmpRc.right / 4; txtRc.top = 10; txtRc.right = bmpRc.right * 3 / 4; txtRc.bottom = pInfo->headerbitmap.bmHeight / 2; ZeroMemory(&lf, sizeof(LOGFONTW)); if (LoadStringW(hInst, IDS_HEADERTEXT1, szBuffer, sizeof(szBuffer) / sizeof(WCHAR))) { lf.lfHeight = 24; lf.lfCharSet = OEM_CHARSET; lf.lfQuality = DEFAULT_QUALITY; lf.lfWeight = FW_MEDIUM; wcscpy(lf.lfFaceName, L"Tahoma"); hFont = CreateFontIndirectW(&lf); if (hFont) { hFontOld = SelectObject(hdc, hFont); DPtoLP(hdc, (PPOINT)&txtRc, 2); SetTextColor(hdc, RGB(255,255,255)); SetBkMode(hdc, TRANSPARENT); DrawTextW(hdc, szBuffer, -1, &txtRc, DT_BOTTOM | DT_SINGLELINE | DT_NOCLIP); SelectObject(hdc, hFontOld); DeleteObject(hFont); } } txtRc.left = bmpRc.right / 4; txtRc.top = txtRc.bottom - 5; txtRc.right = bmpRc.right * 3 / 4; txtRc.bottom = pInfo->headerbitmap.bmHeight * 9 / 10; if (LoadStringW(hInst, IDS_HEADERTEXT2, szBuffer, sizeof(szBuffer) / sizeof(WCHAR))) { lf.lfHeight = 30; lf.lfCharSet = OEM_CHARSET; lf.lfQuality = DEFAULT_QUALITY; lf.lfWeight = FW_EXTRABOLD; wcscpy(lf.lfFaceName, L"Tahoma"); hFont = CreateFontIndirectW(&lf); if (hFont) { hFontOld = SelectObject(hdc, hFont); DPtoLP(hdc, (PPOINT)&txtRc, 2); SetTextColor(hdc, RGB(255,255,255)); SetBkMode(hdc, TRANSPARENT); DrawTextW(hdc, szBuffer, -1, &txtRc, DT_TOP | DT_SINGLELINE); SelectObject(hdc, hFontOld); DeleteObject(hFont); } } DeleteDC(hdcMem); } EndPaint(hDlg, &ps); } break; } case WM_CLOSE: { Cleanup(pInfo); EndDialog(hDlg, 0); } break; HandleDefaultMessage: default: return FALSE; } return FALSE; }
// // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static HWND hwndNextViewer; HGLOBAL hGlobal; PTSTR pGlobal; RECT rect; switch (message) { case WM_CREATE: hwndNextViewer = SetClipboardViewer(hWnd); break; case WM_CHANGECBCHAIN: if((HWND)wParam == hwndNextViewer) hwndNextViewer = (HWND)lParam; else if(hwndNextViewer) SendMessage(hwndNextViewer, message, wParam, lParam); //return 0; break; case WM_DRAWCLIPBOARD: if(hwndNextViewer) SendMessage(hwndNextViewer, message, wParam, lParam); InvalidateRect(hWnd, NULL, TRUE); //return 0; break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 分析菜单选择: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... // OpenClipboard, GetClipboardData, CloseClipboard GetClientRect(hWnd, &rect); OpenClipboard(hWnd); #ifdef UNICODE hGlobal = GetClipboardData(CF_UNICODETEXT); #else hGlobal = GetClipboardData(CF_TEXT); #endif if(hGlobal != NULL) { pGlobal = (PTSTR)GlobalLock(hGlobal); DrawText(hdc, pGlobal, -1, &rect, DT_EXPANDTABS); GlobalUnlock(hGlobal); } CloseClipboard(); EndPaint(hWnd, &ps); break; case WM_DESTROY: ChangeClipboardChain(hWnd, hwndNextViewer); PostQuitMessage(0); //return 0; break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK ContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ClcContact *contact; ClcGroup *group; BOOL frameHasTitlebar = FALSE; if (wndFrameCLC) frameHasTitlebar = wndFrameCLC->TitleBar.ShowTitleBar; ClcData *dat = (struct ClcData *)GetWindowLongPtr(hwnd, 0); if (msg >= CLM_FIRST && msg < CLM_LAST) return ProcessExternalMessages(hwnd, dat, msg, wParam, lParam); switch (msg) { case WM_CREATE: dat = (struct ClcData *)mir_calloc(sizeof(struct ClcData)); SetWindowLongPtr(hwnd, 0, (LONG_PTR)dat); RowHeight::Init(dat); dat->forceScroll = 0; dat->lastRepaint = 0; dat->hwndParent = GetParent(hwnd); dat->lastSort = GetTickCount(); dat->needsResort = FALSE; { CREATESTRUCT *cs = (CREATESTRUCT *)lParam; if (cs->lpCreateParams == (LPVOID)0xff00ff00) { dat->bisEmbedded = FALSE; dat->bHideSubcontacts = TRUE; cfg::clcdat = dat; if (cfg::dat.bShowLocalTime) SetTimer(hwnd, TIMERID_REFRESH, 65000, NULL); } else dat->bisEmbedded = TRUE; } break; case WM_SIZE: pcli->pfnEndRename(hwnd, dat, 1); KillTimer(hwnd, TIMERID_INFOTIP); KillTimer(hwnd, TIMERID_RENAME); pcli->pfnRecalcScrollBar(hwnd, dat); LBL_Def: return DefWindowProc(hwnd, msg, wParam, lParam); case WM_NCCALCSIZE: return FrameNCCalcSize(hwnd, DefWindowProc, wParam, lParam, frameHasTitlebar); /* * scroll bar handling */ case WM_NCPAINT: return FrameNCPaint(hwnd, DefWindowProc, wParam, lParam, frameHasTitlebar); case INTM_GROUPCHANGED: { WORD iExtraImage[EXTRA_ICON_COUNT]; BYTE flags = 0; if (!FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) memset(iExtraImage, 0xFF, sizeof(iExtraImage)); else { memcpy(iExtraImage, contact->iExtraImage, sizeof(iExtraImage)); flags = contact->flags; } pcli->pfnDeleteItemFromTree(hwnd, wParam); if (GetWindowLongPtr(hwnd, GWL_STYLE) & CLS_SHOWHIDDEN || !CLVM_GetContactHiddenStatus(wParam, NULL, dat)) { pcli->pfnAddContactToTree(hwnd, dat, wParam, 1, 1); if (FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) { memcpy(contact->iExtraImage, iExtraImage, sizeof(iExtraImage)); if (flags & CONTACTF_CHECKED) contact->flags |= CONTACTF_CHECKED; } NMCLISTCONTROL nm; nm.hdr.code = CLN_CONTACTMOVED; nm.hdr.hwndFrom = hwnd; nm.hdr.idFrom = GetDlgCtrlID(hwnd); nm.flags = 0; nm.hItem = (HANDLE)wParam; SendMessage(GetParent(hwnd), WM_NOTIFY, 0, (LPARAM)&nm); } dat->needsResort = TRUE; PostMessage(hwnd, INTM_SORTCLC, 0, 1); } goto LBL_Def; case INTM_ICONCHANGED: { int recalcScrollBar = 0; MCONTACT hContact = wParam; WORD status = ID_STATUS_OFFLINE; int contactRemoved = 0; MCONTACT hSelItem = NULL; ClcContact *selcontact = NULL; char *szProto = GetContactProto(hContact); if (szProto == NULL) status = ID_STATUS_OFFLINE; else status = cfg::getWord(hContact, szProto, "Status", ID_STATUS_OFFLINE); int shouldShow = (GetWindowLongPtr(hwnd, GWL_STYLE) & CLS_SHOWHIDDEN || !CLVM_GetContactHiddenStatus(hContact, szProto, dat)) && ((cfg::dat.bFilterEffective ? TRUE : !pcli->pfnIsHiddenMode(dat, status)) || pcli->pfnGetContactIcon(hContact) != lParam); // XXX CLVM changed - this means an offline msg is flashing, so the contact should be shown if (!FindItem(hwnd, dat, (HANDLE)hContact, &contact, &group, NULL)) { if (shouldShow && CallService(MS_DB_CONTACT_IS, wParam, 0)) { if (dat->selection >= 0 && pcli->pfnGetRowByIndex(dat, dat->selection, &selcontact, NULL) != -1) hSelItem = (MCONTACT)pcli->pfnContactToHItem(selcontact); pcli->pfnAddContactToTree(hwnd, dat, hContact, 0, 0); recalcScrollBar = 1; FindItem(hwnd, dat, (HANDLE)hContact, &contact, NULL, NULL); if (contact) { contact->iImage = (WORD)lParam; pcli->pfnNotifyNewContact(hwnd, hContact); } } } else { //item in list already DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE); if (contact->iImage == (WORD)lParam) break; if (!shouldShow && !(style & CLS_NOHIDEOFFLINE) && (style & CLS_HIDEOFFLINE || group->hideOffline || cfg::dat.bFilterEffective)) { // CLVM changed if (dat->selection >= 0 && pcli->pfnGetRowByIndex(dat, dat->selection, &selcontact, NULL) != -1) hSelItem = (MCONTACT)pcli->pfnContactToHItem(selcontact); pcli->pfnRemoveItemFromGroup(hwnd, group, contact, 0); contactRemoved = TRUE; recalcScrollBar = 1; } else { contact->iImage = (WORD)lParam; if (!pcli->pfnIsHiddenMode(dat, status)) contact->flags |= CONTACTF_ONLINE; else contact->flags &= ~CONTACTF_ONLINE; } } if (hSelItem) { ClcGroup *selgroup; if (pcli->pfnFindItem(hwnd, dat, hSelItem, &selcontact, &selgroup, NULL)) dat->selection = pcli->pfnGetRowsPriorTo(&dat->list, selgroup, List_IndexOf((SortedList*)& selgroup->cl, selcontact)); else dat->selection = -1; } dat->needsResort = TRUE; PostMessage(hwnd, INTM_SORTCLC, 0, recalcScrollBar); PostMessage(hwnd, INTM_INVALIDATE, 0, (LPARAM)(contactRemoved ? 0 : wParam)); if (recalcScrollBar) pcli->pfnRecalcScrollBar(hwnd, dat); } goto LBL_Def; case INTM_METACHANGED: if (!pcli->pfnFindItem(hwnd, dat, wParam, &contact, NULL, NULL)) break; if (contact->bIsMeta && !(cfg::dat.dwFlags & CLUI_USEMETAICONS)) { contact->hSubContact = db_mc_getMostOnline(contact->hContact); contact->metaProto = GetContactProto(contact->hSubContact); contact->iImage = pcli->pfnGetContactIcon(contact->hSubContact); if (contact->pExtra) { TExtraCache *pSub = cfg::getCache(contact->hSubContact, contact->metaProto); ClcContact *subContact; if (!pcli->pfnFindItem(hwnd, dat, contact->hSubContact, &subContact, NULL, NULL)) break; contact->pExtra->proto_status_item = GetProtocolStatusItem(contact->metaProto); if (pSub) { contact->pExtra->status_item = pSub->status_item; memcpy(contact->iExtraImage, subContact->iExtraImage, sizeof(contact->iExtraImage)); } } } SendMessage(hwnd, INTM_NAMEORDERCHANGED, wParam, lParam); goto LBL_Def; case INTM_METACHANGEDEVENT: if (!FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) break; if (lParam == 0) pcli->pfnInitAutoRebuild(hwnd); goto LBL_Def; case INTM_NAMECHANGED: ClcContact *contact; if (!FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) break; mir_tstrncpy(contact->szText, pcli->pfnGetContactDisplayName(wParam, 0), SIZEOF(contact->szText)); RTL_DetectAndSet(contact, 0); dat->needsResort = TRUE; PostMessage(hwnd, INTM_SORTCLC, 0, 0); goto LBL_Def; case INTM_CODEPAGECHANGED: if (!FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) break; contact->codePage = cfg::getDword(wParam, "Tab_SRMsg", "ANSIcodepage", cfg::getDword(wParam, "UserInfo", "ANSIcodepage", CP_ACP)); PostMessage(hwnd, INTM_INVALIDATE, 0, 0); goto LBL_Def; case INTM_AVATARCHANGED: contact = NULL; { avatarCacheEntry *cEntry = (struct avatarCacheEntry *)lParam; if (wParam == 0) { //RemoveFromImgCache(0, cEntry); cfg::dat.bForceRefetchOnPaint = TRUE; RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW); cfg::dat.bForceRefetchOnPaint = FALSE; goto LBL_Def; } if (!FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) return 0; contact->ace = cEntry; if (cEntry == NULL) contact->cFlags &= ~ECF_AVATAR; else { DWORD dwFlags; if (contact->pExtra) dwFlags = contact->pExtra->dwDFlags; else dwFlags = cfg::getDword(contact->hContact, "CList", "CLN_Flags", 0); if (cfg::dat.dwFlags & CLUI_FRAME_AVATARS) contact->cFlags = (dwFlags & ECF_HIDEAVATAR ? contact->cFlags & ~ECF_AVATAR : contact->cFlags | ECF_AVATAR); else contact->cFlags = (dwFlags & ECF_FORCEAVATAR ? contact->cFlags | ECF_AVATAR : contact->cFlags & ~ECF_AVATAR); } PostMessage(hwnd, INTM_INVALIDATE, 0, (LPARAM)contact->hContact); } goto LBL_Def; case INTM_STATUSMSGCHANGED: { TExtraCache *p; char *szProto = NULL; if (!FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) p = cfg::getCache(wParam, NULL); else { p = contact->pExtra; szProto = contact->proto; } GetCachedStatusMsg(p, szProto); PostMessage(hwnd, INTM_INVALIDATE, 0, (LPARAM)(contact ? contact->hContact : 0)); } goto LBL_Def; case INTM_STATUSCHANGED: if (FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) { WORD wStatus = cfg::getWord(wParam, contact->proto, "Status", ID_STATUS_OFFLINE); if (cfg::dat.bNoOfflineAvatars && wStatus != ID_STATUS_OFFLINE && contact->wStatus == ID_STATUS_OFFLINE) { contact->wStatus = wStatus; if (cfg::dat.bAvatarServiceAvail && contact->ace == NULL) LoadAvatarForContact(contact); } contact->wStatus = wStatus; goto LBL_Def; } break; case INTM_PROTOCHANGED: if (!FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) break; contact->proto = GetContactProto(wParam); CallService(MS_CLIST_INVALIDATEDISPLAYNAME, wParam, 0); mir_tstrncpy(contact->szText, pcli->pfnGetContactDisplayName(wParam, 0), SIZEOF(contact->szText)); RTL_DetectAndSet(contact, 0); dat->needsResort = TRUE; PostMessage(hwnd, INTM_SORTCLC, 0, 0); goto LBL_Def; case INTM_INVALIDATE: if (!dat->bNeedPaint) { KillTimer(hwnd, TIMERID_PAINT); SetTimer(hwnd, TIMERID_PAINT, 100, NULL); dat->bNeedPaint = TRUE; } goto LBL_Def; case INTM_INVALIDATECONTACT: if (!FindItem(hwnd, dat, (HANDLE)wParam, &contact, &group, NULL)) break; if (contact && group) { int iItem = pcli->pfnGetRowsPriorTo(&dat->list, group, List_IndexOf((SortedList*) & group->cl, contact)); pcli->pfnInvalidateItem(hwnd, dat, iItem); goto LBL_Def; } break; case INTM_FORCESORT: dat->needsResort = TRUE; return SendMessage(hwnd, INTM_SORTCLC, wParam, lParam); case INTM_SORTCLC: if (dat->needsResort) { pcli->pfnSortCLC(hwnd, dat, TRUE); dat->needsResort = FALSE; } if (lParam) pcli->pfnRecalcScrollBar(hwnd, dat); goto LBL_Def; case INTM_IDLECHANGED: if (FindItem(hwnd, dat, (HANDLE)wParam, &contact, NULL, NULL)) { DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam; char *szProto = (char*)cws->szModule; if (szProto == NULL) break; contact->flags &= ~CONTACTF_IDLE; if (cfg::getDword(wParam, szProto, "IdleTS", 0)) { contact->flags |= CONTACTF_IDLE; } PostMessage(hwnd, INTM_INVALIDATE, 0, (LPARAM)contact->hContact); goto LBL_Def; } break; case INTM_XSTATUSCHANGED: { DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam; char *szProto = (char *)cws->szModule; MCONTACT hContact = wParam; TExtraCache *p; if (!FindItem(hwnd, dat, (HANDLE)hContact, &contact, NULL, NULL)) { p = cfg::getCache(hContact, szProto); if (!dat->bisEmbedded && szProto) { // may be a subcontact, forward the xstatus MCONTACT hMasterContact = db_mc_tryMeta(hContact); if (hMasterContact != hContact) // avoid recursive call of settings handler cfg::writeByte(hMasterContact, META_PROTO, "XStatusId", (BYTE)cfg::getByte(hContact, szProto, "XStatusId", 0)); break; } } else { contact->xStatus = cfg::getByte(hContact, szProto, "XStatusId", 0); p = contact->pExtra; } if (szProto == NULL) break; if (contact) { if (ProtoServiceExists(szProto, PS_GETADVANCEDSTATUSICON)) { int iconId = ProtoCallService(szProto, PS_GETADVANCEDSTATUSICON, hContact, 0); if (iconId != -1) contact->xStatusIcon = iconId >> 16; } } GetCachedStatusMsg(p, szProto); PostMessage(hwnd, INTM_INVALIDATE, 0, (LPARAM)(contact ? contact->hContact : 0)); } goto LBL_Def; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); if (IsWindowVisible(hwnd) && !during_sizing && !cfg::shutDown) { PaintClc(hwnd, dat, hdc, &ps.rcPaint); dat->bNeedPaint = FALSE; dat->lastRepaint = GetTickCount(); } EndPaint(hwnd, &ps); if (dat->selection != dat->oldSelection && !dat->bisEmbedded && g_ButtonItems != NULL) { SetDBButtonStates(0); dat->oldSelection = dat->selection; } } goto LBL_Def; case WM_MOUSEWHEEL: dat->forceScroll = TRUE; break; case WM_TIMER: if (wParam == TIMERID_PAINT) { KillTimer(hwnd, TIMERID_PAINT); InvalidateRect(hwnd, NULL, FALSE); goto LBL_Def; } if (wParam == TIMERID_REFRESH) { InvalidateRect(hwnd, NULL, FALSE); goto LBL_Def; } break; case WM_LBUTTONDBLCLK: ReleaseCapture(); dat->iHotTrack = -1; pcli->pfnHideInfoTip(hwnd, dat); KillTimer(hwnd, TIMERID_RENAME); KillTimer(hwnd, TIMERID_INFOTIP); dat->szQuickSearch[0] = 0; { DWORD hitFlags; dat->selection = HitTest(hwnd, dat, (short) LOWORD(lParam), (short) HIWORD(lParam), &contact, NULL, &hitFlags); if (hitFlags & CLCHT_ONITEMEXTRA) break; InvalidateRect(hwnd, NULL, FALSE); if (dat->selection != -1) pcli->pfnEnsureVisible(hwnd, dat, dat->selection, 0); if (hitFlags & CLCHT_ONAVATAR && cfg::dat.bDblClkAvatars) { CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)contact->hContact, 0); return TRUE; } if (hitFlags & (CLCHT_ONITEMICON | CLCHT_ONITEMLABEL | CLCHT_ONITEMSPACE)) { UpdateWindow(hwnd); pcli->pfnDoSelectionDefaultAction(hwnd, dat); } } return TRUE; case WM_CONTEXTMENU: { HMENU hMenu = NULL; POINT pt; DWORD hitFlags; pcli->pfnEndRename(hwnd, dat, 1); pcli->pfnHideInfoTip(hwnd, dat); KillTimer(hwnd, TIMERID_RENAME); KillTimer(hwnd, TIMERID_INFOTIP); if (GetFocus() != hwnd) SetFocus(hwnd); dat->iHotTrack = -1; dat->szQuickSearch[0] = 0; pt.x = (short) LOWORD(lParam); pt.y = (short) HIWORD(lParam); if (pt.x == -1 && pt.y == -1) { dat->selection = pcli->pfnGetRowByIndex(dat, dat->selection, &contact, NULL); if (dat->selection != -1) pcli->pfnEnsureVisible(hwnd, dat, dat->selection, 0); pt.x = dat->iconXSpace + 15; pt.y = RowHeight::getItemTopY(dat, dat->selection) - dat->yScroll + (int)(dat->row_heights[dat->selection] * .7); hitFlags = dat->selection == -1 ? CLCHT_NOWHERE : CLCHT_ONITEMLABEL; } else { ScreenToClient(hwnd, &pt); dat->selection = HitTest(hwnd, dat, pt.x, pt.y, &contact, NULL, &hitFlags); } InvalidateRect(hwnd, NULL, FALSE); if (dat->selection != -1) pcli->pfnEnsureVisible(hwnd, dat, dat->selection, 0); UpdateWindow(hwnd); if (dat->selection != -1 && hitFlags & (CLCHT_ONITEMICON | CLCHT_ONITEMCHECK | CLCHT_ONITEMLABEL)) { if (contact->type == CLCIT_GROUP) { hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDSUBGROUP, (WPARAM)contact->group, 0); ClientToScreen(hwnd, &pt); TrackPopupMenu(hMenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, pcli->hwndContactList, NULL); CheckMenuItem(hMenu, POPUP_GROUPHIDEOFFLINE, contact->group->hideOffline ? MF_CHECKED : MF_UNCHECKED); DestroyMenu(hMenu); return 0; } else if (contact->type == CLCIT_CONTACT) hMenu = (HMENU) CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM) contact->hContact, 0); } else { //call parent for new group/hide offline menu PostMessage(GetParent(hwnd), WM_CONTEXTMENU, wParam, lParam); return 0; } if (hMenu != NULL) { ClientToScreen(hwnd, &pt); TrackPopupMenu(hMenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL); DestroyMenu(hMenu); } } return 0; case WM_COMMAND: if (LOWORD(wParam) == POPUP_NEWGROUP) SendMessage(GetParent(hwnd), msg, wParam, lParam); break; case WM_NCHITTEST: { LRESULT lr = SendMessage(GetParent(hwnd), WM_NCHITTEST, wParam, lParam); if (lr == HTLEFT || lr == HTRIGHT || lr == HTBOTTOM || lr == HTTOP || lr == HTTOPLEFT || lr == HTTOPRIGHT || lr == HTBOTTOMLEFT || lr == HTBOTTOMRIGHT) return HTTRANSPARENT; } break; case WM_DESTROY: RowHeight::Free(dat); break; } return coreCli.pfnContactListControlWndProc(hwnd, msg, wParam, lParam); }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static RECT rcce = { 0 }; static RECT rcst = { 0 }; static RECT rcsd = { 200, 200, 200, 200 }; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_NCLBUTTONDOWN: { POINT pt = { 0 }; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); RECT rc = { 0 }; ::GetWindowRect(hWnd, &rc); // Cursor to edge rcce.left = rc.left - pt.x; rcce.top = rc.top - pt.y; rcce.right = rc.right - pt.x; rcce.bottom = rc.bottom - pt.y; return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_ENTERSIZEMOVE: { // Snap zone = Work area ::SystemParametersInfo(SPI_GETWORKAREA, 0, &rcst, 0); } break; case WM_EXITSIZEMOVE: break; case WM_MOVING: { LPRECT lprc = (LPRECT)lParam; POINT pt = { 0 }; ::GetCursorPos(&pt); ::SnapUnsnapRect(lprc, &pt, &rcce, &rcst, &rcsd); } break; case WM_SIZING: { PRECT prc = (PRECT)lParam; switch (wParam) { case WMSZ_LEFT: if (prc->left < rcst.left + rcsd.left) prc->left = rcst.left; break; case WMSZ_RIGHT: if (prc->right > rcst.right - rcsd.right) prc->right = rcst.right; break; case WMSZ_TOP: if (prc->top < rcst.top + rcsd.top) prc->top = rcst.top; break; case WMSZ_TOPLEFT: if (prc->left < rcst.left + rcsd.left) prc->left = rcst.left; if (prc->top < rcst.top + rcsd.top) prc->top = rcst.top; break; case WMSZ_TOPRIGHT: if (prc->right > rcst.right - rcsd.right) prc->right = rcst.right; if (prc->top < rcst.top + rcsd.top) prc->top = rcst.top; break; case WMSZ_BOTTOM: if (prc->bottom > rcst.bottom - rcsd.bottom) prc->bottom = rcst.bottom; break; case WMSZ_BOTTOMLEFT: if (prc->left < rcst.left + rcsd.left) prc->left = rcst.left; if (prc->bottom > rcst.bottom - rcsd.bottom) prc->bottom = rcst.bottom; break; case WMSZ_BOTTOMRIGHT: if (prc->right > rcst.right - rcsd.right) prc->right = rcst.right; if (prc->bottom > rcst.bottom - rcsd.bottom) prc->bottom = rcst.bottom; break; } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; HPEN oldPen, hPen; HBRUSH oldBrush, pieceBrush[2], boardBrush[3]; RECT rect; static HWND msgbox; static bool show = true; static int step = 0; static PieceAct rc = { -1, -1, -1, -1, -1, -1, -1, -1}; static enum State state = Start; static short role = BLACK; static short board[8][8] = {}; short x_mouse = 0, y_mouse = 0; static CString s; const int ID_TIMER = 1; static time_t start, finish, elapsed; struct tm * ptm; switch (message) { case WM_CREATE: msgbox = CreateWindowEx(NULL, L"ListBox", L"Message",WS_VISIBLE, 750, 50, 250, 250, hWnd, NULL, hInst, NULL); ShowWindow(msgbox, SW_SHOW); UpdateWindow(msgbox); memcpy(board,initboard,sizeof(board)); start = time(0); state = NextState(0,0,state,board,&role,&rc); hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; s.Format(L"Welcome to checker!"); TextOut(hdc, 20,125,s, s.GetLength()); switch (state){ case MovePick: s.Format(L"Action: Pick a piece to move."); break; case MoveDrop: s.Format(L"Action: Drop a piece to move."); break; case JumpPick: s.Format(L"Action: Pick a piece to jump."); break; case JumpDrop: s.Format(L"Action: Drop a piece to jump."); break; case MultiJump: s.Format(L"Action: You can jump again."); break; default: s.Format(L"Game Stop!"); break; } TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); if (state == Animate) { step = STEP; SetTimer(hWnd, ID_TIMER, 10 , NULL); //update every 10 milliseconds } break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case ID_RESET: step = 0; rc.x_pick = -1; rc.y_pick = -1; rc.x_drop = -1; rc.y_drop = -1; rc.x_jump2 = -1; rc.y_jump2 = -1; rc.x_jump3 = -1; rc.y_jump3 = -1; state = Start; role = BLACK; //curent role memcpy(board,initboard,sizeof(board)); start = time(0); state = NextState(0,0,state,board,&role,&rc); ShowWindow(msgbox, SW_HIDE); ShowWindow(msgbox, SW_SHOW); UpdateWindow(msgbox); hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; s.Format(L"Game Reset!"); TextOut(hdc, 20,125,s, s.GetLength()); switch (state){ case MovePick: s.Format(L"Action: Pick a piece to move."); break; case MoveDrop: s.Format(L"Action: Drop a piece to move."); break; case JumpPick: s.Format(L"Action: Pick a piece to jump."); break; case JumpDrop: s.Format(L"Action: Drop a piece to jump."); break; case MultiJump: s.Format(L"Action: You can jump again."); break; default: s.Format(L"Game Stop!"); break; } TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); if (state == Animate) { step = STEP; SetTimer(hWnd, ID_TIMER, 10 , NULL); //update every 10 milliseconds } InvalidateRect (hWnd, NULL, TRUE) ; break; case ID_SHOW: show = !show; if (show) ShowWindow(msgbox, SW_SHOW); else ShowWindow(msgbox, SW_HIDE); UpdateWindow(msgbox); SetFocus(hWnd); break; case ID_DIFFICULTY_LEVEL1: maxDepth = 1; break; case ID_DIFFICULTY_LEVEL2: maxDepth = 4; break; case ID_DIFFICULTY_LEVEL3: maxDepth = 8; break; case ID_DIFFICULTY_LEVEL4: maxDepth = 15; break; case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_LBUTTONDOWN: if(state == Animate) break; // do not react while moving x_mouse = short(HIWORD (lParam)/LENGTH); y_mouse = short(LOWORD (lParam)/LENGTH); state = NextState(x_mouse,y_mouse,state,board,&role,&rc); if (state == Animate) { step = STEP; SetTimer(hWnd, ID_TIMER, 10 , NULL); //update every 10 milliseconds if (role == BLACK) start = time(0); } else if (state != GameStop) { hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; switch (state){ case MovePick: s.Format(L"Next Action: Pick a piece to move."); break; case MoveDrop: s.Format(L"Next Action: Drop a piece to move."); break; case JumpPick: s.Format(L"Next Action: Pick a piece to jump."); break; case JumpDrop: s.Format(L"Next Action: Drop a piece to jump."); break; case MultiJump: s.Format(L"Next Action: You can jump again."); break; default: s.Format(L"Game Stop!"); break; } TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); } InvalidateRect (hWnd, NULL, TRUE) ; break; case WM_TIMER: if (step--==0) { state = NextState(0,0,state,board,&role,&rc); KillTimer(hWnd, ID_TIMER); if (state == GameStop && show!=false) { // update the message box ShowWindow(msgbox, SW_HIDE); ShowWindow(msgbox, SW_SHOW); UpdateWindow(msgbox); hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; s.Format(L"Game finished!"); TextOut(hdc, 20,110,s, s.GetLength()); int b_score = 0, w_score = 0; for(int i = 0; i<8; i++) for(int j = 0; j<8; j++) { if(board[i][j] == BLACK) if (i == 0) b_score += 2; else b_score ++; if(board[i][j] == WHITE) if (i == 7) w_score += 2; else w_score ++; } s.Format(L"Black Score : %d",b_score); TextOut(hdc, 20,140,s, s.GetLength()); s.Format(L"White Score : %d",w_score); TextOut(hdc, 20,170,s, s.GetLength()); if (b_score>w_score) s.Format(L"You Win!"); if (b_score==w_score) s.Format(L"Draw!"); if (b_score<w_score) s.Format(L"You Lost!"); TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); } else if (role == BLACK && state != Animate) { finish = time(0); elapsed = static_cast<time_t>(difftime(finish,start)); ptm = gmtime (&elapsed); // update the message box if (show) { ShowWindow(msgbox, SW_HIDE); ShowWindow(msgbox, SW_SHOW); UpdateWindow(msgbox); hdc = GetWindowDC(msgbox); GetClientRect (msgbox, &rect) ; s.Format(L"Maximum tree depth: %d.",treeDepth); TextOut(hdc, 20,50,s, s.GetLength()); s.Format(L"Node generated: %d.",genNode); TextOut(hdc, 20,80,s, s.GetLength()); s.Format(L"MAX-VALUE pruned: %d.",pruneMax); TextOut(hdc, 20,110,s, s.GetLength()); s.Format(L"MIN-VALUE pruned: %d.",pruneMin); TextOut(hdc, 20,140,s, s.GetLength()); s.Format(L"Running Time: %2d:%2d.", ptm->tm_min, ptm->tm_sec); TextOut(hdc, 20, 170,s, s.GetLength()); switch (state){ case MovePick: s.Format(L"Next Action: Pick a piece to move."); break; case MoveDrop: s.Format(L"Next Action: Drop a piece to move."); break; case JumpPick: s.Format(L"Next Action: Pick a piece to jump."); break; case JumpDrop: s.Format(L"Next Action: Drop a piece to jump."); break; case MultiJump: s.Format(L"Next Action: You can jump again."); break; default: s.Format(L"BLACK move first!"); break; } TextOut(hdc, 20,200,s, s.GetLength()); SetFocus(hWnd); } } else if (state == Animate) { step = STEP; SetTimer(hWnd, ID_TIMER, 10 , NULL); //update every 10 milliseconds } } InvalidateRect (hWnd, NULL, TRUE) ; break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... //create the pen & brush inside "case" and delete before leave! hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); // black pieceBrush[0] = CreateSolidBrush(RGB(255, 255, 255)); // white pieceBrush[1] = CreateSolidBrush(RGB(0, 0, 0)); // black boardBrush[0] = CreateSolidBrush(RGB(255, 255, 255)); // white boardBrush[1] = CreateSolidBrush(RGB(200, 200, 200)); // gray boardBrush[2] = CreateSolidBrush(RGB(0, 200, 0)); // green // Select our green pen into the device context and remember previous pen oldPen = (HPEN)SelectObject(hdc, hPen); oldBrush = (HBRUSH)SelectObject(hdc, pieceBrush[0]); // draw back ground board for (int i = 0 ; i < 8 ; i++) for (int j = 0 ; j < 8 ; j++) { rect.top = i * LENGTH; rect.bottom = (i + 1) * LENGTH; rect.left = j * LENGTH; rect.right = (j + 1) * LENGTH; FillRect(hdc, &rect, boardBrush[(i+j)%2]); } // draw pick board if (state == MoveDrop || state == JumpDrop || state == MultiJump || state == Animate){ rect.top = rc.x_pick * LENGTH; rect.bottom = (rc.x_pick + 1) * LENGTH; rect.left = rc.y_pick * LENGTH; rect.right = (rc.y_pick + 1) * LENGTH; FillRect(hdc, &rect, boardBrush[2]); } // draw piece for (int i = 0 ; i < 8 ; i++) for (int j = 0 ; j < 8 ; j++) { if(board[i][j] != 0) // i & j is transpost in board { SelectObject(hdc, pieceBrush[(board[i][j]+1)%2]); // WHITE % 2 = 1, BLACK % 2 = 0; Ellipse (hdc, j * LENGTH + 10, i * LENGTH + 10, (j+1) * LENGTH - 10, (i+1) * LENGTH - 10) ; SelectObject(hdc, pieceBrush[board[i][j]%2]); Ellipse (hdc, j * LENGTH + 30, i * LENGTH + 30, (j+1) * LENGTH - 30, (i+1) * LENGTH - 30) ; } } // draw moving piece if (state == Animate){ int xCurrent = (STEP - step) * (rc.x_drop * LENGTH - rc.x_pick * LENGTH)/STEP + rc.x_pick * LENGTH; int yCurrent = (STEP - step) * (rc.y_drop * LENGTH - rc.y_pick * LENGTH)/STEP + rc.y_pick * LENGTH; SelectObject(hdc, pieceBrush[(role+1)%2]); Ellipse (hdc, yCurrent + 10, xCurrent + 10, yCurrent + LENGTH - 10, xCurrent + LENGTH - 10) ; SelectObject(hdc, pieceBrush[role%2]); Ellipse (hdc, yCurrent + 30, xCurrent + 30, yCurrent + LENGTH - 30, xCurrent + LENGTH - 30) ; } // Do not forget to clean up. // Select the old pen back into the device context SelectObject(hdc, oldPen); DeleteObject(hPen); SelectObject(hdc, oldBrush); DeleteObject(pieceBrush[0]); DeleteObject(pieceBrush[1]); DeleteObject(boardBrush[0]); DeleteObject(boardBrush[1]); DeleteObject(boardBrush[2]); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxChar, cxCaps, cyChar, cxClient, cyClient, iMaxWidth ; HDC hdc ; int i, x, y, iVertPos, iHorzPos, iPaintBeg, iPaintEnd ; PAINTSTRUCT ps ; SCROLLINFO si ; TCHAR szBuffer[10] ; TEXTMETRIC tm ; switch (message) { case WM_CREATE: hdc = GetDC (hwnd) ; GetTextMetrics (hdc, &tm) ; cxChar = tm.tmAveCharWidth ; cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ; cyChar = tm.tmHeight + tm.tmExternalLeading ; ReleaseDC (hwnd, hdc) ; // Save the width of the three columns iMaxWidth = 40 * cxChar + 22 * cxCaps ; return 0 ; case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; // Set vertical scroll bar range and page size si.cbSize = sizeof (si) ; si.fMask = SIF_RANGE | SIF_PAGE ; si.nMin = 0 ; si.nMax = NUMLINES - 1 ; si.nPage = cyClient / cyChar ; SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ; // Set horizontal scroll bar range and page size si.cbSize = sizeof (si) ; si.fMask = SIF_RANGE | SIF_PAGE ; si.nMin = 0 ; si.nMax = 2 + iMaxWidth / cxChar ; si.nPage = cxClient / cxChar ; SetScrollInfo (hwnd, SB_HORZ, &si, TRUE) ; return 0 ; case WM_VSCROLL: // Get all the vertical scroll bar information si.cbSize = sizeof (si) ; si.fMask = SIF_ALL ; GetScrollInfo (hwnd, SB_VERT, &si) ; // Save the position for comparison later on iVertPos = si.nPos ; switch (LOWORD (wParam)) { case SB_TOP: si.nPos = si.nMin ; break ; case SB_BOTTOM: si.nPos = si.nMax ; break ; case SB_LINEUP: si.nPos -= 1 ; break ; case SB_LINEDOWN: si.nPos += 1 ; break ; case SB_PAGEUP: si.nPos -= si.nPage ; break ; case SB_PAGEDOWN: si.nPos += si.nPage ; break ; case SB_THUMBTRACK: si.nPos = si.nTrackPos ; break ; default: break ; } // Set the position and then retrieve it. Due to adjustments // by Windows it might not be the same as the value set. si.fMask = SIF_POS ; SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ; GetScrollInfo (hwnd, SB_VERT, &si) ; // If the position has changed, scroll the window and update it if (si.nPos != iVertPos) { ScrollWindow (hwnd, 0, cyChar * (iVertPos - si.nPos), NULL, NULL) ; UpdateWindow (hwnd) ; } return 0 ; case WM_HSCROLL: // Get all the vertical scroll bar information si.cbSize = sizeof (si) ; si.fMask = SIF_ALL ; // Save the position for comparison later on GetScrollInfo (hwnd, SB_HORZ, &si) ; iHorzPos = si.nPos ; switch (LOWORD (wParam)) { case SB_LINELEFT: si.nPos -= 1 ; break ; case SB_LINERIGHT: si.nPos += 1 ; break ; case SB_PAGELEFT: si.nPos -= si.nPage ; break ; case SB_PAGERIGHT: si.nPos += si.nPage ; break ; case SB_THUMBPOSITION: si.nPos = si.nTrackPos ; break ; default: break ; } // Set the position and then retrieve it. Due to adjustments // by Windows it might not be the same as the value set. si.fMask = SIF_POS ; SetScrollInfo (hwnd, SB_HORZ, &si, TRUE) ; GetScrollInfo (hwnd, SB_HORZ, &si) ; // If the position has changed, scroll the window if (si.nPos != iHorzPos) { ScrollWindow (hwnd, cxChar * (iHorzPos - si.nPos), 0, NULL, NULL) ; } return 0 ; case WM_KEYDOWN: switch (wParam) { case VK_HOME: SendMessage (hwnd, WM_VSCROLL, SB_TOP, 0) ; break ; case VK_END: SendMessage (hwnd, WM_VSCROLL, SB_BOTTOM, 0) ; break ; case VK_PRIOR: SendMessage (hwnd, WM_VSCROLL, SB_PAGEUP, 0) ; break ; case VK_NEXT: SendMessage (hwnd, WM_VSCROLL, SB_PAGEDOWN, 0) ; break ; case VK_UP: SendMessage (hwnd, WM_VSCROLL, SB_LINEUP, 0) ; break ; case VK_DOWN: SendMessage (hwnd, WM_VSCROLL, SB_LINEDOWN, 0) ; break ; case VK_LEFT: SendMessage (hwnd, WM_HSCROLL, SB_PAGEUP, 0) ; break ; case VK_RIGHT: SendMessage (hwnd, WM_HSCROLL, SB_PAGEDOWN, 0) ; break ; } return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; // Get vertical scroll bar position si.cbSize = sizeof (si) ; si.fMask = SIF_POS ; GetScrollInfo (hwnd, SB_VERT, &si) ; iVertPos = si.nPos ; // Get horizontal scroll bar position GetScrollInfo (hwnd, SB_HORZ, &si) ; iHorzPos = si.nPos ; // Find painting limits iPaintBeg = max (0, iVertPos + ps.rcPaint.top / cyChar) ; iPaintEnd = min (NUMLINES - 1, iVertPos + ps.rcPaint.bottom / cyChar) ; for (i = iPaintBeg ; i <= iPaintEnd ; i++) { x = cxChar * (1 - iHorzPos) ; y = cyChar * (i - iVertPos) ; TextOut (hdc, x, y, sysmetrics[i].szLabel, lstrlen (sysmetrics[i].szLabel)) ; TextOut (hdc, x + 22 * cxCaps, y, sysmetrics[i].szDesc, lstrlen (sysmetrics[i].szDesc)) ; SetTextAlign (hdc, TA_RIGHT | TA_TOP) ; TextOut (hdc, x + 22 * cxCaps + 40 * cxChar, y, szBuffer, wsprintf (szBuffer, TEXT ("%5d"), GetSystemMetrics (sysmetrics[i].iIndex))) ; SetTextAlign (hdc, TA_LEFT | TA_TOP) ; } EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
LRESULT CALLBACK Listview_WindowProc( HWND hwnd, // handle of window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { LPLISTVIEW_PARAM lv = LPLISTVIEW_PARAM(GetWindowLong(hwnd, 16)); WNDPROC pwndProc = (WNDPROC) GetWindowLong(hwnd, 12); switch(uMsg) { case WM_NCCREATE: { lv = InitializeListViewInstance(hwnd); TCHAR pszClassName[MAX_PATH] = { 0 }; GetClassName(hwnd, pszClassName, MAX_PATH); if ( lstrcmpi(pszClassName, TEXT("DBFListView32")) ) { int preflen = sizeof(DBF_CONTROL) / sizeof(TCHAR) - 1, chr = 0; while(chr <= preflen && pszClassName[chr] == DBF_CONTROL[chr] ) chr++; if ( chr == preflen ) { WNDCLASS wc = { 0 }; if ( GetClassInfo( (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), &pszClassName[chr], &wc ) ) { SetWindowLong(hwnd, 12, (LONG) wc.lpfnWndProc); lv->pfnWndProc = wc.lpfnWndProc; lv->fIsListView = FALSE; pwndProc = wc.lpfnWndProc; } else return FALSE; } else return FALSE; } SetRect(&lv->rc, LPCREATESTRUCT(lParam)->x, LPCREATESTRUCT(lParam)->y, LPCREATESTRUCT(lParam)->cx, LPCREATESTRUCT(lParam)->cy ); lv->hHeader = NULL; break; } case WM_ERASEBKGND: { if ( lv->fIsListView ) { if ( !lv->hHeader ) lv->hHeader = (HWND) lv->pfnWndProc(hwnd, LVM_GETHEADER, 0, 0); GetClientRect(lv->hHeader, &lv->header_rc); return CallWindowProc(lv->pfnWndProc, hwnd, uMsg, WPARAM(lv->hDC), lParam); } else return pwndProc(hwnd, uMsg, WPARAM(lv->hDC), lParam); break; } case WM_SIZING: case WM_SIZE: { GetClientRect(hwnd, &lv->rc); if ( lv->fIsListView ) { if ( !lv->hHeader ) lv->hHeader = (HWND) lv->pfnWndProc(hwnd, LVM_GETHEADER, 0, 0); GetClientRect(lv->hHeader, &lv->header_rc); } break; } case WM_PRINT: { WNDPROC pwnd = ( lv->fIsListView ? lv->pfnWndProc : pwndProc ); // pwnd(hwnd, WM_ERASEBKGND, (WPARAM) lv->hDC, 0); // pwnd(hwnd, WM_PAINT, (WPARAM) lv->hDC, 0); pwnd(hwnd, WM_PRINT, (WPARAM) lv->hDC, lParam); if ( !PBYTE(lv->pvBits)[0] ) FillRect((HDC) wParam, &lv->rc, GetSysColorBrush(COLOR_WINDOW)); else BitBlt((HDC) wParam, 0, 0, lv->rc.right, lv->rc.bottom, lv->hDC, 0, 0, SRCCOPY); return 0; } case WM_PAINT: { PAINTSTRUCT ps = { 0 }; HDC hdc = BeginPaint(hwnd, &ps); if ( lv->fIsListView ) CallWindowProc(lv->pfnWndProc, hwnd, uMsg, WPARAM(lv->hDC), lParam); else pwndProc(hwnd, uMsg, WPARAM(lv->hDC), lParam); if ( lv->fIsListView ) BitBlt(hdc, 0, lv->header_rc.bottom, lv->rc.right, lv->rc.bottom - lv->header_rc.bottom, lv->hDC, 0, lv->header_rc.bottom, SRCCOPY); else BitBlt(hdc, 0, 0, lv->rc.right, lv->rc.bottom, lv->hDC, 0, 0, SRCCOPY); EndPaint(hwnd, &ps); return 0; } case WM_NCDESTROY: { LRESULT ret = ( lv->fIsListView ? lv->pfnWndProc(hwnd, uMsg, wParam, lParam) : pwndProc(hwnd, uMsg, wParam, lParam) ); UninitializeListViewInstance(hwnd); return ret; } } if ( lv->fIsListView && lv->pfnWndProc ) return lv->pfnWndProc(hwnd, uMsg, wParam, lParam); else if ( !lv->fIsListView && pwndProc ) return pwndProc(hwnd, uMsg, wParam, lParam); return DefWindowProc(hwnd, uMsg, wParam, lParam); }
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { NPP instance = (NPP)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (uiMsg == WM_PAINT) { InstanceData *data = (InstanceData *)instance->pdata; PAINTSTRUCT ps; HDC hDC = BeginPaint(hWnd, &ps); HBRUSH brushBg = CreateSolidBrush(COL_WINDOW_BG); HFONT hFont = GetSimpleFont(hDC, L"MS Shell Dlg", 14); bool isRtL = IsLanguageRtL(gTranslationIdx); // set up double buffering RectI rcClient = ClientRect(hWnd); DoubleBuffer buffer(hWnd, rcClient); HDC hDCBuffer = buffer.GetDC(); // display message centered in the window FillRect(hDCBuffer, &rcClient.ToRECT(), brushBg); hFont = (HFONT)SelectObject(hDCBuffer, hFont); SetTextColor(hDCBuffer, RGB(0, 0, 0)); SetBkMode(hDCBuffer, TRANSPARENT); DrawCenteredText(hDCBuffer, rcClient, data->message, isRtL); // draw a progress bar, if a download is in progress if (0 < data->progress && data->progress <= 1) { SIZE msgSize; RectI rcProgress = rcClient; HBRUSH brushProgress = CreateSolidBrush(RGB(0x80, 0x80, 0xff)); GetTextExtentPoint32(hDCBuffer, data->message, (int)str::Len(data->message), &msgSize); rcProgress.Inflate(-(rcProgress.dx - msgSize.cx) / 2, -(rcProgress.dy - msgSize.cy) / 2 + 2); rcProgress.Offset(0, msgSize.cy + 4 + 2); FillRect(hDCBuffer, &rcProgress.ToRECT(), GetStockBrush(WHITE_BRUSH)); RectI rcProgressAll = rcProgress; rcProgress.dx = (int)(data->progress * rcProgress.dx); FillRect(hDCBuffer, &rcProgress.ToRECT(), brushProgress); DeleteObject(brushProgress); ScopedMem<WCHAR> currSize(FormatSizeSuccint(data->currSize)); if (0 == data->totalSize || data->currSize > data->totalSize) { // total size unknown or bogus => show just the current size DrawCenteredText(hDCBuffer, rcProgressAll, currSize, isRtL); } else { ScopedMem<WCHAR> totalSize(FormatSizeSuccint(data->totalSize)); ScopedMem<WCHAR> s(str::Format(_TR("%s of %s"), currSize, totalSize)); DrawCenteredText(hDCBuffer, rcProgressAll, s, isRtL); } } // draw the buffer on screen buffer.Flush(hDC); DeleteObject(SelectObject(hDCBuffer, hFont)); DeleteObject(brushBg); EndPaint(hWnd, &ps); HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL); if (hChild) InvalidateRect(hChild, NULL, FALSE); } else if (uiMsg == WM_SIZE) { HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL); if (hChild) { ClientRect rcClient(hWnd); MoveWindow(hChild, rcClient.x, rcClient.y, rcClient.dx, rcClient.dy, FALSE); } } else if (uiMsg == WM_COPYDATA) { COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lParam; if (cds && 0x4C5255 /* URL */ == cds->dwData) { plogf("sp: NPN_GetURL %s", cds->dwData, (const char *)cds->lpData); gNPNFuncs.geturl(instance, (const char *)cds->lpData, "_blank"); return TRUE; } } return DefWindowProc(hWnd, uiMsg, wParam, lParam); }