void MCStack::setopacity(uint1 p_level) { if (!MCModeMakeLocalWindows()) return; if (window != NULL) SetWindowAlpha((WindowPtr)window -> handle . window, p_level / 255.0); }
void IncreaseWindowAlpha(HWND hWnd, int inc) { int nAlpha = (int)GetWindowAlpha(hWnd) + inc; if ( nAlpha > 255 ) nAlpha = 255; else if ( nAlpha < 5 ) nAlpha = 5; SetWindowAlpha(hWnd, (BYTE)nAlpha); }
//default keyboard event handler static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) { OSStatus result = noErr; UInt32 class = GetEventClass (event); UInt32 kind = GetEventKind (event); result = CallNextEventHandler(nextHandler, event); if(class == kEventClassKeyboard) { char macCharCodes; UInt32 macKeyCode; UInt32 macKeyModifiers; GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(macCharCodes), NULL, &macCharCodes); GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(macKeyModifiers), NULL, &macKeyModifiers); if(macKeyModifiers != 256) { if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown) { int key = convert_key(macKeyCode, macCharCodes); if(key != -1) mplayer_put_key(key); } } else if(macKeyModifiers == 256) { switch(macCharCodes) { case '[': SetWindowAlpha(theWindow, winAlpha-=0.05); break; case ']': SetWindowAlpha(theWindow, winAlpha+=0.05); break; } } else result = eventNotHandledErr; } return result; }
BOOL COscillogram::Create(CWnd* lParent,const RECT& rect ,DWORD dwStyle ) { CString wndcls=AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,0, (HBRUSH)GetStockObject(WHITE_BRUSH),LoadIcon(NULL,IDI_APPLICATION)); m_TitleTip.Create(CRect(0,0,0,0)); SetWindowAlpha(m_TitleTip,180); BOOL re = CWnd::Create(wndcls,"波形图",dwStyle,rect,lParent,600); ModifyStyleEx(0, WS_EX_CLIENTEDGE); return re; }
int main(int argc, char* argv[]) { IBNibRef nibRef; WindowRef window; OSStatus err; eh2_EventHeapFactory* factory; //EY: char name[] = "fuller"; if (argc>1) { //More than just the function call //strcpy(&name,argv[0]); printf("Arg num %d\n", argc); printf("Name without arg %s\n", name); printf("Want to connect to %s\n", argv[1]); strcpy(name,argv[1]); } printf("Connecting to %s\n", name); id = 0; wheelPos = 0; // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. //err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); //require_noerr( err, CantSetMenuBar ); // Then create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. //err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window); //err = CreateCustomWindow(null, ,&window); //UInt32 attributes = kWindowNoShadowAttribute | kWindowNoActivatesAttribute | kWindowOpaqueForEventsAttribute ; //UInt32 attributes = kWindowNoShadowAttribute | kWindowNoActivatesAttribute; //UInt32 attributes = 0x000000; Rect size; //[NSScreen mainScreen]; size.top = 0; size.left = 0; size.bottom = 400; size.right = 600; printf("b4 create"); //Have to make it a window that cannot refocus // + has to delegates all events to underlying window //err = CreateNewWindow(CGShieldingWindowLevel(),attributes,&size,&window); //err = CreateNewWindow(kModalWindowClass,attributes,&size,&window); err = CreateNewWindow(kFloatingWindowClass,0,&size,&window); //WindowActivationScope scope = kWindowActivationScopeNone; //SetWindowActivationScope(&window, scope); //err = CreateNewWindow(kOverlayWindowClass, overlayAttributes,&window,&size,null); Ptr oldState; BeginFullScreen(&oldState,nil,0,0,&window,0,fullScreenAllowEvents); printf("aft create"); require_noerr( err, CantCreateWindow ); printf("no error"); // We don't need the nib reference anymore. DisposeNibReference(nibRef); //Change the window such that it is transparent and passing the event //[window setLevel:NSNormalWindowLevel] //setAlphaValue: // //window->setLevel(NSScreenSaverWindowLevel); //SetWindowAlpha(window, 0.5); SetWindowAlpha(window, 0.0); //SendWindowGroupBehind(window, GetWindowGroupOfClass(kDocumentWindowClass)); // The window was created hidden so show it. ShowWindow( window ); //EY: EventTypeSpec eventTypes[1]; EventHandlerUPP handlerUPP; eventTypes[0].eventClass = kEventClassMouse; eventTypes[0].eventKind = kEventMouseWheelMoved; handlerUPP = NewEventHandlerUPP(MouseHandler); //printf("install event handler\n"); InstallApplicationEventHandler (handlerUPP, 1, eventTypes, NULL, NULL); //Init event heap eh2_init(NULL,NULL); factory = eh2_EventHeapFactory::cs_getInstance(); eventHeapPtr = factory->createEventHeap( NULL, name, -1 ); // Call the event loop RunApplicationEventLoop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }
BOOL CThhylDlg::OnInitDialog() { CDlgBaseWZ::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here //设置RPYAnalyzer框字体大小 LoadEditCtrlFont((CEdit*)GetDlgItem(IDC_RPYINFO)); // 初始化与控件关联的变量 m_rpyfile = ((CThhylApp*)AfxGetApp())->m_rpyfile; m_bOnTop = ((CThhylApp*)AfxGetApp())->m_bOnTop; m_bAutocomp = HasConfigOption(CFG_AUTOCOMP); CoInitialize(NULL); if (m_rpyfile.IsEmpty()) { m_rpyfile.LoadString(IDS_HINTNOFILE); m_rpyinfo.LoadString(IDS_HINTSTART); UpdateData(FALSE); // 没有文件打开,将焦点置于“录像文件”框,方便输入文件路径 CEdit* const pRpyFileEdit = (CEdit*)GetDlgItem(IDC_RPYFILE); pRpyFileEdit->SetFocus(); pRpyFileEdit->SetSel(0, -1); //全选 } else { UpdateData(FALSE); Analyze(); // analyze() 将置焦点于 RPYAnalyzer 框 } // 置顶 if (m_bOnTop) OnOntop(); if (m_bAutocomp) OnAutocomp(); // Set window pos if (cfg.WinPlace.length == sizeof(WINDOWPLACEMENT)) { cfg.WinPlace.showCmd = AfxGetApp()->m_nCmdShow; SetWindowPlacement(&cfg.WinPlace); } // set button titles to graphical unicode characters ((CButton*)GetDlgItem(IDC_CUTFILE))->SetWindowText(_T("\x2704")); ((CButton*)GetDlgItem(IDC_COPYFILE))->SetWindowText(_T("\x2750")); // 设置 tooltip m_tooltip.AddTool( GetDlgItem(IDC_RPYFILE), _T("鼠标左键+滚轮可以调整本窗口的不透明度") ); m_tooltip.AddTool( GetDlgItem(IDC_RPYINFO), _T("Ctrl+滚轮可以调整录像信息框的字体大小") ); m_tooltip.AddTool( GetDlgItem(IDC_BROWSE), _T("打开录像文件[CTRL+B 或 CTRL+O]") ); m_tooltip.AddTool( GetDlgItem(IDC_CLOSEFILE), _T("关闭录像文件[CTRL+L 或 CTRL+W]") ); m_tooltip.AddTool( GetDlgItem(IDC_CUTFILE), _T("剪切[F9]") ); m_tooltip.AddTool( GetDlgItem(IDC_COPYFILE), _T("复制[F10]") ); m_tooltip.AddTool( GetDlgItem(IDC_CHGFONT), _T("更改录像信息框的字体") ); m_tooltip.AddTool( GetDlgItem(IDC_COPY), _T("复制录像信息到剪贴板(若有选区则只复制选区内容,否则复制全部)") ); m_tooltip.AddTool( GetDlgItem(IDC_EDITCOMMENT), _T("编辑录像注释(红魔乡和妖妖梦的录像不支持该功能)") ); m_tooltip.AddTool( GetDlgItem(IDC_ONTOP), _T("让本窗口总在最前") ); m_tooltip.AddTool( GetDlgItem(IDC_AUTOCOMP), _T("手动输入路径时是否显示自动完成的提示框") ); m_tooltip.Activate(TRUE); // 设置不透明度 SetWindowAlpha(this->GetSafeHwnd(), cfg.byteAlpha); // 设置 DlgBaseWZ 对话框选项 m_dlgopt = DLGWZ_OPT_ENABLEMAXIMIZE; return FALSE; // return TRUE unless you set the focus to a control }
void MacOSXWindow::setOpacity( uint8_t value ) const { SetWindowAlpha( m_win, (float)value / 255.0 ); }
OSStatus MakeWindowTransparent(WindowRef aWindowRef) { OSStatus status = paramErr; require(aWindowRef != NULL, paramErr); // is the window compositing or not? WindowAttributes attributes; status = GetWindowAttributes(aWindowRef, &attributes); require_noerr(status, GetWindowAttributes); /* if (attributes & kWindowCompositingAttribute) { // it is compositing so we intercept the kEventWindowGetRegion event to be able to specify an empty opaque region EventTypeSpec wCompositingEvents = { kEventClassWindow, kEventWindowGetRegion }; status = InstallWindowEventHandler(aWindowRef, TransparentWindowHandler, 1, &wCompositingEvents, aWindowRef, NULL); require_noerr(status, InstallWindowEventHandler); HIViewRef contentView; status = HIViewFindByID(HIViewGetRoot(aWindowRef), kHIViewWindowContentID, &contentView); require_noerr(status, HIViewFindByID); // and we intercept the kEventControlDraw event of our content view so that we can make it transparent EventTypeSpec cCompositingEvents = { kEventClassControl, kEventControlDraw }; status = InstallControlEventHandler(contentView, TransparentWindowHandler, 1, &cCompositingEvents, contentView, NULL); require_noerr(status, InstallControlEventHandler); } else*/ { // it is non-compositing so we intercept the kEventWindowGetRegion event to be able to specify an empty opaque region // and we intercept the kEventWindowDrawContent event of our window so that we can make it transparent EventTypeSpec wNonCompositingEvents[] = { { kEventClassWindow, kEventWindowGetRegion }, { kEventClassWindow, kEventWindowDrawContent } }; status = InstallWindowEventHandler(aWindowRef, TransparentWindowHandler, GetEventTypeCount(wNonCompositingEvents), wNonCompositingEvents, aWindowRef, NULL); require_noerr(status, InstallWindowEventHandler); } // telling the HIToolbox that our window is not opaque so that we will be asked for the opaque region UInt32 features; status = GetWindowFeatures(aWindowRef, &features); require_noerr(status, GetWindowFeatures); if ( ( features & kWindowIsOpaque ) != 0 ) { status = HIWindowChangeFeatures(aWindowRef, 0, kWindowIsOpaque); require_noerr(status, HIWindowChangeFeatures); } // force opaque shape to be recalculated status = ReshapeCustomWindow(aWindowRef); require_noerr(status, ReshapeCustomWindow); // ensure that HIToolbox doesn't use standard shadow style, which defeats custom opaque shape status = SetWindowAlpha(aWindowRef, 0.999); require_noerr(status, SetWindowAlpha); SetWindowAlpha: ReshapeCustomWindow: HIWindowChangeFeatures: GetWindowFeatures: InstallControlEventHandler: HIViewFindByID: InstallWindowEventHandler: GetWindowAttributes: paramErr: return status; }
COSXScreen::COSXScreen(bool isPrimary) : m_isPrimary(isPrimary), m_isOnScreen(m_isPrimary), m_cursorPosValid(false), m_cursorHidden(false), m_dragNumButtonsDown(0), m_dragTimer(NULL), m_keyState(NULL), m_sequenceNumber(0), m_screensaver(NULL), m_screensaverNotify(false), m_clipboardTimer(NULL), m_hiddenWindow(NULL), m_userInputWindow(NULL), m_switchEventHandlerRef(0), m_pmMutex(new CMutex), m_pmWatchThread(NULL), m_pmThreadReady(new CCondVar<bool>(m_pmMutex, false)), m_activeModifierHotKey(0), m_activeModifierHotKeyMask(0) { try { m_displayID = CGMainDisplayID(); updateScreenShape(m_displayID, 0); m_screensaver = new COSXScreenSaver(getEventTarget()); m_keyState = new COSXKeyState(); if (m_isPrimary) { // 1x1 window (to minimze the back buffer allocated for this // window. Rect bounds = { 100, 100, 101, 101 }; // m_hiddenWindow is a window meant to let us get mouse moves // when the focus is on another computer. If you get your event // from the application event target you'll get every mouse // moves. On the other hand the Window event target will only // get events when the mouse moves over the window. // The ignoreClicks attributes makes it impossible for the // user to click on our invisible window. CreateNewWindow(kUtilityWindowClass, kWindowNoShadowAttribute | kWindowIgnoreClicksAttribute | kWindowNoActivatesAttribute, &bounds, &m_hiddenWindow); // Make it invisible SetWindowAlpha(m_hiddenWindow, 0); ShowWindow(m_hiddenWindow); // m_userInputWindow is a window meant to let us get mouse moves // when the focus is on this computer. Rect inputBounds = { 100, 100, 200, 200 }; CreateNewWindow(kUtilityWindowClass, kWindowNoShadowAttribute | kWindowOpaqueForEventsAttribute | kWindowStandardHandlerAttribute, &inputBounds, &m_userInputWindow); SetWindowAlpha(m_userInputWindow, 0); } // install display manager notification handler CGDisplayRegisterReconfigurationCallback(displayReconfigurationCallback, this); // install fast user switching event handler EventTypeSpec switchEventTypes[2]; switchEventTypes[0].eventClass = kEventClassSystem; switchEventTypes[0].eventKind = kEventSystemUserSessionDeactivated; switchEventTypes[1].eventClass = kEventClassSystem; switchEventTypes[1].eventKind = kEventSystemUserSessionActivated; EventHandlerUPP switchEventHandler = NewEventHandlerUPP(userSwitchCallback); InstallApplicationEventHandler(switchEventHandler, 2, switchEventTypes, this, &m_switchEventHandlerRef); DisposeEventHandlerUPP(switchEventHandler); // watch for requests to sleep EVENTQUEUE->adoptHandler(COSXScreen::getConfirmSleepEvent(), getEventTarget(), new TMethodEventJob<COSXScreen>(this, &COSXScreen::handleConfirmSleep)); // create thread for monitoring system power state. LOG((CLOG_DEBUG "starting watchSystemPowerThread")); m_pmWatchThread = new CThread(new TMethodJob<COSXScreen> (this, &COSXScreen::watchSystemPowerThread)); } catch (...) { EVENTQUEUE->removeHandler(COSXScreen::getConfirmSleepEvent(), getEventTarget()); if (m_switchEventHandlerRef != 0) { RemoveEventHandler(m_switchEventHandlerRef); } CGDisplayRemoveReconfigurationCallback(displayReconfigurationCallback, this); if (m_hiddenWindow) { CFRelease(m_hiddenWindow); m_hiddenWindow = NULL; } if (m_userInputWindow) { CFRelease(m_userInputWindow); m_userInputWindow = NULL; } delete m_keyState; delete m_screensaver; throw; } // install event handlers EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(), new TMethodEventJob<COSXScreen>(this, &COSXScreen::handleSystemEvent)); // install the platform event queue EVENTQUEUE->adoptBuffer(new COSXEventQueueBuffer); }