static BOOL CALLBACK SkinEdit_ExtBkDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { SKINDESCRIPTION *psd = (SKINDESCRIPTION *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if(psd) { ID_EXTBK_FIRST = psd->firstItem; ID_EXTBK_LAST = psd->lastItem; StatusItems = psd->StatusItems; } switch (msg) { case WM_INITDIALOG: psd = (SKINDESCRIPTION *)malloc(sizeof(SKINDESCRIPTION)); ZeroMemory(psd, sizeof(SKINDESCRIPTION)); CopyMemory(psd, (void *)lParam, sizeof(SKINDESCRIPTION)); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)psd); if(psd) { ID_EXTBK_FIRST = psd->firstItem; ID_EXTBK_LAST = psd->lastItem; StatusItems = psd->StatusItems; } TranslateDialogDefault(hwndDlg); FillItemList(hwndDlg); SendMessage(hwndDlg, WM_USER + 101, 0, 0); psd->hMenuItems = CreatePopupMenu(); AppendMenu(psd->hMenuItems, MF_STRING | MF_DISABLED, (UINT_PTR)0, _T("Copy from")); AppendMenuA(psd->hMenuItems, MF_SEPARATOR, (UINT_PTR)0, NULL); { int i; for(i = ID_EXTBK_FIRST; i <= ID_EXTBK_LAST; i++) { int iOff = StatusItems[i - ID_EXTBK_FIRST].szName[0] == '{' ? 3 : 0; if(iOff) AppendMenuA(psd->hMenuItems, MF_SEPARATOR, (UINT_PTR)0, NULL); AppendMenuA(psd->hMenuItems, MF_STRING, (UINT_PTR)i, &StatusItems[i - ID_EXTBK_FIRST].szName[iOff]); } } return TRUE; case WM_USER + 101: { SendDlgItemMessage(hwndDlg, IDC_MRGN_LEFT_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_MRGN_TOP_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_MRGN_RIGHT_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_MRGN_BOTTOM_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_ALPHASPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); SendDlgItemMessage(hwndDlg, IDC_ALPHASPIN2, UDM_SETRANGE, 0, MAKELONG(100, 0)); return 0; } case WM_DRAWITEM: { DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *) lParam; int iItem = dis->itemData; TStatusItem *item = 0; SetBkMode(dis->hDC, TRANSPARENT); FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_WINDOW)); if(iItem >= ID_EXTBK_FIRST && iItem <= ID_EXTBK_LAST) item = &StatusItems[iItem - ID_EXTBK_FIRST]; if (dis->itemState & ODS_SELECTED && iItem != ID_EXTBKSEPARATOR) { FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT)); SetTextColor(dis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { FillRect(dis->hDC, &dis->rcItem, GetSysColorBrush(COLOR_WINDOW)); if(item && item->IGNORED) SetTextColor(dis->hDC, RGB(255, 0, 0)); else if(item && item->dwFlags & S_ITEM_IMAGE_ONLY) SetTextColor(dis->hDC, RGB(0, 0, 255)); else SetTextColor(dis->hDC, GetSysColor(COLOR_WINDOWTEXT)); } if(iItem == ID_EXTBKSEPARATOR) { HPEN hPen, hPenOld; POINT pt; hPen = CreatePen(PS_SOLID, 2, GetSysColor(COLOR_WINDOWTEXT)); hPenOld = (HPEN)SelectObject(dis->hDC, hPen); MoveToEx(dis->hDC, dis->rcItem.left, (dis->rcItem.top + dis->rcItem.bottom) / 2, &pt); LineTo(dis->hDC, dis->rcItem.right, (dis->rcItem.top + dis->rcItem.bottom) / 2); SelectObject(dis->hDC, hPenOld); DeleteObject((HGDIOBJ)hPen); } else if(dis->itemID >= 0 && item) { char *szName = item->szName[0] == '{' ? &item->szName[3] : item->szName; TextOutA(dis->hDC, dis->rcItem.left, dis->rcItem.top, szName, lstrlenA(szName)); } return TRUE; } case WM_CONTEXTMENU: { POINT pt; RECT rc; HWND hwndList = GetDlgItem(hwndDlg, IDC_ITEMS); GetCursorPos(&pt); GetWindowRect(hwndList, &rc); if(PtInRect(&rc, pt)) { int iSelection = (int)TrackPopupMenu(psd->hMenuItems, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL); if(iSelection >= ID_EXTBK_FIRST && iSelection <= ID_EXTBK_LAST) { iSelection -= ID_EXTBK_FIRST; for(int i = ID_EXTBK_FIRST; i <= ID_EXTBK_LAST; i++) { if(SendMessage(hwndList, LB_GETSEL, i - ID_EXTBK_FIRST, 0) > 0) { int iIndex = SendMessage(hwndList, LB_GETITEMDATA, i - ID_EXTBK_FIRST, 0); iIndex -= ID_EXTBK_FIRST; if(iIndex >= 0) { StatusItems[iIndex].ALPHA = StatusItems[iSelection].ALPHA; StatusItems[iIndex].COLOR = StatusItems[iSelection].COLOR; StatusItems[iIndex].COLOR2 = StatusItems[iSelection].COLOR2; StatusItems[iIndex].ALPHA2 = StatusItems[iSelection].ALPHA2; StatusItems[iIndex].CORNER = StatusItems[iSelection].CORNER; StatusItems[iIndex].GRADIENT = StatusItems[iSelection].GRADIENT; StatusItems[iIndex].IGNORED = StatusItems[iSelection].IGNORED; StatusItems[iIndex].imageItem = StatusItems[iSelection].imageItem; StatusItems[iIndex].MARGIN_BOTTOM = StatusItems[iSelection].MARGIN_BOTTOM; StatusItems[iIndex].MARGIN_LEFT = StatusItems[iSelection].MARGIN_LEFT; StatusItems[iIndex].MARGIN_RIGHT = StatusItems[iSelection].MARGIN_RIGHT; StatusItems[iIndex].MARGIN_TOP = StatusItems[iSelection].MARGIN_TOP; StatusItems[iIndex].TEXTCOLOR = StatusItems[iSelection].TEXTCOLOR; StatusItems[iIndex].dwFlags = StatusItems[iSelection].dwFlags; } } } OnListItemsChange(hwndDlg); } } break; } case WM_COMMAND: // this will check if the user changed some actual statusitems values // if yes the flag bChanged will be set to TRUE SetChangedStatusItemFlag(wParam, hwndDlg); switch(LOWORD(wParam)) { case IDC_ITEMS: if (HIWORD(wParam) != LBN_SELCHANGE) return FALSE; { int iItem = SendDlgItemMessage(hwndDlg, IDC_ITEMS, LB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_ITEMS, LB_GETCURSEL, 0, 0), 0); if(iItem == ID_EXTBKSEPARATOR) return FALSE; } OnListItemsChange(hwndDlg); if(psd->pfnClcOptionsChanged) psd->pfnClcOptionsChanged(); break; case IDC_SKIP_UNDERLAY: case IDC_SKIP_IMAGE: case IDC_GRADIENT: case IDC_CORNER: case IDC_IGNORE: ReActiveCombo(hwndDlg); break; } if ((LOWORD(wParam) == IDC_ALPHA || LOWORD(wParam) == IDC_ALPHA2 || LOWORD(wParam) == IDC_MRGN_LEFT || LOWORD(wParam) == IDC_MRGN_BOTTOM || LOWORD(wParam) == IDC_MRGN_TOP || LOWORD(wParam) == IDC_MRGN_RIGHT) && (HIWORD(wParam) != EN_CHANGE || (HWND) lParam != GetFocus())) return 0; SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case WM_NOTIFY: switch (((LPNMHDR) lParam)->idFrom) { case 0: switch (((LPNMHDR) lParam)->code) { case PSN_APPLY: // save user made changes SaveLatestChanges(hwndDlg); // save struct to DB if(psd->pfnSaveCompleteStruct) psd->pfnSaveCompleteStruct(); if(psd->pfnClcOptionsChanged) psd->pfnClcOptionsChanged(); if(psd->hwndCLUI) { SendMessage(psd->hwndCLUI, WM_SIZE, 0, 0); PostMessage(psd->hwndCLUI, WM_USER+100, 0, 0); // CLUIINTM_REDRAW } break; } } break; case WM_DESTROY: DestroyMenu(psd->hMenuItems); break; case WM_NCDESTROY: free(psd); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)0); break; } return FALSE; }
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hwndLifeForms; static HWND hwndSetBtn; static HWND hwndStartBtn; static HWND hwndStopBtn; static HWND hwndSpeed; static HWND hwndColor; static bool gameOn; static bool drawLifeForms; int iLifeFormIndex; int xMouse; int yMouse; char text[10]; PAINTSTRUCT ps; HPEN hPEN; RECT gameArea = {11, 11, 509, 509}; HDC hdc; switch(message) { case WM_CREATE: // Life form group box CreateWindowEx(0, "Button", "Life Form", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 520, 40, 170, 90, hwnd, 0, hInstance, NULL); // LIFEFORMS combobox hwndLifeForms = CreateWindow("ComboBox", "", CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE, 530, 65, 150, 25, hwnd, (HMENU)IDC_LIFEFORMS, hInstance, NULL); // SET button hwndSetBtn = CreateWindow("Button", "Set", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 530, 95, 150, 25, hwnd, (HMENU)IDB_SETBTN, hInstance, NULL); // Animation group box CreateWindowEx(0, "Button", "Animation", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 520, 160, 170, 150, hwnd, 0, hInstance, NULL); // START button hwndStartBtn = CreateWindow("Button", "Start", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 530, 185, 150, 25, hwnd, (HMENU)IDB_STARTBTN, hInstance, NULL); // STOP button hwndStopBtn = CreateWindow("Button", "Stop", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 530, 215, 150, 25, hwnd, (HMENU)IDB_STOPBTN, hInstance, NULL); // Color checkbox hwndColor = CreateWindowEx(0, "Button", "Color", WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX, 530, 245, 150, 20, hwnd, (HMENU)0, hInstance, NULL); // Speed title label CreateWindow("Static", "Speed:", WS_VISIBLE | WS_CHILD, 530, 280, 50, 20, hwnd, 0, hInstance, NULL); // Speed value label hwndSpeed = CreateWindow("Static", "10%", WS_VISIBLE | WS_CHILD | SS_RIGHT, 630, 280, 50, 20, hwnd, 0, hInstance, NULL); // About group box CreateWindowEx(0, "Button", "About", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 520, 340, 170, 170, hwnd, 0, hInstance, NULL); // About text label CreateWindow("Static", TEXT("\"Game Of Life\"\n\nWindows Programming\nLaboratory #4\n\n(c) Roman Roibu"), WS_VISIBLE | WS_CHILD | SS_CENTER, 530, 370, 150, 120, hwnd, 0, hInstance, NULL); // Add lifeforms to combo-box for(int i = 0; i < NUMLIFEFORMS; i++) { SendMessage(hwndLifeForms, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)lifeforms[i].szLabel); } // Set initial timer SetTimer(hwnd, ID_TIMER, (10000 / gameSpeed), NULL); // Set game booleans drawLifeForms = false; gameOn = false; // Disable Start and Stop buttons EnableWindow(hwndStartBtn, FALSE); EnableWindow(hwndStopBtn, FALSE); // Init Game settings game_of_life_initialize(); return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case IDB_SETBTN: // Get selected life form index iLifeFormIndex = SendMessage(hwndLifeForms, CB_GETCURSEL, (WPARAM)0, (LPARAM)0); // If no item is selected, break imediately if(iLifeFormIndex == CB_ERR) break; // Set game map set_game_map(iLifeFormIndex); // Set user's drawing ability if(iLifeFormIndex == 5) drawLifeForms = true; else drawLifeForms = false; // Draw game map draw_game_map(hwnd, gameArea); // Pause the game, to wait for the start button gameOn = false; // Enable the start button, disable the stop button EnableWindow(hwndStartBtn, TRUE); EnableWindow(hwndStopBtn, FALSE); break; case IDB_STARTBTN: gameOn = true; EnableWindow(hwndStartBtn, FALSE); EnableWindow(hwndStopBtn, TRUE); break; case IDB_STOPBTN: gameOn = false; EnableWindow(hwndStopBtn, FALSE); EnableWindow(hwndStartBtn, TRUE); break; default: DefWindowProc(hwnd, WM_COMMAND, wParam, lParam); break; } return 0; case WM_LBUTTONDOWN: case WM_MOUSEMOVE: xMouse = GET_X_LPARAM(lParam); yMouse = GET_Y_LPARAM(lParam); if((xMouse > 10)&&(xMouse < 510)&& // If inside gameArea horizontally (yMouse > 10)&&(yMouse < 510)&& // And inside gameArea vertically ((message == WM_LBUTTONDOWN)|| // And left button is pressed (wParam == MK_LBUTTON))&& // Or left button is dragged (drawLifeForms)){ // And user is allowed to draw life forms int i = (yMouse - 10) / gamePixel; int j = (xMouse - 10) / gamePixel; if(!gameMap[i][j]) { gameMap[i][j] = 1; draw_game_pixel(hwnd, gameArea, i, j); } } return 0; case WM_MOUSEWHEEL: // Break if speed is MAX or MIN if(GET_WHEEL_DELTA_WPARAM(wParam) < 0) { // wheel rotated forward, away from user if(gameSpeed < 100) gameSpeed += 10; else return 0; } else { // wheel rotated backward, toward user if(gameSpeed > 10) gameSpeed -= 10; else return 0; } // Delete old timer, and create new timer KillTimer(hwnd, ID_TIMER); SetTimer(hwnd, ID_TIMER, (10000 / gameSpeed), NULL); // Update speed label sprintf(text, "%i", gameSpeed); strcat(text, "%"); SendMessage(hwndSpeed, WM_SETTEXT, (WPARAM)0, (LPARAM)text); return 0; case WM_TIMER: addColor = (Button_GetCheck(hwndColor) == BST_CHECKED); if((gameOn)&&(wParam == ID_TIMER)) { // Update game map if(update_game_map()) { // Draw game map, if changes to the map have been made draw_game_map(hwnd, gameArea); } else { // If map is static, stop the execution SendMessage(hwnd, WM_COMMAND, (WPARAM)IDB_STOPBTN, (LPARAM)0); } } break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); // Draw game area hPEN = CreatePen(PS_SOLID, 1, RGB(0,0,0)); SelectObject(hdc, hPEN); SelectObject(hdc, (HBRUSH)GetStockObject(WHITE_BRUSH)); Rectangle(hdc, 10, 10, 510, 510); DeleteObject(hPEN); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }
int qt_wince_GetDIBits(HDC /*hdc*/ , HBITMAP hSourceBitmap, uint, uint, LPVOID lpvBits, LPBITMAPINFO, uint) { if (!lpvBits) { qWarning("::GetDIBits(), lpvBits NULL"); return 0; } BITMAP bm; GetObject(hSourceBitmap, sizeof(BITMAP), &bm); bm.bmHeight = qAbs(bm.bmHeight); HBITMAP hTargetBitmap; void *pixels; BITMAPINFO dibInfo; memset(&dibInfo, 0, sizeof(dibInfo)); dibInfo.bmiHeader.biBitCount = 32; dibInfo.bmiHeader.biClrImportant = 0; dibInfo.bmiHeader.biClrUsed = 0; dibInfo.bmiHeader.biCompression = BI_RGB;; dibInfo.bmiHeader.biHeight = -bm.bmHeight; dibInfo.bmiHeader.biWidth = bm.bmWidth; dibInfo.bmiHeader.biPlanes = 1; dibInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); dibInfo.bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4; HDC displayDC = GetDC(NULL); if (!displayDC) { qWarning("::GetDIBits(), failed to GetDC"); return 0; } int ret = bm.bmHeight; hTargetBitmap = CreateDIBSection(displayDC, (const BITMAPINFO*) &dibInfo, DIB_RGB_COLORS, (void**)&pixels, NULL, 0); if (!hTargetBitmap) { qWarning("::GetDIBits(), failed to CreateDIBSection"); return 0; } HDC hdcSrc = CreateCompatibleDC(displayDC); HDC hdcDst = CreateCompatibleDC(displayDC); if (!(hdcDst && hdcSrc)) { qWarning("::GetDIBits(), failed to CreateCompatibleDC"); ret = 0; } HBITMAP hOldBitmap1 = (HBITMAP) SelectObject(hdcSrc, hSourceBitmap); HBITMAP hOldBitmap2 = (HBITMAP) SelectObject(hdcDst, hTargetBitmap); if (!(hOldBitmap1 && hOldBitmap2)) { qWarning("::GetDIBits(), failed to SelectObject for bitmaps"); ret = 0; } if (!BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY)) { qWarning("::GetDIBits(), BitBlt failed"); ret = 0; } SelectObject(hdcSrc, hOldBitmap1); SelectObject(hdcDst, hOldBitmap2); DeleteDC(hdcSrc); DeleteDC(hdcDst); ReleaseDC(NULL, displayDC); memcpy(lpvBits, pixels, dibInfo.bmiHeader.biSizeImage); DeleteObject(hTargetBitmap); return ret; }
//Basic Init, create the font, backbuffer, etc WINDOW *curses_init(void) { // _windows = new WINDOW[20]; //initialize all of our variables lastchar=-1; inputdelay=-1; std::string typeface = "Terminus"; char * typeface_c = 0; std::ifstream fin; fin.open("data/FONTDATA"); if (!fin.is_open()){ typeface_c = (char*) "Terminus"; fontwidth = 8; fontheight = 16; std::ofstream fout;//create data/FONDATA file fout.open("data\\FONTDATA"); if(fout.is_open()) { fout << typeface << "\n"; fout << fontwidth << "\n"; fout << fontheight; fout.close(); } } else { getline(fin, typeface); fin >> fontwidth; fin >> fontheight; if ((fontwidth <= 4) || (fontheight <=4)){ MessageBox(WindowHandle, "Invalid font size specified!", NULL, 0); fontheight = 16; fontwidth = 8; } } typeface_c = new char [typeface.size()+1]; strcpy (typeface_c, typeface.c_str()); halfwidth=fontwidth / 2; halfheight=fontheight / 2; WindowWidth= (55 + (OPTIONS["VIEWPORT_X"] * 2 + 1)) * fontwidth; WindowHeight = (OPTIONS["VIEWPORT_Y"] * 2 + 1) *fontheight; WinCreate(); //Create the actual window, register it, etc timeBeginPeriod(1); // Set Sleep resolution to 1ms CheckMessages(); //Let the message queue handle setting up the window WindowDC = GetDC(WindowHandle); backbuffer = CreateCompatibleDC(WindowDC); BITMAPINFO bmi = BITMAPINFO(); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = WindowWidth; bmi.bmiHeader.biHeight = -WindowHeight; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 8; bmi.bmiHeader.biCompression = BI_RGB; // Raw RGB bmi.bmiHeader.biSizeImage = WindowWidth * WindowHeight * 1; bmi.bmiHeader.biClrUsed = 16; // Colors in the palette bmi.bmiHeader.biClrImportant = 16; // Colors in the palette backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0); DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC // Load private fonts if (SetCurrentDirectory("data\\font")){ WIN32_FIND_DATA findData; for (HANDLE findFont = FindFirstFile(".\\*", &findData); findFont != INVALID_HANDLE_VALUE; ) { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders AddFontResourceExA(findData.cFileName, FR_PRIVATE,NULL); } if (!FindNextFile(findFont, &findData)){ FindClose(findFont); break; } } SetCurrentDirectory("..\\.."); } // Use desired font, if possible font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_MODERN, typeface_c); SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds SelectObject(backbuffer, font);//Load our font into the DC // WindowCount=0; init_colors(); delete typeface_c; mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(55 + (OPTIONS["VIEWPORT_Y"] * 2 + 1)),0,0); return mainwin; //create the 'stdscr' window and return its ref }
HRGN CXTPPopupControl::BitmapToRegion(CXTPImageManagerIcon* pIcon) { HRGN hRgn = NULL; if (!pIcon) return NULL; // Create a memory DC inside which we will scan the bitmap content CDC dcMemDC; if (!dcMemDC.CreateCompatibleDC(NULL)) return NULL; int nWidth = pIcon->GetWidth(); int nHeight = pIcon->GetHeight(); LPBYTE lpBits = NULL; HBITMAP hbm32 = CXTPImageManager::Create32BPPDIBSection(dcMemDC, nWidth, nHeight, &lpBits); if (!hbm32 || lpBits == NULL) return NULL; HBITMAP holdBmp = (HBITMAP)SelectObject(dcMemDC, hbm32); dcMemDC.FillSolidRect(0, 0, nWidth, nHeight, 0xFF00FF); pIcon->Draw(&dcMemDC, CPoint(0, 0)); SelectObject(dcMemDC, holdBmp); const DWORD nAlloc = 100; DWORD mMaxRects = nAlloc; RGNDATA *pData = (RGNDATA *)malloc(sizeof(RGNDATAHEADER) + (sizeof(RECT) * mMaxRects)); if (!pData) { DeleteObject(hbm32); return NULL; } pData->rdh.dwSize = sizeof(RGNDATAHEADER); pData->rdh.iType = RDH_RECTANGLES; pData->rdh.nCount = pData->rdh.nRgnSize = 0; SetRect(&pData->rdh.rcBound, 0, 0, nWidth, nHeight); BYTE *p32 = (BYTE *)lpBits + (nHeight - 1) * nWidth * 4; for (int y = 0; y < nHeight; y++) { for (int x = 0; x < nWidth; x++) { int x0 = x; COLORREF* p = (COLORREF*)p32 + x; while (x < nWidth) { if (*p == 0xFF00FF) break; p++; x++; } if (x > x0) { if (pData->rdh.nCount >= mMaxRects) { mMaxRects += nAlloc; RGNDATA* pReData = (RGNDATA*)realloc(pData, sizeof(RGNDATAHEADER) + (sizeof(RECT) * mMaxRects)); if (!pReData) { DeleteObject(hbm32); free(pData); return NULL; } pData = pReData; } RECT *pr = (RECT *)&pData->Buffer; SetRect(&pr[pData->rdh.nCount], x0, y, x, y + 1); pData->rdh.nCount++; if (pData->rdh.nCount > 2000) { HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * mMaxRects), pData); if (hRgn) { CombineRgn(hRgn, hRgn, h, RGN_OR); DeleteObject(h); } else { hRgn = h; } pData->rdh.nCount = 0; } } } p32 -= nWidth * 4; } HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * mMaxRects), pData); if (hRgn) { CombineRgn(hRgn, hRgn, h, RGN_OR); DeleteObject(h); } else { hRgn = h; } free(pData); DeleteObject(hbm32); return hRgn; }
LRESULT CALLBACK WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { //these hold the dimensions of the client window area static int cxClient, cyClient; switch (msg) { //A WM_CREATE msg is sent when your application window is first //created case WM_CREATE: { //to get get the size of the client window first we need to create //a RECT and then ask Windows to fill in our RECT structure with //the client window size. Then we assign to cxClient and cyClient //accordingly RECT rect; GetClientRect(hwnd, &rect); cxClient = rect.right; cyClient = rect.bottom; } break; case WM_KEYUP: { switch(wParam) { case VK_ESCAPE: { PostQuitMessage(0); } break; } } case WM_PAINT: { PAINTSTRUCT ps; BeginPaint (hwnd, &ps); //Make the bottom part of window a pattern so you can see what //the transparency flag does HBRUSH PatternBrush = CreateHatchBrush(HS_BDIAGONAL, RGB(0,0,255)); HBRUSH OldBrush = (HBRUSH)SelectObject(ps.hdc, PatternBrush); Rectangle(ps.hdc,0, cyClient/2, cxClient, cyClient); //replace the old brush SelectObject(ps.hdc, OldBrush); //first a demonstration of TextOut char* text = "1. I ain't got time to bleed."; TextOut(ps.hdc, 5, 5, text, strlen(text)); //now DrawText. First we create a text box RECT TextBox; TextBox.top = 30; TextBox.left = 100; TextBox.bottom = 200; TextBox.right = cxClient-100; //assign some text text = "2. You take the blue pill and the story ends.You wake in your bed and believe whatever you want to believe.You take the red pill and you stay in Wonderland and I show you how deep the rabbit-hole goes."; //now print the text DrawText(ps.hdc, text, strlen(text), &TextBox, DT_WORDBREAK); //now to change the colors. First set text to red SetTextColor(ps.hdc, RGB(255, 0, 0)); //background to black SetBkColor(ps.hdc, RGB(0, 0, 0)); TextBox.top = 200; TextBox.left = 5; TextBox.bottom = 300; TextBox.right = cxClient-200; text = "3. The greatest trick the devil ever pulled was convincing the world he didn't exist."; DrawText(ps.hdc, text, strlen(text), &TextBox, DT_WORDBREAK); //now set background to transparent SetBkMode(ps.hdc, TRANSPARENT); TextBox.top = 300; TextBox.left = 100; TextBox.bottom = cyClient; TextBox.right = cxClient-50; text = "4. ...I’m 42 years old. In less than a year I’ll be dead"; DrawText(ps.hdc, text, strlen(text), &TextBox, DT_WORDBREAK); EndPaint (hwnd, &ps); } break; //has the user resized the client area? case WM_SIZE: { //if so we need to update our variables so that any drawing //we do using cxClient and cyClient is scaled accordingly cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); } break; case WM_DESTROY: { // kill the application, this sends a WM_QUIT message PostQuitMessage (0); } break; }//end switch //this is where all the messages not specifically handled by our //winproc are sent to be processed return DefWindowProc (hwnd, msg, wParam, lParam); }
LRESULT CALLBACK notificationWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; RECT rc = {0}; UINT notify_duration = 0; static BOOL is_fading_out = FALSE; static HHOOK hook_mouse_over = NULL; static NotifyNotification notification_data_copy = {L"", L"", ICON_INFO}; switch (message) { case WM_LIBNOTIFYSHOW: /* close if already running */ if(IsWindowVisible(hWnd)) { SendMessage(hWnd, WM_LIBNOTIFYCLOSE, 0, 0); } /* guarded by CS to make sure notification_data doesn't get corrupted when this code and notify_notification_update is running in parallel */ { EnterCriticalSection(&thread_guard); NotifyNotification *notification_data = (NotifyNotification*) lParam; if(notification_data && notification_data->body && notification_data->summary) { notification_data_copy = *notification_data; } else { LeaveCriticalSection(&thread_guard); break; } LeaveCriticalSection(&thread_guard); } /* deduce the allowed text width from the max width; see geometry for rationale */ rc.right = notification_window_width_max - (icon_size + (icon_padding * 3)); hdc = GetDC(hWnd); if(hdc) { HRGN hRgn = NULL; HGDIOBJ hOldFont = SelectObject(hdc, (HGDIOBJ) font_body); if(hOldFont) { DrawText(hdc, notification_data_copy.body, -1, &rc, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_NOPREFIX | DT_EXTERNALLEADING); SelectObject(hdc, hOldFont); } ReleaseDC(hWnd, hdc); if(!hOldFont) return 0; /* exit if font selection failed */ /* calculate the actual bounding rectangle from the DrawText output */ notify_wnd.notification_window_height = notify_wnd.summary_body_divider + rc.bottom + (icon_padding * 3); notify_wnd.notification_window_width = rc.right + icon_size + (icon_padding * 3); /* word count * milliseconds per word */ notify_duration = word_count(notification_data_copy.body) * milliseconds_per_word; /* in case the calculation renders too low a value, replace it with a de facto minimum */ notify_duration = MAX(notify_duration, min_notification_timeout); /* get the screen area uncluttered by the taskbar */ if(SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0)) { LONG window_x = 0, window_y = 0; /* system tray @ right bottom */ if((rc.bottom != GetSystemMetrics(SM_CYSCREEN)) || (rc.right != GetSystemMetrics(SM_CXSCREEN))) { window_x = rc.right - (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) - notify_wnd.notification_window_width; window_y = rc.bottom - (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) - notify_wnd.notification_window_height; } else if(rc.left != 0) /* left bottom */ { window_x = rc.left + (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor); window_y = rc.bottom - (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) - notify_wnd.notification_window_height; } else /* right top */ { window_x = rc.right - (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) - notify_wnd.notification_window_width; window_y = rc.top + (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor); } /* resize and reposition the window */ MoveWindow(hWnd, window_x, window_y, notify_wnd.notification_window_width, notify_wnd.notification_window_height, TRUE); /* set the new positions to be used by the mouse over hook */ notify_wnd.notification_window_rect.left = window_x; notify_wnd.notification_window_rect.top = window_y; notify_wnd.notification_window_rect.right = window_x + notify_wnd.notification_window_width; notify_wnd.notification_window_rect.bottom = window_y + notify_wnd.notification_window_height; /* make it as a rounded rect. */ hRgn = CreateRoundRectRgn(0, 0, notify_wnd.notification_window_width, notify_wnd.notification_window_height, rounded_rect_edge, rounded_rect_edge); SetWindowRgn(hWnd, hRgn, TRUE); /* since bRedraw is set to TRUE in SetWindowRgn invalidation isn't required */ /*InvalidateRect(hWnd, NULL, TRUE);*/ /* show the window and set the timers for animation and overall visibility */ ShowWindow(hWnd, SW_SHOWNOACTIVATE); SetTimer(hWnd, TIMER_ANIMATION, fade_duration, NULL); SetTimer(hWnd, TIMER_NOTIFICATION, notify_duration, NULL); } } break; case WM_LIBNOTIFYCLOSE: /* clean up and reset flags */ { if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } KillTimer(hWnd, TIMER_ANIMATION); KillTimer(hWnd, TIMER_NOTIFICATION); is_fading_out = FALSE; ShowWindow(hWnd, SW_HIDE); } break; case WM_PAINT: if((L'\0' != notification_data_copy.body[0]) && (L'\0' != notification_data_copy.summary[0])) { hdc = BeginPaint(hWnd, &ps); SetTextColor(hdc, RGB(255, 255, 255)); SetBkMode(hdc, TRANSPARENT); HGDIOBJ hOldFont = SelectObject(hdc, (HGDIOBJ) font_summary); if(hOldFont) { /* set the padding as left offset and center the icon horizontally */ DrawIcon(hdc, icon_padding, (notify_wnd.notification_window_height / 2) - (icon_size / 2), notification_icons[notification_data_copy.icon_req]); /* calculate and DrawText for both summary and body based on the geometry given above */ rc.left = icon_size + (icon_padding * 2); rc.right = notify_wnd.notification_window_width - icon_padding; rc.top = icon_padding; rc.bottom = notify_wnd.summary_body_divider + (icon_padding * 2); DrawText(hdc, notification_data_copy.summary, -1, &rc, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); if(SelectObject(hdc, (HGDIOBJ) font_body)) { rc.top = rc.bottom; rc.bottom = notify_wnd.notification_window_height - icon_padding; DrawText(hdc, notification_data_copy.body, -1, &rc, DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_NOPREFIX | DT_EXTERNALLEADING); } SelectObject(hdc, hOldFont); } EndPaint(hWnd, &ps); } break; case WM_LIBNOTIFYEXIT: if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } KillTimer(notify_wnd.notification_window, TIMER_ANIMATION); KillTimer(notify_wnd.notification_window, TIMER_NOTIFICATION); PostQuitMessage(0); break; case WM_TIMER: if(IsWindowVisible(hWnd)) { if(wParam == TIMER_ANIMATION) /* notification animation timer */ { if(is_fading_out) { if(notify_wnd.notification_window_alpha > 5) { notify_wnd.notification_window_alpha -= 25; } else { /* once fully faded out, self destroy and reset the flags */ KillTimer(hWnd, TIMER_ANIMATION); is_fading_out = FALSE; notify_wnd.notification_window_alpha = 0; SendMessage(hWnd, WM_LIBNOTIFYCLOSE, 0, 0); } } else { if(notify_wnd.notification_window_alpha < 250) { notify_wnd.notification_window_alpha += 25; } else { /* self destory as alpha reaches the maximum */ KillTimer(hWnd, TIMER_ANIMATION); notify_wnd.notification_window_alpha = 255; /* set the mouse over hook once the window is fully visible */ hook_mouse_over = SetWindowsHookEx(WH_MOUSE_LL, mouse_over_hook_proc, (HINSTANCE) GetModuleHandle(NULL), 0); } } /* for all the above cases set the newly calculated alpha */ SetLayeredWindowAttributes(notify_wnd.notification_window, 0, notify_wnd.notification_window_alpha, LWA_ALPHA); } else /* notification duration timer */ { /* self destruct once timed out */ KillTimer(hWnd, TIMER_NOTIFICATION); /* kill the hook set by animation timer */ if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } /* start fading out sequence */ is_fading_out = TRUE; SetTimer(hWnd, TIMER_ANIMATION, fade_duration, NULL); } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
HICON TrayIcon_GetProcessorUsageIcon(void) { HICON hTrayIcon = NULL; HDC hScreenDC = NULL; HDC hDC = NULL; HBITMAP hBitmap = NULL; HBITMAP hOldBitmap; HBITMAP hBitmapMask = NULL; ICONINFO iconInfo; ULONG ProcessorUsage; int nLinesToDraw; HBRUSH hBitmapBrush = NULL; RECT rc; /* * Get a handle to the screen DC */ hScreenDC = GetDC(NULL); if (!hScreenDC) goto done; /* * Create our own DC from it */ hDC = CreateCompatibleDC(hScreenDC); if (!hDC) goto done; /* * Load the bitmaps */ hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TRAYICON)); hBitmapMask = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TRAYMASK)); if (!hBitmap || !hBitmapMask) goto done; hBitmapBrush = CreateSolidBrush(RGB(0, 255, 0)); if (!hBitmapBrush) goto done; /* * Select the bitmap into our device context * so we can draw on it. */ hOldBitmap = SelectObject(hDC, hBitmap); /* * Get the cpu usage */ ProcessorUsage = PerfDataGetProcessorUsage(); /* * Calculate how many lines to draw * since we have 11 rows of space * to draw the cpu usage instead of * just having 10. */ nLinesToDraw = (ProcessorUsage + (ProcessorUsage / 10)) / 11; rc.left = 3; rc.top = 12 - nLinesToDraw; rc.right = 13; rc.bottom = 13; /* * Now draw the cpu usage */ if (nLinesToDraw) FillRect(hDC, &rc, hBitmapBrush); /* * Now that we are done drawing put the * old bitmap back. */ SelectObject(hDC, hOldBitmap); iconInfo.fIcon = TRUE; iconInfo.xHotspot = 0; iconInfo.yHotspot = 0; iconInfo.hbmMask = hBitmapMask; iconInfo.hbmColor = hBitmap; hTrayIcon = CreateIconIndirect(&iconInfo); done: /* * Cleanup */ if (hScreenDC) ReleaseDC(NULL, hScreenDC); if (hDC) DeleteDC(hDC); if (hBitmapBrush) DeleteObject(hBitmapBrush); if (hBitmap) DeleteObject(hBitmap); if (hBitmapMask) DeleteObject(hBitmapMask); /* * Return the newly created tray icon (if successful) */ return hTrayIcon; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_CREATE: { if (!hmWnd) hmWnd = hWnd; hdc = GetDC(hWnd); CBIT = GetDeviceCaps(hdc, BITSPIXEL); CBYTE = CBIT/8; ReleaseDC(hWnd, hdc); buffer = malloc(width*height*CBYTE); bmp.bmType = 0; bmp.bmWidth = width; bmp.bmHeight = height; bmp.bmWidthBytes = width*CBYTE; bmp.bmPlanes = 1; bmp.bmBitsPixel = CBIT; bmp.bmBits = buffer; if (CBYTE == 4) fmt = COLOR_FORMAT_BGRA; else if (CBYTE == 3) fmt = COLOR_FORMAT_BGR; else if (CBYTE == 2) fmt = COLOR_FORMAT_RGB565; ps_initialize(); canvas = ps_canvas_create_with_data(buffer, fmt, width, height, width*CBYTE); context = ps_context_create(canvas, 0); on_init(context, width, height); } break; case WM_PAINT: { HDC mdc; HGDIOBJ h; hdc = BeginPaint(hWnd, &ps); on_draw(context); mdc = CreateCompatibleDC(hdc); hbmp = CreateBitmapIndirect(&bmp); h = SelectObject(mdc, hbmp); BitBlt(hdc, 0, 0, width, height, mdc, 0, 0, SRCCOPY); SelectObject(mdc, h); DeleteObject(hbmp); DeleteDC(mdc); EndPaint(hWnd, &ps); } break; case WM_TIMER: on_timer(); break; case WM_SIZE: { ps_canvas* old_canvas = 0; width = LOWORD(lParam); height = HIWORD(lParam); free(buffer); if (width < 1) width = 1; if (height < 1) height = 1; buffer = malloc(width*height*CBYTE); bmp.bmType = 0; bmp.bmWidth = width; bmp.bmHeight = height; bmp.bmWidthBytes = width*CBYTE; bmp.bmPlanes = 1; bmp.bmBitsPixel = CBIT; bmp.bmBits = buffer; canvas = ps_canvas_create_with_data(buffer, fmt, width, height, width*CBYTE); old_canvas = ps_context_set_canvas(context, canvas); ps_canvas_unref(old_canvas); on_size(width, height); } break; case WM_ERASEBKGND: break; case WM_LBUTTONDOWN: on_mouse_event(LEFT_BUTTON_DOWN, (int)wParam, LOWORD(lParam), HIWORD(lParam)); break; case WM_MOUSEMOVE: on_mouse_event(MOUSE_MOVE, (int)wParam, LOWORD(lParam), HIWORD(lParam)); break; case WM_KEYDOWN: on_key_event(KEY_EVENT_DOWN, (int)wParam); break; case WM_KEYUP: on_key_event(KEY_EVENT_UP, (int)wParam); break; case WM_DESTROY: { on_term(context); ps_context_unref(context); ps_canvas_unref(canvas); ps_shutdown(); free(buffer); PostQuitMessage(0); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/** * Returns the updated control for the OSVR Tracker node. * Allways return >nullptr< if there is no update for the control !! ***/ HBITMAP OSVR_Tracker::GetControl() { if (!m_hBitmapControl) { // create bitmap, set control update to true HWND hwnd = GetActiveWindow(); HDC hdc = GetDC(hwnd); m_hBitmapControl = CreateCompatibleBitmap(hdc, 1024, 1700); if (!m_hBitmapControl) OutputDebugString(L"Failed to create bitmap!"); m_bControlUpdate = true; } if (m_bControlUpdate) { // get control bitmap dc HDC hdcImage = CreateCompatibleDC(NULL); HBITMAP hbmOld = (HBITMAP)SelectObject(hdcImage, m_hBitmapControl); HFONT hOldFont; // clear the background RECT rc; SetRect(&rc, 0, 0, 1024, 1700); FillRect(hdcImage, &rc, (HBRUSH)CreateSolidBrush(RGB(238, 238, 238))); // create font if (!m_hFont) m_hFont = CreateFont(64, 0, 0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, L"Consolas"); // Select the variable stock font into the specified device context. if ((hOldFont = (HFONT)SelectObject(hdcImage, m_hFont)) && (m_psOSVR_ClientContext)) { int nY = 16; std::wstringstream szBuffer; SetTextColor(hdcImage, RGB(253, 128, 0)); SetBkColor(hdcImage, RGB(238, 238, 238)); // display the values suiteable to the data commanders... first yaw pitch roll szBuffer << m_afEuler[0]; TextOut(hdcImage, 730, nY, L"Pitch X", 7); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); szBuffer << m_afEuler[1]; TextOut(hdcImage, 780, nY, L"Yaw Y", 5); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); szBuffer << m_afEuler[2]; TextOut(hdcImage, 765, nY, L"Roll Z", 6); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); // orientation szBuffer << m_sState.rotation.data[0]; TextOut(hdcImage, 570, nY, L"Orientation W", 13); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); szBuffer << m_sState.rotation.data[1]; TextOut(hdcImage, 570, nY, L"Orientation X", 13); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); szBuffer << m_sState.rotation.data[2]; TextOut(hdcImage, 570, nY, L"Orientation Y", 13); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); szBuffer << m_sState.rotation.data[3]; TextOut(hdcImage, 570, nY, L"Orientation Z", 13); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); // position tracking szBuffer << m_sState.translation.data[0]; TextOut(hdcImage, 650, nY, L"Position X", 10); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); szBuffer << m_sState.translation.data[1]; TextOut(hdcImage, 650, nY, L"Position Y", 10); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); szBuffer << m_sState.translation.data[2]; TextOut(hdcImage, 650, nY, L"Position Z", 10); TextOut(hdcImage, 200, nY, szBuffer.str().c_str(), (int)szBuffer.str().length()); nY += 64; szBuffer = std::wstringstream(); // Restore the original font. SelectObject(hdcImage, hOldFont); } SelectObject(hdcImage, hbmOld); DeleteDC(hdcImage); // next update only by request, return updated bitmap m_bControlUpdate = false; return m_hBitmapControl; } else return nullptr; }
void outwnd_paint(HWND hwnd) { int i, n, x, y, len; int old_nrows, scroll_pos; HDC hdc; PAINTSTRUCT ps; RECT client; TEXTMETRIC tm; HFONT newfont, oldfont; HBRUSH newbrush, oldbrush; Outwnd_changed = 0; hdc = BeginPaint(hwnd, &ps); GetClientRect(hOutputWnd, &client); newfont = (HFONT)GetStockObject(ANSI_FIXED_FONT); oldfont = (HFONT)SelectObject(hdc,newfont); GetTextMetrics(hdc, &tm); nTextHeight = tm.tmHeight + tm.tmExternalLeading; nTextWidth = tm.tmAveCharWidth; old_nrows = nCharRows; nCharRows = ((client.bottom-client.top)/nTextHeight)+1; newbrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW)); oldbrush = (HBRUSH)SelectObject(hdc,newbrush); y = client.bottom - nTextHeight * nCharRows; // starting y position at top client_top_yoffset = y - nTextHeight; scroll_pos = (max_scroll_pos - GetScrollPos( hOutputWnd, SB_VERT )); cur_line_index = x = mprintf_last_line - scroll_pos - nCharRows; if (x >= marked_top && x < marked_bottom) // starting in marked area text_hilight(hdc); else text_normal(hdc); if (scroll_pos != old_scroll_pos) { if (!scroll_pos) { char tmp[1024]; sprintf( tmp, "Debug Spew"); SetWindowText( hOutputWnd, tmp ); } else { char tmp[1024]; sprintf( tmp, "Debug Spew [Scrolled back %d lines]", scroll_pos ); SetWindowText( hOutputWnd, tmp ); } old_scroll_pos = scroll_pos; } i = nCharRows; while (i--) { n = mprintf_last_line - scroll_pos - i; if (n < 0) n += SCROLL_BUFFER_SIZE; if (n >= 0 && n < SCROLL_BUFFER_SIZE) { len = strlen(outtext[n]); if (marked) { if (n == marked_top && n == marked_bottom) // special 1 line case { if (marked_left) TextOut(hdc, 0, y, outtext[n], marked_left); text_hilight(hdc); x = marked_left * nTextWidth; TextOut(hdc, x, y, outtext[n] + marked_left, marked_right - marked_left); text_normal(hdc); x = marked_right * nTextWidth; if (marked_right < len) TextOut(hdc, x, y, outtext[n] + marked_right, len - marked_right); x = len * nTextWidth; TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - len); } else if (n == marked_top) { // start marked on this line if (marked_left) TextOut(hdc, 0, y, outtext[n], marked_left); text_hilight(hdc); x = marked_left * nTextWidth; TextOut(hdc, x, y, outtext[n] + marked_left, len - marked_left); x = len * nTextWidth; if (marked_left < MAX_LINE_WIDTH) TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - marked_left); } else if (n == marked_bottom) { // end marked on this line if (marked_right) TextOut(hdc, 0, y, outtext[n], marked_right); text_normal(hdc); x = marked_right * nTextWidth; if (marked_right < len) TextOut(hdc, x, y, outtext[n] + marked_right, len - marked_right); x = len * nTextWidth; TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - len); } else { // whole line marked TextOut(hdc, 0, y, outtext[n], len); x = len * nTextWidth; TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - len); } } else { TextOut(hdc, 0, y, outtext[n], len); x = len * nTextWidth; TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - len); } } else TextOut(hdc, 0, y, spaces, MAX_LINE_WIDTH); y += nTextHeight; } text_normal(hdc); SelectObject(hdc, oldfont); SelectObject(hdc, oldbrush); DeleteObject(newbrush); if ( old_nrows != nCharRows ) { SCROLLINFO si; max_scroll_pos = SCROLL_BUFFER_SIZE-nCharRows - 1; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_RANGE; si.nMin = 0; si.nMax = max_scroll_pos; SetScrollInfo(hwnd, SB_VERT, &si, 1 ); } EndPaint(hwnd, &ps); }
void draw_button( int button_id, DRAWITEMSTRUCT FAR * draw ) { HBITMAP bmp; HBITMAP oldbmp; HPEN blackpen, shadowpen, brightpen, facepen; HPEN oldpen; BITMAP bitmap; HDC memdc; HINSTANCE inst; int shift; inst = GET_HINSTANCE( draw->hwndItem ); bmp = LoadBitmap( inst, MAKEINTRESOURCE( button_id ) ); if( !bmp ) return; GetObject( bmp, sizeof(BITMAP), &bitmap ); memdc = CreateCompatibleDC( draw->hDC ); oldbmp = SelectObject( memdc, bmp ); if( draw->itemState & ODS_SELECTED ) { shift = 4; } else { shift = 2; } BitBlt( draw->hDC, draw->rcItem.left + shift, draw->rcItem.top + shift, bitmap.bmWidth, bitmap.bmHeight, memdc, 0, 0, SRCCOPY ); SelectObject( memdc, oldbmp ); DeleteDC( memdc ); DeleteObject( bmp ); // Draw four sides of the button except one pixel in each corner blackpen = CreatePen( PS_SOLID, 0, RGB(0,0,0) ); brightpen = CreatePen( PS_SOLID, 0, RGB(255,255,255) ); shadowpen = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNSHADOW ) ); facepen = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNFACE ) ); oldpen = SelectObject( draw->hDC, blackpen ); horizontal( draw, draw->rcItem.top ); horizontal( draw, draw->rcItem.bottom - 1 ); vertical( draw, draw->rcItem.left ); vertical( draw, draw->rcItem.right - 1 ); // Now the shading SelectObject( draw->hDC, shadowpen ); if( draw->itemState & ODS_SELECTED ) { horizontal( draw, draw->rcItem.top + 1 ); vertical( draw, draw->rcItem.left + 1 ); SelectObject( draw->hDC, facepen ); horizontal( draw, draw->rcItem.top + 2 ); vertical( draw, draw->rcItem.left + 2 ); horizontal( draw, draw->rcItem.top + 3 ); vertical( draw, draw->rcItem.left + 3 ); } else { horizontal( draw, draw->rcItem.bottom - 2 ); horizontal( draw, draw->rcItem.bottom - 3 ); vertical( draw, draw->rcItem.right - 2 ); vertical( draw, draw->rcItem.right - 3 ); SelectObject( draw->hDC, brightpen ); horizontal( draw, draw->rcItem.top + 1 ); vertical( draw, draw->rcItem.left + 1 ); } SelectObject( draw->hDC, oldpen ); DeleteObject( blackpen ); DeleteObject( brightpen ); DeleteObject( shadowpen ); DeleteObject( facepen ); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { HDC hDC; PAINTSTRUCT Ps; switch (msg) { case WM_PAINT: { HFONT font; hDC = BeginPaint(hwnd, &Ps); HPEN hLinePen; COLORREF qLineColor; qLineColor = RGB(255, 0, 0); hLinePen = CreatePen(PS_SOLID, 7, qLineColor); { int x1 = 10, x2 = 10, x3 = 1260, x4 = 680; font = CreateFont(3, 3, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "Times New Roman"); SelectObject(hDC, font); TextOut(hDC, 1320, 689, "Johnny", 6); DeleteObject(font); HBRUSH NewBrush; POINT Pt[4]; NewBrush = CreateSolidBrush(RGB(255, 255, 255)); SelectObject(hDC, NewBrush); Pt[0].x = x1; Pt[0].y = x2; Pt[1].x = x3; Pt[1].y = x2; Pt[2].x = x3; Pt[2].y = x4; Pt[3].x = x1; Pt[3].y = x4; Polygon(hDC, Pt, 4); DeleteObject(NewBrush); } EndPaint(hwnd, &Ps); break; } case WM_LBUTTONDOWN: { if (ok_start == 1) { wchar_t waCoord[20]; wsprintf((LPSTR)waCoord, ("(%i, %i)"), LOWORD(lParam), HIWORD(lParam)); int msg_return = MessageBox(hwnd, (LPCSTR)waCoord, ("Ai ales coordonatele:"), MB_OKCANCEL); { if (msg_return == IDOK) { poz_x = LOWORD(lParam); poz_y = HIWORD(lParam); hDC = BeginPaint(hwnd, &Ps); hDC = GetWindowDC(hwnd); if ((poz_x<10 || poz_y<10 || poz_x>1260 || poz_y>680)) { poz_x = poz_y = 0; MessageBox(NULL, (LPCSTR)"Alege un punct din zona incadrata!", "Atentie!!!", MB_ICONERROR); break; } TextOut(hDC, poz_x + 7, poz_y + 23, "x", 1); /* char v[7]; itoa(poz_x, v, 10); TextOut(hDC, poz_x + 7, poz_y + 23, v, lung_nr(poz_x)); TextOut(hDC, poz_x + 38, poz_y + 23, ";", 1); itoa(poz_y, v, 10); TextOut(hDC, poz_x + 40, poz_y + 23, v, lung_nr(poz_y)); EndPaint(hwnd, &Ps);*/ ReleaseDC(hwnd, hDC); } if (msg_return == IDCANCEL) { int poz_x = 0; int poz_y = 0; } } } else MessageBox(NULL, (LPCSTR)"Nu ai citit instructiunile!", "Atentie!!!", MB_ICONERROR); break; } case WM_CREATE: {HICON hIcon; hIcon = (HICON)LoadImage(NULL, "tr.ico", IMAGE_ICON, 16, 16,0); CreateWindowEx(NULL, "BUTTON", "Start!", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 1265, 10, 80, 24, hwnd, (HMENU)IDC_MAIN_BUTTON, GetModuleHandle(NULL), NULL); CreateWindowEx(NULL, "BUTTON", "Localizare", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 1265, 50, 80, 24, hwnd, (HMENU)IDC_LOCATE_BUTTON, GetModuleHandle(NULL), NULL); CreateWindowEx(NULL, "BUTTON", "Adresa", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 1265, 90, 80, 24, hwnd, (HMENU)IDC_ADRESS_BUTTON, GetModuleHandle(NULL), NULL); CreateWindowEx(NULL, "BUTTON", "Instructiuni", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 1265, 130, 80, 24, hwnd, (HMENU)IDC_HELP_BUTTON, GetModuleHandle(NULL), NULL); } break; case WM_COMMAND: { switch (wParam) { case IDC_MAIN_BUTTON: { HFONT font; hDC = BeginPaint(hwnd, &Ps); hDC = GetWindowDC(hwnd); root = radacina("coord.txt"); poz_x = 0; poz_y = 0; afisare_arbore(root, hDC); ok_start = 1; EndPaint(hwnd, &Ps); ReleaseDC(hwnd, hDC); break; } case IDC_HELP_BUTTON: { MessageBox(NULL, (LPCSTR)fisier_help("ajutor.txt"), "Ajutor", MB_ICONINFORMATION); break; } case IDC_LOCATE_BUTTON: {if (poz_x != 0 && poz_y != 0) { MessageBox(NULL, (LPCSTR)nume_localizare(root, poz_x, poz_y), "Zona in care te aflii este:", MB_ICONINFORMATION); } else MessageBox(NULL, (LPCSTR)"Nu ai selectat un punct din zona incadrata!\nAlege mai intai un punct din zona incadrata!", "Atentie!!!", MB_ICONERROR); } break; case IDC_ADRESS_BUTTON: {if (poz_x != 0 && poz_y != 0) { MessageBox(NULL, (LPCSTR)nume_adresa(root, poz_x, poz_y), "Adresa zonei in care te aflii este:", MB_ICONINFORMATION); } else MessageBox(NULL, (LPCSTR)"Nu ai selectat un punct din zona incadrata!\nAlege mai intai un punct din zona incadrata!", "Atentie!!!", MB_ICONERROR); } break; } }break; case WM_DESTROY: PostQuitMessage(WM_QUIT); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
DWORD CALLBACK AboutBoxProc(HWND hWnd, DWORD uMsg, DWORD wParam, DWORD lParam) { static HBITMAP hbmpBackgroundTop = NULL; static HFONT hPageHeadingFont = NULL; static HFONT hTextFont = NULL; static HFONT hAuthorFont = NULL; switch (uMsg) { case WM_INITDIALOG: { //Title SetWindowTextW(hWnd, wGS(PLUG_ABOUT).c_str()); // Use the size of the image hbmpBackgroundTop = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_ABOUT_LOGO)); BITMAP bmTL; GetObject(hbmpBackgroundTop, sizeof(BITMAP), &bmTL); hTextFont = ::CreateFont(18, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial"); hAuthorFont = ::CreateFont(18, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial"); hPageHeadingFont = ::CreateFont(24, 0, 0, 0, FW_BOLD, 0, FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial Bold"); SendDlgItemMessage(hWnd, IDC_VERSION, WM_SETFONT, (WPARAM)hTextFont, TRUE); SendDlgItemMessage(hWnd, IDC_TEAM, WM_SETFONT, (WPARAM)hPageHeadingFont, TRUE); SendDlgItemMessage(hWnd, IDC_THANKS, WM_SETFONT, (WPARAM)hPageHeadingFont, TRUE); SendDlgItemMessage(hWnd, IDC_ZILMAR, WM_SETFONT, (WPARAM)hAuthorFont, TRUE); SendDlgItemMessage(hWnd, IDC_JABO, WM_SETFONT, (WPARAM)hAuthorFont, TRUE); SendDlgItemMessage(hWnd, IDC_SMIFF, WM_SETFONT, (WPARAM)hAuthorFont, TRUE); SendDlgItemMessage(hWnd, IDC_GENT, WM_SETFONT, (WPARAM)hAuthorFont, TRUE); SendDlgItemMessage(hWnd, IDC_ZILMAR_DETAILS, WM_SETFONT, (WPARAM)hTextFont, TRUE); SendDlgItemMessage(hWnd, IDC_JABO_DETAILS, WM_SETFONT, (WPARAM)hTextFont, TRUE); SendDlgItemMessage(hWnd, IDC_SMIFF_DETAILS, WM_SETFONT, (WPARAM)hTextFont, TRUE); SendDlgItemMessage(hWnd, IDC_GENT_DETAILS, WM_SETFONT, (WPARAM)hTextFont, TRUE); SendDlgItemMessage(hWnd, IDC_THANK_LIST, WM_SETFONT, (WPARAM)hTextFont, TRUE); stdstr_f VersionDisplay("Version: %s", VER_FILE_VERSION_STR); SetWindowText(GetDlgItem(hWnd, IDC_VERSION), VersionDisplay.c_str()); } break; case WM_CTLCOLORSTATIC: { HDC hdcStatic = (HDC)wParam; SetTextColor(hdcStatic, RGB(0, 0, 0)); SetBkMode(hdcStatic, TRANSPARENT); return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH)); } break; case WM_ERASEBKGND: { HPEN outline; HBRUSH fill; RECT rect; outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF); fill = CreateSolidBrush(0x00FFFFFF); SelectObject((HDC)wParam, outline); SelectObject((HDC)wParam, fill); GetClientRect(hWnd, &rect); Rectangle((HDC)wParam, rect.left, rect.top, rect.right, rect.bottom); } break; case WM_PAINT: { PAINTSTRUCT ps; if (BeginPaint(hWnd, &ps)) { RECT rcClient; GetClientRect(hWnd, &rcClient); BITMAP bmTL_top; GetObject(hbmpBackgroundTop, sizeof(BITMAP), &bmTL_top); HDC memdc = CreateCompatibleDC(ps.hdc); HGDIOBJ save = SelectObject(memdc, hbmpBackgroundTop); BitBlt(ps.hdc, 0, 0, bmTL_top.bmWidth, bmTL_top.bmHeight, memdc, 0, 0, SRCCOPY); SelectObject(memdc, save); DeleteDC(memdc); EndPaint(hWnd, &ps); } } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: if (hbmpBackgroundTop) { DeleteObject(hbmpBackgroundTop); } if (hTextFont) { ::DeleteObject(hTextFont); } if (hPageHeadingFont) { ::DeleteObject(hPageHeadingFont); } if (hAuthorFont) { ::DeleteObject(hAuthorFont); } //ReleaseCapture(); EndDialog(hWnd, 0); break; } default: return FALSE; } return TRUE; }
/* blunt force truma way of achiving alpha blended plotting */ static bool plot_alpha_bitmap(HDC hdc, struct bitmap *bitmap, int x, int y, int width, int height) { #ifdef WINDOWS_GDI_ALPHA_WORKED BLENDFUNCTION blnd = { AC_SRC_OVER, 0, 0xff, AC_SRC_ALPHA }; HDC bmihdc; bool bltres; bmihdc = CreateCompatibleDC(hdc); SelectObject(bmihdc, bitmap->windib); bltres = AlphaBlend(hdc, x, y, width, height, bmihdc, 0, 0, bitmap->width, bitmap->height, blnd); DeleteDC(bmihdc); return bltres; #else HDC Memhdc; BITMAPINFOHEADER bmih; int v, vv, vi, h, hh, width4, transparency; unsigned char alpha; bool isscaled = false; /* set if the scaled bitmap requires freeing */ BITMAP MemBM; BITMAPINFO *bmi; HBITMAP MemBMh; PLOT_LOG(("%p bitmap %d,%d width %d height %d", bitmap, x, y, width, height)); PLOT_LOG(("clipped %ld,%ld to %ld,%ld",plot_clip.left, plot_clip.top, plot_clip.right, plot_clip.bottom)); Memhdc = CreateCompatibleDC(hdc); if (Memhdc == NULL) { return false; } if ((bitmap->width != width) || (bitmap->height != height)) { PLOT_LOG(("scaling from %d,%d to %d,%d", bitmap->width, bitmap->height, width, height)); bitmap = bitmap_scale(bitmap, width, height); if (bitmap == NULL) return false; isscaled = true; } bmi = (BITMAPINFO *) malloc(sizeof(BITMAPINFOHEADER) + (bitmap->width * bitmap->height * 4)); if (bmi == NULL) { DeleteDC(Memhdc); return false; } MemBMh = CreateCompatibleBitmap(hdc, bitmap->width, bitmap->height); if (MemBMh == NULL){ free(bmi); DeleteDC(Memhdc); return false; } /* save 'background' data for alpha channel work */ SelectObject(Memhdc, MemBMh); BitBlt(Memhdc, 0, 0, bitmap->width, bitmap->height, hdc, x, y, SRCCOPY); GetObject(MemBMh, sizeof(BITMAP), &MemBM); bmih.biSize = sizeof(bmih); bmih.biWidth = bitmap->width; bmih.biHeight = bitmap->height; bmih.biPlanes = 1; bmih.biBitCount = 32; bmih.biCompression = BI_RGB; bmih.biSizeImage = 4 * bitmap->height * bitmap->width; bmih.biXPelsPerMeter = 3600; /* 100 dpi */ bmih.biYPelsPerMeter = 3600; bmih.biClrUsed = 0; bmih.biClrImportant = 0; bmi->bmiHeader = bmih; GetDIBits(hdc, MemBMh, 0, bitmap->height, bmi->bmiColors, bmi, DIB_RGB_COLORS); /* then load 'foreground' bits from bitmap->pixdata */ width4 = bitmap->width * 4; for (v = 0, vv = 0, vi = (bitmap->height - 1) * width4; v < bitmap->height; v++, vv += bitmap->width, vi -= width4) { for (h = 0, hh = 0; h < bitmap->width; h++, hh += 4) { alpha = bitmap->pixdata[vi + hh + 3]; /* multiplication of alpha value; subject to profiling could be optional */ if (alpha == 0xFF) { bmi->bmiColors[vv + h].rgbBlue = bitmap->pixdata[vi + hh + 2]; bmi->bmiColors[vv + h].rgbGreen = bitmap->pixdata[vi + hh + 1]; bmi->bmiColors[vv + h].rgbRed = bitmap->pixdata[vi + hh]; } else if (alpha > 0) { transparency = 0x100 - alpha; bmi->bmiColors[vv + h].rgbBlue = (bmi->bmiColors[vv + h].rgbBlue * transparency + (bitmap->pixdata[vi + hh + 2]) * alpha) >> 8; bmi->bmiColors[vv + h].rgbGreen = (bmi->bmiColors[vv + h]. rgbGreen * transparency + (bitmap->pixdata[vi + hh + 1]) * alpha) >> 8; bmi->bmiColors[vv + h].rgbRed = (bmi->bmiColors[vv + h].rgbRed * transparency + bitmap->pixdata[vi + hh] * alpha) >> 8; } } }
/****************************************************************** * EnumMetaFile (GDI.175) * */ BOOL16 WINAPI EnumMetaFile16( HDC16 hdc16, HMETAFILE16 hmf, MFENUMPROC16 lpEnumFunc, LPARAM lpData ) { METAHEADER *mh = MF_GetMetaHeader16(hmf); METARECORD *mr; HANDLETABLE16 *ht; HDC hdc = HDC_32(hdc16); HGLOBAL16 hHT; SEGPTR spht; unsigned int offset = 0; WORD i, seg; HPEN hPen; HBRUSH hBrush; HFONT hFont; WORD args[8]; BOOL16 result = TRUE; TRACE("(%p, %04x, %p, %08lx)\n", hdc, hmf, lpEnumFunc, lpData); if(!mh) return FALSE; /* save the current pen, brush and font */ hPen = GetCurrentObject(hdc, OBJ_PEN); hBrush = GetCurrentObject(hdc, OBJ_BRUSH); hFont = GetCurrentObject(hdc, OBJ_FONT); /* create the handle table */ hHT = GlobalAlloc16(GMEM_MOVEABLE | GMEM_ZEROINIT, FIELD_OFFSET(HANDLETABLE16, objectHandle[mh->mtNoObjects])); spht = WOWGlobalLock16(hHT); seg = hmf | 7; offset = mh->mtHeaderSize * 2; /* loop through metafile records */ args[7] = hdc16; args[6] = SELECTOROF(spht); args[5] = OFFSETOF(spht); args[4] = seg + (HIWORD(offset) << __AHSHIFT); args[3] = LOWORD(offset); args[2] = mh->mtNoObjects; args[1] = HIWORD(lpData); args[0] = LOWORD(lpData); while (offset < (mh->mtSize * 2)) { DWORD ret; mr = (METARECORD *)((char *)mh + offset); WOWCallback16Ex( (DWORD)lpEnumFunc, WCB16_PASCAL, sizeof(args), args, &ret ); if (!LOWORD(ret)) { result = FALSE; break; } offset += (mr->rdSize * 2); args[4] = seg + (HIWORD(offset) << __AHSHIFT); args[3] = LOWORD(offset); } SelectObject(hdc, hBrush); SelectObject(hdc, hPen); SelectObject(hdc, hFont); ht = GlobalLock16(hHT); /* free objects in handle table */ for(i = 0; i < mh->mtNoObjects; i++) if(*(ht->objectHandle + i) != 0) DeleteObject( (HGDIOBJ)(ULONG_PTR)(*(ht->objectHandle + i) )); /* free handle table */ GlobalFree16(hHT); MF_ReleaseMetaHeader16(hmf); return result; }
void Test_MaskBlt_1bpp() { HDC hdcDst, hdcSrc; struct { BITMAPINFOHEADER bmiHeader; ULONG aulColors[2]; } bmiData = {{sizeof(BITMAPINFOHEADER), 8, 1, 1, 1, BI_RGB, 0, 10, 10, 2,0}, {0, 0xFFFFFF}}; PBITMAPINFO pbmi = (PBITMAPINFO)&bmiData; HBITMAP hbmDst, hbmSrc, hbmMsk; PUCHAR pjBitsDst, pjBitsSrc, pjBitsMsk; BOOL ret; /* Create a dest dc and bitmap */ hdcDst = CreateCompatibleDC(NULL); hbmDst = CreateDIBSection(hdcDst, pbmi, DIB_RGB_COLORS, (PVOID*)&pjBitsDst, NULL, 0); SelectObject(hdcDst, hbmDst); /* Create a source dc and bitmap */ hdcSrc = CreateCompatibleDC(NULL); hbmSrc = CreateDIBSection(hdcSrc, pbmi, DIB_RGB_COLORS, (PVOID*)&pjBitsSrc, NULL, 0); SelectObject(hdcSrc, hbmSrc); /* Create a 1 bpp mask bitmap */ hbmMsk = CreateDIBSection(hdcDst, pbmi, DIB_RGB_COLORS, (PVOID*)&pjBitsMsk, NULL, 0); /* Do the masking (SRCCOPY / NOOP) */ pjBitsDst[0] = 0xAA; pjBitsSrc[0] = 0xCC; pjBitsMsk[0] = 0xF0; ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 1, "MaskBlt failed (%d)\n", ret); ok(pjBitsDst[0] == 0xCA, "pjBitsDst[0] == 0x%x\n", pjBitsDst[0]); pjBitsDst[0] = 0x00; pjBitsSrc[0] = 0xFF; pjBitsMsk[0] = 0xF0; ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 1, "MaskBlt failed (%d)\n", ret); ok(pjBitsDst[0] == 0xF0, "pjBitsDst[0] == 0x%x\n", pjBitsDst[0]); /* Do the masking (NOTSRCERASE / SRCINVERT) */ pjBitsDst[0] = 0xF0; // 11110000 pjBitsSrc[0] = 0xCC; // 11001100 pjBitsMsk[0] = 0xAA; // 10101010 ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(NOTSRCERASE, SRCINVERT)); // 22 ok(ret == 1, "MaskBlt failed (%d)\n", ret); ok(pjBitsDst[0] == 0x16, "pjBitsDst[0] == 0x%x\n", pjBitsDst[0]); /* Do the masking (MERGEPAINT / DSxn) */ pjBitsDst[0] = 0xF0; pjBitsSrc[0] = 0xCC; pjBitsMsk[0] = 0xAA; ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(MERGEPAINT, 0x990000)); ok(ret == 1, "MaskBlt failed (%d)\n", ret); ok(pjBitsDst[0] == 0xE3, "pjBitsDst[0] == 0x%x\n", pjBitsDst[0]); /* Try a ROP that needs a mask with a NULL mask bitmap handle */ ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, NULL, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 1, "MaskBlt failed (%d)\n", ret); ok(pjBitsDst[0] == 0xCC, "pjBitsDst[0] == 0x%x\n", pjBitsDst[0]); /* Try a ROP that needs a mask with an invalid mask bitmap handle */ ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, (HBITMAP)0x123456, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 0, "MaskBlt should fail, but succeeded (%d)\n", ret); /* Try a ROP that needs a mask with an invalid mask bitmap */ ok(ghbmp24 != NULL, "ghbmp24 is NULL!\n"); ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, ghbmp24, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 0, "MaskBlt should fail, but succeeded (%d)\n", ret); /* Try a ROP that needs no mask with an invalid mask bitmap */ ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, (HBITMAP)0x123456, 0, 0, MAKEROP4(SRCCOPY, SRCCOPY)); ok(ret == 1, "MaskBlt failed (%d)\n", ret); /* Try (PATCOPY / NOOP) with a NULL source mask and bitmap */ ret = MaskBlt(hdcDst, 0, 0, 8, 1, NULL, 0, 0, NULL, 0, 0, MAKEROP4(PATCOPY, 0xAA0000)); ok(ret == 0, "MaskBlt should fail, but succeeded (%d)\n", ret); /* Try with a mask that is smaller than the rect */ DeleteObject(hbmMsk); pbmi->bmiHeader.biWidth = 4; hbmMsk = CreateDIBSection(hdcDst, pbmi, DIB_RGB_COLORS, (PVOID*)&pjBitsMsk, NULL, 0); /* Do the masking (SRCCOPY / NOOP) */ pjBitsDst[0] = 0xAA; // 10101010 pjBitsSrc[0] = 0xCC; // 11001100 pjBitsMsk[0] = 0x33; // 00110011 ret = MaskBlt(hdcDst, 0, 0, 5, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 0, "MaskBlt should fail, but succeeded (%d)\n", ret); ret = MaskBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, hbmMsk, 1, 0, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 0, "MaskBlt should fail, but succeeded (%d)\n", ret); ret = MaskBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, hbmMsk, 0, 1, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 0, "MaskBlt should fail, but succeeded (%d)\n", ret); ret = MaskBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000)); ok(ret == 1, "MaskBlt failed (%d)\n", ret); ok(pjBitsDst[0] == 0x8A, "pjBitsDst[0] == 0x%x\n", pjBitsDst[0]); }
void Draw2DCorSys(HWND hWnd,HDC hdc,P_2D_COORSYS p2DCoorSys) { HPEN m_COOR_Pen,mOldPen1,m_Grid_Pen,mOldPen2; RECT mOPAixsRect,mHelpRect; HFONT mTextFont1,mTextFont2,mOldFont; int iFontSize; TCHAR chHelpString[200]; // if((p2DCoorSys == NULL) || (hWnd == NULL) || (hdc == NULL)) return; m_COOR_Pen = CreatePen(PS_SOLID,2,RGB(0,0,0)); mOldPen1 = (HPEN)SelectObject(hdc,m_COOR_Pen); //draw X axis MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - p2DCoorSys->shX_MinusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen); //draw arrow MoveToEx(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio - 5, p2DCoorSys->shOP_YinScreen - 5); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio - 5, p2DCoorSys->shOP_YinScreen + 5); //draw Y aixs MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen + p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); //draw arrow MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - 5,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio + 5); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + 5,p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio + 5); //display "+x" iFontSize = 40; mTextFont1 = CreateFont(iFontSize,0,0,0,FW_BOLD, 0/*非斜体*/,0/*不带下划线*/,0,GB2312_CHARSET/*字符集*/,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,(LPCSTR)"Arial"); mOldFont = (HFONT)SelectObject(hdc,mTextFont1); SetTextColor(hdc,RGB(0,0,255)); mOPAixsRect.left = p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio + 5; mOPAixsRect.right = mOPAixsRect.left + 40; mOPAixsRect.top = p2DCoorSys->shOP_YinScreen - 20; mOPAixsRect.bottom = p2DCoorSys->shOP_YinScreen +20; DrawText(hdc,"+x",2,&mOPAixsRect,DT_LEFT | DT_VCENTER); //display "+y" mOPAixsRect.left = p2DCoorSys->shOP_XinScreen - 20; mOPAixsRect.right = mOPAixsRect.left + 40; mOPAixsRect.bottom = p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_PlusAxisValue * p2DCoorSys->shPixelMapRatio +30; mOPAixsRect.top = mOPAixsRect.bottom - 40; DrawText(hdc,"+y",2,&mOPAixsRect,DT_LEFT | DT_VCENTER); //display help information. iFontSize = 15; mTextFont2 = CreateFont(iFontSize,0,0,0,FW_BOLD, 0/*非斜体*/,0/*不带下划线*/,0,GB2312_CHARSET/*字符集*/,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,(LPCSTR)"Arial"); mOldFont = (HFONT)SelectObject(hdc,mTextFont2); SetTextColor(hdc,RGB(255,0,0)); mHelpRect.left = mTextRect.left; mHelpRect.top = mTextRect.top; mHelpRect.bottom = mHelpRect.top + 20; mHelpRect.right = mHelpRect.left + 300; sprintf(chHelpString,"X_OP:%d Y_OP:%d\0",p2DCoorSys->shOP_XinScreen,p2DCoorSys->shOP_YinScreen); DrawText(hdc,chHelpString,strlen(chHelpString),&mHelpRect,DT_LEFT|DT_VCENTER); mHelpRect.top = mHelpRect.bottom; mHelpRect.bottom = mHelpRect.top + 20; sprintf(chHelpString,"Pixel Scale Ratio: 1:%d\0",p2DCoorSys->shPixelMapRatio); DrawText(hdc,chHelpString,strlen(chHelpString),&mHelpRect,DT_LEFT|DT_VCENTER); mHelpRect.top = mHelpRect.bottom; mHelpRect.bottom = mHelpRect.top + 20; sprintf(chHelpString,"Mouse_X:%d Mouse_Y:%d\0",p2DCoorSys->shMouseXPos,p2DCoorSys->shMouseYPos); DrawText(hdc,chHelpString,strlen(chHelpString),&mHelpRect,DT_LEFT|DT_VCENTER); //draw grid. if(p2DCoorSys->bShowGrid) { int iTmp; m_Grid_Pen = CreatePen(PS_SOLID,1,RGB(255,0,0)); mOldPen2 = (HPEN)SelectObject(hdc,m_Grid_Pen); for(iTmp = 1; iTmp <= p2DCoorSys->shX_PlusAxisValue; iTmp++) { MoveToEx(hdc,p2DCoorSys->shOP_XinScreen + iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen + p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen + iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); } for(iTmp = 1; iTmp <= p2DCoorSys->shX_PlusAxisValue; iTmp++) { MoveToEx(hdc,p2DCoorSys->shOP_XinScreen - iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen + p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen - iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - iTmp * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen - p2DCoorSys->shY_MinusAxisValue * p2DCoorSys->shPixelMapRatio); } for(iTmp = 1; iTmp <= p2DCoorSys->shY_PlusAxisValue; iTmp++) { MoveToEx(hdc,p2DCoorSys->shOP_XinScreen, p2DCoorSys->shOP_YinScreen - iTmp * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen - iTmp * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen, p2DCoorSys->shOP_YinScreen - iTmp * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen - iTmp * p2DCoorSys->shPixelMapRatio); } for(iTmp = 1; iTmp <= p2DCoorSys->shY_MinusAxisValue; iTmp++) { MoveToEx(hdc,p2DCoorSys->shOP_XinScreen, p2DCoorSys->shOP_YinScreen + iTmp * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen + p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen + iTmp * p2DCoorSys->shPixelMapRatio); MoveToEx(hdc,p2DCoorSys->shOP_XinScreen, p2DCoorSys->shOP_YinScreen + iTmp * p2DCoorSys->shPixelMapRatio,NULL); LineTo(hdc,p2DCoorSys->shOP_XinScreen - p2DCoorSys->shX_PlusAxisValue * p2DCoorSys->shPixelMapRatio, p2DCoorSys->shOP_YinScreen + iTmp * p2DCoorSys->shPixelMapRatio); } } SelectObject(hdc,mOldPen1); SelectObject(hdc,mOldPen2); DeleteObject(m_COOR_Pen); DeleteObject(m_Grid_Pen); SelectObject(hdc,mOldFont); DeleteObject(mOldFont); return; }
/* helper functions */ DWORD notification_daemon_main(LPVOID lpdwThreadParam) { HINSTANCE hDLLInstance = (HINSTANCE) GetModuleHandle(NULL); WNDCLASSEX wcex = {sizeof(WNDCLASSEX)}; wchar_t szTitle[] = L"libnotify_notification"; wchar_t szWindowClass[] = L"libnotify"; HDC hdc = NULL; HGDIOBJ hOldFont = NULL; RECT rc = {0}; MSG msg = {0}; /* register window class */ wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW; wcex.lpfnWndProc = notificationWndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hDLLInstance; wcex.hIcon = NULL; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = NULL; if(0 == RegisterClassEx(&wcex)) return ((DWORD) -1); /* create the notification window */ notify_wnd.notification_window = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_LAYERED | WS_EX_TRANSPARENT, szWindowClass, szTitle, WS_OVERLAPPED | WS_POPUP, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hDLLInstance, NULL); if(!notify_wnd.notification_window) return ((DWORD) -1); /* height and width set here are dummy, they will later be reset based on DrawText */ notify_wnd.notification_window_width = notification_window_width_max; notify_wnd.notification_window_height = notify_wnd.notification_window_width / 4; /* setting wnd's alpha should be done before hiding the window (SetWindowPos); calling it after hiding leads to high CPU usage due to continous WM_PAINT messages there by wasting CPU cycles with transparent draw (BlendFunction) calls; this stops only after the first time the window is hidden i.e. after a notify_notification_close is called (which would be after a show request; refer Bug 1010930 & Question 184541 */ if(!SetLayeredWindowAttributes(notify_wnd.notification_window, 0, 0, LWA_ALPHA)) return ((DWORD) -1); if(!SetWindowPos(notify_wnd.notification_window, HWND_TOPMOST, 0, 0, notification_window_width_max, notification_window_width_max / 4, SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOREPOSITION)) return ((DWORD) -1); hdc = GetDC(notify_wnd.notification_window); if(hdc) { hOldFont = SelectObject(hdc, (HGDIOBJ) font_summary); if(hOldFont) { /* set the width and get the height for a single line (summary) from DrawText; for rational on width calc., see the above geometry */ rc.right = notify_wnd.notification_window_width - (icon_size + (icon_padding * 3)); DrawText(hdc, L"placeholder", -1, &rc, DT_CALCRECT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); notify_wnd.summary_body_divider = (uint16_t) rc.bottom; SelectObject(hdc, hOldFont); } ReleaseDC(notify_wnd.notification_window, hdc); if(!hOldFont) return ((DWORD) -1); } else return ((DWORD) -1); // signal that the library initialization was successful before entering in to the message loop SetEvent((HANDLE) lpdwThreadParam); BOOL mesg_status = FALSE; while((mesg_status = GetMessage(&msg, NULL, 0, 0))) { if(-1 != mesg_status) { // these are sent as thread messages and not window messages, hence route it to the // window proc., passing the right HWND, since msg's HWND will be NULL if((msg.message >= WM_LIBNOTIFYSHOW) && (msg.message <= WM_LIBNOTIFYEXIT)) { notificationWndProc(notify_wnd.notification_window, msg.message, msg.wParam, msg.lParam); } else { DispatchMessage(&msg); } } else { return GetLastError(); } } return msg.wParam; }
void CALLBACK PaintPageGraphic(LPWIZARD pWiz, HDC hdc, LPRECT prTarget, HPALETTE hpal) { static HFONT hFont = AfsAppLib_CreateFont(IDS_GRAPHIC_FONT); static HPEN hPenWhite = CreatePen(PS_SOLID, 1, clrWHITE); static HPEN hPenHighlight = CreatePen(PS_SOLID, 1, clrHIGHLIGHT); static HPEN hPenShadow = CreatePen(PS_SOLID, 1, clrSHADOW); static HPEN hPenBlack = CreatePen(PS_SOLID, 1, clrBLACK); static HPEN hPenBarIntLeft = CreatePen(PS_SOLID, 1, clrBAR_INT_LEFT); static HPEN hPenBarIntRight = CreatePen(PS_SOLID, 1, clrBAR_INT_RIGHT); static HPEN hPenArrowInterior = CreatePen(PS_SOLID, 1, clrARROW_INTERIOR); // First find out where we'll be drawing things. RECT rArea; rArea.top = prTarget->bottom - cyAREA - cyBOTTOM_MARGIN; rArea.bottom = prTarget->bottom - cyBOTTOM_MARGIN; rArea.left = prTarget->left + cxLEFT_MARGIN; rArea.right = prTarget->right - cxRIGHT_MARGIN; // Draw the "Current Step:" text HGDIOBJ hFontOld = SelectObject(hdc, hFont); COLORREF clrTextOld = SetTextColor (hdc, clrTEXT_CURRENT); SetBkMode (hdc, TRANSPARENT); TCHAR szText[cchRESOURCE]; GetResString(IDS_CURRENT_STEP, szText); RECT rText = rArea; DWORD dwFlags = DT_CENTER | DT_TOP | DT_SINGLELINE; DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags | DT_CALCRECT, NULL); rText.right = rArea.right; DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL); // Draw the progress bar; it should look like this: // wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww // (w=white, b=black... // whhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhb // h=highlight, s=shadow... // whllllllllllllllllrrrrrrrrrrrrrrrsb // l=left/int, r=right/int) // whllllllllllllllllrrrrrrrrrrrrrrrsb // l=left/int, r=right/int) // whssssssssssssssssssssssssssssssssb // h=highlight, s=shadow... // wbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb // h=highlight, s=shadow... // Oh--we'll need to know where the pointer's point should go. We'll // make that be where the leftmost dot of the pointer's tip, and the // rightmost dot that's colored "l". One state 0, we want the pointer // to be all the way to the left--and on state {g_nNumStates-1}, we want // it all the way to the right RECT rBar = rArea; rBar.top = rText.bottom + cyBELOW_CURRENT; rBar.bottom = rBar.top + 6; RECT rBarInterior = rBar; InflateRect (&rBarInterior, -2, -2); int nStepSize = (rBarInterior.right - rBarInterior.left) / (g_nNumStates-1); int xCurPos = rBarInterior.left + (g_pWiz->GetState() * nStepSize); if (!g_pWiz->GetState()) xCurPos = rBarInterior.left-1; // don't draw *any* green else if (g_pWiz->GetState() == (int)(g_nNumStates-1)) xCurPos = rBarInterior.right-1; // don't draw *any* red // Draw that bar! HGDIOBJ hPenOld = SelectObject (hdc, hPenWhite); MoveToEx (hdc, rBar.left, rBar.bottom-1, 0); LineTo (hdc, rBar.left, rBar.top); LineTo (hdc, rBar.right, rBar.top); MoveToEx (hdc, rBar.left, rBar.bottom, 0); SelectObject (hdc, hPenHighlight); MoveToEx (hdc, rBar.left+1, rBar.bottom-2, 0); LineTo (hdc, rBar.left+1, rBar.top+1); LineTo (hdc, rBar.right-1, rBar.top+1); SelectObject (hdc, hPenShadow); MoveToEx (hdc, rBar.left+2, rBar.bottom-2, 0); LineTo (hdc, rBar.right-2, rBar.bottom-2); LineTo (hdc, rBar.right-2, rBar.top+1); SelectObject (hdc, hPenBlack); MoveToEx (hdc, rBar.left+1, rBar.bottom-1, 0); LineTo (hdc, rBar.right-1, rBar.bottom-1); LineTo (hdc, rBar.right-1, rBar.top); if (xCurPos >= rBarInterior.left) { SelectObject (hdc, hPenBarIntLeft); MoveToEx (hdc, rBarInterior.left, rBarInterior.top, 0); LineTo (hdc, xCurPos+1, rBarInterior.top); MoveToEx (hdc, rBarInterior.left, rBarInterior.top+1, 0); LineTo (hdc, xCurPos+1, rBarInterior.top+1); } if (xCurPos < rBarInterior.right-1) { SelectObject (hdc, hPenBarIntRight); MoveToEx (hdc, xCurPos+1, rBarInterior.top, 0); LineTo (hdc, rBarInterior.right, rBarInterior.top); MoveToEx (hdc, xCurPos+1, rBarInterior.top+1, 0); LineTo (hdc, rBarInterior.right, rBarInterior.top+1); } SelectObject (hdc, hPenOld); // Draw the arrow underneath it; it should look like this: // wb // whsb // whassb // whaaassb // whaaaaassb // wssssssssssb // Remember that the topmost "w" is where xCurPos is. RECT rArrow; rArrow.top = rBar.bottom +1; rArrow.bottom = rArrow.top +6; rArrow.left = xCurPos -5; rArrow.right = xCurPos +7; hPenOld = SelectObject (hdc, hPenWhite); MoveToEx (hdc, rArrow.left, rArrow.bottom-1, 0); LineTo (hdc, xCurPos+1, rArrow.top-1); SelectObject (hdc, hPenHighlight); MoveToEx (hdc, rArrow.left+2, rArrow.bottom-2, 0); LineTo (hdc, xCurPos+1, rArrow.top); SelectObject (hdc, hPenShadow); MoveToEx (hdc, rArrow.left+1, rArrow.bottom-1, 0); LineTo (hdc, rArrow.right-1, rArrow.bottom-1); MoveToEx (hdc, xCurPos+1, rArrow.top+1, 0); LineTo (hdc, rArrow.right, rArrow.bottom); MoveToEx (hdc, xCurPos+1, rArrow.top+2, 0); LineTo (hdc, rArrow.right-1, rArrow.bottom); SelectObject (hdc, hPenBlack); MoveToEx (hdc, xCurPos+1, rArrow.top, 0); LineTo (hdc, rArrow.right, rArrow.bottom); // wb // whsb // whassb // whaaassb // whaaaaassb // wssssssssssb SelectObject (hdc, hPenArrowInterior); MoveToEx (hdc, xCurPos, rArrow.top+2, 0); LineTo (hdc, xCurPos+1, rArrow.top+2); MoveToEx (hdc, xCurPos-1, rArrow.top+3, 0); LineTo (hdc, xCurPos+2, rArrow.top+3); MoveToEx (hdc, xCurPos-2, rArrow.top+4, 0); LineTo (hdc, xCurPos+3, rArrow.top+4); SelectObject (hdc, hPenOld); // Draw the description text SetTextColor (hdc, clrTEXT_STEP); GetResString(g_StateDesc[g_pWiz->GetState()], szText); rText = rArea; rText.top = rArrow.bottom + cyBELOW_ARROW; dwFlags = DT_CENTER | DT_TOP | DT_WORDBREAK; DrawTextEx (hdc, szText, lstrlen(szText), &rText, dwFlags, NULL); SetTextColor (hdc, clrTextOld); SelectObject (hdc, hFontOld); }
// // 函数: 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 POINT apt[4]; static int cxClient, cyClient; switch (message) { case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); apt[0].x = cxClient/4; apt[0].y = cyClient/2; apt[1].x = cxClient/2; apt[1].y = cyClient/4; apt[2].x = cxClient/2; apt[2].y = cyClient/4*3; apt[3].x = cxClient/4*3; apt[3].y = cyClient/2; 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: 在此添加任意绘图代码... PolyBezier(hdc, apt, 4); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: hdc = GetDC(hWnd); SelectObject(hdc, GetStockObject(WHITE_PEN)); PolyBezier(hdc, apt, 4); apt[1].x = LOWORD(lParam); apt[1].y = HIWORD(lParam); SelectObject(hdc, GetStockObject(BLACK_PEN)); PolyBezier(hdc, apt, 4); ReleaseDC(hWnd, hdc); break; case WM_RBUTTONDOWN: hdc = GetDC(hWnd); SelectObject(hdc, GetStockObject(WHITE_PEN)); PolyBezier(hdc, apt, 4); apt[2].x = LOWORD(lParam); apt[2].y = HIWORD(lParam); SelectObject(hdc, GetStockObject(BLACK_PEN)); PolyBezier(hdc, apt, 4); ReleaseDC(hWnd, hdc); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
static bool rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { PLOT_LOG(("rectangle from %d,%d to %d,%d", x0, y0, x1, y1)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { LOG(("HDC not set on call to plotters")); return false; } HRGN clipregion = CreateRectRgnIndirect(&plot_clip); if (clipregion == NULL) { return false; } x1++; y1++; COLORREF pencol = (DWORD)(style->stroke_colour & 0x00FFFFFF); DWORD penstyle = PS_GEOMETRIC | (style->stroke_type == PLOT_OP_TYPE_DOT ? PS_DOT : (style->stroke_type == PLOT_OP_TYPE_DASH ? PS_DASH : (style->stroke_type == PLOT_OP_TYPE_NONE ? PS_NULL : 0))); LOGBRUSH lb = {BS_SOLID, pencol, 0}; LOGBRUSH lb1 = {BS_SOLID, style->fill_colour, 0}; if (style->fill_type == PLOT_OP_TYPE_NONE) lb1.lbStyle = BS_HOLLOW; HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); if (pen == NULL) { return false; } HGDIOBJ penbak = SelectObject(plot_hdc, (HGDIOBJ) pen); if (penbak == NULL) { DeleteObject(pen); return false; } HBRUSH brush = CreateBrushIndirect(&lb1); if (brush == NULL) { SelectObject(plot_hdc, penbak); DeleteObject(pen); return false; } HGDIOBJ brushbak = SelectObject(plot_hdc, (HGDIOBJ) brush); if (brushbak == NULL) { SelectObject(plot_hdc, penbak); DeleteObject(pen); DeleteObject(brush); return false; } SelectClipRgn(plot_hdc, clipregion); Rectangle(plot_hdc, x0, y0, x1, y1); pen = SelectObject(plot_hdc, penbak); brush = SelectObject(plot_hdc, brushbak); SelectClipRgn(plot_hdc, NULL); DeleteObject(pen); DeleteObject(brush); DeleteObject(clipregion); return true; }
int drawText(const char * pszText, SIZE& tSize, Device::TextAlign eAlign) { int nRet = 0; wchar_t * pwszBuffer = 0; do { CC_BREAK_IF(! pszText); DWORD dwFmt = DT_WORDBREAK; DWORD dwHoriFlag = (int)eAlign & 0x0f; DWORD dwVertFlag = ((int)eAlign & 0xf0) >> 4; switch (dwHoriFlag) { case 1: // left dwFmt |= DT_LEFT; break; case 2: // right dwFmt |= DT_RIGHT; break; case 3: // center dwFmt |= DT_CENTER; break; } int nLen = strlen(pszText); // utf-8 to utf-16 int nBufLen = nLen + 1; pwszBuffer = new wchar_t[nBufLen]; CC_BREAK_IF(! pwszBuffer); memset(pwszBuffer, 0, sizeof(wchar_t)*nBufLen); nLen = MultiByteToWideChar(CP_UTF8, 0, pszText, nLen, pwszBuffer, nBufLen); SIZE newSize = sizeWithText(pwszBuffer, nLen, dwFmt, tSize.cx); RECT rcText = {0}; // if content width is 0, use text size as content size if (tSize.cx <= 0) { tSize = newSize; rcText.right = newSize.cx; rcText.bottom = newSize.cy; } else { LONG offsetX = 0; LONG offsetY = 0; rcText.right = newSize.cx; // store the text width to rectangle // calculate text horizontal offset if (1 != dwHoriFlag // and text isn't align to left && newSize.cx < tSize.cx) // and text's width less then content width, { // then need adjust offset of X. offsetX = (2 == dwHoriFlag) ? tSize.cx - newSize.cx // align to right : (tSize.cx - newSize.cx) / 2; // align to center } // if content height is 0, use text height as content height // else if content height less than text height, use content height to draw text if (tSize.cy <= 0) { tSize.cy = newSize.cy; dwFmt |= DT_NOCLIP; rcText.bottom = newSize.cy; // store the text height to rectangle } else if (tSize.cy < newSize.cy) { // content height larger than text height need, clip text to rect rcText.bottom = tSize.cy; } else { rcText.bottom = newSize.cy; // store the text height to rectangle // content larger than text, need adjust vertical position dwFmt |= DT_NOCLIP; // calculate text vertical offset offsetY = (2 == dwVertFlag) ? tSize.cy - newSize.cy // align to bottom : (3 == dwVertFlag) ? (tSize.cy - newSize.cy) / 2 // align to middle : 0; // align to top } if (offsetX || offsetY) { OffsetRect(&rcText, offsetX, offsetY); } } CC_BREAK_IF(! prepareBitmap(tSize.cx, tSize.cy)); // draw text HGDIOBJ hOldFont = SelectObject(_DC, _font); HGDIOBJ hOldBmp = SelectObject(_DC, _bmp); SetBkMode(_DC, TRANSPARENT); SetTextColor(_DC, RGB(255, 255, 255)); // white color // draw text nRet = DrawTextW(_DC, pwszBuffer, nLen, &rcText, dwFmt); //DrawTextA(_DC, pszText, nLen, &rcText, dwFmt); SelectObject(_DC, hOldBmp); SelectObject(_DC, hOldFont); } while (0); CC_SAFE_DELETE_ARRAY(pwszBuffer); return nRet; }
static bool polygon(const int *p, unsigned int n, const plot_style_t *style) { PLOT_LOG(("polygon %d points", n)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { LOG(("HDC not set on call to plotters")); return false; } POINT points[n]; unsigned int i; HRGN clipregion = CreateRectRgnIndirect(&plot_clip); if (clipregion == NULL) { return false; } COLORREF pencol = (DWORD)(style->fill_colour & 0x00FFFFFF); COLORREF brushcol = (DWORD)(style->fill_colour & 0x00FFFFFF); HPEN pen = CreatePen(PS_GEOMETRIC | PS_NULL, 1, pencol); if (pen == NULL) { DeleteObject(clipregion); return false; } HPEN penbak = SelectObject(plot_hdc, pen); if (penbak == NULL) { DeleteObject(clipregion); DeleteObject(pen); return false; } HBRUSH brush = CreateSolidBrush(brushcol); if (brush == NULL) { DeleteObject(clipregion); SelectObject(plot_hdc, penbak); DeleteObject(pen); return false; } HBRUSH brushbak = SelectObject(plot_hdc, brush); if (brushbak == NULL) { DeleteObject(clipregion); SelectObject(plot_hdc, penbak); DeleteObject(pen); DeleteObject(brush); return false; } SetPolyFillMode(plot_hdc, WINDING); for (i = 0; i < n; i++) { points[i].x = (long) p[2 * i]; points[i].y = (long) p[2 * i + 1]; PLOT_LOG(("%ld,%ld ", points[i].x, points[i].y)); } SelectClipRgn(plot_hdc, clipregion); if (n >= 2) Polygon(plot_hdc, points, n); SelectClipRgn(plot_hdc, NULL); pen = SelectObject(plot_hdc, penbak); brush = SelectObject(plot_hdc, brushbak); DeleteObject(clipregion); DeleteObject(pen); DeleteObject(brush); return true; }
/********************************************************* ** ** Adds a new font to the buffer. ** ** If no space is available, the least used font is ** replaced. ** ** NOTE: If an existing font is being replaced, ** the function selects the SYSTEM font into the ** given HDC so that it can be sure that the font ** being deleted is not currently selected. ** **********************************************************/ BOOL __far __pascal AddFont( HWND hWnd, HFONTBUFFER hFontBuffer, HFONT hFont, WORD wFontNumber ) { FPFONTBUFFER fpFontBuffer; FPFONTINFO fpFontInfo, fpFontLeastUsed; WORD wIndex; HDC hDC; /* No font buffer. */ if( hFontBuffer == NULL ) return FALSE; /* Get pointer to the font buffer. */ fpFontBuffer = ( FPFONTBUFFER ) GlobalLock( hFontBuffer ); /* Get pointer to the first font info node. */ fpFontInfo = GlobalLock( fpFontBuffer->hFontInfo ); /* If we haven't reached - add space for the new font to the buffer. */ if( fpFontBuffer->wNumFonts < MAX_FONTS ) { /* Skip to the next unused slot.*/ fpFontInfo = fpFontInfo + fpFontBuffer->wNumFonts; /* ** Increment the count of how many fonts are ** in the font buffer. */ fpFontBuffer->wNumFonts = fpFontBuffer->wNumFonts + 1; } /* We've reached maximum buffer space. */ else { /* 1st font will be replaced. */ fpFontLeastUsed = fpFontInfo; /* Find the font that hasn't been used for the longest time. */ for( wIndex = 0; wIndex < fpFontBuffer->wNumFonts; wIndex++ ) { /* Last time font used. */ if( fpFontInfo->dwTickCount < fpFontLeastUsed->dwTickCount ) { /* New replacement font. */ fpFontLeastUsed = fpFontInfo; } /* Goto next node. */ fpFontInfo++; } /* Make sure the font is not selected. */ hDC = GetDC( hWnd ); SelectObject( hDC, GetStockObject( SYSTEM_FONT ) ); ReleaseDC( hWnd, hDC ); /* Free the least used font. */ DeleteObject( fpFontInfo->hFont ); /* Point to the least used slot. */ fpFontInfo = fpFontLeastUsed; } /* Modify the data. */ fpFontInfo->wFontNumber = wFontNumber; fpFontInfo->hFont = hFont; fpFontInfo->dwTickCount = GetTickCount(); /* Unlock the font info. */ GlobalUnlock( fpFontBuffer->hFontInfo ); /* Unlock the font buffer. */ GlobalUnlock( hFontBuffer ); /* Success. */ return( TRUE ); }
static bool disc(int x, int y, int radius, const plot_style_t *style) { PLOT_LOG(("disc at %d,%d radius %d", x, y, radius)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { LOG(("HDC not set on call to plotters")); return false; } HRGN clipregion = CreateRectRgnIndirect(&plot_clip); if (clipregion == NULL) { return false; } COLORREF col = (DWORD)((style->fill_colour | style->stroke_colour) & 0x00FFFFFF); HPEN pen = CreatePen(PS_GEOMETRIC | PS_SOLID, 1, col); if (pen == NULL) { DeleteObject(clipregion); return false; } HGDIOBJ penbak = SelectObject(plot_hdc, (HGDIOBJ) pen); if (penbak == NULL) { DeleteObject(clipregion); DeleteObject(pen); return false; } HBRUSH brush = CreateSolidBrush(col); if (brush == NULL) { DeleteObject(clipregion); SelectObject(plot_hdc, penbak); DeleteObject(pen); return false; } HGDIOBJ brushbak = SelectObject(plot_hdc, (HGDIOBJ) brush); if (brushbak == NULL) { DeleteObject(clipregion); SelectObject(plot_hdc, penbak); DeleteObject(pen); DeleteObject(brush); return false; } /* RECT r; r.left = x - radius; r.top = y - radius; r.right = x + radius; r.bottom = y + radius; */ SelectClipRgn(plot_hdc, clipregion); if (style->fill_type == PLOT_OP_TYPE_NONE) Arc(plot_hdc, x - radius, y - radius, x + radius, y + radius, x - radius, y - radius, x - radius, y - radius); else Ellipse(plot_hdc, x - radius, y - radius, x + radius, y + radius); SelectClipRgn(plot_hdc, NULL); pen = SelectObject(plot_hdc, penbak); brush = SelectObject(plot_hdc, brushbak); DeleteObject(clipregion); DeleteObject(pen); DeleteObject(brush); return true; }
static LRESULT WINAPI submenuWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { const int itemheight = 12, lcol=12, rcol=12, mcol=10; switch (uMsg) { case WM_CREATE: m_trackingMenus.Add(hwnd); SetWindowLongPtr(hwnd,GWLP_USERDATA,lParam); if (m_trackingPar && !(m_trackingFlags&TPM_NONOTIFY)) SendMessage(m_trackingPar,WM_INITMENUPOPUP,(WPARAM)lParam,0); { HDC hdc = GetDC(hwnd); HMENU__ *menu = (HMENU__*)lParam; int ht = menu->items.GetSize()*itemheight, wid=100,wid2=0; int xpos=m_trackingPt.x; int ypos=m_trackingPt.y; int x; for (x=0; x < menu->items.GetSize(); x++) { MENUITEMINFO *inf = menu->items.Get(x); if (inf->fType == MFT_STRING && inf->dwTypeData) { RECT r={0,}; const char *pt2 = strstr(inf->dwTypeData,"\t"); DrawText(hdc,inf->dwTypeData,pt2 ? pt2-inf->dwTypeData : -1,&r,DT_CALCRECT|DT_SINGLELINE); if (r.right > wid) wid=r.right; if (pt2) { r.right=r.left; DrawText(hdc,pt2+1,-1,&r,DT_CALCRECT|DT_SINGLELINE); if (r.right > wid2) wid2=r.right; } } } wid+=lcol+rcol + (wid2?wid2+mcol:0); ReleaseDC(hwnd,hdc); RECT tr={xpos,ypos,xpos+wid,ypos+ht},vp; SWELL_GetViewPort(&vp,&tr,true); if (tr.bottom > vp.bottom) { tr.top += vp.bottom-tr.bottom; tr.bottom=vp.bottom; } if (tr.right > vp.right) { tr.left += vp.right-tr.right; tr.right=vp.right; } if (tr.left < vp.left) { tr.right += vp.left-tr.left; tr.left=vp.left; } if (tr.top < vp.top) { tr.bottom += vp.top-tr.top; tr.top=vp.top; } SetWindowPos(hwnd,NULL,tr.left,tr.top,tr.right-tr.left,tr.bottom-tr.top,SWP_NOZORDER); } SetWindowLong(hwnd,GWL_STYLE,GetWindowLong(hwnd,GWL_STYLE)&~WS_CAPTION); ShowWindow(hwnd,SW_SHOW); SetFocus(hwnd); SetTimer(hwnd,1,250,NULL); break; case WM_PAINT: { PAINTSTRUCT ps; if (BeginPaint(hwnd,&ps)) { RECT cr; GetClientRect(hwnd,&cr); HBRUSH br=CreateSolidBrush(GetSysColor(COLOR_3DFACE)); HPEN pen=CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DSHADOW)); HGDIOBJ oldbr = SelectObject(ps.hdc,br); HGDIOBJ oldpen = SelectObject(ps.hdc,pen); Rectangle(ps.hdc,cr.left,cr.top,cr.right-1,cr.bottom-1); SetBkMode(ps.hdc,TRANSPARENT); int cols[2]={ GetSysColor(COLOR_BTNTEXT),GetSysColor(COLOR_3DHILIGHT)}; HMENU__ *menu = (HMENU__*)GetWindowLongPtr(hwnd,GWLP_USERDATA); int x; for (x=0; x < menu->items.GetSize(); x++) { MENUITEMINFO *inf = menu->items.Get(x); RECT r={lcol,x*itemheight,cr.right,(x+1)*itemheight}; bool dis = !!(inf->fState & MF_GRAYED); SetTextColor(ps.hdc,cols[dis]); if (inf->fType == MFT_STRING && inf->dwTypeData) { const char *pt2 = strstr(inf->dwTypeData,"\t"); DrawText(ps.hdc,inf->dwTypeData,pt2 ? pt2-inf->dwTypeData : -1,&r,DT_VCENTER|DT_SINGLELINE); if (pt2) { RECT tr=r; tr.right-=rcol; DrawText(ps.hdc,pt2+1,-1,&tr,DT_VCENTER|DT_SINGLELINE|DT_RIGHT); } } else { MoveToEx(ps.hdc,r.left - lcol/2,(r.top+r.bottom)/2,NULL); LineTo(ps.hdc,r.right - rcol*3/2,(r.top+r.bottom)/2); } if (inf->hSubMenu) { RECT r2=r; r2.left = r2.right - rcol; DrawText(ps.hdc,">",-1,&r2,DT_VCENTER|DT_RIGHT|DT_SINGLELINE); } if (inf->fState&MF_CHECKED) { RECT r2=r; r2.left = 0; r2.right=lcol; DrawText(ps.hdc,"X",-1,&r2,DT_VCENTER|DT_CENTER|DT_SINGLELINE); } } SelectObject(ps.hdc,oldbr); SelectObject(ps.hdc,oldpen); DeleteObject(br); DeleteObject(pen); EndPaint(hwnd,&ps); } } break; case WM_TIMER: if (wParam==1) { HWND GetFocusIncludeMenus(); HWND h = GetFocusIncludeMenus(); if (h!=hwnd) { int a = h ? m_trackingMenus.Find(h) : -1; if (a<0 || a < m_trackingMenus.Find(hwnd)) DestroyWindow(hwnd); } } break; case WM_DESTROY: { int a = m_trackingMenus.Find(hwnd); m_trackingMenus.Delete(a); if (m_trackingMenus.Get(a)) DestroyWindow(m_trackingMenus.Get(a)); RemoveProp(hwnd,"SWELL_MenuOwner"); } break; case WM_LBUTTONUP: case WM_RBUTTONUP: { RECT r; GetClientRect(hwnd,&r); if (GET_X_LPARAM(lParam)>=r.left && GET_X_LPARAM(lParam)<r.right) { int which = GET_Y_LPARAM(lParam)/itemheight; HMENU__ *menu = (HMENU__*)GetWindowLongPtr(hwnd,GWLP_USERDATA); MENUITEMINFO *inf = menu->items.Get(which); if (inf) { if (inf->fState&MF_GRAYED){ } else if (inf->hSubMenu) { int a = m_trackingMenus.Find(hwnd); HWND next = m_trackingMenus.Get(a+1); if (next) DestroyWindow(next); m_trackingPt.x=r.right; m_trackingPt.y=r.top + which*itemheight; ClientToScreen(hwnd,&m_trackingPt); HWND hh; submenuWndProc(hh=new HWND__(NULL,0,NULL,"menu",false,submenuWndProc,NULL),WM_CREATE,0,(LPARAM)inf->hSubMenu); SetProp(hh,"SWELL_MenuOwner",GetProp(hh,"SWELL_MenuOwner")); } else if (inf->wID) m_trackingRet = inf->wID; } else DestroyWindow(hwnd); } else DestroyWindow(hwnd); } break; } return DefWindowProc(hwnd,uMsg,wParam,lParam); }
static bool arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style) { PLOT_LOG(("arc centre %d,%d radius %d from %d to %d", x, y, radius, angle1, angle2)); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { LOG(("HDC not set on call to plotters")); return false; } HRGN clipregion = CreateRectRgnIndirect(&plot_clip); if (clipregion == NULL) { return false; } COLORREF col = (DWORD)(style->stroke_colour & 0x00FFFFFF); HPEN pen = CreatePen(PS_GEOMETRIC | PS_SOLID, 1, col); if (pen == NULL) { DeleteObject(clipregion); return false; } HGDIOBJ penbak = SelectObject(plot_hdc, (HGDIOBJ) pen); if (penbak == NULL) { DeleteObject(clipregion); DeleteObject(pen); return false; } int q1, q2; double a1=1.0, a2=1.0, b1=1.0, b2=1.0; q1 = (int) ((angle1 + 45) / 90) - 45; q2 = (int) ((angle2 + 45) / 90) - 45; while (q1 > 4) q1 -= 4; while (q2 > 4) q2 -= 4; while (q1 <= 0) q1 += 4; while (q2 <= 0) q2 += 4; angle1 = ((angle1 + 45) % 90) - 45; angle2 = ((angle2 + 45) % 90) - 45; switch(q1) { case 1: a1 = 1.0; b1 = -tan((M_PI / 180) * angle1); break; case 2: b1 = -1.0; a1 = -tan((M_PI / 180) * angle1); break; case 3: a1 = -1.0; b1 = tan((M_PI / 180) * angle1); break; case 4: b1 = 1.0; a1 = tan((M_PI / 180) * angle1); break; } switch(q2) { case 1: a2 = 1.0; b2 = -tan((M_PI / 180) * angle2); break; case 2: b2 = -1.0; a2 = -tan((M_PI / 180) * angle2); break; case 3: a2 = -1.0; b2 = tan((M_PI / 180) * angle2); break; case 4: b2 = 1.0; a2 = tan((M_PI / 180) * angle2); break; } /* RECT r; r.left = x - radius; r.top = y - radius; r.right = x + radius; r.bottom = y + radius; */ SelectClipRgn(plot_hdc, clipregion); Arc(plot_hdc, x - radius, y - radius, x + radius, y + radius, x + (int)(a1 * radius), y + (int)(b1 * radius), x + (int)(a2 * radius), y + (int)(b2 * radius)); SelectClipRgn(plot_hdc, NULL); pen = SelectObject(plot_hdc, penbak); DeleteObject(clipregion); DeleteObject(pen); return true; }
/***************************************************************************** * Select a fixed font into the printer DC. Since the DC is scaled for rows * and columns, we set the font size to 1x1 always. * This function returns a handle to the previous selected font. *****************************************************************************/ static HFONT SetFont( void ) { // Create font lf.lfWidth = lf.lfHeight = 1; return ( HFONT )SelectObject( pd.hDC, CreateFontIndirect( &lf ) ); }
static VOID MonthCalPaint(IN PMONTHCALWND infoPtr, IN HDC hDC, IN LPRECT prcUpdate) { LONG x, y; RECT rcCell; COLORREF crOldText, crOldCtrlText = CLR_INVALID; HFONT hOldFont; INT iOldBkMode; #if MONTHCAL_CTRLBG != MONTHCAL_DISABLED_CTRLBG if (!infoPtr->Enabled) { FillRect(hDC, prcUpdate, GetSysColorBrush(MONTHCAL_DISABLED_CTRLBG)); } #endif iOldBkMode = SetBkMode(hDC, TRANSPARENT); hOldFont = (HFONT)SelectObject(hDC, infoPtr->hFont); for (y = prcUpdate->top / infoPtr->CellSize.cy; y <= prcUpdate->bottom / infoPtr->CellSize.cy && y < 7; y++) { rcCell.top = y * infoPtr->CellSize.cy; rcCell.bottom = rcCell.top + infoPtr->CellSize.cy; if (y == 0) { RECT rcHeader; /* Paint the header */ rcHeader.left = prcUpdate->left; rcHeader.top = rcCell.top; rcHeader.right = prcUpdate->right; rcHeader.bottom = rcCell.bottom; FillRect(hDC, &rcHeader, infoPtr->hbHeader); crOldText = SetTextColor(hDC, GetSysColor(infoPtr->Enabled ? MONTHCAL_HEADERFG : MONTHCAL_DISABLED_HEADERFG)); for (x = prcUpdate->left / infoPtr->CellSize.cx; x <= prcUpdate->right / infoPtr->CellSize.cx && x < 7; x++) { rcCell.left = x * infoPtr->CellSize.cx; rcCell.right = rcCell.left + infoPtr->CellSize.cx; /* Write the first letter of each weekday */ DrawTextW(hDC, &infoPtr->Week[x], 1, &rcCell, DT_SINGLELINE | DT_NOPREFIX | DT_CENTER | DT_VCENTER); } SetTextColor(hDC, crOldText); } else { if (crOldCtrlText == CLR_INVALID) { crOldCtrlText = SetTextColor(hDC, GetSysColor(infoPtr->Enabled ? MONTHCAL_CTRLFG : MONTHCAL_DISABLED_CTRLFG)); } for (x = prcUpdate->left / infoPtr->CellSize.cx; x <= prcUpdate->right / infoPtr->CellSize.cx && x < 7; x++) { UINT Day = infoPtr->Days[y - 1][x]; rcCell.left = x * infoPtr->CellSize.cx; rcCell.right = rcCell.left + infoPtr->CellSize.cx; /* Write the day number */ if (Day != 0 && Day < 100) { WCHAR szDay[3]; INT szDayLen; RECT rcText; SIZE TextSize; szDayLen = swprintf(szDay, L"%lu", Day); if (GetTextExtentPoint32W(hDC, szDay, szDayLen, &TextSize)) { RECT rcHighlight = { 0, 0, 0, 0 }; rcText.left = rcCell.left + (infoPtr->CellSize.cx / 2) - (TextSize.cx / 2); rcText.top = rcCell.top + (infoPtr->CellSize.cy / 2) - (TextSize.cy / 2); rcText.right = rcText.left + TextSize.cx; rcText.bottom = rcText.top + TextSize.cy; if (Day == infoPtr->Day) { SIZE TextSel; TextSel.cx = (infoPtr->CellSize.cx * 2) / 3; TextSel.cy = (infoPtr->CellSize.cy * 3) / 4; if (TextSel.cx < rcText.right - rcText.left) TextSel.cx = rcText.right - rcText.left; if (TextSel.cy < rcText.bottom - rcText.top) TextSel.cy = rcText.bottom - rcText.top; rcHighlight.left = rcCell.left + (infoPtr->CellSize.cx / 2) - (TextSel.cx / 2); rcHighlight.right = rcHighlight.left + TextSel.cx; rcHighlight.top = rcCell.top + (infoPtr->CellSize.cy / 2) - (TextSel.cy / 2); rcHighlight.bottom = rcHighlight.top + TextSel.cy; InflateRect(&rcHighlight, GetSystemMetrics(SM_CXFOCUSBORDER), GetSystemMetrics(SM_CYFOCUSBORDER)); if (!FillRect(hDC, &rcHighlight, infoPtr->hbSelection)) { goto FailNoHighlight; } /* Highlight the selected day */ crOldText = SetTextColor(hDC, GetSysColor(infoPtr->Enabled ? MONTHCAL_SELFG : MONTHCAL_DISABLED_SELFG)); } else { FailNoHighlight: /* Don't change the text color, we're not highlighting it... */ crOldText = CLR_INVALID; } TextOutW(hDC, rcText.left, rcText.top, szDay, szDayLen); if (Day == infoPtr->Day && crOldText != CLR_INVALID) { if (infoPtr->HasFocus && infoPtr->Enabled && !(infoPtr->UIState & UISF_HIDEFOCUS)) { COLORREF crOldBk; crOldBk = SetBkColor(hDC, GetSysColor(infoPtr->Enabled ? MONTHCAL_SELBG : MONTHCAL_DISABLED_SELBG)); DrawFocusRect(hDC, &rcHighlight); SetBkColor(hDC, crOldBk); } SetTextColor(hDC, crOldText); } } } } } } if (crOldCtrlText != CLR_INVALID) { SetTextColor(hDC, crOldCtrlText); } SetBkMode(hDC, iOldBkMode); SelectObject(hDC, (HGDIOBJ)hOldFont); }