static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: { // draw a frame and display the string PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); RECT rc; GetClientRect(hWnd, &rc); FillRect(hdc, &rc, GetStockBrush(WHITE_BRUSH)); FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH)); // get our plugin instance object and ask it for the version string nsPluginInstance *plugin = (nsPluginInstance *)GetWindowLong(hWnd, GWL_USERDATA); if (plugin) { CComBSTR _string; CComBSTR::LoadStringResource(IDS_STRING_MODULETEXT, _string.m_str); ::DrawTextW(hdc, _string, _string.Length(), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); } else { char string[] = "Error occured"; DrawText(hdc, string, strlen(string), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); } EndPaint(hWnd, &ps); } break; default: break; } return DefWindowProc(hWnd, msg, wParam, lParam); }
/* register the window class */ int text_register_class(TW *tw, HICON hicon) { #ifdef WINDOWS_NO_UNICODE WNDCLASS wndclass; #else WNDCLASSW wndclass; #endif HINSTANCE hInstance = GetModuleHandle(NULL); tw->hIcon = hicon; /* register window class */ wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndTextProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = sizeof(void *); wndclass.hInstance = hInstance; wndclass.hIcon = tw->hIcon ? tw->hIcon : LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = GetStockBrush(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = TextWinClassName; #ifdef WINDOWS_NO_UNICODE return RegisterClass(&wndclass); #else return RegisterClassW(&wndclass); #endif }
static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: { // draw a frame and display the string PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); RECT rc; GetClientRect(hWnd, &rc); FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH)); CPlugin * p = (CPlugin *)GetWindowLong(hWnd, GWL_USERDATA); if(p) { if (p->m_String[0] == 0) { strcpy("foo", p->m_String); } DrawText(hdc, p->m_String, strlen(p->m_String), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); } EndPaint(hWnd, &ps); } break; default: break; } return DefWindowProc(hWnd, msg, wParam, lParam); }
static LRESULT OnPaint(HWND hwnd) { ClientRect rect(hwnd); DoubleBuffer buffer(hwnd, rect); HDC hdc = buffer.GetDC(); HBRUSH brushBg = CreateSolidBrush(COL_WINDOW_BG); HBRUSH brushWhite = GetStockBrush(WHITE_BRUSH); FillRect(hdc, &rect.ToRECT(), brushBg); PreviewBase *preview = (PreviewBase *)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (preview && preview->renderer) { int pageNo = GetScrollPos(hwnd, SB_VERT); RectD page = preview->renderer->GetPageRect(pageNo); if (!page.IsEmpty()) { rect.Inflate(-PREVIEW_MARGIN, -PREVIEW_MARGIN); float zoom = (float)min(rect.dx / page.dx, rect.dy / page.dy) - 0.001f; RectI onScreen = RectD(rect.x, rect.y, page.dx * zoom, page.dy * zoom).Round(); onScreen.Offset((rect.dx - onScreen.dx) / 2, (rect.dy - onScreen.dy) / 2); FillRect(hdc, &onScreen.ToRECT(), brushWhite); preview->renderer->Render(hdc, onScreen, pageNo, zoom); } } DeleteObject(brushBg); DeleteObject(brushWhite); PAINTSTRUCT ps; buffer.Flush(BeginPaint(hwnd, &ps)); EndPaint(hwnd, &ps); return 0; }
DWORD WINAPI ThreadProcCircle(LPVOID pParam){ HWND hWnd = g_hWnd; HDC hdc = g_hdc; PAINTSTRUCT ps; HBRUSH hBrush; SetDCBrushColor(hdc, BLACK); hBrush = GetStockBrush(DC_BRUSH); SelectObject(hdc, hBrush); struct LOC{ int x, y; }M, N; const double pi = 3.14159265358979; M.x = 750; M.y = 250; //以(M.x,M.y)为圆心,以R为半径,描点画圆 //共描720个点,隔0.5度(STEP)描一次 double angle = -pi, R = 160, STEP = (pi * 0.5) / 180; while (angle - 180 < 1e10){ N.x = M.x + R * sin(angle); N.y = M.y + R * cos(angle); angle += STEP; SetPixel(hdc, N.x, N.y, BLACK); Sleep(50); } DeleteObject(hBrush); EndPaint(hWnd, &ps); ReleaseDC(hWnd, hdc); return 0; }
DWORD WINAPI ThreadProcSquare(LPVOID pParam){ HWND hWnd = g_hWnd; HDC hdc = g_hdc;; PAINTSTRUCT ps; HBRUSH hBrush; SetDCBrushColor(hdc, BLACK); hBrush = GetStockBrush(DC_BRUSH); SelectObject(hdc, hBrush); int x, y; //顺时针方向描点画矩形 for (x = 160; x < 340; x++){ SetPixel(hdc, x, 160, BLACK); Sleep(50); } for (y = 160; y < 340; y++){ SetPixel(hdc, 340, y, BLACK); Sleep(50); } for (x = 340; x > 160; x--){ SetPixel(hdc, x, 340, BLACK); Sleep(50); } for (y = 340; y > 160; y--){ SetPixel(hdc, 160, y, BLACK); Sleep(50); } DeleteObject(hBrush); EndPaint(hWnd, &ps); ReleaseDC(hWnd, hdc); return 0; }
void TrayNotifyDlg::InsertItem(HTREEITEM hparent, HTREEITEM after, const NotifyIconDlgInfo& entry, HDC hdc, HICON hicon, NOTIFYICONMODE mode) { int idx = _info.size() + 1; _info[idx] = entry; String mode_str = string_from_mode(mode); switch(mode) { case NIM_SHOW: mode_str = ResString(IDS_NOTIFY_SHOW); break; case NIM_HIDE: mode_str = ResString(IDS_NOTIFY_HIDE); break; case NIM_AUTO: mode_str = ResString(IDS_NOTIFY_AUTOHIDE); } FmtString txt(TEXT("%s - %s [%s]"), entry._tipText.c_str(), entry._windowTitle.c_str(), mode_str.c_str()); TV_INSERTSTRUCT tvi; tvi.hParent = hparent; tvi.hInsertAfter = after; TV_ITEM& tv = tvi.item; tv.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tv.lParam = (LPARAM)idx; tv.pszText = txt.str(); tv.iSelectedImage = tv.iImage = ImageList_AddAlphaIcon(_himl, hicon, GetStockBrush(WHITE_BRUSH), hdc); (void)TreeView_InsertItem(_tree_ctrl, &tvi); }
static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: { // draw a frame and display the string PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); RECT rc; GetClientRect(hWnd, &rc); FillRect( hdc, &rc, (HBRUSH) (COLOR_WINDOW+1)); FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH)); CPlugin * p = (CPlugin*) GetWindowLongPtr(hWnd, GWLP_USERDATA); if(p) { //kk: some fancy GUI stuff /*if (p->m_String[0] == 0) { strcpy("foo", p->m_String); }*/ char *s = p->GetGuiText(); DrawText(hdc, s, strlen(s), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); } EndPaint(hWnd, &ps); } break; default: break; } return DefWindowProc(hWnd, msg, wParam, lParam); }
// Default dialog procedure, which handles common functions INT_PTR CALLBACK PSPBaseProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { CCtrlList *pCtrlList; pCtrlList = CCtrlList::GetObj(hDlg); if (PtrIsValid(pCtrlList)) { switch (uMsg) { case WM_INITDIALOG: return TRUE; // set propertysheet page's background white in aero mode case WM_CTLCOLORSTATIC: case WM_CTLCOLORDLG: if (IsAeroMode()) return (INT_PTR)GetStockBrush(WHITE_BRUSH); break; // Set text color of edit boxes according to the source of information they display. case WM_CTLCOLOREDIT: return pCtrlList->OnSetTextColour((HWND)lParam, (HDC)wParam); case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case 0: MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; LPSTR pszProto; switch (((LPNMHDR)lParam)->code) { case PSN_RESET: pCtrlList->OnReset(); break; case PSN_INFOCHANGED: if (PSGetBaseProto(hDlg, pszProto) && *pszProto) { BOOL bChanged = (GetWindowLongPtr(hDlg, DWLP_MSGRESULT)&PSP_CHANGED) | pCtrlList->OnInfoChanged(hContact, pszProto); SetWindowLongPtr(hDlg, DWLP_MSGRESULT, bChanged ? PSP_CHANGED : 0); } break; case PSN_APPLY: if (PSGetBaseProto(hDlg, pszProto) && *pszProto) pCtrlList->OnApply(hContact, pszProto); break; } break; } break; case WM_COMMAND: if (!PspIsLocked(hDlg)) pCtrlList->OnChangedByUser(LOWORD(wParam), HIWORD(wParam)); break; case WM_DESTROY: // destroy all control objects and the list pCtrlList->Release(); } } return 0; }
static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: { // draw a frame and display the string PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); RECT rc; GetClientRect(hWnd, &rc); HBRUSH hbr = CreateSolidBrush(RGB(rand()%255, rand()%255, rand()%255)); FillRect(hdc, &rc, hbr); FrameRect(hdc, &rc, GetStockBrush(DKGRAY_BRUSH)); CPlugin * p = (CPlugin *)GetWindowLong(hWnd, GWL_USERDATA); if(p) { if (p->m_String[0] == 0) { strcpy("NPPublishCardX", p->m_String); } DrawTextA(hdc, p->m_String, strlen(p->m_String), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); } DeleteObject(hbr); EndPaint(hWnd, &ps); } break; default: break; } return DefWindowProc(hWnd, msg, wParam, lParam); }
void DrawFigure() //Draw next figure { HDC dc = GetDC(g_hFigure); RECT rectWndFigure; HBRUSH hOldBrach; HBRUSH hBrash = CreateSolidBrush(RGB(100, 100, 100)); HBRUSH hBlackBrash = GetStockBrush(BLACK_BRUSH); GetWindowRect(g_hFigure, &rectWndFigure); int x = (rectWndFigure.right - rectWndFigure.left) / 4; int y = (rectWndFigure.bottom - rectWndFigure.top) / 4; for (int i = 0; i<4; i++) for (int j = 0; j<4; j++) { if (g_bNextFigur[i][j]) { hOldBrach = SelectBrush(dc, hBrash); Rectangle(dc, i*x, j*y, ((i + 1)*x) + x, (j*y) + y); hBrash = SelectBrush(dc, hOldBrach); } else { hOldBrach = SelectBrush(dc, hBlackBrash); Rectangle(dc, i*x, j*y, ((i + 1)*x) + x, (j*y) + y); SelectBrush(dc, hOldBrach); } } DeleteBrush(SelectBrush(dc, hOldBrach)); ReleaseDC(g_hFigure, dc); ValidateRect(g_hFigure, &rectWndFigure); }
static void NotificationWndOnPaint(HWND hwnd, NotificationWnd *wnd) { PAINTSTRUCT ps; HDC hdcWnd = BeginPaint(hwnd, &ps); ClientRect rect(hwnd); DoubleBuffer buffer(hwnd, rect); HDC hdc = buffer.GetDC(); HFONT oldfnt = SelectFont(hdc, wnd->font); RECT rTmp = rect.ToRECT(); DrawFrameControl(hdc, &rTmp, DFC_BUTTON, DFCS_BUTTONPUSH); if (wnd->highlight) { SetBkMode(hdc, OPAQUE); SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT)); } else { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT)); } rect.Inflate(-PADDING, -PADDING); RectI rectMsg = rect; if (wnd->hasProgress) rectMsg.dy -= PROGRESS_HEIGHT + PADDING / 2; if (wnd->hasCancel) rectMsg.dx -= 20; ScopedMem<WCHAR> text(win::GetText(hwnd)); rTmp = rectMsg.ToRECT(); DrawText(hdc, text, -1, &rTmp, DT_SINGLELINE | DT_NOPREFIX); if (wnd->hasCancel) { rTmp = GetCancelRect(hwnd).ToRECT(); DrawFrameControl(hdc, &rTmp, DFC_CAPTION, DFCS_CAPTIONCLOSE | DFCS_FLAT); } if (wnd->hasProgress) { rect.dx = wnd->progressWidth; rect.y += rectMsg.dy + PADDING / 2; rect.dy = PROGRESS_HEIGHT; PaintRect(hdc, rect); rect.x += 2; rect.dx = (wnd->progressWidth - 3) * wnd->progress / 100; rect.y += 2; rect.dy -= 3; HBRUSH brush = GetStockBrush(BLACK_BRUSH); rTmp = rect.ToRECT(); FillRect(hdc, &rTmp, brush); DeleteObject(brush); } SelectFont(hdc, oldfnt); buffer.Flush(hdcWnd); EndPaint(hwnd, &ps); }
void MessageLoopThread_Win32(PetscDraw draw) { PetscDraw_Win32 *windraw = (PetscDraw_Win32*)draw->data; MSG msg; HWND hWnd = NULL; char classname[MAX_LOADSTRING + 1]; WNDCLASSEX wclass; LPVOID lpMsgBuf; PetscFunctionBegin; /* initialize window class parameters */ wclass.cbSize = sizeof(WNDCLASSEX); wclass.style = CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW; wclass.lpfnWndProc = (WNDPROC)PetscWndProc; wclass.cbClsExtra = 0; wclass.cbWndExtra = 0; wclass.hInstance = NULL; wclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); wclass.hCursor = LoadCursor(NULL,IDC_ARROW); wclass.hbrBackground = GetStockBrush(WHITE_BRUSH); wclass.lpszMenuName = NULL; wclass.lpszClassName = classname; wclass.hIconSm = NULL; RegisterClassEx(&wclass); hWnd = CreateWindowEx(0, classname, NULL, WS_OVERLAPPEDWINDOW, draw->x, draw->y, draw->w, draw->h, NULL, NULL, hInst, NULL); if (!hWnd) { lpMsgBuf = (LPVOID)"Window Not Succesfully Created"; MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); LocalFree( lpMsgBuf ); exit(0); } windraw->hWnd = hWnd; /* display and update new window */ ShowWindow(hWnd,SW_SHOWNORMAL); UpdateWindow(hWnd); SetEvent(windraw->hReadyEvent); while (GetMessage(&msg,hWnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } PetscFunctionReturnVoid(); }
BOOL CUserControlList::ProcessMessages(UINT Msg,WPARAM wParam,LPARAM lParam) { //проверить, что сообщение относитс¤ именно к этому списку if(wParam!=mControlID) return FALSE; //выбор по сообщению switch(Msg) { case WM_DRAWITEM: //рисование { //получить структуру с информацией о рисовании DRAWITEMSTRUCT* pDrawItem=(DRAWITEMSTRUCT*)lParam; //если элементов нет, закончить if(pDrawItem->itemID==LB_ERR) return TRUE; //кэшировать некоторые параметры HDC hdc=pDrawItem->hDC; RECT Rect=pDrawItem->rcItem; //указать шрифт HFONT hLastFont=SelectFont(hdc,gApplication.mhFontCode); //установить режим прозрачности SetBkMode(hdc,TRANSPARENT); //выделить перо и кисть в контекст HPEN hLastPen=SelectPen(hdc,gApplication.mhPenSelect); HBRUSH hLastBrush=SelectBrush(hdc,gApplication.mhBrushSelect); //если элемент выделен if(pDrawItem->itemState & ODS_SELECTED) //нарисовать выдел¤ющий пр¤моугольник Rectangle(hdc,Rect.left,Rect.top,Rect.right,Rect.bottom); //иначе очистить пр¤моугольник else FillRect(hdc,&Rect,GetStockBrush(WHITE_BRUSH)); //нарисовать элемент ((CUserControlListElement*)pDrawItem->itemData)->Draw(hdc,&Rect); //вернуть прежние перо и кисть SelectPen(hdc,hLastPen); SelectBrush(hdc,hLastBrush); //вернуть шрифт SelectFont(hdc,hLastFont); } return TRUE; case WM_MEASUREITEM: //создание элементов { //получить структуру MEASUREITEMSTRUCT* pMeasureItem=(MEASUREITEMSTRUCT*)lParam; //указать высоту элемента pMeasureItem->itemHeight=((CUserControlListElement*)pMeasureItem->itemData)->GetHeight(); } return TRUE; } //сообщение не обработано return FALSE; }
//Draws a rectangle on the given DC with a NOT ROP2 void WindowMagnetizer::DrawNotRectangle(HDC hDC, CONST LPRECT rect) { int oldROP=SetROP2(hDC,R2_NOT); BEGIN_SELOBJ(hDC,GetStockPen(BLACK_PEN),pen); BEGIN_SELOBJ(hDC,GetStockBrush(NULL_BRUSH),brush); Rectangle(hDC,rect->left,rect->top,rect->right,rect->bottom); END_SELOBJ(hDC,brush); END_SELOBJ(hDC,pen); SetROP2(hDC,oldROP); };
void OnPaint(HWND hwnd) { PAINTSTRUCT ps; BeginPaint(hwnd, &ps); RECT rc; GetClientRect(hwnd, &rc); COLORREF bg = (COLORREF)GetWindowLongPtr(hwnd, GWLP_USERDATA); SetDCBrushColor(ps.hdc, bg); FillRect(ps.hdc, &rc, GetStockBrush(DC_BRUSH)); EndPaint(hwnd, &ps); }
static void DrawPreview(HWND hwnd, HDC hdc) { BITMAPINFO bi; bi.bmiHeader.biSize = sizeof(bi.bmiHeader); bi.bmiHeader.biWidth = 8; bi.bmiHeader.biHeight = -8; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB; HBITMAP hBmpBrush = CreateDIBSection(0, &bi, DIB_RGB_COLORS, 0, 0, 0); HDC dcBmp = CreateCompatibleDC(0); HBITMAP hBmpSave = (HBITMAP)SelectObject(dcBmp, hBmpBrush); HBRUSH hbr = CreateSolidBrush(RGB(0xcc, 0xcc, 0xcc)); RECT rc; SetRect(&rc, 0, 0, 8, 8); FillRect(dcBmp, &rc, hbr); DeleteObject(hbr); hbr = CreateSolidBrush(RGB(0xff, 0xff, 0xff)); SetRect(&rc, 4, 0, 8, 4); FillRect(dcBmp, &rc, hbr); SetRect(&rc, 0, 4, 4, 8); FillRect(dcBmp, &rc, hbr); DeleteObject(hbr); SelectObject(dcBmp, hBmpSave); DeleteDC(dcBmp); GetClientRect(hwnd, &rc); hbr = CreatePatternBrush(hBmpBrush); SetBrushOrgEx(hdc, 1, 1, 0); FillRect(hdc, &rc, hbr); DeleteObject(hbr); DeleteObject(hBmpBrush); if (gPreviewOk) { int width = min(rc.right, wndPreview->getContent()->getWidth()); int height = min(rc.bottom, wndPreview->getContent()->getHeight()); int left = (rc.right - width) / 2; int top = (rc.bottom - height) / 2; BLENDFUNCTION bf; bf.BlendOp = AC_SRC_OVER; bf.BlendFlags = 0; bf.SourceConstantAlpha = 255; bf.AlphaFormat = AC_SRC_ALPHA; AlphaBlend(hdc, left, top, width, height, wndPreview->getContent()->getDC(), 0, 0, width, height, bf); } FrameRect(hdc, &rc, GetStockBrush(LTGRAY_BRUSH)); }
void CDC::Brush(int iObjectID) { HBRUSH hOldBrush = SelectBrush(m_hDC, GetStockBrush(iObjectID)); // Delete the old one? if (m_bDelOldBrush) DeleteBrush(hOldBrush); // This object doesn't need deleting. m_bDelOldBrush = FALSE; }
int MainWindow(HINSTANCE hInstance, int nCmdShow){ WNDCLASSEX ClassOfWindow; memset(&ClassOfWindow, 0, sizeof(WNDCLASSEX)); ClassOfWindow.cbSize = sizeof(WNDCLASSEX); ClassOfWindow.style = CS_VREDRAW | CS_HREDRAW; ClassOfWindow.lpfnWndProc = WinProcess; ClassOfWindow.hInstance = hInstance; ClassOfWindow.hIcon = (HICON)LoadImageA(NULL, "Icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE); ClassOfWindow.hCursor = LoadCursor(NULL, IDC_ARROW); ClassOfWindow.hbrBackground = GetStockBrush(WHITE_BRUSH); ClassOfWindow.lpszClassName = TEXT("ClassOfWindow"); ClassOfWindow.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); if (!RegisterClassEx(&ClassOfWindow)) return MYERROR; glbHpenBomb = CreatePen(PS_SOLID, 2, RGB(0, 0, 0)); glbHpenGun = CreatePen(PS_SOLID, 2, RGB(0, 0, 0)); glbHpenGround = CreatePen(PS_SOLID, 2, RGB(0, 0, 0)); glbHbrushBomb = CreateSolidBrush(RGB(0xff, 0, 0)); glbHbrushStand = CreateSolidBrush(RGB(228, 228, 228)); glbHpenHoopVisible = CreatePen(PS_DASH, 2, RGB(0, 0, 0)); glbHpenHoopInvisible = CreatePen(PS_DASH, 2, RGB(228, 228, 228)); glbHbrushBackGround = CreateSolidBrush(RGB(228, 228, 228)); glbTotalEnd = FALSE; int xPosition = (GetSystemMetrics(SM_CXSCREEN) - WINDOW_WIDTH) / 2; HWND hwndMain = CreateWindow(ClassOfWindow.lpszClassName, TEXT("јЋЋј’ј Ѕј–"), WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, xPosition, 10, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL); if (!hwndMain) return MYERROR; _beginthread(UpdateImage, 0, &hwndMain); _beginthread(ChangeAngle, 0, &hwndMain); _beginthread(PhysicalProcesses, 0, &hwndMain); PWINDOWINFO pwi=malloc(sizeof(WINDOWINFO)); GetWindowInfo(hwndMain, pwi); pwi->rcClient; pwi->rcWindow; ShowWindow(hwndMain, nCmdShow); UpdateWindow(hwndMain); MSG message; // циклически обрабатываем сообщени¤ от окна while (TRUE) { if (glbTotalEnd == TRUE) return MYERROR; if (PeekMessage(&message, hwndMain, 0, 0, PM_REMOVE) != 0){ TranslateMessage(&message); DispatchMessage(&message); } } return 0; }
HBRUSH CPlayerStatusBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor); if (*pWnd == m_type) { hbr = GetStockBrush(BLACK_BRUSH); } // TODO: Return a different brush if the default is not desired return hbr; }
VOID ClearDrawDevice() { HBRUSH brush = GetStockBrush(NULL_BRUSH); SelectBrush(brush); m_switcher.push_back(CGDIHandleSwitcher (m_hDC,brush,TRUE,FALSE)); HPEN pen = GetStockPen(NULL_PEN); SelectPen(pen); m_switcher.push_back(CGDIHandleSwitcher (m_hDC,pen,TRUE,FALSE)); SetBkMode(TRANSPARENT); }
static VOID NcAreaInitializeTheme( _Inout_ PEDIT_CONTEXT Context ) { Context->CXBorder = GetSystemMetrics(SM_CXBORDER) * 2; //Context->CYBorder = GetSystemMetrics(SM_CYBORDER) * 2; Context->BackgroundColorRef = GetSysColor(COLOR_WINDOW); Context->BrushFill = GetSysColorBrush(COLOR_WINDOW); Context->BrushNormal = GetStockBrush(BLACK_BRUSH); Context->BrushHot = WindowsVersion < WINDOWS_VISTA ? CreateSolidBrush(RGB(50, 150, 255)) : GetSysColorBrush(COLOR_HIGHLIGHT); Context->BrushFocused = WindowsVersion < WINDOWS_VISTA ? CreateSolidBrush(RGB(50, 150, 255)) : GetSysColorBrush(COLOR_HIGHLIGHT); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX wndClass = { 0 }; wndClass.cbSize = sizeof( WNDCLASSEX ) ; wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndClass.hCursor = LoadCursor( NULL, IDC_ARROW ); wndClass.hbrBackground = GetStockBrush(WHITE_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = WINDOW_CLASS; if( !RegisterClassEx( &wndClass ) ) return -1; g_hInst = hInstance; HWND hWnd = InitInstance(hInstance, nShowCmd); if ( !hWnd) return -1; MSG msg = { 0 }; DWORD dwTick, dwPreTick = GetTickCount(); if ( !GameInit(hWnd)) return -1; while( msg.message != WM_QUIT ) { if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else { dwTick = GetTickCount(); if (dwTick - dwPreTick > 40) { if (GameAction(hWnd)) GamePaint(hWnd); dwPreTick = GetTickCount(); } } } UnregisterClass(WINDOW_CLASS, wndClass.hInstance); return 0; }
LRESULT StartmenuSettingsDlg::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) { switch(nmsg) { case WM_PAINT: { PaintCanvas canvas(_hwnd); FillRect(canvas, &canvas.rcPaint, GetStockBrush(DKGRAY_BRUSH)); break;} default: return super::WndProc(nmsg, wparam, lparam); } return 0; }
static void CreatePreview(TSelectorData *sd, TCHAR *fn, LPDRAWITEMSTRUCT lps) { HDC hdc = CreateCompatibleDC(lps->hDC); sd->hbmpPreview = CreateCompatibleBitmap(lps->hDC, lps->rcItem.right - lps->rcItem.left, lps->rcItem.bottom - lps->rcItem.top); SelectObject(hdc, sd->hbmpPreview); RECT rc; HBRUSH hbr; BITMAPINFO bi = {0}; bi.bmiHeader.biSize = sizeof(bi.bmiHeader); bi.bmiHeader.biWidth = 8; bi.bmiHeader.biHeight = -8; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB; HBITMAP hBmpBrush = (HBITMAP)CreateDIBSection(0, &bi, DIB_RGB_COLORS, 0, 0, 0); HDC dcBmp = CreateCompatibleDC(0); HBITMAP hBmpSave = (HBITMAP)SelectObject(dcBmp, hBmpBrush); hbr = CreateSolidBrush(RGB(0xcc, 0xcc, 0xcc)); SetRect(&rc, 0, 0, 8, 8); FillRect(dcBmp, &rc, hbr); DeleteObject(hbr); hbr = CreateSolidBrush(RGB(0xff, 0xff, 0xff)); SetRect(&rc, 4, 0, 8, 4); FillRect(dcBmp, &rc, hbr); SetRect(&rc, 0, 4, 4, 8); FillRect(dcBmp, &rc, hbr); DeleteObject(hbr); SelectObject(dcBmp, hBmpSave); DeleteDC(dcBmp); rc = lps->rcItem; OffsetRect(&rc, -rc.left, -rc.top); hbr = CreatePatternBrush(hBmpBrush); SetBrushOrgEx(hdc, 1, 1, 0); FillRect(hdc, &rc, hbr); DeleteObject(hbr); DeleteObject(hBmpBrush); HDC hdcSave = lps->hDC; lps->hDC = hdc; sttPreviewSkin(sd->obj, fn, lps); lps->hDC = hdcSave; FrameRect(hdc, &rc, GetStockBrush(LTGRAY_BRUSH)); DeleteDC(hdc); }
void CDC::Cleanup(void) { // Currently selected pen needs deleting? if (m_bDelOldPen) { HPEN hOldPen = SelectPen(m_hDC, GetStockPen(BLACK_PEN)); DeletePen(hOldPen); } // Currently selected brush needs deleting? if (m_bDelOldBrush) { HBRUSH hOldBrush = SelectBrush(m_hDC, GetStockBrush(WHITE_BRUSH)); DeleteBrush(hOldBrush); } }
////////////////////////////////////// // Register the window ////////////////////////////////////// BOOL Register(HINSTANCE hInst) { WNDCLASS WndClass; WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT; WndClass.lpfnWndProc = WindowProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = hInst; WndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_KFW)); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hbrBackground = GetStockBrush(BLACK_BRUSH); WndClass.lpszMenuName = NULL; WndClass.lpszClassName = WinName; return RegisterClass (&WndClass); }
HWND ConsoleOverlayWindow::CreateOverlayWindow() { ::WNDCLASSEX wcex{}; wcex.cbSize = sizeof(wcex); wcex.hInstance = ::GetModuleHandle(NULL); wcex.lpszClassName = L"ConsoleOverlayWindow-CCBE8432-6AC5-476C-8EE6-E4E21DB90138"; wcex.lpfnWndProc = SimpleWindow::Static_WndProc; wcex.hbrBackground = GetStockBrush(HOLLOW_BRUSH); #ifdef _DEBUG wcex.hbrBackground = ::CreateSolidBrush(RGB(255, 0, 0)); wcex.hCursor = ::LoadCursor(NULL, IDC_CROSS); #endif // NOTE: without the following set there are drawing artifacts especialy when maximizing/restoring // the console. it seems like part of the window becomes "dirty" and loose its transparency property. // TODO: find out why. wcex.style = CS_HREDRAW | CS_VREDRAW; if (!SimpleWindow::RegisterWindowClass(wcex)) return false; // making the console window as the owner will cause this window to always stay above it. // in addition when the console window is minimized this window will be automatically hidden as well. auto hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_ACCEPTFILES, wcex.lpszClassName, NULL, WS_POPUP, 0, 0, 0, 0, _hWndConsole, NULL, wcex.hInstance, this); if (!hWnd) { debug_print("ConsoleOverlayWindow::CreateOverlayWindow - CreateWindowEx failed, err=%#x\n", ::GetLastError()); return NULL; } debug_print("ConsoleOverlayWindow::CreateOverlayWindow - overlay window created, hwnd=%#x\n", hWnd); // setup window for alpha transperancy #ifdef _DEBUG ::SetLayeredWindowAttributes(hWnd, 0, 100, LWA_ALPHA); #else ::SetLayeredWindowAttributes(hWnd, 0, 1, LWA_ALPHA); #endif // mark that the overlay window can accept dropping files onto it ::DragAcceptFiles(hWnd, TRUE); return hWnd; }
// Create the Taskbar's Window Class BOOL WINAPI TaskBar_CreateClass(HINSTANCE hInstance) { WNDCLASS wc; wc.style = /*CS_HREDRAW | CS_VREDRAW | */CS_DBLCLKS; wc.lpfnWndProc = (WNDPROC)TaskBarWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = GetStockBrush(LTGRAY_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = HHTASKBARCLASSNAME; // Register the window class and return success/failure code. return RegisterClass(&wc); }
//Draws the cursor on the DC void PrecisionCursor::drawCursor(RECT cursorRct, DWORD cursorShape, bool cross) { //Save the DC state int DCState=SaveDC(m_wndDC); //Set the NOT ROP2 SetROP2(m_wndDC,R2_NOT); //Remove any clipping region SelectClipRgn(m_wndDC,NULL); //Select a null brush SelectBrush(m_wndDC,GetStockBrush(NULL_BRUSH)); //Draw the cursor switch(cursorShape) { case PS_ENDCAP_ROUND: Ellipse(m_wndDC,EXPANDRECT_C(cursorRct)); break; case PS_ENDCAP_SQUARE: Rectangle(m_wndDC,EXPANDRECT_C(cursorRct)); break; default: break; } //Eventually draw the cross if(cross) { //Find the medium point between the center and the pixel next to it POINT pos=m_position,pos2=m_position; pos2.x++; pos2.y++; DIB2IVWndPoint(&pos); DIB2IVWndPoint(&pos2); pos.x=(pos.x+pos2.x)/2; pos.y=(pos.y+pos2.y)/2; //Draw the cross MoveToEx(m_wndDC,pos.x-PREC_CURSOR_CROSS_SIZE,pos.y-PREC_CURSOR_CROSS_SIZE,NULL); LineTo(m_wndDC,pos.x+PREC_CURSOR_CROSS_SIZE,pos.y+PREC_CURSOR_CROSS_SIZE); MoveToEx(m_wndDC,pos.x+PREC_CURSOR_CROSS_SIZE,pos.y-PREC_CURSOR_CROSS_SIZE,NULL); LineTo(m_wndDC,pos.x-PREC_CURSOR_CROSS_SIZE,pos.y+PREC_CURSOR_CROSS_SIZE); } //Restore the DC state RestoreDC(m_wndDC,DCState); }