void CardButton::Draw(HDC hdc, bool fNormal) { SIZE textsize; int x, y; //text x, y int ix, iy; //icon x, y int iconwidth = 0; RECT cliprect; if(fVisible == 0) return; if(hFont == 0) SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT)); else SelectObject(hdc, hFont); GetTextExtentPoint32(hdc, szText, lstrlen(szText), &textsize); if(hIcon) { x = rect.left + 32 + 8; } else { if(uStyle & CB_ALIGN_LEFT) { x = rect.left + iconwidth; } else if(uStyle & CB_ALIGN_RIGHT) { x = rect.left + (rect.right-rect.left-iconwidth-textsize.cx); } else //centered { x = rect.right - rect.left - iconwidth; x = (x - textsize.cx) / 2; x += rect.left + iconwidth; } } y = rect.bottom - rect.top; y = (y - textsize.cy) / 2; y += rect.top; //calc icon position.. ix = rect.left + 4; iy = rect.top + (rect.bottom-rect.top-32) / 2; //if button is pressed, then shift text if(fNormal == false && (uStyle & CB_PUSHBUTTON)) { x += 1; y += 1; ix += 1; iy += 1; } SetRect(&cliprect, x, y, x+textsize.cx, y+textsize.cy); ExcludeClipRect(hdc, x, y, x+textsize.cx, y+textsize.cy); // // Calc icon pos // if(hIcon) { ExcludeClipRect(hdc, ix, iy, ix + 32, iy + 32); } if(uStyle & CB_PUSHBUTTON) { DrawRect(hdc, &rect, fNormal); SetBkColor(hdc, MAKE_PALETTERGB(crBack)); SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText)); SelectClipRgn(hdc, 0); ExtTextOut(hdc, x, y, ETO_OPAQUE, &cliprect, szText, lstrlen(szText), 0); } else { SetBkColor(hdc, MAKE_PALETTERGB(crBack)); SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText)); SelectClipRgn(hdc, 0); ExtTextOut(hdc, x, y, ETO_OPAQUE, &rect, szText, lstrlen(szText), 0); } if(hIcon) { HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBack)); DrawIconEx(hdc, ix, iy, hIcon, 32, 32, 0, hbr, 0); DeleteObject(hbr); } }
Brush::Brush(COLORREF color) : m_brush(CreateSolidBrush(color)) { assert(m_brush != 0); }
VOID GUIFont::DrawOnTexture( LPWSTR _pStr, DWORD _dColor, LPDIRECT3DTEXTURE9 _pTexture, INT _itexX, INT _itexY, INT _itexWidth, INT _itexHeight ) { if( _pTexture == NULL ) { MessageBox( NULL, L"DrawFontOnTexture{... _pTexture == NULL }", NULL, MB_OK ); return; } HDC hDC; HBITMAP hBit; LPVOID pBits; BITMAPINFO BitInfo; ZeroMemory( &BitInfo, sizeof( BITMAPINFO ) ); BitInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); // 구조체 크기 BitInfo.bmiHeader.biWidth = _itexWidth; BitInfo.bmiHeader.biHeight = _itexHeight; BitInfo.bmiHeader.biPlanes = 1; // 목표장차의 플레인 수( 이미지 장수, bitmap은 layer가 존재하지 않음으로 항상 1 ) BitInfo.bmiHeader.biBitCount = 32; // 각 픽셀의 비트수 BitInfo.bmiHeader.biCompression = BI_RGB/*BI_PNG*/; // 압축방법( BI_RGB 또는 0 : 무압축비트맵 ) BitInfo.bmiHeader.biSizeImage = 0; // 비트맵 영상크기 BitInfo.bmiHeader.biXPelsPerMeter = 100; // 미터당 픽셀수 BitInfo.bmiHeader.biYPelsPerMeter = 100; // 미터당 픽셀수 BitInfo.bmiHeader.biClrUsed = 0; // 사용된 컬러수 BitInfo.bmiHeader.biClrImportant = 0; // 비트맵 디스플레이에 사용되는 컬러 수 hDC = CreateCompatibleDC( NULL ); hBit = CreateDIBSection( hDC, &BitInfo, DIB_RGB_COLORS, &pBits, NULL, 0 ); RECT rt; SetRect( &rt, 0, 0, _itexWidth, _itexHeight ); HBRUSH hBackgroundBrush = CreateSolidBrush( 0x00dddddd ); SelectObject( hDC, hBit ); SelectObject( hDC, m_hFont ); FillRect( hDC, &rt, hBackgroundBrush ); SetBkMode( hDC, TRANSPARENT ); // TRANSPARENT : 투명한 배경 색상 SetTextColor( hDC, _dColor ); // 2,2 대신 좌상단, 중단, 좌하단 3가지로 나누어 할 수 있게 하면 좋을 듯 TextOut( hDC, _itexX, _itexY, _pStr, lstrlen( _pStr ) ); D3DLOCKED_RECT d3drt; _pTexture->LockRect( 0, &d3drt, NULL, 0 ); UINT* pSrc32 = static_cast< UINT* >( pBits ); UINT* pDst32 = static_cast< UINT* >( d3drt.pBits ); pSrc32 += ( _itexHeight * _itexWidth ) - _itexWidth; UINT* pTemp = pSrc32; for( INT y=0 ; y<_itexHeight ; y++ ) { for( INT x=0 ; x<_itexWidth ; x++ ) { if( (*pSrc32) != 0x00dddddd ) (*pDst32) = (*pSrc32) | 0xff000000; pSrc32++; pDst32++; } pTemp -= _itexWidth; pSrc32 = pTemp; } _pTexture->UnlockRect( 0 ); DeleteObject( hBackgroundBrush ); DeleteObject( hBit ); DeleteDC( hDC ); }
static int config(uint32_t width, uint32_t height, uint32_t d_width,uint32_t d_height, uint32_t flags, char *title, uint32_t format){ title = "MPlayer VIDIX WIN32 Overlay"; panscan_init(); image_height = height; image_width = width; image_format = format; vo_screenwidth = GetSystemMetrics(SM_CXSCREEN); vo_screenheight = GetSystemMetrics(SM_CYSCREEN); vo_depthonscreen = GetDeviceCaps(GetDC(GetDesktopWindow()),BITSPIXEL); aspect_save_orig(width, height); aspect_save_prescale(d_width, d_height); aspect_save_screenres(vo_screenwidth, vo_screenheight); vo_dx = 0; vo_dy = 0; vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2; geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight); vo_fs = flags&VOFLAG_FULLSCREEN; aspect(&d_width, &d_height, A_NOZOOM); vo_dwidth=d_width; vo_dheight=d_height; window_aspect = (float)d_width / (float)d_height; if(!vo_config_count){ HINSTANCE hInstance = GetModuleHandle(NULL); WNDCLASS wc; RECT rd; rd.left = vo_dx; rd.top = vo_dy; rd.right = rd.left + vo_dwidth; rd.bottom = rd.top + vo_dheight; AdjustWindowRect(&rd,WS_OVERLAPPEDWINDOW| WS_SIZEBOX,0); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hIcon =ExtractIcon(hInstance,"mplayer.exe",0); //LoadIcon(NULL,IDI_APPLICATION); wc.hbrBackground = CreateSolidBrush(RGB(255,0,255)); wc.lpszClassName = "MPlayer - The Movie Player"; wc.lpszMenuName = NULL; RegisterClass(&wc); hWnd = CreateWindow("MPlayer - The Movie Player", title, WS_OVERLAPPEDWINDOW| WS_SIZEBOX, rd.left, rd.top, rd.right - rd.left, rd.bottom - rd.top, NULL, NULL, hInstance, NULL); wc.hbrBackground = CreateSolidBrush(RGB(0,0,0)); wc.lpszClassName = "MPlayer - Fullscreen"; RegisterClass(&wc); hWndFS = CreateWindow("MPlayer - Fullscreen","MPlayer VIDIX Fullscreen",WS_POPUP,0,0,vo_screenwidth,vo_screenheight,hWnd,NULL,hInstance,NULL); } ShowWindow(hWnd,SW_SHOW); if(vo_fs)ShowWindow(hWndFS,SW_SHOW); return(0); }
LRESULT CFrameHolder::OnPaint(HWND hWnd, HDC hdc, UINT uMsg) { if (hdc == NULL) { LRESULT lRc = 0; PAINTSTRUCT ps = {0}; hdc = BeginPaint(hWnd, &ps); if (hdc != NULL) { lRc = OnPaint(hWnd, hdc, uMsg); EndPaint(hWnd, &ps); } else { _ASSERTE(hdc != NULL); } return lRc; } #ifdef _DEBUG RECT rcClientReal = {}; GetClientRect(hWnd, &rcClientReal); MapWindowPoints(hWnd, NULL, (LPPOINT)&rcClientReal, 2); #endif // Если "завис" PostUpdate if (gpConEmu->mp_TabBar->NeedPostUpdate()) gpConEmu->mp_TabBar->Update(); // Go RECT wr, cr; RecalculateFrameSizes(); wr = gpConEmu->GetGuiClientRect(); #ifdef _DEBUG wchar_t szPaint[140]; _wsprintf(szPaint, SKIPCOUNT(szPaint) L"MainClient %s at {%i,%i}-{%i,%i} screen coords, size (%ix%i) calc (%ix%i)", (uMsg == WM_PAINT) ? L"WM_PAINT" : (uMsg == WM_PRINTCLIENT) ? L"WM_PRINTCLIENT" : L"UnknownMsg", LOGRECTCOORDS(rcClientReal), LOGRECTSIZE(rcClientReal), LOGRECTSIZE(wr)); DEBUGSTRPAINT(szPaint); #endif #if defined(CONEMU_TABBAR_EX) #ifdef RED_CLIENT_FILL HBRUSH h = CreateSolidBrush(RGB(255,0,0)); FillRect(hdc, &wr, h); DeleteObject(h); return 0; #endif #endif if (gpSet->isStatusBarShow) { int nHeight = gpSet->StatusBarHeight(); if (nHeight < (wr.bottom - wr.top)) { RECT rcStatus = {wr.left, wr.bottom - nHeight, wr.right, wr.bottom}; gpConEmu->mp_Status->PaintStatus(hdc, &rcStatus); wr.bottom = rcStatus.top; } } cr = wr; DEBUGTEST(FrameDrawStyle dt = gpConEmu->DrawType()); #if defined(CONEMU_TABBAR_EX) RECT tr = {}; if (!gpSet->isTabsInCaption) { _ASSERTE(gpConEmu->GetDwmClientRectTopOffset() == 0); // CheckIt, must be zero if (gpSet->isTabs) { RECT captrect = gpConEmu->CalcRect(CER_TAB, wr, CER_MAINCLIENT); //CalculateCaptionPosition(cr, &captrect); CalculateTabPosition(cr, captrect, &tr); PaintDC dc = {false}; RECT pr = {captrect.left, 0, captrect.right, captrect.bottom}; gpConEmu->BeginBufferedPaint(hdc, pr, dc); gpConEmu->mp_TabBar->PaintTabs(dc, captrect, tr); gpConEmu->EndBufferedPaint(dc, TRUE); } } else if (dt == fdt_Aero || dt == fdt_Win8) { _ASSERTE(gpSet->isTabsInCaption); int nOffset = gpConEmu->GetDwmClientRectTopOffset(); // "Рамка" расширена на клиентскую область, поэтому // нужно зарисовать заголовок черной кистью, иначе идет // искажение цвета для кнопок Min/Max/Close if (gpSet->isTabs) { RECT captrect = gpConEmu->CalcRect(CER_TAB, wr, CER_MAINCLIENT); //CalculateCaptionPosition(cr, &captrect); CalculateTabPosition(cr, captrect, &tr); PaintDC dc = {false}; RECT pr = {captrect.left, 0, captrect.right, captrect.bottom}; gpConEmu->BeginBufferedPaint(hdc, pr, dc); gpConEmu->mp_TabBar->PaintTabs(dc, captrect, tr); gpConEmu->EndBufferedPaint(dc, TRUE); // There is no "Glass" in Win8 mb_WasGlassDraw = IsWindows7 && !IsWindows8; } cr.top += nOffset; } #endif #ifdef _DEBUG int nWidth = (cr.right-cr.left); int nHeight = (cr.bottom-cr.top); #endif WARNING("Пока табы рисуем не сами и ExtendDWM отсутствует - дополнительные изыски с временным DC не нужны"); #if 0 if (!gpSet->isTabsInCaption) { //OnPaintClient(hdc/*, nWidth, nHeight*/); } else // Создадим временный DC, для удобства отрисовки в Glass-режиме и для фикса глюка DWM(?) см.ниже // В принципе, для режима Win2k/XP временный DC можно не создавать, если это будет тормозить { //_ASSERTE(FALSE && "Need to be rewritten"); HDC hdcPaint = CreateCompatibleDC(hdc); HBITMAP hbmp = CreateCompatibleBitmap(hdc, nWidth, nHeight); HBITMAP hOldBmp = (HBITMAP)SelectObject(hdcPaint, hbmp); //OnPaintClient(hdcPaint/*, nWidth, nHeight*/); if ((dt == fdt_Aero) || !(mb_WasGlassDraw && gpConEmu->isZoomed())) { BitBlt(hdc, cr.left, cr.top, nWidth, nHeight, hdcPaint, 0, 0, SRCCOPY); } else { //mb_WasGlassDraw = FALSE; // Какой-то странный глюк DWM. При отключении Glass несколько верхних строк // клиентской области оказываются "разрушенными" - у них остается атрибут "прозрачности" // хотя прозрачность (Glass) уже отключена. В результате эти строки - белесые BITMAPINFOHEADER bi = {sizeof(BITMAPINFOHEADER)}; bi.biWidth = cr.right-cr.left+1; bi.biHeight = GetFrameHeight()+1; bi.biPlanes = 1; bi.biBitCount = 32; COLORREF *pPixels = NULL; HDC hdcTmp = CreateCompatibleDC(hdc); HBITMAP hTmp = CreateDIBSection(hdcTmp, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void**)&pPixels, NULL, 0); if (hTmp == NULL) { _ASSERTE(hTmp == NULL); BitBlt(hdc, cr.left, cr.top, nWidth, nHeight, hdcPaint, 0, 0, SRCCOPY); } else { HBITMAP hOldTmp = (HBITMAP)SelectObject(hdcTmp, hTmp); BitBlt(hdcTmp, 0, 0, bi.biWidth, bi.biHeight, hdcPaint, 0, 0, SRCCOPY); int i = 0; for (int y = 0; y < bi.biHeight; y++) { for (int x = 0; x < bi.biWidth; x++) { pPixels[i++] |= 0xFF000000; } } BitBlt(hdc, cr.left, cr.top, bi.biWidth, bi.biHeight, hdcTmp, 0, 0, SRCCOPY); if (nHeight > bi.biHeight) BitBlt(hdc, cr.left, cr.top+bi.biHeight, nWidth, nHeight-bi.biHeight, hdcPaint, 0, bi.biHeight, SRCCOPY); SelectObject(hdcTmp, hOldTmp); DeleteObject(hbmp); } DeleteDC(hdcTmp); } SelectObject(hdcPaint, hOldBmp); DeleteObject(hbmp); DeleteDC(hdcPaint); } #endif return 0; }
static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { HDC dc; PAINTSTRUCT ps; GDisplay * g; winPriv * priv; #if GINPUT_NEED_TOGGLE HBRUSH hbrOn, hbrOff; HPEN pen; RECT rect; HGDIOBJ old; POINT p; coord_t pos; uint8_t bit; #endif switch (Msg) { case WM_CREATE: // Get our GDisplay structure and attach it to the window g = (GDisplay *)((LPCREATESTRUCT)lParam)->lpCreateParams; priv = (winPriv *)g->priv; SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)g); // Fill in the private area priv->hwnd = hWnd; dc = GetDC(hWnd); priv->dcBitmap = CreateCompatibleBitmap(dc, g->g.Width, g->g.Height); priv->dcBuffer = CreateCompatibleDC(dc); ReleaseDC(hWnd, dc); priv->dcOldBitmap = SelectObject(priv->dcBuffer, priv->dcBitmap); // Mark the window as ready to go g->flags |= GDISP_FLG_READY; break; #if GINPUT_NEED_MOUSE || GINPUT_NEED_TOGGLE case WM_LBUTTONDOWN: // Get our GDisplay structure g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; // Handle mouse down on the window #if GINPUT_NEED_MOUSE if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons |= GINPUT_MOUSE_BTN_LEFT; goto mousemove; } #endif // Handle mouse down on the toggle area #if GINPUT_NEED_TOGGLE if ((coord_t)HIWORD(lParam) >= GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASTOGGLE)) { bit = 1 << ((coord_t)LOWORD(lParam)*8/g->g.Width); priv->toggles ^= bit; rect.left = 0; rect.right = GDISP_SCREEN_WIDTH; rect.top = GDISP_SCREEN_HEIGHT; rect.bottom = GDISP_SCREEN_HEIGHT + WIN32_BUTTON_AREA; InvalidateRect(hWnd, &rect, FALSE); UpdateWindow(hWnd); #if GINPUT_TOGGLE_POLL_PERIOD == TIME_INFINITE ginputToggleWakeup(); #endif } #endif break; case WM_LBUTTONUP: // Get our GDisplay structure g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; // Handle mouse up on the toggle area #if GINPUT_NEED_TOGGLE if ((g->flags & GDISP_FLG_HASTOGGLE)) { if ((priv->toggles & 0x0F)) { priv->toggles &= ~0x0F; rect.left = 0; rect.right = GDISP_SCREEN_WIDTH; rect.top = GDISP_SCREEN_HEIGHT; rect.bottom = GDISP_SCREEN_HEIGHT + WIN32_BUTTON_AREA; InvalidateRect(hWnd, &rect, FALSE); UpdateWindow(hWnd); #if GINPUT_TOGGLE_POLL_PERIOD == TIME_INFINITE ginputToggleWakeup(); #endif } } #endif // Handle mouse up on the window #if GINPUT_NEED_MOUSE if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT; goto mousemove; } #endif break; #endif #if GINPUT_NEED_MOUSE case WM_MBUTTONDOWN: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE; goto mousemove; } break; case WM_MBUTTONUP: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE; goto mousemove; } break; case WM_RBUTTONDOWN: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons |= GINPUT_MOUSE_BTN_RIGHT; goto mousemove; } break; case WM_RBUTTONUP: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT; goto mousemove; } break; case WM_MOUSEMOVE: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; if ((coord_t)HIWORD(lParam) >= GDISP_SCREEN_HEIGHT) break; mousemove: priv->mousex = (coord_t)LOWORD(lParam); priv->mousey = (coord_t)HIWORD(lParam); if ((gmvmt(priv->mouse)->d.flags & GMOUSE_VFLG_NOPOLL)) // For normal setup this is always TRUE _gmouseWakeup(priv->mouse); break; #endif case WM_SYSKEYDOWN: case WM_KEYDOWN: case WM_SYSKEYUP: case WM_KEYUP: break; case WM_CHAR: case WM_DEADCHAR: case WM_SYSCHAR: case WM_SYSDEADCHAR: break; case WM_ERASEBKGND: // Pretend we have erased the background. // We know we don't really need to do this as we // redraw the entire surface in the WM_PAINT handler. return TRUE; case WM_PAINT: // Get our GDisplay structure g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; // Paint the main window area WaitForSingleObject(drawMutex, INFINITE); dc = BeginPaint(hWnd, &ps); BitBlt(dc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, (ps.rcPaint.bottom > GDISP_SCREEN_HEIGHT ? GDISP_SCREEN_HEIGHT : ps.rcPaint.bottom) - ps.rcPaint.top, priv->dcBuffer, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); // Paint the toggle area #if GINPUT_NEED_TOGGLE if (ps.rcPaint.bottom >= GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASTOGGLE)) { pen = CreatePen(PS_SOLID, 1, gdispColor2Native(Black)); hbrOn = CreateSolidBrush(gdispColor2Native(Blue)); hbrOff = CreateSolidBrush(gdispColor2Native(Gray)); old = SelectObject(dc, pen); MoveToEx(dc, 0, GDISP_SCREEN_HEIGHT, &p); LineTo(dc, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT); for(pos = 0, bit=1; pos < wWidth; pos=rect.right, bit <<= 1) { rect.left = pos; rect.right = pos + GDISP_SCREEN_WIDTH/8; rect.top = GDISP_SCREEN_HEIGHT; rect.bottom = GDISP_SCREEN_HEIGHT + WIN32_BUTTON_AREA; FillRect(dc, &rect, (priv->toggles & bit) ? hbrOn : hbrOff); if (pos > 0) { MoveToEx(dc, rect.left, rect.top, &p); LineTo(dc, rect.left, rect.bottom); } } DeleteObject(hbrOn); DeleteObject(hbrOff); SelectObject(dc, old); } #endif EndPaint(hWnd, &ps); ReleaseMutex(drawMutex); break; case WM_DESTROY: // Get our GDisplay structure g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; // Restore the window and free our bitmaps SelectObject(priv->dcBuffer, priv->dcOldBitmap); DeleteDC(priv->dcBuffer); DeleteObject(priv->dcBitmap); // Cleanup the private area gfxFree(priv); // Quit the application PostQuitMessage(0); // Actually the above doesn't work (who knows why) ExitProcess(0); break; default: return DefWindowProc(hWnd, Msg, wParam, lParam); } return 0; }
BOOL CALLBACK ColourPopup::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { int nColor; for (nColor = 0 ; nColor < int(sizeof(colourItems)/sizeof(DWORD)) ; nColor++) { ::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_ADDSTRING, nColor, (LPARAM) ""); ::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETITEMDATA , nColor, (LPARAM) colourItems[nColor]); //if (g_bgColor == colourItems[nColor]) //::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETCURSEL, nColor, 0); } //::SetCapture(_hSelf); return TRUE; } case WM_CTLCOLORLISTBOX: return (LRESULT) CreateSolidBrush(GetSysColor(COLOR_3DFACE)); case WM_DRAWITEM: { HDC hdc; COLORREF cr; HBRUSH hbrush; DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; hdc = pdis->hDC; RECT rc = pdis->rcItem; // Transparent. SetBkMode(hdc,TRANSPARENT); // NULL object if (pdis->itemID == UINT(-1)) return 0; switch (pdis->itemAction) { case ODA_DRAWENTIRE: switch (pdis->CtlID) { case IDC_COLOUR_LIST: rc = pdis->rcItem; cr = (COLORREF) pdis->itemData; InflateRect(&rc, -3, -3); hbrush = CreateSolidBrush((COLORREF)cr); FillRect(hdc, &rc, hbrush); DeleteObject(hbrush); FrameRect(hdc, &rc, (HBRUSH) GetStockObject(GRAY_BRUSH)); break; NO_DEFAULT_CASE; } // *** FALL THROUGH *** //lint -fallthrough case ODA_SELECT: rc = pdis->rcItem; if (pdis->itemState & ODS_SELECTED) { rc.bottom --; rc.right --; // Draw the lighted side. HPEN hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW)); HPEN holdPen = (HPEN)SelectObject(hdc, hpen); MoveToEx(hdc, rc.left, rc.bottom, NULL); LineTo(hdc, rc.left, rc.top); LineTo(hdc, rc.right, rc.top); SelectObject(hdc, holdPen); DeleteObject(hpen); // Draw the darkened side. hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT)); holdPen = (HPEN)SelectObject(hdc, hpen); LineTo(hdc, rc.right, rc.bottom); LineTo(hdc, rc.left, rc.bottom); SelectObject(hdc, holdPen); DeleteObject(hpen); } else { hbrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); FrameRect(hdc, &rc, hbrush); DeleteObject(hbrush); } break; case ODA_FOCUS: rc = pdis->rcItem; InflateRect(&rc, -2, -2); DrawFocusRect(hdc, &rc); break; default: break; } return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK : { isColourChooserLaunched = true; CHOOSECOLOR cc; // common dialog box structure static COLORREF acrCustClr[16] = { RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),\ RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),\ RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),\ RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),\ }; // array of custom colors // Initialize CHOOSECOLOR ::ZeroMemory(&cc, sizeof(cc)); cc.lStructSize = sizeof(cc); cc.hwndOwner = _hParent; cc.lpCustColors = (LPDWORD) acrCustClr; cc.rgbResult = _colour; cc.Flags = CC_FULLOPEN | CC_RGBINIT; display(false); if (ChooseColor(&cc)==TRUE) { ::SendMessage(_hParent, WM_PICKUP_COLOR, cc.rgbResult, 0); } else { ::SendMessage(_hParent, WM_PICKUP_CANCEL, 0, 0); } return TRUE; } case IDC_COLOUR_LIST : { if (HIWORD(wParam) == LBN_SELCHANGE) { int i = ::SendMessage((HWND)lParam, LB_GETCURSEL, 0L, 0L); _colour = ::SendMessage((HWND)lParam, LB_GETITEMDATA, i, 0L); ::SendMessage(_hParent, WM_PICKUP_COLOR, _colour, 0); return TRUE; } return FALSE; } default : return FALSE; } case WM_ACTIVATE : { if (LOWORD(wParam) == WA_INACTIVE) if (!isColourChooserLaunched) ::SendMessage(_hParent, WM_PICKUP_CANCEL, 0, 0); return TRUE; } default: break; } return FALSE; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; WORD x, y; HBRUSH hOldBrush, hNewBrush; x = LOWORD(lParam); y = HIWORD(lParam); switch (message) { case WM_LBUTTONUP: color[0] = false; color[1] = false; color[2] = false; color[3] = false; InvalidateRect(hWnd, NULL, TRUE); break; case WM_LBUTTONDOWN: if(x >= 177 && x <= 257 && y >= 61 && y <= 140) color[0] = true; if(x >= 256 && x <= 335 && y >= 61 && y <= 141) color[1] = true; if(x >= 177 && x <= 257 && y >= 139 && y <= 219) color[2] = true; if(x >= 256 && x <= 335 && y >= 140 && y <= 219) color[3] = true; InvalidateRect(hWnd, NULL, TRUE); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); if(color[0]) { hNewBrush = CreateSolidBrush(RGB(0, 255, 0)); hOldBrush = (HBRUSH) SelectObject(hdc, hNewBrush); } MoveToEx(hdc, 177, 61, NULL); Rectangle(hdc, 177, 61, 257, 140); hNewBrush = CreateSolidBrush(RGB(255, 255, 255)); hOldBrush = (HBRUSH) SelectObject(hdc, hNewBrush); if(color[1]) { hNewBrush = CreateSolidBrush(RGB(0, 0, 255)); hOldBrush = (HBRUSH) SelectObject(hdc, hNewBrush); } MoveToEx(hdc, 256, 61, NULL); Rectangle(hdc, 256, 61, 335, 141); hNewBrush = CreateSolidBrush(RGB(255, 255, 255)); hOldBrush = (HBRUSH) SelectObject(hdc, hNewBrush); if(color[2]) { hNewBrush = CreateSolidBrush(RGB(255, 0, 0)); hOldBrush = (HBRUSH) SelectObject(hdc, hNewBrush); } MoveToEx(hdc, 177, 139, NULL); Rectangle(hdc, 177, 139, 257, 219); hNewBrush = CreateSolidBrush(RGB(255, 255, 255)); hOldBrush = (HBRUSH) SelectObject(hdc, hNewBrush); if(color[3]) { hNewBrush = CreateSolidBrush(RGB(255, 255, 0)); hOldBrush = (HBRUSH) SelectObject(hdc, hNewBrush); } MoveToEx(hdc, 256, 140, NULL); Rectangle(hdc, 256, 140, 335, 219); hNewBrush = CreateSolidBrush(RGB(255, 255, 255)); hOldBrush = (HBRUSH) SelectObject(hdc, hNewBrush); TextOut(hdc, 200, 256, "Your turn...", 12); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc = NULL; PAINTSTRUCT ps; RECT rect; HFONT fontCorbel, fontText1, fontText2, buttonFont, temp1, temp2; static HWND textArea1, buttonSubmit, buttonClear, textArea2, buttonRed, buttonGreen, buttonBlue; HBRUSH textArea1Brush; static int cxCoord, cyCoord; static HGDIOBJ defaultFont; LRESULT textSize, textSize2; char textStore[1000]; static bool textFlagRed, textFlagBlue, textFlagGreen; static bool backgFlag; static int a, b, c; switch (message) /* handle the messages */ { case WM_CREATE: { textArea1 = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(" "), WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL, 0, 0, 0, 0, hwnd, (HMENU)IDC_TEXT1, GetModuleHandle(NULL), NULL); buttonSubmit = CreateWindowEx(NULL, TEXT("BUTTON"), TEXT("Submit"), WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 0, 0, 0, 0, hwnd, (HMENU)IDC_BUTTON1, GetModuleHandle(NULL), NULL); buttonClear = CreateWindowEx(NULL, TEXT("BUTTON"), TEXT("Clear"), WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 0, 0, 0, 0, hwnd, (HMENU)IDC_BUTTON2, GetModuleHandle(NULL), NULL); textArea2 = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(" "), WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL | ES_READONLY, 0, 0, 0, 0, hwnd, (HMENU)IDC_TEXT1, GetModuleHandle(NULL), NULL); buttonRed = CreateWindowEx(NULL, TEXT("BUTTON"), TEXT("Red"), WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 0, 0, 0, 0, hwnd, (HMENU)IDC_BUTTON3, GetModuleHandle(NULL), NULL); buttonGreen = CreateWindowEx(NULL, TEXT("BUTTON"), TEXT("Green"), WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 0, 0, 0, 0, hwnd, (HMENU)IDC_BUTTON4, GetModuleHandle(NULL), NULL); buttonBlue = CreateWindowEx(NULL, TEXT("BUTTON"), TEXT("Blue"), WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 0, 0, 0, 0, hwnd, (HMENU)IDC_BUTTON5, GetModuleHandle(NULL), NULL); HGDIOBJ defaultFont = GetStockObject(DEFAULT_GUI_FONT); SendMessage(textArea1, WM_SETTEXT, NULL, (LPARAM)"Insert text here... "); SendMessage(buttonSubmit, WM_SETFONT, (WPARAM)defaultFont, MAKELPARAM(FALSE,0)); SendMessage(buttonClear, WM_SETFONT, (WPARAM)defaultFont, MAKELPARAM(FALSE,0)); break; } case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); fontCorbel = CreateFont(20, 0, 0, 0, FW_BOLD, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Corbel"); SetBkMode(hdc, TRANSPARENT); GetClientRect(hwnd, &rect); fontText1 = (HFONT)SelectObject(hdc, fontCorbel); buttonFont = CreateFont(20, 0, 0, 0, FW_DONTCARE, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Consolas"); SendMessage(buttonRed, WM_SETFONT, WPARAM(buttonFont), TRUE); SendMessage(buttonGreen, WM_SETFONT, WPARAM(buttonFont), TRUE); SendMessage(buttonBlue, WM_SETFONT, WPARAM(buttonFont), TRUE); temp2 = CreateFont(14, 0, 0, 0, FW_DONTCARE, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Arial"); temp1 = (HFONT)SelectObject(hdc, temp2); SetTextColor(hdc, RGB(144, 0, 0)); DrawText(hdc, TEXT("Done with Pride and Prejudice by Valeria Bega"), -1, &rect, DT_SINGLELINE| DT_CENTER| DT_TOP); EndPaint(hwnd, &ps); break; } case WM_GETMINMAXINFO: { LPMINMAXINFO winSize = (LPMINMAXINFO)lParam; winSize->ptMinTrackSize.x = 510; winSize->ptMinTrackSize.y = 375; winSize->ptMaxTrackSize.x = 630; winSize->ptMaxTrackSize.y = 425; break; } case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_BUTTON1: { textSize = SendMessage(textArea1, WM_GETTEXT, 100, (LPARAM)textStore); // text size textStore[textSize] = _T('\0'); // initialization with null character SendMessage(textArea2, EM_REPLACESEL, 0, (LPARAM)textStore); // add inputed text to window SendMessage(textArea2, EM_REPLACESEL, 0, (LPARAM)" "); RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE); fontCorbel = CreateFont(20, 0, 0, 0, FW_DONTCARE, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Corbel"); SendMessage(textArea2, WM_SETFONT, (WPARAM)fontCorbel, TRUE); break; } case IDC_BUTTON2: { SendMessage(textArea2, WM_SETTEXT, NULL, NULL); break; } case IDC_BUTTON3: { textFlagRed = true; textFlagBlue = false; textFlagGreen = false; InvalidateRect(textArea2, NULL, TRUE); break; } case IDC_BUTTON4: { textFlagGreen = true; textFlagBlue = false; textFlagRed = false; InvalidateRect(textArea2, NULL, TRUE); break; } case IDC_BUTTON5: { textFlagBlue = true; textFlagRed = false; textFlagGreen = false; InvalidateRect(textArea2, NULL, TRUE); break; } } break; case WM_SYSCOMMAND: { switch(wParam) { case SC_MINIMIZE: { srand(time(NULL)); a = rand() % 255 + 1; b = rand() % 255 + 1; c = rand() % 255 + 1; backgFlag = true; if(backgFlag == true) { SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)CreateSolidBrush(RGB(a, b, c))); } InvalidateRect(hwnd, NULL, TRUE); break; } case SC_MAXIMIZE: { double i = 20; while (i < 330) { SetWindowPos(hwnd, HWND_TOP, 411, i,544, 375, SWP_SHOWWINDOW); i = i + 0.1; } while (i > 20) { SetWindowPos(hwnd, HWND_TOP, 411, i,544, 375, SWP_SHOWWINDOW); i = i - 0.1; } break; } case SC_CLOSE: { if(MessageBox(hwnd, "Do you want to close the program?", "Alert", MB_YESNO) == IDYES) { exit(1); } break; } default: return DefWindowProc(hwnd, message, wParam, lParam); } break; case WM_SIZE: { cxCoord = LOWORD(lParam); // 544 cyCoord = HIWORD(lParam); // 375 MoveWindow(textArea1, 20, 45, cxCoord-40, cyCoord/2-97, TRUE); MoveWindow(buttonSubmit, 20, cyCoord/2-40, cxCoord-430, cyCoord/2-144, TRUE); MoveWindow(buttonClear, 411, cyCoord/2-40, cxCoord-430, cyCoord/2-144, TRUE); MoveWindow(textArea2, 20, cyCoord-170, cxCoord-40, cyCoord/2-97, TRUE); MoveWindow(buttonRed, 20, (cyCoord-200) + cyCoord/2-55, cxCoord-425, cyCoord/2-135, TRUE); MoveWindow(buttonBlue, 406, (cyCoord-200) + cyCoord/2-55, cxCoord-425, cyCoord/2-135, TRUE); MoveWindow(buttonGreen, 213, (cyCoord-200) + cyCoord/2-55, cxCoord-425, cyCoord/2-135, TRUE); break; } case WM_CTLCOLOREDIT: { if(IDC_TEXT1 == GetDlgCtrlID((HWND)lParam)) { textArea1Brush = CreateSolidBrush(RGB(198, 226, 255)); SetBkMode((HDC)wParam, TRANSPARENT); return(INT_PTR)textArea1Brush; } break; } case WM_CTLCOLORSTATIC: { if(textFlagRed == true && (HWND)lParam == textArea2) { HBRUSH hbr = (HBRUSH) DefWindowProc(hwnd, message, wParam, lParam); SetTextColor((HDC) wParam, RGB(255, 0, 0)); return (BOOL) hbr; } else if(textFlagBlue == true && (HWND)lParam == textArea2) { HBRUSH hbr = (HBRUSH) DefWindowProc(hwnd, message, wParam, lParam); SetTextColor((HDC) wParam, RGB(0, 0, 255)); return (BOOL) hbr; } else if(textFlagGreen == true && (HWND)lParam == textArea2) { HBRUSH hbr = (HBRUSH) DefWindowProc(hwnd, message, wParam, lParam); SetTextColor((HDC) wParam, RGB(0, 255, 0)); return (BOOL) hbr; } break; } case WM_DESTROY: { PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; } default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } }
static LRESULT CALLBACK ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static bool s_timePolarity; switch (uMsg) { case WM_ACTIVATE: if ( LOWORD( wParam ) != WA_INACTIVE ) { SetFocus( s_wcd.hwndInputLine ); } break; case WM_CLOSE: if ( cvarSystem->IsInitialized() && com_skipRenderer.GetBool() ) { cmdSystem->BufferCommandText(CMD_EXEC_APPEND, "quit\n"); } else if ( s_wcd.quitOnClose ) { PostQuitMessage( 0 ); } else { Sys_ShowConsole( 0, false ); win32.win_viewlog.SetBool( false ); } return 0; case WM_CTLCOLORSTATIC: if ( ( HWND ) lParam == s_wcd.hwndBuffer ) { SetBkColor( ( HDC ) wParam, RGB( 0x00, 0x00, 0x80 ) ); SetTextColor( ( HDC ) wParam, RGB( 0xff, 0xff, 0x00 ) ); return ( LRESULT ) s_wcd.hbrEditBackground; } else if ( ( HWND ) lParam == s_wcd.hwndErrorBox ) { if ( s_timePolarity & 1 ) { SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) ); SetTextColor( ( HDC ) wParam, RGB( 0xff, 0x0, 0x00 ) ); } else { SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) ); SetTextColor( ( HDC ) wParam, RGB( 0x00, 0x0, 0x00 ) ); } return ( LRESULT ) s_wcd.hbrErrorBackground; } break; case WM_SYSCOMMAND: if ( wParam == SC_CLOSE ) { PostQuitMessage( 0 ); } break; case WM_COMMAND: if ( wParam == COPY_ID ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); SendMessage( s_wcd.hwndBuffer, WM_COPY, 0, 0 ); } else if ( wParam == QUIT_ID ) { if ( s_wcd.quitOnClose ) { PostQuitMessage( 0 ); } else { cmdSystem->BufferCommandText(CMD_EXEC_APPEND, "quit\n"); } } else if ( wParam == CLEAR_ID ) { SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 ); SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, FALSE, ( LPARAM ) "" ); UpdateWindow( s_wcd.hwndBuffer ); } break; case WM_CREATE: s_wcd.hbrEditBackground = CreateSolidBrush( RGB( 0x00, 0x00, 0x80 ) ); s_wcd.hbrErrorBackground = CreateSolidBrush( RGB( 0x80, 0x80, 0x80 ) ); SetTimer( hWnd, 1, 1000, NULL ); break; /* case WM_ERASEBKGND: HGDIOBJ oldObject; HDC hdcScaled; hdcScaled = CreateCompatibleDC( ( HDC ) wParam ); assert( hdcScaled != 0 ); if ( hdcScaled ) { oldObject = SelectObject( ( HDC ) hdcScaled, s_wcd.hbmLogo ); assert( oldObject != 0 ); if ( oldObject ) { StretchBlt( ( HDC ) wParam, 0, 0, s_wcd.windowWidth, s_wcd.windowHeight, hdcScaled, 0, 0, 512, 384, SRCCOPY ); } DeleteDC( hdcScaled ); hdcScaled = 0; } return 1; */ case WM_TIMER: if ( wParam == 1 ) { s_timePolarity = (bool)!s_timePolarity; if ( s_wcd.hwndErrorBox ) { InvalidateRect( s_wcd.hwndErrorBox, NULL, FALSE ); } } break; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
// ImageList_Destroy() the return value // refresh on WM_THEMECHANGED static HIMAGELIST CreateRadioImages(COLORREF clrBk, COLORREF clrText) { /* draw bitmap */ HDC hdcScreen = GetDC(NULL); if (hdcScreen == NULL) return NULL; HIMAGELIST himl = NULL; HDC hdc = CreateCompatibleDC(NULL); /* compatible to screen */ if (hdc != NULL) { SIZE size = { GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON) }; RECT rc; SetRect(&rc, 0, 0, 2 * size.cx, size.cy); HBITMAP hbm = CreateCompatibleBitmap(hdcScreen, rc.right, rc.bottom); if (hbm != NULL) { HBITMAP hbmPrev = (HBITMAP)SelectObject(hdc, hbm); if (hbmPrev != NULL) { /* error on select? */ HTHEME hTheme = OpenThemeData(NULL, L"Button"); SetRect(&rc, 0, 0, size.cx, size.cy); /* unchecked */ if (!DrawThemeBackground(hTheme, hdc, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL, &rc, NULL)) { /* checked */ OffsetRect(&rc, size.cx, 0); if (!DrawThemeBackground(hTheme, hdc, BP_RADIOBUTTON, RBS_CHECKEDNORMAL, &rc, NULL)) himl = ImageList_Create(size.cx, size.cy, ILC_COLOR32 | ILC_MASK, 3, 0); } CloseThemeData(hTheme); /* the classic way */ if (himl == NULL) { RECT rcRadio; HBRUSH hbrBk = CreateSolidBrush(clrBk); if (hbrBk != NULL) { FillRect(hdc, &rc, hbrBk); DeleteObject(hbrBk); HDC hdcMono = CreateCompatibleDC(hdc); if (hdcMono != NULL) { HBITMAP hbmMono = CreateBitmap(rc.right, rc.bottom, 1, 1, NULL); if (hbmMono != NULL) { HBITMAP hbmPrevMono = (HBITMAP)SelectObject(hdcMono, hbmMono); if (hbmPrevMono != NULL) { /* error on select? */ /* draws a black-and-white mask (see docs) * we need to colorize it using BitBlt with text and background color */ COLORREF clrPrevText = SetTextColor(hdc, clrText); COLORREF clrPrevBk = SetBkColor(hdc, clrBk); /* check mark is slightly smaller than icon size */ SetRect(&rcRadio, 0, 0, GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK)); if (rcRadio.right > size.cx) rcRadio.right = size.cx; if (rcRadio.bottom > size.cy) rcRadio.bottom = size.cy; SetRect(&rc, ((size.cx - rcRadio.right) / 2) + 1, ((size.cy - rcRadio.bottom) / 2) + 1, rcRadio.right + 1, rcRadio.bottom + 1); /* unchecked */ if (BitBlt(hdcMono, 0, 0, rcRadio.right, rcRadio.bottom, NULL, 0, 0, WHITENESS)) { /* white back */ if (DrawFrameControl(hdcMono, &rcRadio, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_FLAT)) { if (BitBlt(hdc, rc.left, rc.top, rcRadio.right, rcRadio.bottom, hdcMono, 0, 0, SRCCOPY | NOMIRRORBITMAP)) { /* checked */ OffsetRect(&rc, size.cx, 0); if (BitBlt(hdcMono, 0, 0, rcRadio.right, rcRadio.bottom, NULL, 0, 0, WHITENESS)) {/* white back */ if (DrawFrameControl(hdcMono, &rcRadio, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_FLAT | DFCS_CHECKED)) { if (BitBlt(hdc, rc.left, rc.top, rcRadio.right, rcRadio.bottom, hdcMono, 0, 0, SRCCOPY | NOMIRRORBITMAP)) himl = ImageList_Create(size.cx, size.cy, ILC_COLOR | ILC_MASK, 3, 0); } else BOX("second DrawFrameControl() failed"); } else BOX("second BitBlt() failed"); } else BOX("intermediate BitBlt() failed"); } else BOX("DrawFrameControl() failed"); } else BOX("first BitBlt() failed"); /* restore */ SetBkColor(hdc, clrPrevBk); SetTextColor(hdc, clrPrevText); SelectObject(hdcMono, hbmPrevMono); } else BOX("hbmPrevMono == NULL"); DeleteObject(hbmMono); } else BOX("hbmMono == NULL"); DeleteDC(hdcMono); } else BOX("hdcMono == NULL"); } } SelectObject(hdc, hbmPrev); /* create imagelist */ if (himl != NULL) { if (himl == NULL) BOX("img list create failed"); if (himl != NULL) if (ImageList_AddMasked(himl, hbm, clrBk) == -1) BOX("add failed"); } else BOX("Win9x: drawing code not reached"); } DeleteObject(hbm); } DeleteDC(hdc); } ReleaseDC(NULL, hdcScreen); return himl; }
void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam) { if (!debugger->isAlive()) return; PAINTSTRUCT ps; HDC actualHdc = BeginPaint(wnd, &ps); HDC hdc = CreateCompatibleDC(actualHdc); HBITMAP hBM = CreateCompatibleBitmap(actualHdc, rect.right-rect.left, rect.bottom-rect.top); SelectObject(hdc, hBM); SetBkMode(hdc, TRANSPARENT); HPEN nullPen=CreatePen(0,0,0xffffff); HBRUSH nullBrush=CreateSolidBrush(0xffffff); HBRUSH currentBrush=CreateSolidBrush(0xffefe8); HPEN oldPen=(HPEN)SelectObject(hdc,nullPen); HBRUSH oldBrush=(HBRUSH)SelectObject(hdc,nullBrush); HFONT oldFont = (HFONT)SelectObject(hdc,(HGDIOBJ)font); HICON breakPoint = (HICON)LoadIcon(GetModuleHandle(0),(LPCWSTR)IDI_STOP); HICON breakPointDisable = (HICON)LoadIcon(GetModuleHandle(0),(LPCWSTR)IDI_STOPDISABLE); unsigned int address = windowStart; std::map<u32,int> addressPositions; const std::set<std::string> currentArguments = getSelectedLineArguments(); DisassemblyLineInfo line; for (int i = 0; i < visibleRows; i++) { manager.getLine(address,displaySymbols,line); int rowY1 = rowHeight*i; int rowY2 = rowHeight*(i+1); addressPositions[address] = rowY1; // draw background COLORREF backgroundColor = whiteBackground ? 0xFFFFFF : debugger->getColor(address); COLORREF textColor = 0x000000; if (isInInterval(address,line.totalSize,debugger->getPC())) { backgroundColor = scaleColor(backgroundColor,1.05f); } if (address >= selectRangeStart && address < selectRangeEnd && searching == false) { if (hasFocus) { backgroundColor = address == curAddress ? 0xFF8822 : 0xFF9933; textColor = 0xFFFFFF; } else { backgroundColor = 0xC0C0C0; } } HBRUSH backgroundBrush = CreateSolidBrush(backgroundColor); HPEN backgroundPen = CreatePen(0,0,backgroundColor); SelectObject(hdc,backgroundBrush); SelectObject(hdc,backgroundPen); Rectangle(hdc,0,rowY1,rect.right,rowY1+rowHeight); SelectObject(hdc,currentBrush); SelectObject(hdc,nullPen); DeleteObject(backgroundBrush); DeleteObject(backgroundPen); // display address/symbol bool enabled; if (CBreakPoints::IsAddressBreakPoint(address,&enabled)) { if (enabled) textColor = 0x0000FF; int yOffset = max(-1,(rowHeight-14+1)/2); if (!enabled) yOffset++; DrawIconEx(hdc,2,rowY1+1+yOffset,enabled ? breakPoint : breakPointDisable,32,32,0,0,DI_NORMAL); } SetTextColor(hdc,textColor); char addressText[64]; getDisasmAddressText(address,addressText,true,line.type == DISTYPE_OPCODE); TextOutA(hdc,pixelPositions.addressStart,rowY1+2,addressText,(int)strlen(addressText)); if (isInInterval(address,line.totalSize,debugger->getPC())) { TextOut(hdc,pixelPositions.opcodeStart-8,rowY1,L"■",1); } // display whether the condition of a branch is met if (line.info.isConditional && address == debugger->getPC()) { line.params += line.info.conditionMet ? " ; true" : " ; false"; } drawArguments(hdc, line, pixelPositions.argumentsStart, rowY1 + 2, textColor, currentArguments); SelectObject(hdc,boldfont); TextOutA(hdc,pixelPositions.opcodeStart,rowY1+2,line.name.c_str(),(int)line.name.size()); SelectObject(hdc,font); address += line.totalSize; } std::vector<BranchLine> branchLines = manager.getBranchLines(windowStart,address-windowStart); for (size_t i = 0; i < branchLines.size(); i++) { drawBranchLine(hdc,addressPositions,branchLines[i]); } SelectObject(hdc,oldFont); SelectObject(hdc,oldPen); SelectObject(hdc,oldBrush); // copy bitmap to the actual hdc BitBlt(actualHdc, 0, 0, rect.right, rect.bottom, hdc, 0, 0, SRCCOPY); DeleteObject(hBM); DeleteDC(hdc); DeleteObject(nullPen); DeleteObject(nullBrush); DeleteObject(currentBrush); DestroyIcon(breakPoint); DestroyIcon(breakPointDisable); EndPaint(wnd, &ps); }
/////////////////////////////////////////////////////////////////////////////// // Draw int CXHtmlDraw::Draw(HDC hDC, LPCTSTR lpszText, XHTMLDRAWSTRUCT * pXHDS, BOOL bUnderlineUrl) { TRACE(_T("in CXHtmlDraw::Draw: <%s> bUnderlineUrl=%d\n"), lpszText, bUnderlineUrl); static BOOL bInDraw = FALSE; if (bInDraw) return 0; bInDraw = TRUE; // check parameters ---------------------------------------------- _ASSERTE(hDC); _ASSERTE(lpszText); _ASSERTE(pXHDS); if (!hDC || !lpszText || (lpszText[0] == _T('\0')) || !pXHDS) { bInDraw = FALSE; return 0; } HWND hWnd = ::WindowFromDC(hDC); if (!::IsWindow(hWnd)) { TRACE(_T("warn: not a window\n")); bInDraw = FALSE; return 0; } // check if window is hidden ------------------------------------ if (!::IsWindowVisible(hWnd)) { TRACE(_T("warn: window invisible\n")); bInDraw = FALSE; return 0; } RECT rectClip; int nResult = ::GetClipBox(hDC, &rectClip); if (nResult == NULLREGION) { // window is covered TRACE(_T("warn: window is covered\n")); bInDraw = FALSE; return 0; } // initialize for drawing --------------------------------------- // rectText is used to draw into the dc RECT rectText = pXHDS->rect; if ((rectText.left >= rectText.right) || (rectText.top >= rectText.bottom)) { TRACE(_T("warn: bad rect\n")); bInDraw = FALSE; return 0; } // rectDraw is the rect for the entire drawing area RECT rectDraw = pXHDS->rect; int nRectWidth = rectDraw.right - rectDraw.left; int nRectHeight = rectDraw.bottom - rectDraw.top; int nXOffset = rectDraw.left; // set up for double buffering HDC hMemDC = CreateCompatibleDC(hDC); HBITMAP hBitmap = CreateCompatibleBitmap(hDC, nRectWidth, nRectHeight); HBITMAP hOldBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap); if (pXHDS->bTransparent && !pXHDS->hDC) { // save a bitmap of the original drawing area, in case // there are links, and we need to erase the underline pXHDS->hDC = CreateCompatibleDC(hDC); pXHDS->hBitmap = CreateCompatibleBitmap(hDC, nRectWidth, nRectHeight); pXHDS->hOldBitmap = (HBITMAP) SelectObject(pXHDS->hDC, pXHDS->hBitmap); BitBlt(pXHDS->hDC, 0, 0, nRectWidth, nRectHeight, hDC, rectDraw.left, rectDraw.top, SRCCOPY); BitBlt(hMemDC, 0, 0, nRectWidth, nRectHeight, hDC, rectDraw.left, rectDraw.top, SRCCOPY); } else if (pXHDS->bTransparent && pXHDS->hDC) { // restore the original drawing area from saved HDC BitBlt(hMemDC, 0, 0, nRectWidth, nRectHeight, pXHDS->hDC, 0, 0, SRCCOPY); } pXHDS->rectAnchor = rectText; // save rect in case of anchor // remap rectText to memory dc - left and top start at 0 rectText.left = 0; rectText.top = 0; rectText.right = nRectWidth; rectText.bottom = nRectHeight; // create initial font ------------------------------------------ LOGFONT lf = { 0 }; LOGFONT prev_lf = { 0 }; if (pXHDS->bLogFont) { TRACE(_T("using logfont\n")); memcpy(&lf, &pXHDS->lf, sizeof(LOGFONT)); } else { HFONT hfont = (HFONT)::GetCurrentObject(hDC, OBJ_FONT); //+++1.1 if (hfont) GetObject(hfont, sizeof(LOGFONT), &lf); else GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf); } memcpy(&prev_lf, &lf, sizeof(LOGFONT)); // variable initialization -------------------------------------- TCHAR *pszText = new TCHAR [m_nMaxText+1]; memset(pszText, 0, (m_nMaxText+1)*sizeof(TCHAR)); _tcsncpy(pszText, lpszText, m_nMaxText); TCHAR *pTextBuffer = pszText; // save buffer address for delete TCHAR *pszText1 = new TCHAR [m_nMaxText+1]; memset(pszText1, 0, (m_nMaxText+1)*sizeof(TCHAR)); if (pXHDS->pszAnchor) delete [] pXHDS->pszAnchor; pXHDS->pszAnchor = NULL; pXHDS->bHasAnchor = FALSE; pXHDS->bAnchorIsUnderlined = FALSE; BOOL bInAnchor = FALSE; int n = (int) _tcslen(pszText); // n must be int int i = 0; int nWidth = 0; pXHDS->bHasAnchor = FALSE; pXHDS->nRightX = 0; COLORREF crText = pXHDS->crText; if (crText == COLOR_NONE) crText = GetSysColor(COLOR_WINDOWTEXT); COLORREF crBackground = pXHDS->crBackground; if (crBackground == COLOR_NONE) crBackground = GetSysColor(COLOR_WINDOW); COLORREF crTextNew = crText; COLORREF crBkgndNew = crBackground; // if no transparency, fill entire rect with default bg color if (!pXHDS->bTransparent) { HBRUSH hbrush = CreateSolidBrush(crBkgndNew); _ASSERTE(hbrush); FillRect(hMemDC, &rectText, hbrush); if (hbrush) DeleteObject(hbrush); } BOOL bBold = pXHDS->bBold; BOOL bItalic = pXHDS->bItalic; BOOL bUnderline = pXHDS->bUnderline; BOOL bStrikeThrough = pXHDS->bStrikeThrough; BOOL bSubscript = FALSE; BOOL bSuperscript = FALSE; int nSizeChange = 0; // replace character entity names in text with codes ------------ TCHAR ent[3] = { _T('\0') }; ent[0] = _T('\001'); // each entity name is replaced with a two-character // code that begins with \001 BOOL bCharacterEntities = FALSE; // assume no char entities // we are replacing character entites with a two-character sequence, // so the resulting string will be shorter size_t buflen = _tcslen(pszText) + 100; TCHAR *buf = new TCHAR [buflen]; memset(buf, 0, buflen*sizeof(TCHAR)); for (i = 0; m_aCharEntities[i].pszName != NULL; i++) { ent[1] = m_aCharEntities[i].cCode; int nRep = _tcsistrrep(pszText, m_aCharEntities[i].pszName, ent, buf); if (nRep > 0) { bCharacterEntities = TRUE; _tcscpy(pszText, buf); } } delete [] buf; buf = NULL; TEXTMETRIC tm = { 0 }; n = (int) _tcslen(pszText); // get length again after char entity substitution int textLen = n; while ((n > 0) && pszText && (pszText < (pTextBuffer + textLen))) { TRACE(_T("start while: n=%d pszText=<%s>\n"), n, pszText); /////////////////////////////////////////////////////////////////////// if (_tcsnicmp(pszText, _T("<B>"), 3) == 0) // check for <b> or <B> { n -= 3; pszText += 3; bBold++;// = TRUE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</B>"), 4) == 0) // check for </B> { n -= 4; pszText += 4; if (bBold) bBold--;// = FALSE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<I>"), 3) == 0) // check for <I> { n -= 3; pszText += 3; bItalic++;// = TRUE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</I>"), 4) == 0) // check for </I> { n -= 4; pszText += 4; if (bItalic) bItalic--;// = FALSE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<U>"), 3) == 0) // check for <U> { n -= 3; pszText += 3; bUnderline++;// = TRUE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</U>"), 4) == 0) // check for </U> { n -= 4; pszText += 4; if (bUnderline) bUnderline--;// = FALSE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<S>"), 3) == 0) // check for <S> { n -= 3; pszText += 3; bStrikeThrough++;// = TRUE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</S>"), 4) == 0) // check for </S> { n -= 4; pszText += 4; if (bStrikeThrough) bStrikeThrough--;// = FALSE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<BIG>"), 5) == 0) // check for <BIG> { n -= 5; pszText += 5; if (lf.lfHeight > 0) lf.lfHeight += 2; else lf.lfHeight -= 2; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</BIG>"), 6) == 0) // check for </BIG> { n -= 6; pszText += 6; if (lf.lfHeight > 0) lf.lfHeight -= 2; else lf.lfHeight += 2; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<SMALL>"), 7) == 0) // check for <SMALL> { n -= 7; pszText += 7; if (lf.lfHeight > 0) lf.lfHeight -= 2; else lf.lfHeight += 2; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</SMALL>"), 8) == 0) // check for </SMALL> { n -= 8; pszText += 8; if (lf.lfHeight > 0) lf.lfHeight += 2; else lf.lfHeight -= 2; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<SUB>"), 5) == 0) // check for <SUB> { n -= 5; pszText += 5; bSubscript++;// = TRUE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</SUB>"), 6) == 0) // check for </SUB> { n -= 6; pszText += 6; if (bSubscript) bSubscript--;// = FALSE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<SUP>"), 5) == 0) // check for <SUP> { n -= 5; pszText += 5; bSuperscript++;// = TRUE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</SUP>"), 6) == 0) // check for </SUP> { n -= 6; pszText += 6; if (bSuperscript) bSuperscript--;// = FALSE; continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<FONT"), 5) == 0) // check for <FONT { TRACE(_T("found font\n")); TCHAR *cp = _tcschr(pszText, _T('>')); if (cp) { TCHAR szAttributes[XHTMLDRAW_MAX_TEXT] = { 0 }; _tcsncpy(szAttributes, &pszText[5], cp-pszText-5); TRACE(_T("szAttributes=<%s>\n"), szAttributes); size_t m = _tcslen(szAttributes); n -= (int) (cp - pszText + 1); pszText = cp + 1; // loop to parse FONT attributes while (m > 0) { // trim left whitespace if ((_tcslen(szAttributes) > 0) && (szAttributes[0] == _T(' '))) { m--; _tcscpy(szAttributes, &szAttributes[1]); continue; } /////////////////////////////////////////////////////////// if (_tcsnicmp(szAttributes, _T("COLOR"), 5) == 0) { TRACE(_T("found color\n")); TCHAR *cp2 = _tcschr(szAttributes, _T('"')); if (cp2) { m -= (cp2 - szAttributes) + 1; _tcscpy(szAttributes, cp2+1); cp2 = _tcschr(szAttributes, _T('"')); if (cp2) { *cp2 = _T('\0'); TCHAR szColor[XHTMLDRAW_MAX_TEXT] = { _T('\0') }; _tcsncpy(szColor, szAttributes, cp2-szAttributes+1); TRACE(_T("szColor=<%s>\n"), szColor); CXNamedColors nc(szColor); if (!pXHDS->bIgnoreColorTag) crTextNew = nc.GetRGB(); _tcscpy(szAttributes, cp2+1); m = _tcslen(szAttributes); } } else break; } /////////////////////////////////////////////////////////// else if (_tcsnicmp(szAttributes, _T("BGCOLOR"), 7) == 0) { TRACE(_T("found bgcolor\n")); TCHAR *cp2 = _tcschr(szAttributes, _T('"')); if (cp2) { m -= cp2 - szAttributes + 1; _tcscpy(szAttributes, cp2+1); cp2 = _tcschr(szAttributes, _T('"')); if (cp2) { *cp2 = _T('\0'); TCHAR szBgColor[XHTMLDRAW_MAX_TEXT] = { _T('\0') }; _tcsncpy(szBgColor, szAttributes, cp2-szAttributes+1); TRACE(_T("szBgColor=<%s>\n"), szBgColor); CXNamedColors nc(szBgColor); crBkgndNew = nc.GetRGB(); _tcscpy(szAttributes, cp2+1); m = _tcslen(szAttributes); } } else break; } /////////////////////////////////////////////////////////// else if (_tcsnicmp(szAttributes, _T("FACE"), 4) == 0) { TCHAR *cp2 = _tcschr(szAttributes, _T('"')); if (cp2) { m -= cp2 - szAttributes + 1; _tcscpy(szAttributes, cp2+1); cp2 = _tcschr(szAttributes, _T('"')); if (cp2) { const int nFaceSize = sizeof(lf.lfFaceName); // in bytes int nMaxFaceSize = nFaceSize / sizeof(TCHAR); // in TCHARs memset(lf.lfFaceName, 0, nFaceSize); int nNewFaceSize = (int)(cp2 - szAttributes); // in TCHARs memset(&lf.lfFaceName, 0, nFaceSize); _tcsncpy(lf.lfFaceName, szAttributes, (nNewFaceSize > nMaxFaceSize) ? nMaxFaceSize : nNewFaceSize); TRACE(_T("lf.lfFaceName=<%s>\n"), lf.lfFaceName); m -= cp2 - szAttributes + 1; if (m > 0) _tcscpy(szAttributes, cp2+1); else szAttributes[0] = _T('\0'); m = _tcslen(szAttributes); } } else break; } /////////////////////////////////////////////////////////// else if (_tcsnicmp(szAttributes, _T("SIZE"), 4) == 0) { TCHAR *cp2 = _tcschr(szAttributes, _T('"')); if (cp2) { m -= cp2 - szAttributes + 1; _tcscpy(szAttributes, cp2+1); cp2 = _tcschr(szAttributes, _T('"')); if (cp2) { int nSize = _ttoi(szAttributes); lf.lfHeight -= nSize; nSizeChange = nSize; m -= cp2 - szAttributes + 1; if (m > 0) _tcscpy(szAttributes, cp2+1); else szAttributes[0] = _T('\0'); m = _tcslen(szAttributes); } } else break; } else { while ((_tcslen(szAttributes) > 0) && (szAttributes[0] != _T(' '))) { m--; _tcscpy(szAttributes, &szAttributes[1]); } } } } else { TRACE(_T("ERROR no closing >\n")); pszText += 5; n -= 5; } continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</FONT>"), 7) == 0) // check for </FONT> { n -= 7; pszText += 7; crTextNew = crText; crBkgndNew = crBackground; memcpy(&lf, &prev_lf, sizeof(lf)); continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("<A"), 2) == 0) // check for <A { TCHAR *cp = 0; if ((cp = _tcsistr(pszText, _T("HREF="))) != NULL) // check for HREF= { cp += 5; if (*cp == _T('"')) cp += 1; TCHAR *cp2 = _tcschr(cp, _T('>')); if (cp2) { size_t len = cp2 - cp; if (pXHDS->pszAnchor) delete [] pXHDS->pszAnchor; pXHDS->pszAnchor = new TCHAR [len+4]; memset(pXHDS->pszAnchor, 0, (len+4)*sizeof(TCHAR)); _tcsncpy(pXHDS->pszAnchor, cp, len); size_t last = _tcslen(pXHDS->pszAnchor); if (last > 0) last--; if (pXHDS->pszAnchor[last] == _T('"')) pXHDS->pszAnchor[last] = _T('\0'); TRACE(_T("len=%d pXHDS->szUrl=<%s>\n"), len, pXHDS->pszAnchor); n -= (int) (cp2 + 1 - pszText); pszText = cp2 + 1; TRACE(_T("pszText=<%s>\n"), pszText); // set start X of url pXHDS->rectAnchor.left = rectText.left + nXOffset; TRACE(_T("setting pXHDS->rectAnchor.left to %d\n"), pXHDS->rectAnchor.left); crTextNew = pXHDS->crAnchorText; //RGB(0,0,255); //pXHDS->crText; crBkgndNew = crBackground; memcpy(&lf, &prev_lf, sizeof(lf)); bInAnchor = TRUE; if (bUnderlineUrl) { pXHDS->bAnchorIsUnderlined = TRUE; bUnderline++; } } } else { TRACE(_T("ERROR no closing >\n")); pszText += 2; n -= 2; } continue; } /////////////////////////////////////////////////////////////////////// else if (_tcsnicmp(pszText, _T("</A>"), 4) == 0) // check for </A> { n -= 4; pszText += 4; if (bInAnchor) { pXHDS->rectAnchor.right = rectText.left + nXOffset; pXHDS->bHasAnchor = TRUE; TRACE(_T("setting pXHDS->rectAnchor.right to %d\n"), pXHDS->rectAnchor.right); if (bUnderlineUrl) bUnderline--; crTextNew = crText; crBkgndNew = crBackground; memcpy(&lf, &prev_lf, sizeof(lf)); } bInAnchor = FALSE; continue; } /////////////////////////////////////////////////////////////////////// // plain text else { TRACE(_T("text: pszText=<%s>\n"), pszText); TCHAR *cp = _tcschr(pszText, _T('<')); if (cp) { // there's another tag _tcsncpy(pszText1, pszText, cp - pszText); pszText1[cp-pszText] = _T('\0'); TRACE(_T("pszText1=<%s>\n"), pszText1); if (_tcslen(pszText1) <= 0) { if (_tcslen(pszText) != 0) { _tcscpy(pszText1, pszText); n -= 1; } } pszText = cp; } else { // no more html tags _tcscpy(pszText1, pszText); pszText = NULL; } } TRACE(_T("pszText=<%s>\n"), pszText); TRACE(_T("pszText1=<%s>\n"), pszText1); // create new font ------------------------------------------ lf.lfWeight = bBold ? FW_BOLD : FW_NORMAL; lf.lfUnderline = (BYTE) bUnderline; lf.lfItalic = (BYTE) bItalic; lf.lfStrikeOut = (BYTE) bStrikeThrough; HFONT hNewFont = CreateFontIndirect(&lf); _ASSERTE(hNewFont); HFONT hOldFont = (HFONT) SelectObject(hMemDC, hNewFont); SetTextColor(hMemDC, crTextNew); if (pXHDS->crTextBackground != COLOR_NONE) SetBkColor(hMemDC, pXHDS->crTextBackground); else SetBkMode(hMemDC, TRANSPARENT); // need transparency for italic fonts // replace char entities ------------------------------------ size_t end = _tcslen(pszText1); buflen = end + 100; _ASSERTE(buf == NULL); buf = new TCHAR [buflen]; memset(buf, 0, buflen*sizeof(TCHAR)); _tcsncpy(buf, pszText1, buflen-1); ReplaceCharEntities(buf, end); int len = (int)_tcslen(buf); SIZE size; GetTextExtentPoint32(hMemDC, buf, len, &size); LONG width = size.cx; if ((crBkgndNew != crBackground) && (pXHDS->crTextBackground == COLOR_NONE)) { // changing backgrounds, so fill in with new color HBRUSH hbrushnew = CreateSolidBrush(crBkgndNew); if (hbrushnew) { RECT rect = rectText; rect.right = rect.left + width + 1; if (bItalic) { rect.right += 1; // italic needs a little more if (!IsTrueType(hMemDC)) rect.right += 2; // non-TTF fonts need even more } if (rect.right > rectText.right) rect.right = rectText.right; FillRect(hMemDC, &rect, hbrushnew); DeleteObject(hbrushnew); } } UINT uFormat = pXHDS->uFormat; if (pXHDS->bUseEllipsis) uFormat |= DT_END_ELLIPSIS; if (pXHDS->bHasAnchor) { // set rect for anchor RECT rectCalc = rectText; int nHeight = DrawText(hMemDC, buf, -1, &rectCalc, uFormat | DT_CALCRECT); TRACE(_T("nHeight=%d -----\n"), nHeight); pXHDS->rectAnchor.bottom = pXHDS->rectAnchor.top + nHeight; } RECT savedrect = rectText; GetTextMetrics(hMemDC, &tm); int nBaselineAdjust = tm.tmAscent / 2; if (bSubscript) { rectText.top += nBaselineAdjust; rectText.bottom += nBaselineAdjust; } if (bSuperscript) { rectText.top -= nBaselineAdjust; rectText.bottom -= nBaselineAdjust; } // draw text ------------------------------------------------ TRACE(_T("DrawText: <%s>\n"), buf); DrawText(hMemDC, buf, -1, &rectText, uFormat); rectText = savedrect; nSizeChange = 0; if (hOldFont) SelectObject(hMemDC, hOldFont); if (hNewFont) DeleteObject(hNewFont); hNewFont = 0; hOldFont = 0; delete [] buf; buf = NULL; rectText.left += width; n -= (int)_tcslen(pszText1); } // while // save the rightmost pixel position - note that rectText // is remapped to 0,0 for the memory dc pXHDS->nRightX = rectText.left + nXOffset; TRACE(_T("nRightX = %d =====\n"), pXHDS->nRightX); // end double buffering BitBlt(hDC, rectDraw.left, rectDraw.top, nRectWidth, nRectHeight, hMemDC, 0, 0, SRCCOPY); // swap back the original bitmap if (hOldBitmap) SelectObject(hMemDC, hOldBitmap); if (hBitmap) DeleteObject(hBitmap); hBitmap = 0; DeleteDC(hMemDC); hMemDC = 0; if (pTextBuffer) delete [] pTextBuffer; pTextBuffer = 0; if (pszText1) delete [] pszText1; pszText1 = 0; bInDraw = FALSE; return nWidth; }
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, GS(PLUG_ABOUT)); // 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; }
Cgdi::Cgdi() { m_BlackPen = CreatePen(PS_SOLID, 1, colors[black]); m_WhitePen = CreatePen(PS_SOLID, 1, colors[white]); m_RedPen = CreatePen(PS_SOLID, 1, colors[red]); m_GreenPen = CreatePen(PS_SOLID, 1, colors[green]); m_BluePen = CreatePen(PS_SOLID, 1, colors[blue]); m_GreyPen = CreatePen(PS_SOLID, 1, colors[grey]); m_PinkPen = CreatePen(PS_SOLID, 1, colors[pink]); m_YellowPen = CreatePen(PS_SOLID, 1, colors[yellow]); m_OrangePen = CreatePen(PS_SOLID, 1, colors[orange]); m_PurplePen = CreatePen(PS_SOLID, 1, colors[purple]); m_BrownPen = CreatePen(PS_SOLID, 1, colors[brown]); m_DarkGreenPen = CreatePen(PS_SOLID, 1, colors[dark_green]); m_LightBluePen = CreatePen(PS_SOLID, 1, colors[light_blue]); m_LightGreyPen = CreatePen(PS_SOLID, 1, colors[light_grey]); m_LightPinkPen = CreatePen(PS_SOLID, 1, colors[light_pink]); m_ThickBlackPen = CreatePen(PS_SOLID, 2, colors[black]); m_ThickWhitePen = CreatePen(PS_SOLID, 2, colors[white]); m_ThickRedPen = CreatePen(PS_SOLID, 2, colors[red]); m_ThickGreenPen = CreatePen(PS_SOLID, 2, colors[green]); m_ThickBluePen = CreatePen(PS_SOLID, 2, colors[blue]); m_GreenBrush = CreateSolidBrush(colors[green]); m_RedBrush = CreateSolidBrush(colors[red]); m_BlueBrush = CreateSolidBrush(colors[blue]); m_GreyBrush = CreateSolidBrush(colors[grey]); m_BrownBrush = CreateSolidBrush(colors[brown]); m_YellowBrush = CreateSolidBrush(colors[yellow]); m_LightBlueBrush = CreateSolidBrush(colors[light_blue]); m_DarkGreenBrush = CreateSolidBrush(colors[dark_green]); m_OrangeBrush = CreateSolidBrush(colors[orange]); m_PurpleBrush = CreateSolidBrush(colors[purple]); m_tmpPen = CreatePen(PS_SOLID,1,RGB(0,0,0)); m_tmpBrush = CreateSolidBrush(RGB(0,0,0)); m_hdc = NULL; }
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_VREDRAW | CS_HREDRAW; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wincl.hbrBackground = CreateSolidBrush(RGB(121,205,205)); // SETTING BACKGROUND COLOR /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ _T("Windows Programming #1"), /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ 411, /* Windows decides the position */ 179, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow (hwnd, nCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }
LRESULT CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { char sTitle[100]="title"; PAINTSTRUCT ps; static HDC dc; static RECT r; LPDRAWITEMSTRUCT dItem; char text[20]; int len; SIZE sz; HBRUSH hB; // brush handle static HINSTANCE hInst; static RECT btnrect; // The struct that WM_DRAWITEM needs: static DRAWITEMSTRUCT* pdis; // Width and height of the client area: static long cxClient, cyClient; TCHAR s[BUFFSIZE]; int iResult; HWND hLevelUpButton,hLevelDnButton; HWND hButton; switch (uMsg) { case WM_INITDIALOG:// WM_INITDIALOG message is sent before dialog is displayed { hButton = CreateWindow(TEXT("button"), TEXT("Beep"), WS_VISIBLE | WS_CHILD , 20, 50, 80, 25, hwndDlg, (HMENU) 1, NULL, NULL); GetWindowText(hButton,sTitle,sizeof(sTitle)/sizeof(char)); //~ MessageBoxPrintf("hi",sTitle); hButton = CreateWindow(TEXT("button"), TEXT("Quit!"), WS_VISIBLE | WS_CHILD|BS_OWNERDRAW, 120, 50, 80, 25, hwndDlg, (HMENU) 2, NULL, NULL); //~ // 2. A button with style BS_OWNERDRAW //~ // This is what the article is about :) //~ hLevelUpButton = CreateWindow(_T("button"), TEXT("Beep"), //~ WS_CHILD | WS_VISIBLE|BS_OWNERDRAW, //~ 0,0,40,30, //~ hwndDlg, //~ (HMENU) IDC_BUTTON1, //~ hInst, //~ NULL); //~ if (NULL == hLevelUpButton) { //~ _stprintf(s, _T("! hLevelUpButton NULL")); //~ myWriteToLog(s); //~ } //~ // 3. Second owner draw button: //~ hLevelDnButton = CreateWindow(_T("button"), NULL, //~ WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, //~ 0,0,0,0, //~ hwndDlg, //~ (HMENU) IDC_BUTTON2, //~ hInst, //~ NULL); //~ if (NULL == hLevelDnButton) { //~ _stprintf(s, _T("! hLevelDnButton NULL")); //~ myWriteToLog(s); //~ } return TRUE; } break; case WM_DRAWITEM: dItem = (DRAWITEMSTRUCT*)lParam; SetBkColor(dItem->hDC, RGB(255,0,0)); SetTextColor(dItem->hDC, RGB(0,0,0xFF)); memset(text, '\0', 20); GetWindowText(dItem->hwndItem, text, 20); len=lstrlen(text); GetTextExtentPoint32(dItem->hDC, text, len, &sz); ExtTextOut( dItem->hDC, ((dItem->rcItem.right - dItem->rcItem.left) / 2) + dItem->rcItem.left - (sz.cx / 2), ((dItem->rcItem.bottom - dItem->rcItem.top) / 2) + dItem->rcItem.top - (sz.cy / 2), ETO_OPAQUE | ETO_CLIPPED, &dItem->rcItem, text, len, NULL); DrawEdge( dItem->hDC, &dItem->rcItem, (dItem->itemState & ODS_SELECTED ? BDR_SUNKENOUTER : BDR_RAISEDOUTER), BF_RECT); return DefWindowProc(hwndDlg, uMsg, wParam, lParam); break; case WM_CREATE: { //~ DRAWITEMSTRUCT *dis = (LPDRAWITEMSTRUCT)lParam; //~ HDC hDC = dis->hDC; //~ HWND hwndDlg = dis->hwndItem; //~ RECT r; //~ GetClientRect(hwndDlg, &r); //~ FrameRect(hDC,&r,(HBRUSH)GetStockObject(BLACK_BRUSH)); // 2. A button with style BS_OWNERDRAW // This is what the article is about :) } break; case WM_COMMAND:// { switch(wParam) { case IDC_BUTTON1: { //~ MessageBoxPrintf("hi","%s\n",buff); } break; case IDC_BUTTON2: { } break; default: break; } return TRUE; } break; case WM_CLOSE://Massage for terminate/exit (may close button clicked on title bar) { //Close dialog EndDialog(hwndDlg,0); break; } //~ case WM_CTLCOLORDLG: //set its text and background colors using the specified display device context handle. case WM_CTLCOLORBTN: { hB = CreateSolidBrush(RGB(255,0,0)); return (LONG)hB; break; } case WM_PAINT: { PAINTSTRUCT ps; TRIVERTEX vert[2]; RECT r; GRADIENT_RECT gRect; HDC hDC = BeginPaint(hwndDlg,&ps); GetClientRect(hwndDlg,&r); vert[0].Alpha = 0x0000; vert[0].Red = 0xff00; vert[0].Green = 0x0000; vert[0].Blue = 0x8800; vert[0].x = r.left; vert[0].y = r.top; vert[1].Alpha = 0x0000; vert[1].Red = 0xff00; vert[1].Green = 0xff00; vert[1].Blue = 0xff00; vert[1].x = r.right; vert[1].y = r.bottom; gRect.UpperLeft = 0; gRect.LowerRight = 1; GradientFill(hDC,vert,2,&gRect,1,GRADIENT_FILL_RECT_H); EndPaint(hwndDlg,&ps); break; } case WM_CTLCOLORSTATIC: //可以控制静态控件的颜色 { break; } default: break; } return FALSE; }
static void copy_pixtemp(int id, int x, int y) { COLORREF cf; HDC hdc, hdcPix; HBITMAP xpixOld; HBRUSH hBrush, hOBrush; int x0, y0, x1, y1, x_abs, y_abs; if (!WI[id].pixcopymode) return; x -= tempx; y -= tempy; if (pixclamp) { x = max(clampx1, x); x = min(clampx2, x); y = max(clampy1, y); y = min(clampy2, y); } x0 = max(0, -x); x0 = min(x0, temp_dx); y0 = max(0, -y); y0 = min(y0, temp_dy); x1 = max(0, x); x1 = min(x1, temp_dx); y1 = max(0, y); y1 = min(y1, temp_dy); x_abs = abs(x); y_abs = abs(y); hdc = GetDC(WI[id].child[C_DRAWAREA].hwnd); hdcPix = CreateCompatibleDC(hdc); xpixOld = SelectObject(hdcPix, pixtemp); cf = GetNearestColor(hdc, RGB(127,127,127)); hBrush = CreateSolidBrush(cf); hOBrush = SelectObject(hdc, hBrush); if (x1) FillRectangle(tempx1, tempy1, x1, temp_dy, hdc, hBrush); if (y1) FillRectangle(tempx1, tempy1, temp_dx, y1, hdc, hBrush); if (x0) FillRectangle(tempx1 + (temp_dx - x_abs), tempy1, x0, temp_dy, hdc, hBrush); if (y0) FillRectangle(tempx1, tempy1 + (temp_dy - y_abs), temp_dx, y0, hdc, hBrush); SelectObject(hdc, hOBrush); DeleteObject(hBrush); BitBlt(hdc, tempx1 + x1, tempy1 + y1, temp_dx - x_abs, temp_dy - y_abs, hdcPix, x0, y0, SRCCOPY); SelectObject(hdcPix, xpixOld); DeleteDC(hdcPix); ReleaseDC(WI[id].child[C_DRAWAREA].hwnd, hdc); }
LLDSPEC void gdisp_lld_fill_area(GDisplay *g) { winPriv * priv; RECT rect; HBRUSH hbr; COLORREF color; priv = g->priv; color = gdispColor2Native(g->p.color); hbr = CreateSolidBrush(color); #if GDISP_NEED_CONTROL switch(g->g.Orientation) { case GDISP_ROTATE_0: default: rect.top = g->p.y; rect.bottom = rect.top + g->p.cy; rect.left = g->p.x; rect.right = rect.left + g->p.cx; break; case GDISP_ROTATE_90: rect.bottom = g->g.Width - g->p.x; rect.top = rect.bottom - g->p.cx; rect.left = g->p.y; rect.right = rect.left + g->p.cy; break; case GDISP_ROTATE_180: rect.bottom = g->g.Height - g->p.y; rect.top = rect.bottom - g->p.cy; rect.right = g->g.Width - g->p.x; rect.left = rect.right - g->p.cx; break; case GDISP_ROTATE_270: rect.top = g->p.x; rect.bottom = rect.top + g->p.cx; rect.right = g->g.Height - g->p.y; rect.left = rect.right - g->p.cy; break; } #else rect.top = g->p.y; rect.bottom = rect.top + g->p.cy; rect.left = g->p.x; rect.right = rect.left + g->p.cx; #endif WaitForSingleObject(drawMutex, INFINITE); FillRect(priv->dcBuffer, &rect, hbr); #if GDISP_WIN32_USE_INDIRECT_UPDATE ReleaseMutex(drawMutex); InvalidateRect(priv->hwnd, &rect, FALSE); #else { HDC dc; dc = GetDC(priv->hwnd); FillRect(dc, &rect, hbr); ReleaseDC(priv->hwnd, dc); ReleaseMutex(drawMutex); } #endif DeleteObject(hbr); }
LRESULT CALLBACK LConProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { HWND view; HDC hdc; HBRUSH hbr; HGDIOBJ oldfont; RECT rect; int titlelen; SIZE size; LOGFONT lf; TEXTMETRIC tm; HINSTANCE inst = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); DRAWITEMSTRUCT *drawitem; CHARFORMAT2W format; switch (msg) { case WM_CREATE: // Create game title static control memset (&lf, 0, sizeof(lf)); hdc = GetDC (hWnd); lf.lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72); lf.lfCharSet = ANSI_CHARSET; lf.lfWeight = FW_BOLD; lf.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN; strcpy (lf.lfFaceName, "Trebuchet MS"); GameTitleFont = CreateFontIndirect (&lf); oldfont = SelectObject (hdc, GetStockObject (DEFAULT_GUI_FONT)); GetTextMetrics (hdc, &tm); DefaultGUIFontHeight = tm.tmHeight; if (GameTitleFont == NULL) { GameTitleFontHeight = DefaultGUIFontHeight; } else { SelectObject (hdc, GameTitleFont); GetTextMetrics (hdc, &tm); GameTitleFontHeight = tm.tmHeight; } SelectObject (hdc, oldfont); // Create log read-only edit control view = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "RichEdit20W", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | WS_CLIPSIBLINGS, 0, 0, 0, 0, hWnd, NULL, inst, NULL); HRESULT hr; hr = GetLastError(); if (view == NULL) { ReleaseDC (hWnd, hdc); return -1; } SendMessage (view, EM_SETREADONLY, TRUE, 0); SendMessage (view, EM_EXLIMITTEXT, 0, 0x7FFFFFFE); SendMessage (view, EM_SETBKGNDCOLOR, 0, RGB(70,70,70)); // Setup default font for the log. //SendMessage (view, WM_SETFONT, (WPARAM)GetStockObject (DEFAULT_GUI_FONT), FALSE); format.cbSize = sizeof(format); format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET; format.dwEffects = 0; format.yHeight = 200; format.crTextColor = RGB(223,223,223); format.bCharSet = ANSI_CHARSET; format.bPitchAndFamily = FF_SWISS | VARIABLE_PITCH; wcscpy(format.szFaceName, L"DejaVu Sans"); // At least I have it. :p SendMessageW(view, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format); ConWindow = view; ReleaseDC (hWnd, hdc); view = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW, 0, 0, 0, 0, hWnd, NULL, inst, NULL); if (view == NULL) { return -1; } SetWindowLong (view, GWL_ID, IDC_STATIC_TITLE); GameTitleWindow = view; return 0; case WM_SIZE: if (wParam != SIZE_MAXHIDE && wParam != SIZE_MAXSHOW) { LayoutMainWindow (hWnd, ErrorPane); } return 0; case WM_DRAWITEM: // Draw title banner. if (wParam == IDC_STATIC_TITLE && DoomStartupInfo.Name.IsNotEmpty()) { const PalEntry *c; // Draw the game title strip at the top of the window. drawitem = (LPDRAWITEMSTRUCT)lParam; // Draw the background. rect = drawitem->rcItem; rect.bottom -= 1; c = (const PalEntry *)&DoomStartupInfo.BkColor; hbr = CreateSolidBrush (RGB(c->r,c->g,c->b)); FillRect (drawitem->hDC, &drawitem->rcItem, hbr); DeleteObject (hbr); // Calculate width of the title string. SetTextAlign (drawitem->hDC, TA_TOP); oldfont = SelectObject (drawitem->hDC, GameTitleFont != NULL ? GameTitleFont : (HFONT)GetStockObject (DEFAULT_GUI_FONT)); titlelen = (int)DoomStartupInfo.Name.Len(); GetTextExtentPoint32 (drawitem->hDC, DoomStartupInfo.Name, titlelen, &size); // Draw the title. c = (const PalEntry *)&DoomStartupInfo.FgColor; SetTextColor (drawitem->hDC, RGB(c->r,c->g,c->b)); SetBkMode (drawitem->hDC, TRANSPARENT); TextOut (drawitem->hDC, rect.left + (rect.right - rect.left - size.cx) / 2, 2, DoomStartupInfo.Name, titlelen); SelectObject (drawitem->hDC, oldfont); return TRUE; } // Draw startup screen else if (wParam == IDC_STATIC_STARTUP) { if (StartupScreen != NULL) { drawitem = (LPDRAWITEMSTRUCT)lParam; rect = drawitem->rcItem; // Windows expects DIBs to be bottom-up but ours is top-down, // so flip it vertically while drawing it. StretchDIBits (drawitem->hDC, rect.left, rect.bottom - 1, rect.right - rect.left, rect.top - rect.bottom, 0, 0, StartupBitmap->bmiHeader.biWidth, StartupBitmap->bmiHeader.biHeight, ST_Util_BitsForBitmap(StartupBitmap), StartupBitmap, DIB_RGB_COLORS, SRCCOPY); // If the title banner is gone, then this is an ENDOOM screen, so draw a short prompt // where the command prompt would have been in DOS. if (GameTitleWindow == NULL) { static const char QuitText[] = "Press any key or click anywhere in the window to quit."; SetTextColor (drawitem->hDC, RGB(240,240,240)); SetBkMode (drawitem->hDC, TRANSPARENT); oldfont = SelectObject (drawitem->hDC, (HFONT)GetStockObject (DEFAULT_GUI_FONT)); TextOut (drawitem->hDC, 3, drawitem->rcItem.bottom - DefaultGUIFontHeight - 3, QuitText, countof(QuitText)-1); SelectObject (drawitem->hDC, oldfont); } return TRUE; } } // Draw stop icon. else if (wParam == IDC_ICONPIC) { HICON icon; POINTL char_pos; drawitem = (LPDRAWITEMSTRUCT)lParam; // This background color should match the edit control's. hbr = CreateSolidBrush (RGB(70,70,70)); FillRect (drawitem->hDC, &drawitem->rcItem, hbr); DeleteObject (hbr); // Draw the icon aligned with the first line of error text. SendMessage (ConWindow, EM_POSFROMCHAR, (WPARAM)&char_pos, ErrorIconChar); icon = (HICON)LoadImage (0, IDI_ERROR, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED); DrawIcon (drawitem->hDC, 6, char_pos.y, icon); return TRUE; } return FALSE; case WM_COMMAND: if (ErrorIcon != NULL && (HWND)lParam == ConWindow && HIWORD(wParam) == EN_UPDATE) { // Be sure to redraw the error icon if the edit control changes. InvalidateRect (ErrorIcon, NULL, TRUE); return 0; } break; case WM_CLOSE: PostQuitMessage (0); break; case WM_DESTROY: if (GameTitleFont != NULL) { DeleteObject (GameTitleFont); } break; } return DefWindowProc (hWnd, msg, wParam, lParam); }
INT_PTR CALLBACK DlgSkinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch ( msg ) { case WM_DESTROY: { if ( hPreviewBitmap ) ske_UnloadGlyphImage( hPreviewBitmap ); break; } case WM_INITDIALOG: { TranslateDialogDefault( hwndDlg ); HTREEITEM it = FillAvailableSkinList( hwndDlg ); HWND wnd = GetDlgItem( hwndDlg, IDC_TREE1 ); TreeView_SelectItem( wnd, it ); } return 0; case WM_COMMAND: { int isLoad = 0; switch ( LOWORD(wParam )) { case IDC_COLOUR_MENUNORMAL: case IDC_COLOUR_MENUSELECTED: case IDC_COLOUR_FRAMES: case IDC_COLOUR_STATUSBAR: SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); break; case IDC_BUTTON_INFO: { TCHAR Author[255], URL[MAX_PATH], Contact[255], Description[400], text[2000]; SkinListData *sd = NULL; HTREEITEM hti = TreeView_GetSelection( GetDlgItem( hwndDlg, IDC_TREE1 )); if ( hti == 0 ) return 0; { TVITEM tvi = {0}; tvi.hItem = hti; tvi.mask = TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem( GetDlgItem( hwndDlg, IDC_TREE1 ), &tvi ); sd = ( SkinListData* )( tvi.lParam); } if (!sd ) return 0; if ( sd->File && !_tcschr( sd->File, _T('%'))) { GetPrivateProfileString( _T("Skin_Description_Section"), _T("Author"), TranslateT("( unknown )"), Author, SIZEOF( Author ), sd->File ); GetPrivateProfileString( _T("Skin_Description_Section"), _T("URL"), _T(""), URL, SIZEOF( URL ), sd->File ); GetPrivateProfileString( _T("Skin_Description_Section"), _T("Contact"), _T(""), Contact, SIZEOF( Contact ), sd->File ); GetPrivateProfileString( _T("Skin_Description_Section"), _T("Description"), _T(""), Description, SIZEOF( Description ), sd->File ); mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAuthor(s):\t %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"), sd->Name, Description, Author, Contact, URL, sd->File); } else { mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAuthor(s): %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"), TranslateT("reVista for Modern v0.5"), TranslateT("This is second default Modern Contact list skin in Vista Aero style"), TranslateT("Angeli-Ka (graphics), FYR (template)"), _T("JID: [email protected]"), _T("fyr.mirandaim.ru"), TranslateT("Inside library")); } MessageBox( hwndDlg, text, TranslateT("Skin Information"), MB_OK|MB_ICONINFORMATION ); } break; case IDC_BUTTON_APPLY_SKIN: if ( HIWORD(wParam ) == BN_CLICKED ) { SkinListData *sd = NULL; HTREEITEM hti = TreeView_GetSelection( GetDlgItem( hwndDlg, IDC_TREE1 )); if ( hti == 0 ) return 0; { TVITEM tvi = {0}; tvi.hItem = hti; tvi.mask = TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem( GetDlgItem( hwndDlg, IDC_TREE1 ), &tvi ); sd = ( SkinListData* )( tvi.lParam); } if (!sd ) return 0; if ( glSkinWasModified>0 ) { int res = 0; if ( glSkinWasModified == 1 ) res = MessageBox( hwndDlg, TranslateT("Skin editor contains not stored changes.\n\nAll changes will be lost.\n\n Continue to load new skin?"), TranslateT("Warning!"), MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2|MB_TOPMOST ); else res = MessageBox( hwndDlg, TranslateT("Current skin was not saved to file.\n\nAll changes will be lost.\n\n Continue to load new skin?"), TranslateT("Warning!"), MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2|MB_TOPMOST ); if ( res != IDOK ) return 0; } ske_LoadSkinFromIniFile( sd->File, FALSE ); ske_LoadSkinFromDB(); glOtherSkinWasLoaded = TRUE; pcli->pfnClcBroadcast( INTM_RELOADOPTIONS, 0, 0 ); Sync( CLUIFrames_OnClistResize_mod, 0, 0 ); ske_RedrawCompleteWindow( ); Sync( CLUIFrames_OnClistResize_mod, 0, 0 ); { HWND hwnd = pcli->hwndContactList; RECT rc = {0}; GetWindowRect( hwnd, &rc ); Sync( CLUIFrames_OnMoving, hwnd, &rc ); } if ( g_hCLUIOptionsWnd ) { SendDlgItemMessage( g_hCLUIOptionsWnd, IDC_LEFTMARGINSPIN, UDM_SETPOS, 0, db_get_b( NULL, "CLUI", "LeftClientMargin", SETTING_LEFTCLIENTMARIGN_DEFAULT )); SendDlgItemMessage( g_hCLUIOptionsWnd, IDC_RIGHTMARGINSPIN, UDM_SETPOS, 0, db_get_b( NULL, "CLUI", "RightClientMargin", SETTING_RIGHTCLIENTMARIGN_DEFAULT )); SendDlgItemMessage( g_hCLUIOptionsWnd, IDC_TOPMARGINSPIN, UDM_SETPOS, 0, db_get_b( NULL, "CLUI", "TopClientMargin", SETTING_TOPCLIENTMARIGN_DEFAULT )); SendDlgItemMessage( g_hCLUIOptionsWnd, IDC_BOTTOMMARGINSPIN, UDM_SETPOS, 0, db_get_b( NULL, "CLUI", "BottomClientMargin", SETTING_BOTTOMCLIENTMARIGN_DEFAULT )); } } break; case IDC_BUTTON_RESCAN: if (HIWORD(wParam ) == BN_CLICKED) { HTREEITEM it = FillAvailableSkinList(hwndDlg); HWND wnd = GetDlgItem(hwndDlg, IDC_TREE1); TreeView_SelectItem(wnd, it); } } break; } case WM_DRAWITEM: if ( wParam == IDC_PREVIEW ) { //TODO:Draw hPreviewBitmap here int mWidth, mHeight; HBRUSH hbr = CreateSolidBrush( GetSysColor( COLOR_3DFACE )); DRAWITEMSTRUCT *dis = ( DRAWITEMSTRUCT * )lParam; mWidth = dis->rcItem.right-dis->rcItem.left; mHeight = dis->rcItem.bottom-dis->rcItem.top; HDC memDC = CreateCompatibleDC( dis->hDC ); HBITMAP hbmp = ske_CreateDIB32( mWidth, mHeight ); HBITMAP holdbmp = ( HBITMAP )SelectObject( memDC, hbmp ); RECT workRect = dis->rcItem; OffsetRect( &workRect, -workRect.left, -workRect.top ); FillRect( memDC, &workRect, hbr ); DeleteObject( hbr ); if ( hPreviewBitmap ) { //variables BITMAP bmp = {0}; POINT imgPos = {0}; float xScale = 1, yScale = 1; //GetSize GetObject( hPreviewBitmap, sizeof( BITMAP ), &bmp ); int wWidth = workRect.right-workRect.left; int wHeight = workRect.bottom-workRect.top; if ( wWidth < bmp.bmWidth ) xScale = ( float )wWidth/bmp.bmWidth; if ( wHeight < bmp.bmHeight ) yScale = ( float )wHeight/bmp.bmHeight; xScale = min( xScale, yScale ); yScale = xScale; int dWidth = ( int )( xScale*bmp.bmWidth ); int dHeight = ( int )( yScale*bmp.bmHeight ); //CalcPosition imgPos.x = workRect.left+(( wWidth-dWidth )>>1 ); imgPos.y = workRect.top+(( wHeight-dHeight )>>1 ); //DrawImage DrawAvatarImageWithGDIp( memDC, imgPos.x, imgPos.y, dWidth, dHeight, hPreviewBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, 8, 255 ); } BitBlt( dis->hDC, dis->rcItem.left, dis->rcItem.top, mWidth, mHeight, memDC, 0, 0, SRCCOPY ); SelectObject( memDC, holdbmp ); DeleteObject( hbmp ); DeleteDC( memDC ); } break; case WM_NOTIFY: switch (( ( LPNMHDR )lParam)->idFrom ) { case IDC_TREE1: { NMTREEVIEW * nmtv = ( NMTREEVIEW * ) lParam; if (nmtv == NULL) return 0; if (nmtv->hdr.code == TVN_SELCHANGEDA || nmtv->hdr.code == TVN_SELCHANGEDW) { SkinListData * sd = NULL; if (hPreviewBitmap) { ske_UnloadGlyphImage( hPreviewBitmap ); hPreviewBitmap = NULL; } if (nmtv->itemNew.lParam) { sd = ( SkinListData* )nmtv->itemNew.lParam; TCHAR buf[MAX_PATH]; PathToRelativeT(sd->File, buf); SetDlgItemText(hwndDlg,IDC_EDIT_SKIN_FILENAME,buf); TCHAR prfn[MAX_PATH] = {0}, imfn[MAX_PATH] = {0}, skinfolder[MAX_PATH] = {0}; GetPrivateProfileString( _T("Skin_Description_Section"), _T("Preview"), _T(""), imfn, SIZEOF( imfn ), sd->File ); IniParser::GetSkinFolder( sd->File, skinfolder ); mir_sntprintf(prfn, SIZEOF(prfn), _T("%s\\%s"), skinfolder, imfn); PathToAbsoluteT(prfn, imfn); hPreviewBitmap = ske_LoadGlyphImage(imfn); EnableWindow( GetDlgItem( hwndDlg, IDC_BUTTON_APPLY_SKIN ), TRUE ); EnableWindow( GetDlgItem( hwndDlg, IDC_BUTTON_INFO ), TRUE ); if ( hPreviewBitmap ) InvalidateRect( GetDlgItem( hwndDlg, IDC_PREVIEW ), NULL, TRUE ); else { //prepare text TCHAR Author[255], URL[MAX_PATH], Contact[255], Description[400], text[2000]; SkinListData* sd = NULL; HTREEITEM hti = TreeView_GetSelection( GetDlgItem( hwndDlg, IDC_TREE1 )); if ( hti == 0 ) return 0; { TVITEM tvi = {0}; tvi.hItem = hti; tvi.mask = TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem( GetDlgItem( hwndDlg, IDC_TREE1 ), &tvi ); sd = ( SkinListData* )( tvi.lParam); } if (!sd ) return 0; if ( sd->File && !_tcschr( sd->File, _T('%'))) { GetPrivateProfileString( _T("Skin_Description_Section"), _T("Author"), TranslateT("( unknown )"), Author, SIZEOF( Author ), sd->File ); GetPrivateProfileString( _T("Skin_Description_Section"), _T("URL"), _T(""), URL, SIZEOF( URL ), sd->File ); GetPrivateProfileString( _T("Skin_Description_Section"), _T("Contact"), _T(""), Contact, SIZEOF( Contact ), sd->File ); GetPrivateProfileString( _T("Skin_Description_Section"), _T("Description"), _T(""), Description, SIZEOF( Description ), sd->File ); mir_sntprintf(text, SIZEOF(text), TranslateT("Preview is not available\n\n%s\n----------------------\n\n%s\n\nAUTHOR(S):\n%s\n\nCONTACT:\n%s\n\nHOMEPAGE:\n%s"), sd->Name, Description, Author, Contact, URL); } else { mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAUTHORS:\n%s\n\nCONTACT:\n%s\n\nWEB:\n%s\n\n\n"), TranslateT("reVista for Modern v0.5"), TranslateT("This is second default Modern Contact list skin in Vista Aero style"), TranslateT("graphics by Angeli-Ka\ntemplate by FYR"), _T("JID: [email protected]"), _T("fyr.mirandaim.ru")); } ShowWindow( GetDlgItem( hwndDlg, IDC_PREVIEW ), SW_HIDE ); ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_INFO ), SW_SHOW ); SetDlgItemText(hwndDlg, IDC_STATIC_INFO, text); } } else { //no selected SetDlgItemText(hwndDlg, IDC_EDIT_SKIN_FILENAME, TranslateT("Select skin from list")); EnableWindow( GetDlgItem( hwndDlg, IDC_BUTTON_APPLY_SKIN ), FALSE ); EnableWindow( GetDlgItem( hwndDlg, IDC_BUTTON_INFO ), FALSE ); SetDlgItemText(hwndDlg, IDC_STATIC_INFO, TranslateT("Please select skin to apply")); ShowWindow( GetDlgItem( hwndDlg, IDC_PREVIEW ), SW_HIDE ); } ShowWindow( GetDlgItem( hwndDlg, IDC_PREVIEW ), hPreviewBitmap?SW_SHOW:SW_HIDE ); return 0; } else if (nmtv->hdr.code == TVN_DELETEITEMA || nmtv->hdr.code == TVN_DELETEITEMW) { mir_free_and_nil( nmtv->itemOld.lParam); return 0; } } break; case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: pcli->pfnClcBroadcast( INTM_RELOADOPTIONS, 0, 0 ); NotifyEventHooks( g_CluiData.hEventBkgrChanged, 0, 0 ); pcli->pfnClcBroadcast( INTM_INVALIDATE, 0, 0 ); RedrawWindow( GetParent( pcli->hwndContactTree ), NULL, NULL, RDW_INVALIDATE|RDW_FRAME|RDW_ALLCHILDREN ); } break; } }
BOOL CToolSetupPage::OnInitDialog() { m_BackgroundBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); return CPropertyPage::OnInitDialog(); }
int DisasmView_DrawDisassemble(HDC hdc, CProcessor* pProc, WORD base, WORD previous, int x, int y) { int result = -1; int cxChar, cyLine; GetFontWidthAndHeight(hdc, &cxChar, &cyLine); COLORREF colorText = GetSysColor(COLOR_WINDOWTEXT); WORD proccurrent = pProc->GetPC(); WORD current = base; // Draw current line background if (!m_okDisasmSubtitles) //NOTE: Subtitles can move lines down { HGDIOBJ oldBrush = SelectObject(hdc, CreateSolidBrush(COLOR_CURRENT)); int yCurrent = (proccurrent - (current - 5)) * cyLine; PatBlt(hdc, 0, yCurrent, 1000, cyLine, PATCOPY); SelectObject(hdc, oldBrush); } // Читаем из памяти процессора в буфер const int nWindowSize = 30; WORD memory[nWindowSize + 2]; for (int idx = 0; idx < nWindowSize; idx++) { int addrtype; memory[idx] = g_pBoard->GetWordView( current + idx * 2 - 10, pProc->IsHaltMode(), TRUE, &addrtype); } WORD address = current - 10; WORD disasmfrom = current; if (previous >= address && previous < current) disasmfrom = previous; int length = 0; WORD wNextBaseAddr = 0; for (int index = 0; index < nWindowSize; index++) // Рисуем строки { if (m_okDisasmSubtitles) // Subtitles - комментарий к блоку { DisasmSubtitleItem* pSubItem = DisasmView_FindSubtitle(address, SUBTYPE_BLOCKCOMMENT); if (pSubItem != NULL && pSubItem->comment != NULL) { LPCTSTR strBlockSubtitle = pSubItem->comment; ::SetTextColor(hdc, COLOR_SUBTITLE); TextOut(hdc, x + 21 * cxChar, y, strBlockSubtitle, (int) _tcslen(strBlockSubtitle)); ::SetTextColor(hdc, colorText); y += cyLine; } } DrawOctalValue(hdc, x + 5 * cxChar, y, address); // Address // Value at the address WORD value = memory[index]; ::SetTextColor(hdc, COLOR_VALUE); DrawOctalValue(hdc, x + 13 * cxChar, y, value); ::SetTextColor(hdc, colorText); // Current position if (address == current) { TextOut(hdc, x + 1 * cxChar, y, _T(" >"), 3); result = y; // Remember line for the focus rect } if (address == proccurrent) { BOOL okPCchanged = DebugView_IsRegisterChanged(7); if (okPCchanged) ::SetTextColor(hdc, COLOR_RED); TextOut(hdc, x + 1 * cxChar, y, _T("PC"), 2); ::SetTextColor(hdc, colorText); TextOut(hdc, x + 3 * cxChar, y, _T(">>"), 2); } else if (address == previous) { ::SetTextColor(hdc, COLOR_BLUE); TextOut(hdc, x + 1 * cxChar, y, _T(" >"), 3); } BOOL okData = FALSE; if (m_okDisasmSubtitles) // Show subtitle { DisasmSubtitleItem* pSubItem = DisasmView_FindSubtitle(address, SUBTYPE_COMMENT | SUBTYPE_DATA); if (pSubItem != NULL && (pSubItem->type & SUBTYPE_DATA) != 0) okData = TRUE; if (pSubItem != NULL && (pSubItem->type & SUBTYPE_COMMENT) != 0 && pSubItem->comment != NULL) { LPCTSTR strSubtitle = pSubItem->comment; ::SetTextColor(hdc, COLOR_SUBTITLE); TextOut(hdc, x + 52 * cxChar, y, strSubtitle, (int) _tcslen(strSubtitle)); ::SetTextColor(hdc, colorText); // Строку с субтитром мы можем использовать как опорную для дизассемблера if (disasmfrom > address) disasmfrom = address; } } if (address >= disasmfrom && length == 0) { TCHAR strInstr[8]; TCHAR strArg[32]; if (okData) // По этому адресу лежат данные -- нет смысла дизассемблировать { lstrcpy(strInstr, _T("data")); PrintOctalValue(strArg, *(memory + index)); length = 1; } else { length = DisassembleInstruction(memory + index, address, strInstr, strArg); int delta; if (!m_okDisasmSubtitles && //NOTE: Subtitles can move lines down DisasmView_CheckForJump(memory + index, address, &delta) && abs(delta) < 32) { DisasmView_DrawJump(hdc, y, delta, x + (30 + _tcslen(strArg)) * cxChar, cyLine); } } if (index + length <= nWindowSize) { TextOut(hdc, x + 21 * cxChar, y, strInstr, (int) _tcslen(strInstr)); TextOut(hdc, x + 29 * cxChar, y, strArg, (int) _tcslen(strArg)); } ::SetTextColor(hdc, colorText); if (wNextBaseAddr == 0) wNextBaseAddr = address + length * 2; } if (length > 0) length--; address += 2; y += cyLine; } m_wDisasmNextBaseAddr = wNextBaseAddr; return result; }
int ShowSettings() { PROPSHEETPAGE psp[3]; psp[0].dwSize = sizeof(PROPSHEETPAGE); psp[0].dwFlags = PSP_USETITLE; psp[0].hInstance = g_hInst; psp[0].pszTemplate = MAKEINTRESOURCE(IDD_SET_GAME); psp[0].pszTitle = LoadStr(L"Game", IDS_SET_GAME); psp[0].pfnDlgProc = [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR { switch (message) { case WM_INITDIALOG: { HWND hWnd = GetDlgItem(hDlg, IDC_EDIT_PLAYERNAME); Edit_LimitText(hWnd, 23); SetWindowTextA(hWnd, g_browserSettings.playerName); hWnd = GetDlgItem(hDlg, IDC_EDIT_GTAPATH); Edit_LimitText(hWnd, 260); SetWindowText(hWnd, g_browserSettings.gamePath); return (INT_PTR)TRUE; } case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { switch (LOWORD(wParam)) { case IDC_BTN_BROWSE: { OPENFILENAME ofn = {}; wchar_t gamePath[MAX_PATH]; HWND hWnd = GetDlgItem(hDlg, IDC_EDIT_GTAPATH); GetWindowText(hWnd, gamePath, sizeof(gamePath)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hDlg; ofn.lpstrFile = gamePath; ofn.nMaxFile = sizeof(gamePath); ofn.lpstrFilter = L"gta-vc.exe\0gta-vc.exe\0testapp.exe\0testapp.exe\0"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; if (GetOpenFileName(&ofn)) SetWindowText(hWnd, gamePath); } break; } } else if (HIWORD(wParam) == EN_CHANGE) PropSheet_Changed(GetParent(hDlg), hDlg); break; case PSM_QUERYSIBLINGS: // Save settings GetDlgItemTextA(hDlg, IDC_EDIT_PLAYERNAME, g_browserSettings.playerName, 24); GetDlgItemText(hDlg, IDC_EDIT_GTAPATH, g_browserSettings.gamePath, 260); break; } return (INT_PTR)FALSE; }; psp[1].dwSize = sizeof(PROPSHEETPAGE); psp[1].dwFlags = PSP_USETITLE; psp[1].hInstance = g_hInst; psp[1].pszTemplate = MAKEINTRESOURCE(IDD_SET_UPDATE); psp[1].pszTitle = LoadStr(L"Update", IDS_SET_UPDATE); psp[1].pfnDlgProc = [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR { switch (message) { case WM_INITDIALOG: { HWND hComboBox = GetDlgItem(hDlg, IDC_COM_FREQ); ComboBox_AddString(hComboBox, LoadStr(L"Every start", IDS_EVERY_START)); ComboBox_AddString(hComboBox, LoadStr(L"Every day", IDS_EVERY_DAY)); ComboBox_AddString(hComboBox, LoadStr(L"Every two days", IDS_EVERY_2DAY)); ComboBox_AddString(hComboBox, LoadStr(L"Every week", IDS_EVERY_WEEK)); ComboBox_AddString(hComboBox, LoadStr(L"Never", IDS_NEVER)); ComboBox_SetCurSel(hComboBox, g_browserSettings.gameUpdateFreq); SetWindowTextA(GetDlgItem(hDlg, IDC_EDIT_UPD_URL), g_browserSettings.gameUpdateURL.c_str()); SetWindowTextA(GetDlgItem(hDlg, IDC_EDIT_UPD_PASS), g_browserSettings.gameUpdatePassword.c_str()); SetWindowTextA(GetDlgItem(hDlg, IDC_EDIT_MASTER_URL), g_browserSettings.masterlistURL.c_str()); return (INT_PTR)TRUE; } case WM_COMMAND: if (HIWORD(wParam) == EN_CHANGE || HIWORD(wParam) == CBN_SELCHANGE) PropSheet_Changed(GetParent(hDlg), hDlg); break; case PSM_QUERYSIBLINGS: // Save settings g_browserSettings.gameUpdateFreq = (updateFreq)ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COM_FREQ)); g_browserSettings.gameUpdateURL = GetText(GetDlgItem(hDlg, IDC_EDIT_UPD_URL)); g_browserSettings.gameUpdatePassword = GetText(GetDlgItem(hDlg, IDC_EDIT_UPD_PASS)); g_browserSettings.masterlistURL = GetText(GetDlgItem(hDlg, IDC_EDIT_MASTER_URL)); break; } return (INT_PTR)FALSE; }; psp[2].dwSize = sizeof(PROPSHEETPAGE); psp[2].dwFlags = PSP_USETITLE; psp[2].hInstance = g_hInst; psp[2].pszTemplate = MAKEINTRESOURCE(IDD_SET_UI); psp[2].pszTitle = LoadStr(L"UI", IDS_SET_UI); psp[2].pfnDlgProc = [](HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -> INT_PTR { static COLORREF officialColor; static std::vector<std::pair<int, std::wstring>> codePages; switch (message) { case WM_INITDIALOG: { HWND hComboBox = GetDlgItem(hDlg, IDC_COM_LANGUAGE); for (size_t i = 0; i < std::size(languages); i++) { ComboBox_AddString(hComboBox, languageNames[i]); } ComboBox_SetCurSel(hComboBox, g_browserSettings.language); officialColor = g_browserSettings.officialColor; /*std::pair<int, std::wstring> info = { CP_ACP, L"Default" }; codePages.push_back(info); EnumSystemCodePages([](LPWSTR lpCodePageString) -> BOOL { int codePage = _wtoi(lpCodePageString); CPINFOEX cpinfo; if (GetCPInfoEx(codePage, 0, &cpinfo)) { std::pair<int, std::wstring> info = { codePage, std::wstring(cpinfo.CodePageName) }; codePages.push_back(info); } return TRUE; }, CP_SUPPORTED); hComboBox = GetDlgItem(hDlg, IDC_COM_CHARSET); for (auto codePage : codePages) { ComboBox_AddString(hComboBox, codePage.second.c_str()); }*/ //ComboBox_SetCurSel(hComboBox, g_browserSettings.language); return (INT_PTR)TRUE; } case WM_DESTROY: codePages.clear(); break; case WM_DRAWITEM: if (wParam = IDC_STATIC_OFFICIAL_COLOR) { LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; HBRUSH hBrush = CreateSolidBrush(officialColor); if (hBrush) { FillRect(dis->hDC, &dis->rcItem, hBrush); DeleteObject(hBrush); } } break; case WM_COMMAND: if (HIWORD(wParam) == CBN_SELCHANGE) PropSheet_Changed(GetParent(hDlg), hDlg); switch (LOWORD(wParam)) { case IDC_BTN_OFFICIAL_COLOR: { CHOOSECOLOR cc = {}; cc.lStructSize = sizeof(cc); cc.hwndOwner = hDlg; cc.lpCustColors = g_browserSettings.custColors; cc.rgbResult = officialColor; cc.Flags = CC_FULLOPEN | CC_RGBINIT; if (ChooseColor(&cc)) { officialColor = cc.rgbResult; InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_OFFICIAL_COLOR), nullptr, FALSE); PropSheet_Changed(GetParent(hDlg), hDlg); } } break; } break; case PSM_QUERYSIBLINGS: // Save settings g_browserSettings.language = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COM_LANGUAGE)); g_browserSettings.officialColor = officialColor; break; } return (INT_PTR)FALSE; }; PROPSHEETHEADER psh; psh.dwSize = sizeof(PROPSHEETHEADER); psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOCONTEXTHELP | PSH_USECALLBACK; psh.hwndParent = g_hMainWnd; psh.hInstance = g_hInst; psh.pszCaption = LoadStr(L"Settings", IDS_SETTINGS); psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE); psh.nStartPage = 0; psh.ppsp = psp; psh.pfnCallback = [](HWND hWndDlg, UINT uMsg, LPARAM lParam) -> int { switch (uMsg) { case PSCB_BUTTONPRESSED: if (lParam == PSBTN_APPLYNOW || lParam == PSBTN_OK) { PropSheet_QuerySiblings(hWndDlg, 0, 0); SaveSettings(); InvalidateRect(g_hWndListViewServers, nullptr, FALSE); InvalidateRect(g_hWndListViewHistory, nullptr, FALSE); } break; } return 0; }; return PropertySheet(&psh); }
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { // код уведомления UINT idChild = LOWORD(wParam); // идентификатор дочернего окна HWND hwndChild = (HWND)lParam; // дескриптор дочернего PAINTSTRUCT ps; switch (message){ case WM_CREATE:{ PWINDOWINFO pwi = malloc(sizeof(WINDOWINFO)); if (!pwi){ CloseWindowMy(hwnd); break; } GetWindowInfo(hwnd, pwi); int w = pwi->rcClient.right - pwi->rcClient.left; int h = pwi->rcClient.bottom - pwi->rcClient.top; free(pwi); HWND hwndExit = CreateWindowA("button", "закрыть", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, 0, h - 30, w / 2, 30, hwnd, (HMENU)ID_BUTTON_EXIT, NULL, NULL); HWND hwndTurn = CreateWindowA("button", "свернуть", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, w / 2, h - 30, w / 2, 30, hwnd, (HMENU)ID_BUTTON_TURN, NULL, NULL); HWND hwndAutoRun = CreateWindowA("button", NULL, WS_CHILD | BS_AUTOCHECKBOX | WS_VISIBLE, 300, 131, 15, 15, hwnd, (HMENU)ID_BUTTON_AUTORUN, NULL, NULL); HWND hwndHotKey = CreateWindowA("Edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_READONLY, 230, 10, 50, 20, hwnd, (HMENU)ID_EDIT_HOTKEY, NULL, NULL); glbOldEditProc = SetWindowLongW(hwndHotKey, GWL_WNDPROC, (LONG)newEditProc); //замена процесса обработки сообщений едита ShowWindow(hwndHotKey, SW_NORMAL); ShowWindow(hwndExit, SW_NORMAL); ShowWindow(hwndAutoRun, SW_NORMAL); ShowWindow(hwndTurn, SW_NORMAL); UINT ChekAutoRunResult = ChekAutoRun(); //проверяем, есть ли автозагрузка if (ChekAutoRunResult == MYERROR){ CloseWindowMy(hwnd); break; } else if (ChekAutoRunResult == SUCCESS) SendMessageA(hwndAutoRun, BM_SETCHECK, 1, 0); //устанавливаем галочку автозагрузки, если она есть CreatIcon(hwnd); INT hotKeyCode = SetHotKeyToEdit(hwndHotKey); if (hotKeyCode == MYERROR){//установка горячей клавиши CloseWindowMy(hwnd); break; } pInitHotKeyDll(hotKeyCode,hwndHotKey); //в длл ее break; } case WM_ICON:{ switch (lParam) { case WM_LBUTTONDBLCLK:{ ShowWindow(hwnd, SW_NORMAL); // работа с иконкой break; } default: break; } break; } case WM_COMMAND:{ if (idChild == ID_BUTTON_EXIT){ CloseWindowMy(hwnd); } if (idChild == ID_BUTTON_TURN){ ShowWindow(hwnd, SW_HIDE); } if (idChild == ID_BUTTON_AUTORUN){ // если захотели автозагрузку LRESULT result = SendMessageA(hwndChild, BM_GETCHECK, 0, 0); if (result == BST_CHECKED){ //если галочка ставится char *szFileName = malloc(MAX_LENGTH); if (!szFileName){ CloseWindowMy(hwnd); break; } memset(szFileName, 0, MAX_LENGTH); GetModuleFileNameA(NULL, szFileName, MAX_PATH); if (SetAutoRunToReg((LPBYTE)szFileName, strlen(szFileName)) == MYERROR){//добавляем наше приложение в автозагрузку glbPaintError = MYERROR; SendMessageA(hwndChild, BM_SETCHECK, 0, 0); // если вдруг что-то пошло не так, выводим ошибку InvalidateRect(hwnd, 0, 0); SendMessageA(hwnd, WM_PAINT, 0,0); } else{ glbPaintError = SUCCESS; InvalidateRect(hwnd, 0,0); SendMessageA(hwnd, WM_PAINT, 0, 0); } } else { if (SetAutoRunToReg(NULL, 0) == MYERROR){//удаляем наше приложение из автозагрузки dsfdsSDFDSFsdfdasdsadASDSADfdfdsfSDFDSS glbPaintError = MYERROR; SendMessageA(hwndChild, BM_SETCHECK, 1, 0); InvalidateRect(hwnd, 0, 0); SendMessageA(hwnd, WM_PAINT, 0,0); } else{ glbPaintError = SUCCESS; InvalidateRect(hwnd, 0, 0); SendMessageA(hwnd, WM_PAINT, 0, 0); } } } break; } case WM_PAINT:{ HDC hdc = BeginPaint(hwnd, &ps); HBRUSH hBrush = CreateSolidBrush(RGB(0xff, 0xff, 0xff)); HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0xff, 0xff, 0xff)); SelectObject(hdc, hPen); SelectObject(hdc, hBrush); WINDOWINFO wi; GetWindowInfo(hwnd, &wi); int w = wi.rcClient.right - wi.rcClient.left; int h = wi.rcClient.bottom - wi.rcClient.top; Rectangle(hdc, 0, 0, w, h); TextOutA(hdc, 10, 10, "Клавиша для переключения:", 25); TextOutA(hdc, 10, 30, "Для смены клавиши, нажмите мышкой на рамку,", 42); TextOutA(hdc, 10, 50, "Затем нажмите нужную клавишу из списка:", 39); TextOutA(hdc, 10, 70, "1. Shift", 8); TextOutA(hdc, 10, 85, "2. Pause", 8); TextOutA(hdc, 10, 100, "3. ctrl", 7); TextOutA(hdc, 10, 130, "Запуск Свичера при загрузке Windows:", 36); if (glbPaintError == MYERROR){ TextOutA(hdc, 10, 115, "Не удается изменить состояние автозагрузки.", 43); } EndPaint(hwnd, &ps); } default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
LRESULT DisViewBox_OnPaint(disview_struct *win, WPARAM wParam, LPARAM lParam) { HWND hwnd = GetDlgItem(win->hwnd, IDC_DES_BOX); HDC hdc; PAINTSTRUCT ps; SIZE fontsize; TCHAR text[100]; TCHAR txt[100]; RECT rect; int lg; int ht; HDC mem_dc; HBITMAP mem_bmp; u32 nbligne; GetClientRect(hwnd, &rect); lg = rect.right - rect.left; ht = rect.bottom - rect.top; hdc = BeginPaint(hwnd, &ps); mem_dc = CreateCompatibleDC(hdc); mem_bmp = CreateCompatibleBitmap(hdc, lg, ht); SelectObject(mem_dc, mem_bmp); FillRect(mem_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH)); SelectObject(mem_dc, GetStockObject(SYSTEM_FIXED_FONT)); GetTextExtentPoint32(mem_dc, "0", 1, &fontsize); nbligne = ht/fontsize.cy; SetTextColor(mem_dc, RGB(0,0,0)); if((win->mode==1) || ((win->mode==0) && (win->cpu->CPSR.bits.T == 0))) { u32 i; u32 adr; if (win->autoup) win->curr_ligne = (win->cpu->instruct_adr >> 2) - (win->curr_ligne % nbligne) ; adr = win->curr_ligne*4; for(i = 0; i < nbligne; ++i) { u32 ins = MMU_readWord(win->cpu->proc_ID, adr); des_arm_instructions_set[INDEX(ins)](adr, ins, txt); sprintf(text, "%04X:%04X %08X %s", (int)(adr>>16), (int)(adr&0xFFFF), (int)ins, txt); DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX); rect.top+=fontsize.cy; adr += 4; } if(((win->cpu->instruct_adr&0x0FFFFFFF) >= win->curr_ligne<<2)&&((win->cpu->instruct_adr&0x0FFFFFFF) <= (win->curr_ligne+nbligne<<2))) { HBRUSH brjaune = CreateSolidBrush(RGB(255, 255, 0)); SetBkColor(mem_dc, RGB(255, 255, 0)); rect.top = (((win->cpu->instruct_adr&0x0FFFFFFF)>>2) - win->curr_ligne)*fontsize.cy; rect.bottom = rect.top + fontsize.cy; FillRect(mem_dc, &rect, brjaune); des_arm_instructions_set[INDEX(win->cpu->instruction)](win->cpu->instruct_adr, win->cpu->instruction, txt); sprintf(text, "%04X:%04X %08X %s", (int)((win->cpu->instruct_adr&0x0FFFFFFF)>>16), (int)(win->cpu->instruct_adr&0xFFFF), (int)win->cpu->instruction, txt); DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX); DeleteObject(brjaune); }
LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_TIMER: if (animationDone) break; nameListPos += GFX::TextSpeed; if (nameListPos > (kidList.nRecords-1)) { nameListPos = (float) (kidList.nRecords - 1); KillTimer(hWnd, timerID); timerID = NULL; animationDone = true; showCreditBox = true; } InvalidateRect(hWnd, NULL, false); break; case WM_CREATE: break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); // Create an off-screen DC for double-buffering HDC hdcM = CreateCompatibleDC(hdc); RECT cR; GetClientRect(hWnd, &cR); HBITMAP hbmMem = CreateCompatibleBitmap(hdc, cR.right, cR.bottom); HGDIOBJ hOld = SelectObject(hdcM, hbmMem); HBRUSH oldB = (HBRUSH) SelectObject(hdcM, CreateSolidBrush(GFX::backgr)); HPEN oldP = (HPEN) SelectObject(hdcM, CreatePen(PS_SOLID, 1, GFX::backgr)); Rectangle(hdcM, 0, 0, cR.right+1, cR.bottom+1); SetMapMode(hdcM, MM_TEXT); HFONT font = CreateFont((UINT)(cR.bottom * GFX::TextHeight), 0, 0, 0, GFX::TextWeight, GFX::isItalic, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, DEFAULT_PITCH | GFX::TextFamily, NULL); HFONT oldF = (HFONT)SelectObject(hdcM, font); SetTextColor(hdcM, GFX::textcolor); SetBkColor(hdcM, GFX::backgr); // draw two names, the floor of nameListPos and the ceil of nameListPos UINT n1 = (int)nameListPos; UINT n2 = n1 + 1; float fp = nameListPos - n1; if ( (n1 >= 0) && (n1 < kidList.nRecords)) { RECT cR1 = cR; float off = fp * cR.bottom; cR1.top -= (int) off; cR1.bottom -= (int) off; DrawText(hdcM, kidList.pRecords[n1]->name, wcslen(kidList.pRecords[n1]->name) , &cR1, DT_CENTER | DT_VCENTER); } if ((n2 >= 0) && (n2 < kidList.nRecords)) { RECT cR2 = cR; float off = ((fp-1.0f) * cR.bottom); cR2.top -= (int) off; cR2.bottom -= (int) off; DrawText(hdcM, kidList.pRecords[n2]->name, wcslen(kidList.pRecords[n2]->name) , &cR2, DT_CENTER | DT_VCENTER); } DeleteObject(SelectObject(hdcM, oldB)); DeleteObject(SelectObject(hdcM, oldP)); DeleteObject(SelectObject(hdcM, oldF)); // Transfer the off-screen DC to the screen BitBlt(hdc, 0, 0, cR.right, cR.bottom, hdcM, 0, 0, SRCCOPY); // Free-up the off-screen DC SelectObject(hdcM, hOld); DeleteObject(hbmMem); DeleteDC(hdcM); EndPaint(hWnd, &ps); if (showCreditBox) { showCreditBox = false; UINT msg = MessageBox(hWnd, L"Did student answer?", L"Credit" , MB_YESNOCANCEL | MB_ICONQUESTION | MB_SYSTEMMODAL); UINT n = kidList.nRecords - 1; switch (msg) { case IDYES: kidList.pRecords[n]->credits++; case IDNO: kidList.pRecords[n]->turns++; break; } PostQuitMessage(0); } } break; case WM_ERASEBKGND: return true; break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; //RECT rect; HDC hdc; HDC hdcControl; string result = ""; const int limitEdit = 100; static HBRUSH hBrush = CreateSolidBrush(RGB(230, 230, 230)); DWORD CtrlID; //static int flag = -1; switch (message){ case WM_CTLCOLORSTATIC: { if (staticLabel == (HWND)lParam) //OR if the handle is unavailable to you, get ctrl ID CtrlID = GetDlgCtrlID((HWND)lParam); //Window Control ID if (CtrlID == ID_STATIC_LBL) //If desired control { HDC hdcStatic = (HDC)wParam; SetTextColor(hdcStatic, RGB(0, 0, 0)); SetBkColor(hdcStatic, RGB(230, 230, 230)); return (INT_PTR)hBrush; } } case WM_CREATE: staticLabel = CreateWindowEx(NULL, controlNames[STATIC], "Surname", WS_CHILD | WS_VISIBLE | SS_SIMPLE, LIST_X, LIST_Y, BTN_H_SIZE, BTN_V_SIZE, hWnd, (HMENU)ID_STATIC_LBL, hinst, NULL); editSurname = CreateWindowEx(WS_EX_CLIENTEDGE, controlNames[EDIT], "", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, LIST_X, LIST_Y + BTN_V_SIZE, EDIT_BOX_H_SIZE, BTN_V_SIZE, hWnd, (HMENU)ID_EDIT_SURNAME, hinst, NULL); Edit_LimitText(editSurname, limitEdit); comboboxSpecialty = CreateWindowEx(WS_EX_CLIENTEDGE, controlNames[COMBOBOX], "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN, LIST_X, LIST_Y + BTN_V_SIZE + EDIT_BOX_V_SIZE, BTN_H_SIZE, COMBO_V_SIZE, hWnd, (HMENU)ID_COMBO_BOX_SPEC, hinst, NULL); FillStrings(specialty, hWnd, comboboxSpecialty); buttonRecord = CreateWindowEx(WS_EX_CLIENTEDGE, controlNames[BUTTON], "Record", WS_CHILD | WS_VISIBLE, LIST_X * 2 + BTN_H_SIZE, LIST_Y + BTN_V_SIZE + EDIT_BOX_V_SIZE, BTN_H_SIZE, BTN_V_SIZE, hWnd, (HMENU)ID_BTN_REC, hinst, NULL); listConcat = CreateWindowEx(WS_EX_CLIENTEDGE, controlNames[LISTBOX], "", WS_CHILD | WS_VISIBLE, LIST_X * 2 + EDIT_BOX_H_SIZE, LIST_Y + BTN_V_SIZE, LIST_H_SIZE, LIST_V_SIZE, hWnd, (HMENU)ID_LIST_CONCAT, hinst, NULL); break; case WM_COMMAND: { switch (LOWORD(wParam)){ case ID_BTN_REC: if (HIWORD(wParam) == BN_CLICKED) { try{ result = GetInfo(comboboxSpecialty, editSurname, hWnd); } catch (char* s){ MessageBox(hWnd, s, s, NULL); break; } SendInfo(listConcat, result); break; }//switch (LOWORD(wParam)){ }// case WM_COMMAND: break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; }//switch (message) return 0; }// LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) }
static LRESULT CALLBACK ColourPickerWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { switch(message) { case WM_CREATE: SetWindowLongPtr(hwnd,0,0); SetWindowLongPtr(hwnd,sizeof(COLORREF),0); break; case CPM_SETDEFAULTCOLOUR: SetWindowLongPtr(hwnd,sizeof(COLORREF),lParam); break; case CPM_GETDEFAULTCOLOUR: return GetWindowLongPtr(hwnd,sizeof(COLORREF)); case CPM_SETCOLOUR: SetWindowLongPtr(hwnd,0,lParam); InvalidateRect(hwnd,NULL,FALSE); break; case CPM_GETCOLOUR: return GetWindowLongPtr(hwnd,0); case WM_LBUTTONUP: { CHOOSECOLOR cc={0}; COLORREF custColours[16]={0}; custColours[0]=GetWindowLongPtr(hwnd,sizeof(COLORREF)); cc.lStructSize=sizeof(CHOOSECOLOR); cc.hwndOwner=hwnd; cc.hInstance=(HWND)hMirandaInst; cc.rgbResult=GetWindowLongPtr(hwnd,0); cc.lpCustColors=custColours; cc.Flags=CC_ANYCOLOR|CC_FULLOPEN|CC_RGBINIT; if(ChooseColor(&cc)) { SetWindowLongPtr(hwnd,0,cc.rgbResult); SendMessage(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetDlgCtrlID(hwnd),CPN_COLOURCHANGED),(LPARAM)hwnd); InvalidateRect(hwnd,NULL,FALSE); } break; } case WM_ENABLE: InvalidateRect(hwnd,NULL,FALSE); break; case WM_NCPAINT: case WM_PAINT: { PAINTSTRUCT ps; HDC hdc1; RECT rc; HBRUSH hBrush; hdc1=BeginPaint(hwnd,&ps); GetClientRect(hwnd,&rc); DrawEdge(hdc1,&rc,EDGE_ETCHED,BF_RECT); InflateRect(&rc,-2,-2); if(IsWindowEnabled(hwnd)) hBrush=CreateSolidBrush(GetWindowLongPtr(hwnd,0)); else hBrush=CreateHatchBrush(HS_BDIAGONAL,GetSysColor(COLOR_GRAYTEXT)); SetBkColor(hdc1,GetSysColor(COLOR_BTNFACE)); FillRect(hdc1,&rc,hBrush); DeleteObject(hBrush); EndPaint(hwnd,&ps); break; } case WM_DESTROY: break; } return DefWindowProc(hwnd,message,wParam,lParam); }
int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, int nFunsterStil) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wclScroll; WNDCLASSEX wincl; WNDCLASSEX wclPal; WNDCLASSEX wclSettings; WNDCLASSEX wclSelection; TCHAR progtitle[1000]; TCHAR resstr[100]; HMENU menu; HWND hToolbar; HIMAGELIST hImageList; HANDLE haccel; HBITMAP tempBm; int i; TCHAR tooltips[16][30]; HDC hDC; TCHAR *c; TCHAR sfnFilename[1000]; TCHAR sfnFiletitle[256]; TCHAR sfnFilter[1000]; TCHAR ofnFilename[1000]; TCHAR ofnFiletitle[256]; TCHAR ofnFilter[1000]; TCHAR miniaturetitle[100]; static int custColors[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff }; hProgInstance = hThisInstance; /* Necessary */ InitCommonControls(); /* initializing and registering the window class used for the main window */ wincl.hInstance = hThisInstance; wincl.lpszClassName = _T("WindowsApp"); wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof(WNDCLASSEX); wincl.hIcon = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDI_APPICON)); wincl.hIconSm = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDI_APPICON)); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); RegisterClassEx (&wincl); /* initializing and registering the window class used for the scroll box */ wclScroll.hInstance = hThisInstance; wclScroll.lpszClassName = _T("Scrollbox"); wclScroll.lpfnWndProc = WindowProcedure; wclScroll.style = 0; wclScroll.cbSize = sizeof(WNDCLASSEX); wclScroll.hIcon = NULL; wclScroll.hIconSm = NULL; wclScroll.hCursor = LoadCursor(NULL, IDC_ARROW); wclScroll.lpszMenuName = NULL; wclScroll.cbClsExtra = 0; wclScroll.cbWndExtra = 0; wclScroll.hbrBackground = GetSysColorBrush(COLOR_APPWORKSPACE); RegisterClassEx (&wclScroll); /* initializing and registering the window class used for the palette window */ wclPal.hInstance = hThisInstance; wclPal.lpszClassName = _T("Palette"); wclPal.lpfnWndProc = PalWinProc; wclPal.style = CS_DBLCLKS; wclPal.cbSize = sizeof(WNDCLASSEX); wclPal.hIcon = NULL; wclPal.hIconSm = NULL; wclPal.hCursor = LoadCursor(NULL, IDC_ARROW); wclPal.lpszMenuName = NULL; wclPal.cbClsExtra = 0; wclPal.cbWndExtra = 0; wclPal.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); RegisterClassEx (&wclPal); /* initializing and registering the window class for the settings window */ wclSettings.hInstance = hThisInstance; wclSettings.lpszClassName = _T("ToolSettings"); wclSettings.lpfnWndProc = SettingsWinProc; wclSettings.style = CS_DBLCLKS; wclSettings.cbSize = sizeof(WNDCLASSEX); wclSettings.hIcon = NULL; wclSettings.hIconSm = NULL; wclSettings.hCursor = LoadCursor(NULL, IDC_ARROW); wclSettings.lpszMenuName = NULL; wclSettings.cbClsExtra = 0; wclSettings.cbWndExtra = 0; wclSettings.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); RegisterClassEx (&wclSettings); /* initializing and registering the window class for the selection frame */ wclSelection.hInstance = hThisInstance; wclSelection.lpszClassName = _T("Selection"); wclSelection.lpfnWndProc = SelectionWinProc; wclSelection.style = CS_DBLCLKS; wclSelection.cbSize = sizeof(WNDCLASSEX); wclSelection.hIcon = NULL; wclSelection.hIconSm = NULL; wclSelection.hCursor = LoadCursor(NULL, IDC_SIZEALL); wclSelection.lpszMenuName = NULL; wclSelection.cbClsExtra = 0; wclSelection.cbWndExtra = 0; wclSelection.hbrBackground = NULL; RegisterClassEx (&wclSelection); /* initializing and registering the window class for the size boxes */ wclSettings.hInstance = hThisInstance; wclSettings.lpszClassName = _T("Sizebox"); wclSettings.lpfnWndProc = SizeboxWinProc; wclSettings.style = CS_DBLCLKS; wclSettings.cbSize = sizeof(WNDCLASSEX); wclSettings.hIcon = NULL; wclSettings.hIconSm = NULL; wclSettings.hCursor = LoadCursor(NULL, IDC_ARROW); wclSettings.lpszMenuName = NULL; wclSettings.cbClsExtra = 0; wclSettings.cbWndExtra = 0; wclSettings.hbrBackground = GetSysColorBrush(COLOR_HIGHLIGHT); RegisterClassEx (&wclSettings); LoadString(hThisInstance, IDS_DEFAULTFILENAME, filename, SIZEOF(filename)); LoadString(hThisInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr)); _stprintf(progtitle, resstr, filename); LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, SIZEOF(miniaturetitle)); /* create main window */ hwnd = CreateWindowEx(0, _T("WindowsApp"), progtitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, HWND_DESKTOP, NULL, hThisInstance, NULL); hMainWnd = hwnd; hwndMiniature = CreateWindowEx(WS_EX_PALETTEWINDOW, _T("WindowsApp"), miniaturetitle, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, 180, 200, 120, 100, hwnd, NULL, hThisInstance, NULL); /* loading and setting the window menu from resource */ menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU)); SetMenu(hwnd, menu); haccel = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(800)); /* preloading the draw transparent/nontransparent icons for later use */ hNontranspIcon = LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_NONTRANSPARENT), IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR); hTranspIcon = LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_TRANSPARENT), IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR); hCurFill = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_FILL)); hCurColor = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_COLOR)); hCurZoom = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_ZOOM)); hCurPen = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_PEN)); hCurAirbrush = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_AIRBRUSH)); CreateWindowEx(0, _T("STATIC"), _T(""), WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ, 0, 0, 5000, 2, hwnd, NULL, hThisInstance, NULL); hToolBoxContainer = CreateWindowEx(0, _T("WindowsApp"), _T(""), WS_CHILD | WS_VISIBLE, 2, 2, 52, 350, hwnd, NULL, hThisInstance, NULL); /* creating the 16 bitmap radio buttons and setting the bitmap */ /* * FIXME: Unintentionally there is a line above the tool bar. * To prevent cropping of the buttons height has been increased from 200 to 205 */ hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | TBSTYLE_TOOLTIPS, 1, 1, 50, 205, hToolBoxContainer, NULL, hThisInstance, NULL); hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0); SendMessage(hToolbar, TB_SETIMAGELIST, 0, (LPARAM) hImageList); tempBm = LoadImage(hThisInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0); ImageList_AddMasked(hImageList, tempBm, 0xff00ff); DeleteObject(tempBm); SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); for(i = 0; i < 16; i++) { TBBUTTON tbbutton; int wrapnow = 0; if (i % 2 == 1) wrapnow = TBSTATE_WRAP; LoadString(hThisInstance, IDS_TOOLTIP1 + i, tooltips[i], 30); ZeroMemory(&tbbutton, sizeof(TBBUTTON)); tbbutton.iString = (INT_PTR) tooltips[i]; tbbutton.fsStyle = TBSTYLE_CHECKGROUP; tbbutton.fsState = TBSTATE_ENABLED | wrapnow; tbbutton.idCommand = ID_FREESEL + i; tbbutton.iBitmap = i; SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM) &tbbutton); } SendMessage(hToolbar, TB_CHECKBUTTON, ID_PEN, MAKELONG(TRUE, 0)); SendMessage(hToolbar, TB_SETMAXTEXTROWS, 0, 0); SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(25, 25)); /* creating the tool settings child window */ hToolSettings = CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD | WS_VISIBLE, 5, 208, 42, 140, hToolBoxContainer, NULL, hThisInstance, NULL); hTrackbarZoom = CreateWindowEx(0, TRACKBAR_CLASS, _T(""), WS_CHILD | TBS_VERT | TBS_AUTOTICKS, 1, 1, 40, 64, hToolSettings, NULL, hThisInstance, NULL); SendMessage(hTrackbarZoom, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6)); SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 3); /* creating the palette child window */ hPalWin = CreateWindowEx(0, _T("Palette"), _T(""), WS_CHILD | WS_VISIBLE, 56, 9, 255, 32, hwnd, NULL, hThisInstance, NULL); /* creating the scroll box */ hScrollbox = CreateWindowEx(WS_EX_CLIENTEDGE, _T("Scrollbox"), _T(""), WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE, 56, 49, 472, 248, hwnd, NULL, hThisInstance, NULL); /* creating the status bar */ hStatusBar = CreateWindowEx(0, STATUSCLASSNAME, _T(""), SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, NULL, hThisInstance, NULL); SendMessage(hStatusBar, SB_SETMINHEIGHT, 21, 0); hScrlClient = CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 500, 500, hScrollbox, NULL, hThisInstance, NULL); /* create selection window (initially hidden) */ hSelection = CreateWindowEx(WS_EX_TRANSPARENT, _T("Selection"), _T(""), WS_CHILD | BS_OWNERDRAW, 350, 0, 100, 100, hScrlClient, NULL, hThisInstance, NULL); /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */ hImageArea = CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD | WS_VISIBLE, 3, 3, imgXRes, imgYRes, hScrlClient, NULL, hThisInstance, NULL); hDC = GetDC(hImageArea); hDrawingDC = CreateCompatibleDC(hDC); hSelDC = CreateCompatibleDC(hDC); ReleaseDC(hImageArea, hDC); SelectObject(hDrawingDC, CreatePen(PS_SOLID, 0, fgColor)); SelectObject(hDrawingDC, CreateSolidBrush(bgColor)); hBms[0] = CreateDIBWithProperties(imgXRes, imgYRes); SelectObject(hDrawingDC, hBms[0]); Rectangle(hDrawingDC, 0 - 1, 0 - 1, imgXRes + 1, imgYRes + 1); if (lpszArgument[0] != 0) { HBITMAP bmNew = NULL; LoadDIBFromFile(&bmNew, lpszArgument, &fileTime, &fileSize, &fileHPPM, &fileVPPM); if (bmNew != NULL) { TCHAR tempstr[1000]; TCHAR resstr[100]; TCHAR *temp; insertReversible(bmNew); GetFullPathName(lpszArgument, SIZEOF(filepathname), filepathname, &temp); _tcscpy(filename, temp); LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr)); _stprintf(tempstr, resstr, filename); SetWindowText(hMainWnd, tempstr); clearHistory(); isAFile = TRUE; } } /* initializing the CHOOSECOLOR structure for use with ChooseColor */ choosecolor.lStructSize = sizeof(CHOOSECOLOR); choosecolor.hwndOwner = hwnd; choosecolor.hInstance = NULL; choosecolor.rgbResult = 0x00ffffff; choosecolor.lpCustColors = (COLORREF*) &custColors; choosecolor.Flags = 0; choosecolor.lCustData = 0; choosecolor.lpfnHook = NULL; choosecolor.lpTemplateName = NULL; /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */ CopyMemory(ofnFilename, filename, sizeof(filename)); LoadString(hThisInstance, IDS_OPENFILTER, ofnFilter, SIZEOF(ofnFilter)); for(c = ofnFilter; *c; c++) if (*c == '\1') *c = '\0'; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.hInstance = hThisInstance; ofn.lpstrFilter = ofnFilter; ofn.lpstrFile = ofnFilename; ofn.nMaxFile = SIZEOF(ofnFilename); ofn.lpstrFileTitle = ofnFiletitle; ofn.nMaxFileTitle = SIZEOF(ofnFiletitle); ofn.Flags = OFN_HIDEREADONLY; CopyMemory(sfnFilename, filename, sizeof(filename)); LoadString(hThisInstance, IDS_SAVEFILTER, sfnFilter, SIZEOF(sfnFilter)); for(c = sfnFilter; *c; c++) if (*c == '\1') *c = '\0'; ZeroMemory(&sfn, sizeof(OPENFILENAME)); sfn.lStructSize = sizeof(OPENFILENAME); sfn.hwndOwner = hwnd; sfn.hInstance = hThisInstance; sfn.lpstrFilter = sfnFilter; sfn.lpstrFile = sfnFilename; sfn.nMaxFile = SIZEOF(sfnFilename); sfn.lpstrFileTitle = sfnFiletitle; sfn.nMaxFileTitle = SIZEOF(sfnFiletitle); sfn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; /* creating the size boxes */ hSizeboxLeftTop = CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL); hSizeboxCenterTop = CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL); hSizeboxRightTop = CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL); hSizeboxLeftCenter = CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL); hSizeboxRightCenter = CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL); hSizeboxLeftBottom = CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL); hSizeboxCenterBottom = CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL); hSizeboxRightBottom = CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL); /* placing the size boxes around the image */ SendMessage(hImageArea, WM_SIZE, 0, 0); /* by moving the window, the things in WM_SIZE are done */ MoveWindow(hwnd, 100, 100, 600, 450, TRUE); /* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage(&messages, NULL, 0, 0)) { TranslateAccelerator(hwnd, haccel, &messages); /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }