static int init(struct winampVisModule *this_mod) { DWORD id; FILETIME ft; #if 0//syntax highlighting if (!hRich) hRich=LoadLibrary("RICHED32.dll"); #endif GetSystemTimeAsFileTime(&ft); srand(ft.dwLowDateTime|ft.dwHighDateTime^GetCurrentThreadId()); g_hInstance=this_mod->hDllInstance; GetModuleFileName(g_hInstance,g_path,MAX_PATH); char *p=g_path+strlen(g_path); while (p > g_path && *p != '\\') p--; *p = 0; #ifdef WA2_EMBED if (SendMessage(this_mod->hwndParent,WM_USER,0,0) < 0x2900) { MessageBox(this_mod->hwndParent,"This version of AVS requires Winamp 2.9+","AVS ERROR",MB_OK|MB_ICONSTOP); return 1; } #endif #ifndef NO_MMX extern int is_mmx(void); if (!is_mmx()) { MessageBox(this_mod->hwndParent,"NO MMX SUPPORT FOUND - CANNOT RUN AVS - GET THE NON-MMX VERSION.","AVS ERROR",MB_OK|MB_ICONSTOP); return 1; } #endif #ifdef LASER strcat(g_path,"\\avs_laser"); #else strcat(g_path,"\\avs"); #endif CreateDirectory(g_path,NULL); InitializeCriticalSection(&g_cs); InitializeCriticalSection(&g_render_cs); g_ThreadQuit=0; g_visdata_pstat=1; AVS_EEL_IF_init(); if (Wnd_Init(this_mod)) return 1; { int x; for (x = 0; x < 256; x ++) { double a=log(x*60.0/255.0 + 1.0)/log(60.0); int t=(int)(a*255.0); if (t<0)t=0; if (t>255)t=255; g_logtab[x]=(unsigned char )t; } } initBpm(); Render_Init(g_hInstance); CfgWnd_Create(this_mod); g_hThread=(HANDLE)_beginthreadex(NULL,0,RenderThread,0,0,(unsigned int *)&id); main_setRenderThreadPriority(); SetForegroundWindow(g_hwnd); SetFocus(g_hwnd); return 0; }
HRESULT PlayMovieInWindow(LPTSTR szFile) { USES_CONVERSION; WCHAR wFile[MAX_PATH]; HRESULT hr; // Check input string if (szFile == NULL) return E_POINTER; // Clear open dialog remnants before calling RenderFile() UpdateWindow(ghApp); // Convert filename to wide character string wcsncpy(wFile, T2W(szFile), NUMELMS(wFile)-1); wFile[MAX_PATH-1] = 0; // Get the interface for DirectShow's GraphBuilder JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGB)); if(SUCCEEDED(hr)) { // Create the Video Mixing Renderer and add it to the graph JIF(InitializeWindowlessVMR()); // Have the graph builder construct its the appropriate graph automatically JIF(pGB->RenderFile(wFile, NULL)); // QueryInterface for DirectShow interfaces JIF(pGB->QueryInterface(IID_IMediaControl, (void **)&pMC)); JIF(pGB->QueryInterface(IID_IMediaEventEx, (void **)&pME)); JIF(pGB->QueryInterface(IID_IMediaSeeking, (void **)&pMS)); JIF(pGB->QueryInterface(IID_IBasicAudio, (void **)&pBA)); // Is this an audio-only file (no video component)? if (CheckVideoVisibility()) { JIF(InitVideoWindow(1, 1)); } else { // This sample requires a video clip to be loaded Msg(TEXT("This sample requires media with a video component. ") TEXT("Please select another file.")); return E_FAIL; } // Add the bitmap to the VMR's input BlendApplicationImage(ghApp); // Have the graph signal event via window callbacks for performance JIF(pME->SetNotifyWindow((OAHWND)ghApp, WM_GRAPHNOTIFY, 0)); // Complete the window setup ShowWindow(ghApp, SW_SHOWNORMAL); UpdateWindow(ghApp); SetForegroundWindow(ghApp); SetFocus(ghApp); UpdateMainTitle(); #ifdef REGISTER_FILTERGRAPH hr = AddGraphToRot(pGB, &g_dwGraphRegister); if (FAILED(hr)) { Msg(TEXT("Failed to register filter graph with ROT! hr=0x%x"), hr); g_dwGraphRegister = 0; } #endif // Run the graph to play the media file JIF(pMC->Run()); g_psCurrent=Running; } return hr; }
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { GLuint PixelFormat; // Holds The Results After Searching For A Match WNDCLASS wc; // Windows Class Structure DWORD dwExStyle; // Window Extended Style DWORD dwStyle; // Window Style fullscreen=fullscreenflag; // Set The Global Fullscreen Flag hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window. wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = hInstance; // Set The Instance wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = NULL; // We Don't Want A Menu wc.lpszClassName = "OpenGL"; // Set The Class Name if (!RegisterClass(&wc)) // Attempt To Register The Window Class { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (fullscreen) // Attempt Fullscreen Mode? { DEVMODE dmScreenSettings; // Device Mode memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure dmScreenSettings.dmPelsWidth = width; // Selected Screen Width dmScreenSettings.dmPelsHeight = height; // Selected Screen Height dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar. if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { // If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode. if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE } else { // Pop Up A Message Box Letting User Know The Program Is Closing. MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP); return FALSE; // Return FALSE } } } if (fullscreen) // Are We Still In Fullscreen Mode? { dwExStyle=WS_EX_APPWINDOW; // Window Extended Style dwStyle=WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; // Windows Style ShowCursor(FALSE); // Hide Mouse Pointer } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style dwStyle=WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; // Windows Style } // Create The Window if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window "OpenGL", // Class Name title, // Window Title dwStyle, // Window Style 0, 0, // Window Position width, height, // Selected Width And Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL))) // Dont Pass Anything To WM_CREATE { KillGLWindow(); // Reset The Display MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format bits, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 16, // 16Bit Z-Buffer (Depth Buffer) 1, // Use Stencil Buffer ( * Important * ) 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context? { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format? { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format? { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context? { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context { KillGLWindow(); // Reset The Display MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } ShowWindow(hWnd,SW_SHOW); // Show The Window SetForegroundWindow(hWnd); // Slightly Higher Priority SetFocus(hWnd); // Sets Keyboard Focus To The Window ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen if (!InitGL()) // Initialize Our Newly Created GL Window { KillGLWindow(); // Reset The Display MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } return TRUE; // Success }
/* The InitializeWindows function is where we put the code to build the window we will use to render to. It returns screenWidth and screenHeight back to the calling function so we can make use of them throughout the application. We create the window using some default settings to initialize a plain black window with no borders. The function will make either a small window or make a full screen window depending on a global variable called FULL_SCREEN. If this is set to true then we make the screen cover the entire users desktop window.If it is set to false we just make a 800x600 window in the middle of the screen. I placed the FULL_SCREEN global variable at the top of the graphicsclass.h file in case you want to modify it.It will make sense later why I placed the global in that file instead of the header for this file. */ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight) { WNDCLASSEX wc; DEVMODE dmScreenSettings; int posX, posY; int windowstate; // Get an external pointer to this object. ApplicationHandle = this; // Get the instance of this application. m_hinstance = GetModuleHandle(NULL); // Give the application a name. m_applicationName = L"Engine"; // Setup the windows class with default settings. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = m_hinstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hIconSm = wc.hIcon; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = m_applicationName; wc.cbSize = sizeof(WNDCLASSEX); // Register the window class. RegisterClassEx(&wc); // Determine the resolution of the clients desktop screen. screenWidth = GetSystemMetrics(SM_CXSCREEN); screenHeight = GetSystemMetrics(SM_CYSCREEN); // Setup the screen settings depending on whether it is running in full screen or in windowed mode. if (FULL_SCREEN) { // If full screen set the screen to maximum size of the users desktop and 32bit. memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = (unsigned long)screenWidth; dmScreenSettings.dmPelsHeight = (unsigned long)screenHeight; dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; // Change the display settings to full screen. ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN); // Set the position of the window to the top left corner. posX = posY = 0; windowstate = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP; } else { // If windowed then set it to 800x600 resolution. screenWidth = ConstVars::WINDOW_WIDTH; screenHeight = ConstVars::WINDOW_HEIGHT; // Place the window in the middle of the screen. posX = (GetSystemMetrics(SM_CXSCREEN) - screenWidth) / 2; posY = (GetSystemMetrics(SM_CYSCREEN) - screenHeight) / 2; windowstate = WS_OVERLAPPEDWINDOW; } // Create the window with the screen settings and get the handle to it. m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName, windowstate, posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL); // Bring the window up on the screen and set it as main focus. ShowWindow(m_hwnd, SW_SHOW); SetForegroundWindow(m_hwnd); SetFocus(m_hwnd); // Hide the mouse cursor. ShowCursor(true); return; }
static INT_PTR LinkList_Main(WPARAM hContact, LPARAM) { HWND hWnd = WindowList_Find(hWindowList, hContact); if ( hWnd != NULL ) { int len; SetForegroundWindow(hWnd); SetFocus(hWnd); len = GetWindowTextLength(GetDlgItem(hWnd, IDC_MAIN)); PostMessage(GetDlgItem(hWnd, IDC_MAIN), EM_SETSEL, (WPARAM)len, (LPARAM)len); return 0; } HANDLE hEvent = db_event_first(hContact); if (hEvent == NULL) { MessageBox(NULL, TXT_EMPTYHISTORY, TXT_PLUGINNAME, MB_OK | MB_ICONINFORMATION ); return 0; } int histCount = db_event_count(hContact), actCount = 0; DBEVENTINFO dbe = { sizeof(dbe) }; dbe.cbBlob = db_event_getBlobSize(hEvent); dbe.pBlob = (PBYTE)malloc(dbe.cbBlob+1); db_event_get(hEvent, &dbe); dbe.pBlob[dbe.cbBlob] = 0; RECT DesktopRect; GetWindowRect(GetDesktopWindow(), &DesktopRect); HWND hWndProgress = CreateWindow(_T("Progressbar"), TranslateT("Processing history..."), WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, 350, 45, NULL, NULL, hInst, NULL); if ( hWndProgress == 0 ) { free(dbe.pBlob); MessageBox(NULL, TranslateT("Could not create window!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION ); return -1; } SetWindowPos(hWndProgress, HWND_TOP, (int)(DesktopRect.right*0.5)-175, (int)(DesktopRect.bottom*0.5)-22, 0, 0, SWP_NOSIZE); ShowWindow(hWndProgress, SW_SHOW); SetForegroundWindow(hWndProgress); LISTELEMENT *listStart = (LISTELEMENT*)malloc(sizeof(LISTELEMENT)); ZeroMemory(listStart, sizeof(LISTELEMENT)); while( 1 ) { if ( dbe.eventType == EVENTTYPE_URL || dbe.eventType == EVENTTYPE_MESSAGE ) { // Call function to find URIs if ( ExtractURI(&dbe, hEvent, listStart) < 0 ) { free(dbe.pBlob); RemoveList(listStart); MessageBox(NULL, TranslateT("Could not allocate memory!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION); return -1; } } actCount++; if ( ((int)(((float)actCount/histCount)*100.00)) % 10 == 0 ) SendMessage(hWndProgress, WM_COMMAND, 100, ((int)(((float)actCount/histCount)*100.00))); hEvent = db_event_next(hContact, hEvent); if ( hEvent == NULL ) break; free(dbe.pBlob); dbe.cbBlob = db_event_getBlobSize(hEvent); dbe.pBlob = (PBYTE)malloc(dbe.cbBlob+1); db_event_get(hEvent, &dbe); dbe.pBlob[dbe.cbBlob] = 0; } free(dbe.pBlob); SendMessage(hWndProgress, WM_CLOSE, 0, 0); if ( ListCount(listStart) <= 0 ) { RemoveList(listStart); MessageBox(NULL, TXT_NOLINKINHISTORY, TXT_PLUGINNAME, MB_OK | MB_ICONINFORMATION); return 0; } DIALOGPARAM *DlgParam = (DIALOGPARAM*)malloc(sizeof(DIALOGPARAM)); DlgParam->hContact = hContact; DlgParam->listStart = listStart; DlgParam->findMessage = 0; DlgParam->chrg.cpMax = -1; DlgParam->chrg.cpMin = -1; HWND hWndMain = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, MainDlgProc, (LPARAM)DlgParam); if (hWndMain == 0) { RemoveList(listStart); MessageBox(NULL, TranslateT("Could not create window!"), TranslateT("Error"), MB_OK | MB_ICONEXCLAMATION ); return -1; } ShowWindow(hWndMain, SW_SHOW); return 0; }
void CMSWindowsServerTaskBarReceiver::runMenu(int x, int y) { // do popup menu. we need a window to pass to TrackPopupMenu(). // the SetForegroundWindow() and SendMessage() calls around // TrackPopupMenu() are to get the menu to be dismissed when // another window gets activated and are just one of those // win32 weirdnesses. createWindow(); SetForegroundWindow(m_window); HMENU menu = GetSubMenu(m_menu, 0); SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE); HMENU logLevelMenu = GetSubMenu(menu, 3); CheckMenuRadioItem(logLevelMenu, 0, 6, CLOG->getFilter() - CLog::kERROR, MF_BYPOSITION); int n = TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x, y, 0, m_window, NULL); SendMessage(m_window, WM_NULL, 0, 0); // perform the requested operation switch (n) { case IDC_TASKBAR_STATUS: showStatus(); break; case IDC_TASKBAR_LOG: copyLog(); break; case IDC_TASKBAR_SHOW_LOG: ARCH->showConsole(true); break; case IDC_RELOAD_CONFIG: EVENTQUEUE->addEvent(CEvent(getReloadConfigEvent(), IEventQueue::getSystemTarget())); break; case IDC_FORCE_RECONNECT: EVENTQUEUE->addEvent(CEvent(getForceReconnectEvent(), IEventQueue::getSystemTarget())); break; case IDC_TASKBAR_LOG_LEVEL_ERROR: CLOG->setFilter(CLog::kERROR); break; case IDC_TASKBAR_LOG_LEVEL_WARNING: CLOG->setFilter(CLog::kWARNING); break; case IDC_TASKBAR_LOG_LEVEL_NOTE: CLOG->setFilter(CLog::kNOTE); break; case IDC_TASKBAR_LOG_LEVEL_INFO: CLOG->setFilter(CLog::kINFO); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG: CLOG->setFilter(CLog::kDEBUG); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG1: CLOG->setFilter(CLog::kDEBUG1); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG2: CLOG->setFilter(CLog::kDEBUG2); break; case IDC_TASKBAR_QUIT: quit(); break; } }
static qboolean GLW_CreateWindow( const char *drivername, int width, int height, int colorbits, qboolean cdsFullscreen ) { RECT r; cvar_t *vid_xpos, *vid_ypos; int stylebits; int x, y, w, h; int exstyle; // fullscreen DEVMODE for use with win_allowAltTab memset( &glw_fs_dm, 0, sizeof( glw_fs_dm ) ); // // register the window class if necessary // if ( !s_classRegistered ) { WNDCLASS wc; memset( &wc, 0, sizeof( wc ) ); wc.style = 0; wc.lpfnWndProc = (WNDPROC) glw_state.wndproc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = g_wv.hInstance; wc.hIcon = LoadIcon( g_wv.hInstance, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor (NULL,IDC_ARROW); wc.hbrBackground = (void *)COLOR_GRAYTEXT; wc.lpszMenuName = 0; wc.lpszClassName = CLIENT_WINDOW_TITLE; if ( !RegisterClass( &wc ) ) { ri.Error( ERR_FATAL, "GLW_CreateWindow: could not register window class" ); } s_classRegistered = qtrue; ri.Printf( PRINT_ALL, "...registered window class\n" ); } // // create the HWND if one does not already exist // if ( !g_wv.hWnd ) { // // compute width and height // r.left = 0; r.top = 0; r.right = width; r.bottom = height; if ( cdsFullscreen || !Q_stricmp( _3DFX_DRIVER_NAME, drivername ) ) { exstyle = WS_EX_TOPMOST; stylebits = WS_POPUP|WS_VISIBLE|WS_SYSMENU; } else { exstyle = 0; stylebits = WINDOW_STYLE|WS_SYSMENU|WS_MINIMIZEBOX; AdjustWindowRect (&r, stylebits, FALSE); } w = r.right - r.left; h = r.bottom - r.top; if ( cdsFullscreen || !Q_stricmp( _3DFX_DRIVER_NAME, drivername ) ) { x = 0; y = 0; } else { vid_xpos = ri.Cvar_Get ("vid_xpos", "", 0); vid_ypos = ri.Cvar_Get ("vid_ypos", "", 0); x = vid_xpos->integer; y = vid_ypos->integer; // adjust window coordinates if necessary // so that the window is completely on screen if ( x < 0 ) x = 0; if ( y < 0 ) y = 0; if ( w < glw_state.desktopWidth && h < glw_state.desktopHeight ) { if ( x + w > glw_state.desktopWidth ) x = ( glw_state.desktopWidth - w ); if ( y + h > glw_state.desktopHeight ) y = ( glw_state.desktopHeight - h ); } } g_wv.hWnd = CreateWindowEx ( exstyle, CLIENT_WINDOW_TITLE, CLIENT_WINDOW_TITLE, stylebits, x, y, w, h, NULL, NULL, g_wv.hInstance, NULL); if ( !g_wv.hWnd ) { ri.Error (ERR_FATAL, "GLW_CreateWindow() - Couldn't create window"); } ShowWindow( g_wv.hWnd, SW_SHOW ); UpdateWindow( g_wv.hWnd ); ri.Printf( PRINT_ALL, "...created window@%d,%d (%dx%d)\n", x, y, w, h ); } else { ri.Printf( PRINT_ALL, "...window already present, CreateWindowEx skipped\n" ); } if ( !GLW_InitDriver( drivername, colorbits ) ) { ShowWindow( g_wv.hWnd, SW_HIDE ); DestroyWindow( g_wv.hWnd ); g_wv.hWnd = NULL; return qfalse; } SetForegroundWindow( g_wv.hWnd ); SetFocus( g_wv.hWnd ); return qtrue; }
INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) { switch(msg) { case WM_INITDIALOG: { BOOL ShowPopup,ShowMsg,ShowIco; HACCOUNT ActualAccount; DWORD ErrorCode; char* TitleStrA; char *Message1A=NULL; TCHAR *Message1W=NULL; POPUPDATAT BadConnectPopup; ActualAccount=((struct BadConnectionParam *)lParam)->account; ErrorCode=((struct BadConnectionParam *)lParam)->errcode; #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait\n"); #endif if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait failed\n"); #endif return FALSE; } #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read enter\n"); #endif int size = (int)(strlen(ActualAccount->Name)+strlen(Translate(BADCONNECTTITLE))); TitleStrA = new char[size]; mir_snprintf(TitleStrA, size, Translate(BADCONNECTTITLE), ActualAccount->Name); ShowPopup=ActualAccount->BadConnectN.Flags & YAMN_ACC_POP; ShowMsg=ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG; ShowIco=ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO; if (ShowPopup) { BadConnectPopup.lchIcon = g_LoadIconEx(3); BadConnectPopup.colorBack = ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? ActualAccount->BadConnectN.PopupB : GetSysColor(COLOR_BTNFACE); BadConnectPopup.colorText = ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? ActualAccount->BadConnectN.PopupT : GetSysColor(COLOR_WINDOWTEXT); BadConnectPopup.iSeconds = ActualAccount->BadConnectN.PopupTime; BadConnectPopup.PluginWindowProc = BadConnectPopupProc; BadConnectPopup.PluginData = ActualAccount; lstrcpyn(BadConnectPopup.lptzContactName, _A2T(ActualAccount->Name), SIZEOF(BadConnectPopup.lptzContactName)); } if (ActualAccount->Plugin->Fcn != NULL && ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr != NULL) { Message1W = ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode); SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); lstrcpyn(BadConnectPopup.lptzText,Message1W,sizeof(BadConnectPopup.lptzText)); if (ShowPopup) PUAddPopupT(&BadConnectPopup); } else if (ActualAccount->Plugin->Fcn != NULL && ActualAccount->Plugin->Fcn->GetErrorStringAFcnPtr != NULL) { Message1W=ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode); SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); lstrcpyn(BadConnectPopup.lptzText,Message1W,sizeof(BadConnectPopup.lptzText)); if (ShowPopup) PUAddPopupT(&BadConnectPopup); } else { Message1W=TranslateT("Unknown error"); SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); lstrcpyn(BadConnectPopup.lptzText,Message1W,sizeof(BadConnectPopup.lptzText)); if (ShowPopup) PUAddPopupT(&BadConnectPopup); } if (!ShowMsg && !ShowIco) DestroyWindow(hDlg); #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read done\n"); #endif ReadDoneFcn(ActualAccount->AccountAccessSO); SetWindowTextA(hDlg, TitleStrA); delete[] TitleStrA; if (Message1A != NULL) delete[] Message1A; if (ActualAccount->Plugin->Fcn != NULL && ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr != NULL && Message1A != NULL) ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr(Message1A); if (ActualAccount->Plugin->Fcn != NULL && ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr != NULL && Message1W != NULL) ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr(Message1W); return 0; } case WM_DESTROY: { NOTIFYICONDATA nid; ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); nid.cbSize=sizeof(NOTIFYICONDATA); nid.hWnd=hDlg; nid.uID=0; Shell_NotifyIcon(NIM_DELETE,&nid); PostQuitMessage(0); break; } case WM_YAMN_NOTIFYICON: switch (lParam) { case WM_LBUTTONDBLCLK: ShowWindow(hDlg,SW_SHOWNORMAL); SetForegroundWindow(hDlg); break; } return 0; case WM_CHAR: switch((TCHAR)wParam) { case 27: case 13: DestroyWindow(hDlg); break; } break; case WM_SYSCOMMAND: switch(wParam) { case SC_CLOSE: DestroyWindow(hDlg); break; } case WM_COMMAND: { WORD wNotifyCode = HIWORD(wParam); switch(LOWORD(wParam)) { case IDC_BTNOK: DestroyWindow(hDlg); break; } break; } } return 0; }
//Invis Dialog LRESULT CALLBACK InvisDialogProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static UINT s_uTaskbarRestart; switch (message) /* handle the messages */ { case WM_INITDIALOG: SetClassLong(hwnd,GCL_HICON,(long) LoadIcon(thisinstance,"A")); SetClassLong(hwnd,GCL_HICONSM,(long) LoadIcon(thisinstance,"A")); s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated")); return false; break; case WM_NOTIFYICON: if ((UINT)lParam == WM_RBUTTONUP){ POINT cord; GetCursorPos(&cord); HMENU menu; menu = CreatePopupMenu(); AppendMenu(menu,MF_ENABLED|MF_STRING, ID_MENU_ABOUT,"&About"); AppendMenu(menu,MF_ENABLED|MF_STRING, ID_MENU_HELP,"&Help"); AppendMenu(menu,MF_ENABLED|MF_STRING, ID_MENU_SETT,"Se&ttings"); AppendMenu(menu,MF_ENABLED|MF_STRING, ID_MENU_STATUS,"&Status"); AppendMenu(menu,MF_ENABLED|MF_STRING, ID_MENU_EXIT,"&Exit"); SetForegroundWindow(hwnd); TrackPopupMenu(menu,TPM_RIGHTALIGN,cord.x,cord.y,0,hwnd,NULL); DestroyMenu(menu); PostMessage(hwnd, WM_NULL, 0, 0); } else if ((UINT)lParam == WM_LBUTTONDBLCLK) { PostMessage(hwnd,WM_COMMAND,ID_MENU_STATUS,0); } return 0; break; case WM_CLOSE: case WM_RQUIT: Windowlessquit = true; PostQuitMessage(0); break; // /* case WM_ENDSESSION: Windowlessquit = true; PostQuitMessage(0); return 0; // */ case WM_COMMAND: switch(LOWORD(wParam)) { case ID_MENU_EXIT: Windowlessquit = true; PostQuitMessage (0); break; case ID_MENU_STATUS: Stat.Create(); break; case ID_MENU_SETT: Sett.Create(); break; case ID_MENU_HELP: WinHelp(hwnd,"HELP.HLP",HELP_FINDER,0); break; case ID_MENU_ABOUT: if (!IsWindow(Aboutwnd)) { Aboutwnd = CreateDialog(thisinstance,MAKEINTRESOURCE(IDD_ABOUT),NULL,(DLGPROC)AboutDialogProcedure); ShowWindow(Aboutwnd,SW_SHOW); } SetForegroundWindow(Aboutwnd); break; } return 0; break; default: if( message == s_uTaskbarRestart) { hGlobalIcon->Remove(); Sleep(500); hGlobalIcon->Add(); break; } return false; } return 0; }
static int winDialogSetBringFrontAttrib(Ihandle *ih, const char *value) { if (iupStrBoolean(value)) SetForegroundWindow(ih->handle); return 0; }
BOOL COAKitsApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization //SetRegistryKey(_T("Local AppWizard-Generated Applications")); hMutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,TEXT("OAKits")); if(hMutex) { //AfxMessageBox("程序已经启动,请双击对应的系统图标打开程序!",MB_ICONERROR); HWND hWnd=FindWindow(NULL,TEXT("OA3Client v6.2")); if (hWnd) { if(!IsWindowVisible(hWnd)) ShowWindow(hWnd,SW_SHOW); SetForegroundWindow(hWnd); } return FALSE; } else { hMutex=CreateMutex(NULL,FALSE,TEXT("OAKits")); } SetRegistryKey(_T("OAKits")); COAKitsDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
BOOL CALLBACK vncProperties::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { // We use the dialog-box's USERDATA to store a _this pointer // This is set only once WM_INITDIALOG has been recieved, though! vncProperties *_this = (vncProperties *) GetWindowLong(hwnd, GWL_USERDATA); switch (uMsg) { case WM_INITDIALOG: { // Retrieve the Dialog box parameter and use it as a pointer // to the calling vncProperties object SetWindowLong(hwnd, GWL_USERDATA, lParam); _this = (vncProperties *) lParam; _this->m_dlgvisible = TRUE; // Set the dialog box's title to indicate which Properties we're editting if (_this->m_usersettings) { SetWindowText(hwnd, "WinVNC: Current User Properties"); } else { SetWindowText(hwnd, "WinVNC: Default Local System Properties"); } // Initialise the properties controls HWND hConnectSock = GetDlgItem(hwnd, IDC_CONNECT_SOCK); SendMessage(hConnectSock, BM_SETCHECK, _this->m_server->SockConnected(), 0); HWND hConnectHTTP = GetDlgItem(hwnd, IDC_CONNECT_HTTP); SendMessage(hConnectHTTP, BM_SETCHECK, _this->m_server->HTTPConnectEnabled(), 0); HWND hConnectCorba = GetDlgItem(hwnd, IDC_CONNECT_CORBA); SendMessage(hConnectCorba, BM_SETCHECK, _this->m_server->CORBAConnected(), 0); #if(defined(_CORBA)) ShowWindow(hConnectCorba, SW_SHOW); #else ShowWindow(hConnectCorba, SW_HIDE); #endif HWND hAutoPortNo = GetDlgItem(hwnd, IDC_AUTO_DISPLAY_NO); SendMessage(hAutoPortNo, BM_SETCHECK, _this->m_server->AutoPortSelect(), 0); EnableWindow(hAutoPortNo, _this->m_server->SockConnected()); HWND hPortNo = GetDlgItem(hwnd, IDC_PORTNO); SetDlgItemInt(hwnd, IDC_PORTNO, PORT_TO_DISPLAY(_this->m_server->GetPort()), FALSE); EnableWindow(hPortNo, _this->m_server->SockConnected() && !_this->m_server->AutoPortSelect()); HWND hPassword = GetDlgItem(hwnd, IDC_PASSWORD); EnableWindow(hPassword, _this->m_server->SockConnected()); // Get the password { char plain[MAXPWLEN+1]; _this->m_server->GetPassword(plain); { vncPasswd::ToText plainpwd(plain); int length = strlen(plainpwd); for (int i=0; i<length; i++) { plain[i] = i+1; } plain[length]=0; } SetDlgItemText(hwnd, IDC_PASSWORD, (const char *) plain); } // Remote input settings HWND hEnableRemoteInputs = GetDlgItem(hwnd, IDC_DISABLE_INPUTS); SendMessage(hEnableRemoteInputs, BM_SETCHECK, !(_this->m_server->RemoteInputsEnabled()), 0); // Local input settings HWND hDisableLocalInputs = GetDlgItem(hwnd, IDC_DISABLE_LOCAL_INPUTS); SendMessage(hDisableLocalInputs, BM_SETCHECK, _this->m_server->LocalInputsDisabled(), 0); // Remove the wallpaper HWND hRemoveWallpaper = GetDlgItem(hwnd, IDC_REMOVE_WALLPAPER); SendMessage(hRemoveWallpaper, BM_SETCHECK, _this->m_server->RemoveWallpaperEnabled(), 0); // Lock settings HWND hLockSetting; switch (_this->m_server->LockSettings()) { case 1: hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_LOCK); break; case 2: hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_LOGOFF); break; default: hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_NOTHING); }; SendMessage(hLockSetting, BM_SETCHECK, TRUE, 0); // Set the polling options HWND hPollFullScreen = GetDlgItem(hwnd, IDC_POLL_FULLSCREEN); SendMessage(hPollFullScreen, BM_SETCHECK, _this->m_server->PollFullScreen(), 0); HWND hPollForeground = GetDlgItem(hwnd, IDC_POLL_FOREGROUND); SendMessage(hPollForeground, BM_SETCHECK, _this->m_server->PollForeground(), 0); HWND hPollUnderCursor = GetDlgItem(hwnd, IDC_POLL_UNDER_CURSOR); SendMessage(hPollUnderCursor, BM_SETCHECK, _this->m_server->PollUnderCursor(), 0); HWND hPollConsoleOnly = GetDlgItem(hwnd, IDC_CONSOLE_ONLY); SendMessage(hPollConsoleOnly, BM_SETCHECK, _this->m_server->PollConsoleOnly(), 0); EnableWindow(hPollConsoleOnly, _this->m_server->PollUnderCursor() || _this->m_server->PollForeground() ); HWND hPollOnEventOnly = GetDlgItem(hwnd, IDC_ONEVENT_ONLY); SendMessage(hPollOnEventOnly, BM_SETCHECK, _this->m_server->PollOnEventOnly(), 0); EnableWindow(hPollOnEventOnly, _this->m_server->PollUnderCursor() || _this->m_server->PollForeground() ); SetForegroundWindow(hwnd); return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDC_APPLY: { // Save the password char passwd[MAXPWLEN+1]; if (GetDlgItemText(hwnd, IDC_PASSWORD, (LPSTR) &passwd, MAXPWLEN+1) == 0) { vncPasswd::FromClear crypt; _this->m_server->SetPassword(crypt); } else { char current_pwd[MAXPWLEN+1]; _this->m_server->GetPassword(current_pwd); vncPasswd::ToText current(current_pwd); BOOL password_changed = FALSE; for (int i=0; i<MAXPWLEN; i++) { if (passwd[i] != i+1) password_changed = TRUE; if ((passwd[i] >= 1) && (passwd[i] <= MAXPWLEN)) passwd[i] = current[passwd[i]-1]; } if (password_changed) { vnclog.Print(LL_INTINFO, VNCLOG("password changed\n")); vncPasswd::FromText crypt(passwd); _this->m_server->SetPassword(crypt); } } // Save the new settings to the server HWND hAutoDisplayNo = GetDlgItem(hwnd, IDC_AUTO_DISPLAY_NO); _this->m_server->SetAutoPortSelect( SendMessage(hAutoDisplayNo, BM_GETCHECK, 0, 0) == BST_CHECKED ); // only save the port number if we're not auto selecting! if (!_this->m_server->AutoPortSelect()) { BOOL success; UINT portno = GetDlgItemInt(hwnd, IDC_PORTNO, &success, TRUE); if (success) _this->m_server->SetPort(DISPLAY_TO_PORT(portno)); } HWND hConnectSock = GetDlgItem(hwnd, IDC_CONNECT_SOCK); _this->m_server->SockConnect( SendMessage(hConnectSock, BM_GETCHECK, 0, 0) == BST_CHECKED ); HWND hConnectHTTP = GetDlgItem(hwnd, IDC_CONNECT_HTTP); _this->m_server->EnableHTTPConnect( SendMessage(hConnectHTTP, BM_GETCHECK, 0, 0) == BST_CHECKED ); HWND hConnectCorba = GetDlgItem(hwnd, IDC_CONNECT_CORBA); _this->m_server->CORBAConnect( SendMessage(hConnectCorba, BM_GETCHECK, 0, 0) == BST_CHECKED ); // Remote input stuff HWND hEnableRemoteInputs = GetDlgItem(hwnd, IDC_DISABLE_INPUTS); _this->m_server->EnableRemoteInputs( SendMessage(hEnableRemoteInputs, BM_GETCHECK, 0, 0) != BST_CHECKED ); // Local input stuff HWND hDisableLocalInputs = GetDlgItem(hwnd, IDC_DISABLE_LOCAL_INPUTS); _this->m_server->DisableLocalInputs( SendMessage(hDisableLocalInputs, BM_GETCHECK, 0, 0) == BST_CHECKED ); // Wallpaper handling HWND hRemoveWallpaper = GetDlgItem(hwnd, IDC_REMOVE_WALLPAPER); _this->m_server->EnableRemoveWallpaper( SendMessage(hRemoveWallpaper, BM_GETCHECK, 0, 0) == BST_CHECKED ); // Lock settings handling if (SendMessage(GetDlgItem(hwnd, IDC_LOCKSETTING_LOCK), BM_GETCHECK, 0, 0) == BST_CHECKED) { _this->m_server->SetLockSettings(1); } else if (SendMessage(GetDlgItem(hwnd, IDC_LOCKSETTING_LOGOFF), BM_GETCHECK, 0, 0) == BST_CHECKED) { _this->m_server->SetLockSettings(2); } else { _this->m_server->SetLockSettings(0); } // Handle the polling stuff HWND hPollFullScreen = GetDlgItem(hwnd, IDC_POLL_FULLSCREEN); _this->m_server->PollFullScreen( SendMessage(hPollFullScreen, BM_GETCHECK, 0, 0) == BST_CHECKED ); HWND hPollForeground = GetDlgItem(hwnd, IDC_POLL_FOREGROUND); _this->m_server->PollForeground( SendMessage(hPollForeground, BM_GETCHECK, 0, 0) == BST_CHECKED ); HWND hPollUnderCursor = GetDlgItem(hwnd, IDC_POLL_UNDER_CURSOR); _this->m_server->PollUnderCursor( SendMessage(hPollUnderCursor, BM_GETCHECK, 0, 0) == BST_CHECKED ); HWND hPollConsoleOnly = GetDlgItem(hwnd, IDC_CONSOLE_ONLY); _this->m_server->PollConsoleOnly( SendMessage(hPollConsoleOnly, BM_GETCHECK, 0, 0) == BST_CHECKED ); HWND hPollOnEventOnly = GetDlgItem(hwnd, IDC_ONEVENT_ONLY); _this->m_server->PollOnEventOnly( SendMessage(hPollOnEventOnly, BM_GETCHECK, 0, 0) == BST_CHECKED ); // And to the registry _this->Save(); // Was ok pressed? if (LOWORD(wParam) == IDOK) { // Yes, so close the dialog vnclog.Print(LL_INTINFO, VNCLOG("enddialog (OK)\n")); _this->m_returncode_valid = TRUE; EndDialog(hwnd, IDOK); _this->m_dlgvisible = FALSE; } return TRUE; } case IDCANCEL: vnclog.Print(LL_INTINFO, VNCLOG("enddialog (CANCEL)\n")); _this->m_returncode_valid = TRUE; EndDialog(hwnd, IDCANCEL); _this->m_dlgvisible = FALSE; return TRUE; case IDC_CONNECT_SOCK: // The user has clicked on the socket connect tickbox { HWND hConnectSock = GetDlgItem(hwnd, IDC_CONNECT_SOCK); BOOL connectsockon = (SendMessage(hConnectSock, BM_GETCHECK, 0, 0) == BST_CHECKED); HWND hAutoDisplayNo = GetDlgItem(hwnd, IDC_AUTO_DISPLAY_NO); EnableWindow(hAutoDisplayNo, connectsockon); HWND hPortNo = GetDlgItem(hwnd, IDC_PORTNO); EnableWindow(hPortNo, connectsockon && (SendMessage(hAutoDisplayNo, BM_GETCHECK, 0, 0) != BST_CHECKED)); HWND hPassword = GetDlgItem(hwnd, IDC_PASSWORD); EnableWindow(hPassword, connectsockon); } return TRUE; case IDC_POLL_FOREGROUND: case IDC_POLL_UNDER_CURSOR: // User has clicked on one of the polling mode buttons // affected by the pollconsole and pollonevent options { // Get the poll-mode buttons HWND hPollForeground = GetDlgItem(hwnd, IDC_POLL_FOREGROUND); HWND hPollUnderCursor = GetDlgItem(hwnd, IDC_POLL_UNDER_CURSOR); // Determine whether to enable the modifier options BOOL enabled = (SendMessage(hPollForeground, BM_GETCHECK, 0, 0) == BST_CHECKED) || (SendMessage(hPollUnderCursor, BM_GETCHECK, 0, 0) == BST_CHECKED); HWND hPollConsoleOnly = GetDlgItem(hwnd, IDC_CONSOLE_ONLY); EnableWindow(hPollConsoleOnly, enabled); HWND hPollOnEventOnly = GetDlgItem(hwnd, IDC_ONEVENT_ONLY); EnableWindow(hPollOnEventOnly, enabled); } return TRUE; case IDC_AUTO_DISPLAY_NO: // User has toggled the Auto Port Select feature. // If this is in use, then we don't allow the Display number field // to be modified! { // Get the auto select button HWND hPortNoAuto = GetDlgItem(hwnd, IDC_AUTO_DISPLAY_NO); // Should the portno field be modifiable? BOOL enable = SendMessage(hPortNoAuto, BM_GETCHECK, 0, 0) != BST_CHECKED; // Set the state HWND hPortNo = GetDlgItem(hwnd, IDC_PORTNO); EnableWindow(hPortNo, enable); } return TRUE; } break; } return 0; }
BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: HEdit1 = GetDlgItem(hwndDlg, IDC_EDIT1); HEdit2 = GetDlgItem(hwndDlg, IDC_EDIT2); SetFocus(HEdit2); // SendMessage(HEdit1, EM_LIMITTEXT, 1000, 0); HEdit1_size = SendMessage(HEdit1, EM_GETLIMITTEXT, 0, 0) + 1; HEdit1_buf = (char *) Q_malloc (HEdit1_size); //Sys_Printf("%d\n", HEdit1_size); break; case WM_CTLCOLORSTATIC: if ((HWND)lParam != HEdit1) break; SetTextColor((HDC)wParam, EditBoxColor); SetBkColor((HDC)wParam, EditBoxBgColor); return (LONG)g_hbrBackground; case WM_TRAY: switch (lParam) { case 515: ShowWindow(hwndDlg,SW_RESTORE); SetForegroundWindow(hwndDlg); RemoveNotifyIcon(); break; case 516: { static DWORD id; CreateThread(NULL, 0, TrackPopup, NULL, 0, &id); break; } } break; case WM_SIZE: // we don't care until window is fully created if (DlgHwnd == NULL) break; if ((int)wParam == SIZE_MINIMIZED) { ShowWindow(hwndDlg,SW_HIDE); ShowNotifyIcon(); } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_OK: { char str[1024]; SendMessage(HEdit2, WM_GETTEXT, (WPARAM)sizeof(str),(LPARAM)str); if (!str[0]) break; SendMessage(HEdit2, WM_SETTEXT, 0, (LPARAM)0); // normalize text before add to console. ConsoleAddText(Q_normalizetext(va("] %s\n", str))); Cbuf_AddText (str); Cbuf_AddText ("\n"); return TRUE; } case IDC_QUIT: Cbuf_AddText("quit\n"); return TRUE; case IDC_RESTORE: ShowWindow(hwndDlg,SW_RESTORE); RemoveNotifyIcon(); return TRUE; case IDC_CLEAR: SendMessage(HEdit1, WM_SETTEXT, 0, (LPARAM)0); SetFocus(HEdit2); break; } break; case WM_ACTIVATE: break; case WM_CLOSE: SV_Quit_f(); break; } return FALSE; }
qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) { WNDCLASS wc; RECT r; cvar_t *vid_xpos, *vid_ypos; int stylebits; int x, y, w, h; int exstyle; /* Register the frame class */ wc.style = 0; wc.lpfnWndProc = (WNDPROC)glw_state.wndproc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = glw_state.hInstance; wc.hIcon = 0; wc.hCursor = LoadCursor (NULL,IDC_ARROW); wc.hbrBackground = (void *)COLOR_GRAYTEXT; wc.lpszMenuName = 0; wc.lpszClassName = WINDOW_CLASS_NAME; if (!RegisterClass (&wc) ) ri.Sys_Error (ERR_FATAL, "Couldn't register window class"); if (fullscreen) { exstyle = WS_EX_TOPMOST; stylebits = WS_POPUP|WS_VISIBLE; } else { exstyle = 0; stylebits = WINDOW_STYLE; } r.left = 0; r.top = 0; r.right = width; r.bottom = height; AdjustWindowRect (&r, stylebits, FALSE); w = r.right - r.left; h = r.bottom - r.top; if (fullscreen) { x = 0; y = 0; } else { vid_xpos = ri.Cvar_Get ("vid_xpos", "0", 0); vid_ypos = ri.Cvar_Get ("vid_ypos", "0", 0); x = vid_xpos->value; y = vid_ypos->value; } glw_state.hWnd = CreateWindowEx ( exstyle, WINDOW_CLASS_NAME, "Quake 2", stylebits, x, y, w, h, NULL, NULL, glw_state.hInstance, NULL); if (!glw_state.hWnd) ri.Sys_Error (ERR_FATAL, "Couldn't create window"); ShowWindow( glw_state.hWnd, SW_SHOW ); UpdateWindow( glw_state.hWnd ); // init all the gl stuff for the window if (!GLimp_InitGL ()) { ri.Con_Printf( PRINT_ALL, "VID_CreateWindow() - GLimp_InitGL failed\n"); return false; } SetForegroundWindow( glw_state.hWnd ); SetFocus( glw_state.hWnd ); // let the sound and input subsystems know about the new window ri.Vid_NewWindow (width, height); return true; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char *pb; char *pe; WNDCLASS wc; HMENU hMainMenu; MSG msg; for (pb = lpCmdLine; *pb == ' ' || *pb == '\t'; pb++); for (pe = pb; *pe != '\0'; pe++); while (--pe > pb && (*pe == ' ' || *pe == '\t')); /* Now pb and pe point at respectively the first and last non-blank character in lpCmdLine. If pb > pe then the command line is blank. */ if (*pb == '"' && *pe == '"') pb++; else pe++; *pe = '\0'; /* Now pb contains the filename, if any, specified on the command line. */ hWnd = FindWindow(WND_CLASS_NAME, NULL); if (hWnd != NULL) { /* an instance of WASAP is already running */ if (*pb != '\0') { /* pass the filename */ COPYDATASTRUCT cds = { 'O', (DWORD) (pe + 1 - pb), pb }; SendMessage(hWnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds); } else { /* bring the open dialog to top */ HWND hChild = GetLastActivePopup(hWnd); if (hChild != hWnd) SetForegroundWindow(hChild); } return 0; } hInst = hInstance; wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); wc.lpszMenuName = NULL; wc.lpszClassName = WND_CLASS_NAME; RegisterClass(&wc); hWnd = CreateWindow(WND_CLASS_NAME, APP_TITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); hStopIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_STOP)); hPlayIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PLAY)); hMainMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU)); hTrayMenu = GetSubMenu(hMainMenu, 0); hSongMenu = CreatePopupMenu(); InsertMenu(hTrayMenu, 1, MF_BYPOSITION | MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR) hSongMenu, "So&ng"); SetMenuDefaultItem(hTrayMenu, 0, TRUE); nid.hWnd = hWnd; nid.hIcon = hStopIcon; Shell_NotifyIcon(NIM_ADD, &nid); taskbarCreatedMessage = RegisterWindowMessage("TaskbarCreated"); if (*pb != '\0') { memcpy(current_filename, pb, pe + 1 - pb); LoadAndPlay(-1); } else SelectAndLoadFile(); while (GetMessage(&msg, NULL, 0, 0)) { if (infoDialog == NULL || !IsDialogMessage(infoDialog, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } WaveOut_Close(); Shell_NotifyIcon(NIM_DELETE, &nid); DestroyMenu(hMainMenu); return 0; }
LRESULT CMenuWnd::OnCreate( UINT uMag, WPARAM wParam, LPARAM lParam,BOOL& bHandled ) { if( m_pOwner != NULL) { LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); styleValue &= ~WS_CAPTION; ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); RECT rcClient; ::GetClientRect(*this, &rcClient); ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, \ rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); m_pm.Init(m_hWnd); // The trick is to add the items to the new container. Their owner gets // reassigned by this operation - which is why it is important to reassign // the items back to the righfull owner/manager when the window closes. m_pLayout = new CMenuUI(); m_pm.UseParentResource(m_pOwner->GetManager()); m_pLayout->SetManager(&m_pm, NULL, true); LPCTSTR pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(kMenuUIInterfaceName); if( pDefaultAttributes ) { m_pLayout->ApplyAttributeList(pDefaultAttributes); } m_pLayout->SetBkColor(0xFFFFFFFF); m_pLayout->SetBorderColor(0xFF85E4FF); m_pLayout->SetBorderSize(0); m_pLayout->SetAutoDestroy(false); m_pLayout->EnableScrollBar(); for( int i = 0; i < m_pOwner->GetCount(); i++ ) { if(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL ){ (static_cast<CMenuElementUI*>(m_pOwner->GetItemAt(i)))->SetOwner(m_pLayout); m_pLayout->Add(static_cast<CControlUI*>(m_pOwner->GetItemAt(i))); } } m_pm.AttachDialog(m_pLayout); // Position the popup window in absolute space RECT rcOwner = m_pOwner->GetPos(); RECT rc = rcOwner; int cxFixed = 0; int cyFixed = 0; #if defined(WIN32) && !defined(UNDER_CE) MONITORINFO oMonitor = {}; oMonitor.cbSize = sizeof(oMonitor); ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); CRect rcWork = oMonitor.rcWork; #else CRect rcWork; GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork); #endif SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top }; for( int it = 0; it < m_pOwner->GetCount(); it++ ) { if(m_pOwner->GetItemAt(it)->GetInterface(kMenuElementUIInterfaceName) != NULL ){ CControlUI* pControl = static_cast<CControlUI*>(m_pOwner->GetItemAt(it)); SIZE sz = pControl->EstimateSize(szAvailable); cyFixed += sz.cy; if( cxFixed < sz.cx ) cxFixed = sz.cx; } } cyFixed += 4; cxFixed += 4; RECT rcWindow; GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWindow); rc.top = rcOwner.top; rc.bottom = rc.top + cyFixed; ::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc); rc.left = rcWindow.right; rc.right = rc.left + cxFixed; rc.right += 2; bool bReachBottom = false; bool bReachRight = false; LONG chRightAlgin = 0; LONG chBottomAlgin = 0; RECT rcPreWindow = {0}; ContextMenuObserver::Iterator<BOOL, ContextMenuParam> iterator(s_context_menu_observer); ReceiverImplBase<BOOL, ContextMenuParam>* pReceiver = iterator.next(); while( pReceiver != NULL ) { CMenuWnd* pContextMenu = dynamic_cast<CMenuWnd*>(pReceiver); if( pContextMenu != NULL ) { GetWindowRect(pContextMenu->GetHWND(), &rcPreWindow); bReachRight = rcPreWindow.left >= rcWindow.right; bReachBottom = rcPreWindow.top >= rcWindow.bottom; if( pContextMenu->GetHWND() == m_pOwner->GetManager()->GetPaintWindow() || bReachBottom || bReachRight ) break; } pReceiver = iterator.next(); } if (bReachBottom) { rc.bottom = rcWindow.top; rc.top = rc.bottom - cyFixed; } if (bReachRight) { rc.right = rcWindow.left; rc.left = rc.right - cxFixed; } if( rc.bottom > rcWork.bottom ) { rc.bottom = rc.top; rc.top = rc.bottom - cyFixed; } if (rc.right > rcWork.right) { rc.right = rcWindow.left; rc.left = rc.right - cxFixed; rc.top = rcWindow.bottom; rc.bottom = rc.top + cyFixed; } if( rc.top < rcWork.top ) { rc.top = rcOwner.top; rc.bottom = rc.top + cyFixed; } if (rc.left < rcWork.left) { rc.left = rcWindow.right; rc.right = rc.left + cxFixed; } MoveWindow(m_hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); } else { m_pm.Init(m_hWnd); CDialogBuilder builder; CMenuBuilderCallback menuCallback; CControlUI* pRoot = builder.Create(m_xml, &menuCallback, &m_pm , NULL , m_sType.GetData()); m_pm.AttachDialog(pRoot); #if defined(WIN32) && !defined(UNDER_CE) MONITORINFO oMonitor = {}; oMonitor.cbSize = sizeof(oMonitor); ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); CRect rcWork = oMonitor.rcWork; #else CRect rcWork; /** 原来有bug m_pOwner为NULL,不能用m_pOwner->GetManager(),应为m_pm */ //GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork); GetWindowRect(m_pm.GetPaintWindow(), &rcWork); #endif SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top }; szAvailable = pRoot->EstimateSize(szAvailable); m_pm.SetInitSize(szAvailable.cx, szAvailable.cy); DWORD dwAlignment = eMenuAlignment_Left | eMenuAlignment_Top; SIZE szInit = m_pm.GetInitSize(); CRect rc; CPoint point = m_BasedPoint; rc.left = point.x; rc.top = point.y; rc.right = rc.left + szInit.cx; rc.bottom = rc.top + szInit.cy; int nWidth = rc.GetWidth(); int nHeight = rc.GetHeight(); if (dwAlignment & eMenuAlignment_Right) { rc.right = point.x; rc.left = rc.right - nWidth; } if (dwAlignment & eMenuAlignment_Bottom) { rc.bottom = point.y; rc.top = rc.bottom - nHeight; } SetForegroundWindow(m_hWnd); MoveWindow(m_hWnd, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), FALSE); SetWindowPos(m_hWnd, HWND_TOPMOST, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), SWP_SHOWWINDOW); } return 0; }
int CreateScene(int width, int height, int fullscreen) { WNDCLASS WC; DWORD wStyle; DWORD wExStyle; RECT r; DEVMODE sSettings; unsigned PixelFormat; PIXELFORMATDESCRIPTOR pfd; HGLRC hRC; hWnd = NULL; // create a window class WC.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; WC.lpfnWndProc = WndProc; WC.cbClsExtra = 0; WC.cbWndExtra = 0; WC.hInstance = GetModuleHandle(NULL); WC.hIcon = NULL; WC.hCursor = LoadCursor(NULL, IDC_ARROW); WC.hbrBackground = NULL; WC.lpszMenuName = NULL; WC.lpszClassName = "cgcls"; if (!RegisterClass(&WC)) return -1; wExStyle = WS_EX_APPWINDOW; wStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; if (!fullscreen) wStyle |= WS_OVERLAPPED | WS_CAPTION;// | WS_SYSMENU; r.top = r.left = 0; r.right = width; r.bottom = height; if (fullscreen) { // change display settings memset(&sSettings, 0, sizeof(sSettings)); sSettings.dmSize = sizeof(sSettings); sSettings.dmPelsWidth = width; sSettings.dmPelsHeight = height; sSettings.dmBitsPerPel = 32; sSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; if (ChangeDisplaySettings(&sSettings, 0) != DISP_CHANGE_SUCCESSFUL) return -1; ShowCursor(FALSE); } else { AdjustWindowRectEx(&r,wStyle,FALSE,wExStyle); } hWnd = CreateWindowEx(wExStyle,"cgcls","cg wgl",wStyle, 0,0,width,height, NULL,NULL,GetModuleHandle(NULL),NULL); if (hWnd == NULL) return -1; // display window ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); // create device context if (!(hDC = GetDC(hWnd))) return -1; // set pixel format memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 32; pfd.dwLayerMask = PFD_MAIN_PLANE; if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return -1; if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return -1; if (!(hRC = wglCreateContext(hDC))) return -1; if (!wglMakeCurrent(hDC, hRC)) return -1; glActiveTexture = (PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"); glAttachShader = (PFNGLATTACHSHADERPROC)wglGetProcAddress("glAttachShader"); glBindBuffer = (PFNGLBINDBUFFERPROC)wglGetProcAddress("glBindBuffer"); glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)wglGetProcAddress("glBindVertexArray"); glBufferData = (PFNGLBUFFERDATAPROC)wglGetProcAddress("glBufferData"); glCompileShader = (PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader"); glCreateProgram = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram"); glCreateShader = (PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader"); glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)wglGetProcAddress("glDeleteBuffers"); glDeleteProgram = (PFNGLDELETEPROGRAMPROC)wglGetProcAddress("glDeleteProgram"); glDeleteShader = (PFNGLDELETESHADERPROC)wglGetProcAddress("glDeleteShader"); glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)wglGetProcAddress("glDeleteVertexArrays"); glDetachShader = (PFNGLDETACHSHADERPROC)wglGetProcAddress("glDetachShader"); glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glEnableVertexAttribArray"); glGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffers"); glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)wglGetProcAddress("glGenVertexArrays"); glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)wglGetProcAddress("glGetAttribLocation"); glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)wglGetProcAddress("glGetProgramInfoLog"); glGetProgramiv = (PFNGLGETPROGRAMIVPROC)wglGetProcAddress("glGetProgramiv"); glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)wglGetProcAddress("glGetShaderInfoLog"); glGetShaderiv = (PFNGLGETSHADERIVPROC)wglGetProcAddress("glGetShaderiv"); glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"); glLinkProgram = (PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram"); glMapBuffer = (PFNGLMAPBUFFERPROC)wglGetProcAddress("glMapBuffer"); glPatchParameteri = (PFNGLPATCHPARAMETERIPROC)wglGetProcAddress("glPatchParameteri"); glShaderSource = (PFNGLSHADERSOURCEPROC)wglGetProcAddress("glShaderSource"); glUniform1f = (PFNGLUNIFORM1FPROC)wglGetProcAddress("glUniform1f"); glUniform1i = (PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"); glUniform2f = (PFNGLUNIFORM2FPROC)wglGetProcAddress("glUniform2f"); glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)wglGetProcAddress("glUniformMatrix4fv"); glUnmapBuffer = (PFNGLUNMAPBUFFERPROC)wglGetProcAddress("glUnmapBuffer"); glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"); glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)wglGetProcAddress("glValidateProgram"); glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer"); return 0; }
BOOL CALLBACK SessionDialog::SessDlgProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { // This is a static method, so we don't know which instantiation we're // dealing with. But we can get a pseudo-this from the parameter to // WM_INITDIALOG, which we therafter store with the window and retrieve // as follows: SessionDialog*_this = helper::SafeGetWindowUserData<SessionDialog>(hwnd); switch (uMsg) { case WM_INITDIALOG: { helper::SafeSetWindowUserData(hwnd, lParam); SessionDialog *l_this = (SessionDialog *) lParam; CentreWindow(hwnd); SetForegroundWindow(hwnd); l_this->m_pCC->m_hSessionDialog = hwnd; // Set up recently-used list HWND hcombo = GetDlgItem( hwnd, IDC_HOSTNAME_EDIT); TCHAR valname[256]; for (int i = 0; i < l_this->m_pMRU->NumItems(); i++) { l_this->m_pMRU->GetItem(i, valname, 255); int pos = SendMessage(hcombo, CB_ADDSTRING, 0, (LPARAM) valname); } SendMessage(hcombo, CB_SETCURSEL, 0, 0); // sf@2002 - List available DSM Plugins HWND hPlugins = GetDlgItem(hwnd, IDC_PLUGINS_COMBO); int nPlugins = l_this->m_pDSMPlugin->ListPlugins(hPlugins); if (!nPlugins) { SendMessage(hPlugins, CB_ADDSTRING, 0, (LPARAM) sz_F11); } else { // Use the first detected plugin, so the user doesn't have to check the option // HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK); // SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0); } SendMessage(hPlugins, CB_SETCURSEL, 0, 0); HWND hButton = GetDlgItem(hwnd, IDC_PLUGIN_BUTTON); EnableWindow(hButton, FALSE); // sf@2009 - Disable plugin config button by default //AaronP if( strcmp( l_this->m_pOpt->m_szDSMPluginFilename, "" ) != 0 && l_this->m_pOpt->m_fUseDSMPlugin ) { int pos = SendMessage(hPlugins, CB_FINDSTRINGEXACT, -1, (LPARAM)&(l_this->m_pOpt->m_szDSMPluginFilename[0])); if( pos != CB_ERR ) { SendMessage(hPlugins, CB_SETCURSEL, pos, 0); HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK); SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0); EnableWindow(hButton, TRUE); // sf@2009 - Enable plugin config button } } //EndAaronP TCHAR tmphost[256]; TCHAR tmphost2[256]; _tcscpy(tmphost, l_this->m_pOpt->m_proxyhost); if (strcmp(tmphost,"")!=NULL) { _tcscat(tmphost,":"); _tcscat(tmphost,_itoa(l_this->m_pOpt->m_proxyport,tmphost2,10)); SetDlgItemText(hwnd, IDC_PROXY_EDIT, tmphost); } HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK); SendMessage(hViewOnly, BM_SETCHECK, l_this->m_pOpt->m_ViewOnly, 0); HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK); SendMessage(hAutoScaling, BM_SETCHECK, l_this->m_pOpt->m_fAutoScaling, 0); HWND hExitCheck = GetDlgItem(hwnd, IDC_EXIT_CHECK); //PGM @ Advantig SendMessage(hExitCheck, BM_SETCHECK, l_this->m_pOpt->m_fExitCheck, 0); //PGM @ Advantig HWND hProxy = GetDlgItem(hwnd, IDC_PROXY_CHECK); SendMessage(hProxy, BM_SETCHECK, l_this->m_pOpt->m_fUseProxy, 0); // sf@2005 - Make the save settings optional but always enabled by default (for now) // (maybe disabled as default is better ?) HWND hSave = GetDlgItem(hwnd, IDC_SETDEFAULT_CHECK); //ACT SendMessage(hSave, BM_SETCHECK, true, 0); // sf@2002 - Select Modem Option as default l_this->SetQuickOption(l_this, hwnd); l_this->m_fFromOptions = false; l_this->m_fFromFile = false; return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_DELETE: { char optionfile[MAX_PATH]; VNCOptions::GetDefaultOptionsFileName(optionfile); DeleteFile(optionfile); } return TRUE; case IDOK: { TCHAR tmphost[256]; TCHAR display[256]; TCHAR fulldisplay[256]; // sf@2005 HWND hSave = GetDlgItem(hwnd, IDC_SETDEFAULT_CHECK); _this->m_pCC->saved_set = SendMessage(hSave, BM_GETCHECK, 0, 0) == BST_CHECKED; GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, display, 256); _tcscpy(fulldisplay, display); if (!ParseDisplay(display, tmphost, 255, &_this->m_port)) { MessageBox(hwnd, sz_F8, sz_F10, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST); } else { for (size_t i = 0, len = strlen(tmphost); i < len; i++) { tmphost[i] = toupper(tmphost[i]); } _tcscpy(_this->m_host_dialog, tmphost); _this->m_pMRU->AddItem(fulldisplay); // _tcscpy(_this->m_remotehost, fulldisplay); EndDialog(hwnd, TRUE); } GetDlgItemText(hwnd, IDC_PROXY_EDIT, display, 256); _tcscpy(fulldisplay, display); if (!ParseDisplay(display, tmphost, 255, &_this->m_proxyport)) { MessageBox(hwnd, sz_F8, sz_F10, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST); } else { _tcscpy(_this->m_proxyhost, tmphost); EndDialog(hwnd, TRUE); } HWND hProxy = GetDlgItem(hwnd, IDC_PROXY_CHECK); if (SendMessage(hProxy, BM_GETCHECK, 0, 0) == BST_CHECKED) { _this->m_pOpt->m_fUseProxy = true; _this->m_fUseProxy = true; } else { _this->m_pOpt->m_fUseProxy = false; _this->m_fUseProxy = false; } // sf@2002 - DSMPlugin loading // If Use plugin is checked, load the plugin if necessary HWND hPlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK); if (SendMessage(hPlugin, BM_GETCHECK, 0, 0) == BST_CHECKED) { TCHAR szPlugin[MAX_PATH]; GetDlgItemText(hwnd, IDC_PLUGINS_COMBO, szPlugin, MAX_PATH); _this->m_pOpt->m_fUseDSMPlugin = true; strcpy(_this->m_pOpt->m_szDSMPluginFilename, szPlugin); if (!_this->m_pDSMPlugin->IsLoaded()) { _this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening); if (_this->m_pDSMPlugin->IsLoaded()) { if (_this->m_pDSMPlugin->InitPlugin()) { _this->m_pDSMPlugin->SetEnabled(true); _this->m_pDSMPlugin->DescribePlugin(); } else { _this->m_pDSMPlugin->SetEnabled(false); MessageBox(hwnd, sz_F7, sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST); return TRUE; } } else { _this->m_pDSMPlugin->SetEnabled(false); MessageBox(hwnd, sz_F5, sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST); return TRUE; } } else { // sf@2003 - If the plugin is already loaded here it has been loaded // by clicking on the config button: we need to init it ! // But we must first check that the loaded plugin is the same that // the one currently selected... _this->m_pDSMPlugin->DescribePlugin(); if (_stricmp(_this->m_pDSMPlugin->GetPluginFileName(), szPlugin)) { // Unload the previous plugin _this->m_pDSMPlugin->UnloadPlugin(); // Load the new selected one _this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening); } if (_this->m_pDSMPlugin->IsLoaded()) { if (_this->m_pDSMPlugin->InitPlugin()) { _this->m_pDSMPlugin->SetEnabled(true); _this->m_pDSMPlugin->DescribePlugin(); } else { _this->m_pDSMPlugin->SetEnabled(false); MessageBox(hwnd, sz_F7, sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST); return TRUE; } } else { _this->m_pDSMPlugin->SetEnabled(false); MessageBox(hwnd, sz_F5, sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST); return TRUE; } } } else // If Use plugin unchecked but the plugin is loaded, unload it { _this->m_pOpt->m_fUseDSMPlugin = false; if (_this->m_pDSMPlugin->IsEnabled()) { _this->m_pDSMPlugin->UnloadPlugin(); _this->m_pDSMPlugin->SetEnabled(false); } } if (_this->m_fFromOptions || _this->m_fFromFile) { EndDialog(hwnd, TRUE); return TRUE; } // sf@2002 - Quick options handling _this->ManageQuickOptions(_this, hwnd); HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK); _this->m_pOpt->m_ViewOnly = (SendMessage(hViewOnly, BM_GETCHECK, 0, 0) == BST_CHECKED); HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK); _this->m_pOpt->m_fAutoScaling = (SendMessage(hAutoScaling, BM_GETCHECK, 0, 0) == BST_CHECKED); HWND hExitCheck = GetDlgItem(hwnd, IDC_EXIT_CHECK); //PGM @ Advantig _this->m_pOpt->m_fExitCheck = (SendMessage(hExitCheck, BM_GETCHECK, 0, 0) == BST_CHECKED); //PGM @ Advantig EndDialog(hwnd, TRUE); return TRUE; } case IDCANCEL: EndDialog(hwnd, FALSE); return TRUE; case IDC_OPTIONBUTTON: { if (!_this->m_fFromFile) { _this->ManageQuickOptions(_this, hwnd); HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK); _this->m_pOpt->m_ViewOnly = (SendMessage(hViewOnly, BM_GETCHECK, 0, 0) == BST_CHECKED); HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK); _this->m_pOpt->m_fAutoScaling = (SendMessage(hAutoScaling, BM_GETCHECK, 0, 0) == BST_CHECKED); HWND hExitCheck = GetDlgItem(hwnd, IDC_EXIT_CHECK); //PGM @ Advantig _this->m_pOpt->m_fExitCheck = (SendMessage(hExitCheck, BM_GETCHECK, 0, 0) == BST_CHECKED); //PGM @ Advantig } if (_this->m_pOpt->DoDialog()) { _this->m_fFromOptions = true; HWND hDyn = GetDlgItem(hwnd, IDC_DYNAMIC); SendMessage(hDyn, BM_SETCHECK, false, 0); HWND hLan = GetDlgItem(hwnd, IDC_LAN_RB); SendMessage(hLan, BM_SETCHECK, false, 0); HWND hUltraLan = GetDlgItem(hwnd, IDC_ULTRA_LAN_RB); SendMessage(hUltraLan, BM_SETCHECK, false, 0); HWND hMedium = GetDlgItem(hwnd, IDC_MEDIUM_RB); SendMessage(hMedium, BM_SETCHECK, false, 0); HWND hModem = GetDlgItem(hwnd, IDC_MODEM_RB); SendMessage(hModem, BM_SETCHECK, false, 0); HWND hSlow = GetDlgItem(hwnd, IDC_SLOW_RB); SendMessage(hSlow, BM_SETCHECK, false, 0); HWND hManual = GetDlgItem(hwnd, IDC_MANUAL); SendMessage(hManual, BM_SETCHECK, true, 0); _this->m_pOpt->m_quickoption = 8; } return TRUE; } // sf@2002 case IDC_PLUGIN_CHECK: { HWND hUse = GetDlgItem(hwnd, IDC_PLUGIN_CHECK); BOOL enable = SendMessage(hUse, BM_GETCHECK, 0, 0) == BST_CHECKED; HWND hButton = GetDlgItem(hwnd, IDC_PLUGIN_BUTTON); EnableWindow(hButton, enable); } return TRUE; case IDC_PLUGIN_BUTTON: { HWND hPlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK); if (SendMessage(hPlugin, BM_GETCHECK, 0, 0) == BST_CHECKED) { TCHAR szPlugin[MAX_PATH]; GetDlgItemText(hwnd, IDC_PLUGINS_COMBO, szPlugin, MAX_PATH); // sf@2003 - The config button can be clicked several times with // different selected plugins... bool fLoadIt = true; char szParams[64]; strcpy(szParams, sz_F4); // If a plugin is already loaded, check if it is the same that the one // we want to load. if (_this->m_pDSMPlugin->IsLoaded()) { _this->m_pDSMPlugin->DescribePlugin(); if (!_stricmp(_this->m_pDSMPlugin->GetPluginFileName(), szPlugin)) { fLoadIt = false; _this->m_pDSMPlugin->SetPluginParams(hwnd, szParams); } else { // Unload the previous plugin _this->m_pDSMPlugin->UnloadPlugin(); fLoadIt = true; } } if (!fLoadIt) return TRUE; if (_this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening)) { // We don't know the password yet... no matter the plugin requires // it or not, we will provide it later (at plugin "real" startup) // Knowing the environnement ("viewer") right now can be usefull or // even mandatory for the plugin (specific params saving and so on...) // The plugin receives environnement info but isn't inited at this point _this->m_pDSMPlugin->SetPluginParams(hwnd, szParams); } else { MessageBox(hwnd, sz_F1, sz_F3, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST); } } return TRUE; } case IDC_LOADPROFILE_B: { TCHAR szFileName[MAX_PATH]; memset(szFileName, '\0', MAX_PATH); if (_this->m_pCC->LoadConnection(szFileName, true) != -1) { TCHAR szHost[250]; if (_this->m_pCC->m_port == 5900) _tcscpy(szHost, _this->m_pCC->m_host); else if (_this->m_pCC->m_port > 5900 && _this->m_pCC->m_port <= 5999) _stprintf(szHost, TEXT("%s:%d"), _this->m_pCC->m_host, _this->m_pCC->m_port - 5900); else _stprintf(szHost, TEXT("%s::%d"), _this->m_pCC->m_host, _this->m_pCC->m_port); SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, szHost); //AaronP HWND hPlugins = GetDlgItem(hwnd, IDC_PLUGINS_COMBO); if( strcmp( _this->m_pOpt->m_szDSMPluginFilename, "" ) != 0 && _this->m_pOpt->m_fUseDSMPlugin ) { int pos = SendMessage(hPlugins, CB_FINDSTRINGEXACT, -1, (LPARAM)&(_this->m_pOpt->m_szDSMPluginFilename[0])); if( pos != CB_ERR ) { SendMessage(hPlugins, CB_SETCURSEL, pos, 0); HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK); SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0); } } //EndAaronP } SetFocus(GetDlgItem(hwnd, IDC_HOSTNAME_EDIT)); _this->SetQuickOption(_this, hwnd); HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK); SendMessage(hViewOnly, BM_SETCHECK, _this->m_pOpt->m_ViewOnly, 0); HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK); SendMessage(hAutoScaling, BM_SETCHECK, _this->m_pOpt->m_fAutoScaling, 0); HWND hExitCheck = GetDlgItem(hwnd, IDC_EXIT_CHECK); //PGM @ Advantig SendMessage(hExitCheck, BM_SETCHECK, _this->m_pOpt->m_fExitCheck, 0); //PGM @ Advantig _this->m_fFromOptions = true; _this->m_fFromFile = true; return TRUE; } // [v1.0.2-jp1 fix] case IDC_HOSTNAME_DEL: HWND hcombo = GetDlgItem( hwnd, IDC_HOSTNAME_EDIT); int sel = SendMessage(hcombo, CB_GETCURSEL, 0, 0); if(sel != CB_ERR){ SendMessage(hcombo, CB_DELETESTRING, sel, 0); _this->m_pMRU->RemoveItem(sel); } return TRUE; } break; case WM_DESTROY: EndDialog(hwnd, FALSE); return TRUE; } return 0; }
/*This is the WinMain function. Here we will create the rendering window, initialize OpenGL ES, write the message loop, and, at the end, clean all and release all used resources*/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; //This is the message variable for the message loop WNDCLASS wc; /*This structure will hold some init values for our window*/ hInst = hInstance; // Initialization of our global variable bool done = FALSE; /*This block of code is to ensure that the user only can run one instance of the application. First we search for a window with the same class name, if found, we will focus it and return*/ if(hWnd = FindWindow(szAppName, szAppName)) { /* Set focus to foremost child window. The "| 0x01" is used to bring any owned windows to the foreground and activate them.*/ SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001)); return 0; } wc.style = CS_HREDRAW | CS_VREDRAW; /*Will force a redraw if the window is resized, both horizontally or vertically*/ wc.lpfnWndProc = (WNDPROC) WndProc; /*this is a function pointer, to tell the OS what function should call when a message needs to be processed*/ wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, NULL);//Load default icon wc.hCursor = 0; // Default cursor wc.hbrBackground = 0; //We don't care about the background color wc.lpszMenuName = NULL; //This application does not have a menu wc.lpszClassName = szAppName; /*Important, here we must fill the application class name (the class name is not the same than the caption of the window, but many times they are the same)*/ //Before creating the window, we must register this new window class if(!RegisterClass(&wc)) return FALSE; hWnd=CreateWindow(szAppName, //Class Name szAppName, //Caption string WS_VISIBLE,//Window style CW_USEDEFAULT,CW_USEDEFAULT,//Starting [x,y] pos. CW_USEDEFAULT, CW_USEDEFAULT, //Width and height NULL, NULL, //Parent window and menu handle hInst, NULL); /*Instance handle. Custom value to pass in the creation with the WM_CREATE message*/ if(!hWnd) return FALSE; if(!InitOGLES()) return FALSE; //OpenGL ES Initialization //Bring the window to front, focus it and refresh it ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); //Message Loop while(!done) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message==WM_QUIT) done=TRUE; else { TranslateMessage(&msg); DispatchMessage(&msg); } } else Render(); } //Clean up all Clean(); return 0; }
bool Engine::InitializeScreen() { /** Register the window's class.*/ WNDCLASSEXW wc = { sizeof(WNDCLASSEXW), CS_CLASSDC, WndProc, 0, 0, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, mWindowClassName, NULL }; RegisterClassExW(&wc); /** Calculate the window's position and size.*/ DWORD exstyle = 0; int x = 0, y = 0; int width = mSetting.resolutionX, height = mSetting.resolutionY; if (mSetting.fullScreen) { exstyle = WS_EX_TOPMOST; x = y = 0; width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); } else { RECT windowRect = {0, 0, width, height}; AdjustWindowRect( &windowRect, WS_OVERLAPPEDWINDOW, FALSE); width = windowRect.right - windowRect.left; height = windowRect.bottom - windowRect.top; int screenx = GetSystemMetrics(SM_CXSCREEN); int screeny = GetSystemMetrics(SM_CYSCREEN); x = (screenx - width) / 2; y = (screeny - height) / 2; } /** Create a new visible window.*/ HWND hWnd = CreateWindowExW( exstyle, mWindowClassName, mWindowTitle, WS_POPUP, x, y, width, height, GetDesktopWindow(), NULL, GetModuleHandle(NULL), NULL ); assert(NULL != hWnd); mSetting.resolutionX = width; mSetting.resolutionY = height; ShowWindow(hWnd, SW_SHOWNORMAL); /** Fill window with black color.*/ HDC hdc = GetDC(hWnd); RECT rect = { 0, 0, 0, 0 }; GetClientRect(hWnd, &rect); HBRUSH blackbrush = (HBRUSH)GetStockObject(BLACK_BRUSH); FillRect(hdc, &rect, blackbrush); ReleaseDC(hWnd, hdc); SetForegroundWindow(hWnd); UpdateWindow(hWnd); mScreenHandle = hWnd; return true; }
int main(int argc, char* argv[]) { HWND lHandle, lHandle2; char sText[]="%windir%\\system32\\cmd.exe"; char buffer[256]; lHandle=FindWindow(NULL, "BulletProof FTP Server v2.4.0.31"); if (!lHandle) { printf("\nUsage :\nBulletProof FTP Server v2.4.0.31 doesn't seem to run?\n"); return 0; } else { printf("handle for BulletProof : 0x%X\n",lHandle); } SetForegroundWindow(lHandle); SendMessage(lHandle, WM_IME_KEYDOWN, VK_F1, 0); //send F1 key "help me please!" Sleep(5000); //I need this time to drink a beer ;P //Find the browser Handle //lHandle2=FindWindow(NULL, "BPFTP Server - Mozilla Firefox"); //if (!lHandle2) //{ lHandle2=FindWindow("IEFrame", "BPFTP Server - Microsoft Internet Explorer"); lHandle2=FindWindowEx(NULL, NULL, "IEFrame", NULL); printf("handle for IE : 0x%X\n",lHandle2); if (!lHandle2) { printf("\nError while finding the browser's window.\n"); } //} //else //{ // printf("handle for Firefox : 0x%X\n",lHandle2); //} SetForegroundWindow(lHandle2); lHandle=FindWindowEx(lHandle2, 0, "WorkerW", 0); if (lHandle>=0) { lHandle = FindWindowEx(lHandle, 0, "ReBarWindow32", 0); if (lHandle>=0) { //Where are you Charlie... lHandle = FindWindowEx(lHandle, 0, "ComboBoxEx32", 0); lHandle = FindWindowEx(lHandle, 0, "ComboBox", 0); lHandle = FindWindowEx(lHandle, 0, "Edit", 0); } } else { printf("\nerror :-(\n"); } SendMessage(lHandle, WM_SETFOCUS, 0, 0); Sleep(300); SendMessage(lHandle, WM_SETTEXT, 0, (LPARAM) sText); //Shatter! PostMessage(lHandle, WM_KEYDOWN, VK_RETURN, 0); //whoami? :-) return 0; }
//----------------------------------------------------------------------------- // Entry point into the program. //----------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { Instance = hInstance; InitCommonControls(); // A monospaced font FixedFont = CreateFont(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console"); if(!FixedFont) FixedFont = (HFONT)GetStockObject(SYSTEM_FONT); // Create the root windows: one for control, with text, and one for // the graphics CreateMainWindows(); ThawWindowPos(TextWnd); ThawWindowPos(GraphicsWnd); ShowWindow(TextWnd, SW_SHOWNOACTIVATE); ShowWindow(GraphicsWnd, SW_SHOW); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(GetDC(GraphicsWnd)); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(GetDC(GraphicsWnd)); // Create the heaps for all dynamic memory (AllocTemporary, MemAlloc) InitHeaps(); // A filename may have been specified on the command line; if so, then // strip any quotation marks, and make it absolute. char file[MAX_PATH] = ""; if(strlen(lpCmdLine)+1 < MAX_PATH) { char *s = lpCmdLine; while(*s == ' ' || *s == '"') s++; strcpy(file, s); s = strrchr(file, '"'); if(s) *s = '\0'; } if(*file != '\0') { GetAbsoluteFilename(file); } // Initialize the SpaceBall, if present. Test if the driver is running // first, to avoid a long timeout if it's not. HWND swdc = FindWindow("SpaceWare Driver Class", NULL); if(swdc != NULL) { SiOpenData sod; SiInitialize(); SiOpenWinInit(&sod, GraphicsWnd); SpaceNavigator = SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod); SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS); } // Call in to the platform-independent code, and let them do their init SS.Init(file); // And now it's the message loop. All calls in to the rest of the code // will be from the wndprocs. MSG msg; DWORD ret; while(ret = GetMessage(&msg, NULL, 0, 0)) { // Is it a message from the six degree of freedom input device? if(ProcessSpaceNavigatorMsg(&msg)) goto done; // A message from the keyboard, which should be processed as a keyboard // accelerator? if(msg.message == WM_KEYDOWN) { if(ProcessKeyDown(msg.wParam)) goto done; } if(msg.message == WM_SYSKEYDOWN && msg.hwnd == TextWnd) { // If the user presses the Alt key when the text window has focus, // then that should probably go to the graphics window instead. SetForegroundWindow(GraphicsWnd); } // None of the above; so just a normal message to process. TranslateMessage(&msg); DispatchMessage(&msg); done: SS.DoLater(); } if(swdc != NULL) { if(SpaceNavigator != SI_NO_HANDLE) SiClose(SpaceNavigator); SiTerminate(); } // Write everything back to the registry FreezeWindowPos(TextWnd); FreezeWindowPos(GraphicsWnd); return 0; }
BOOL CALLBACK DlgProcParentWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { DWORD ws; struct ParentWindowData *dat; dat = (struct ParentWindowData *) GetWindowLong(hwndDlg, GWL_USERDATA); if (!dat && msg!=WM_INITDIALOG) return FALSE; switch (msg) { case WM_INITDIALOG: { struct NewMessageWindowLParam *newData = (struct NewMessageWindowLParam *) lParam; dat = (struct ParentWindowData *) malloc(sizeof(struct ParentWindowData)); dat->foregroundWindow = GetForegroundWindow(); dat->hContact = newData->hContact; dat->nFlash = 0; dat->nFlashMax = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_FLASHCOUNT, SRMSGDEFSET_FLASHCOUNT); dat->childrenCount = 0; dat->children = NULL; dat->hwnd = hwndDlg; dat->flags = g_dat->flags;// | SMF_SHOWTITLEBAR; dat->mouseLBDown = 0; dat->windowWasCascaded = 0; dat->hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0, hwndDlg, NULL, g_hInst, NULL); { int statwidths[4]; RECT rc; SendMessage(dat->hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0); GetWindowRect(dat->hwndStatus, &rc); /* statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH - SB_SENDING_WIDTH; statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH - SB_SENDING_WIDTH; //rc.right - rc.left - SB_CHAR_WIDTH; statwidths[2] = rc.right - rc.left - SB_TYPING_WIDTH; //rc.right - rc.left - SB_CHAR_WIDTH; statwidths[3] = -1; SendMessage(dat->hwndStatus, SB_SETPARTS, 4, (LPARAM) statwidths); */ statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH; statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH; statwidths[2] = -1; SendMessage(dat->hwndStatus, SB_SETPARTS, 3, (LPARAM) statwidths); } dat->hwndTabs = GetDlgItem(hwndDlg, IDC_TABS); dat->hwndActive = NULL; SetWindowLong(hwndDlg, GWL_USERDATA, (LONG) dat); if (g_dat->hIconList != NULL) { TabCtrl_SetImageList(dat->hwndTabs, g_dat->hIconList); } WindowList_Add(g_dat->hParentWindowList, hwndDlg, 0); dat->tabCtrlDat = (struct TabCtrlData *) malloc(sizeof(struct TabCtrlData)); dat->tabCtrlDat->bDragging = FALSE; SetWindowLong(dat->hwndTabs, GWL_USERDATA, (LONG) dat->tabCtrlDat); OldTabCtrlProc = (WNDPROC) SetWindowLong(dat->hwndTabs, GWL_WNDPROC, (LONG) TabCtrlProc); ws = GetWindowLong(dat->hwndTabs, GWL_STYLE) & ~(TCS_BOTTOM); if (dat->flags & SMF_TABSATBOTTOM) { ws |= TCS_BOTTOM; } SetWindowLong(dat->hwndTabs, GWL_STYLE, ws); ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION); if (dat->flags & SMF_SHOWTITLEBAR) { ws |= WS_CAPTION; SetWindowLong(hwndDlg, GWL_STYLE, ws); } else { RECT rc; SetWindowLong(hwndDlg, GWL_STYLE, ws); GetWindowRect(hwndDlg, &rc); SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING); } ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED; ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0; SetWindowLong(hwndDlg , GWL_EXSTYLE , ws); if (dat->flags & SMF_USETRANSPARENCY) { pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA); // RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); } //SetWindowPos(dat->hwndTabs, 0, 0, -10, 0, 0, SWP_NOSIZE | SWP_NOZORDER); if (!(dat->flags & SMF_SHOWSTATUSBAR)) { ShowWindow(dat->hwndStatus, SW_HIDE); } if (dat->flags & SMF_USETABS) { if (ScriverRestoreWindowPosition(hwndDlg, NULL, SRMMMOD, "", 0, SW_HIDE)) { SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE | SWP_HIDEWINDOW); } } else { int savePerContact = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT); if (ScriverRestoreWindowPosition(hwndDlg, savePerContact ? dat->hContact : NULL, SRMMMOD, "", 0, SW_HIDE)) { //if (Utils_RestoreWindowPosition(GetParent(hwndDlg), savePerContact ? dat->hContact : NULL, SRMMMOD, "")) { if (savePerContact) { if (ScriverRestoreWindowPosition(hwndDlg, NULL, SRMMMOD, "", RWPF_NOSIZE, SW_HIDE)) // if (Utils_RestoreWindowPositionNoMove(GetParent(hwndDlg), NULL, SRMMMOD, "")) SetWindowPos(GetParent(hwndDlg), 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE); } else SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE); } if (!savePerContact && DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_CASCADE, SRMSGDEFSET_CASCADE)) WindowList_Broadcast(g_dat->hParentWindowList, DM_CASCADENEWWINDOW, (WPARAM) hwndDlg, (LPARAM) & dat->windowWasCascaded); } } return TRUE; case WM_GETMINMAXINFO: { MINMAXINFO *mmi = (MINMAXINFO *) lParam; SIZE size; if (GetKeyState(VK_CONTROL) & 0x8000) { WINDOWPLACEMENT wp; RECT rcDesktop; wp.length = sizeof(wp); GetWindowPlacement(hwndDlg, &wp); SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0); mmi->ptMaxSize.x = wp.rcNormalPosition.right - wp.rcNormalPosition.left; mmi->ptMaxSize.y = rcDesktop.bottom - rcDesktop.top; mmi->ptMaxPosition.x = wp.rcNormalPosition.left; if(IsIconic(hwndDlg)) { mmi->ptMaxPosition.y = rcDesktop.top; } else { mmi->ptMaxPosition.y = 0; } } GetMinimunWindowSize(dat, &size); mmi->ptMinTrackSize.x = size.cx; mmi->ptMinTrackSize.y = size.cy; return FALSE; } case WM_SIZE: if (wParam == SIZE_MINIMIZED) { dat->bMinimized = 1; } if (IsIconic(hwndDlg)) { MoveWindow(dat->hwndActive, dat->childRect.left, dat->childRect.top, dat->childRect.right-dat->childRect.left, dat->childRect.bottom - dat->childRect.top, TRUE); } else { // } // if (!IsIconic(hwndDlg)) { int i; RECT rc, rcStatus, rcChild, rcWindow; SIZE size; dat->bMinimized = 0; GetClientRect(hwndDlg, &rc); GetWindowRect(hwndDlg, &rcWindow); rcStatus.top = rcStatus.bottom = 0; if (dat->flags & SMF_SHOWSTATUSBAR) { int statwidths[4]; GetWindowRect(dat->hwndStatus, &rcStatus); statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH; statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH; statwidths[2] = -1; SendMessage(dat->hwndStatus, SB_SETPARTS, 3, (LPARAM) statwidths); SendMessage(dat->hwndStatus, WM_SIZE, 0, 0); } MoveWindow(dat->hwndTabs, 0, 2, (rc.right - rc.left), (rc.bottom - rc.top) - (rcStatus.bottom - rcStatus.top) - 2, FALSE); RedrawWindow(dat->hwndTabs, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE); GetMinimunWindowSize(dat, &size); if ((rcWindow.bottom-rcWindow.top) < size.cy || (rcWindow.right-rcWindow.left) < size.cx) { if ((rcWindow.bottom-rcWindow.top) < size.cy) { rcWindow.bottom = rcWindow.top + size.cy; } if ((rcWindow.right-rcWindow.left) < size.cx) { rcWindow.right = rcWindow.left + size.cx; } MoveWindow(hwndDlg, rcWindow.left, rcWindow.top, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, TRUE); } GetChildWindowRect(dat, &rcChild); memcpy(&dat->childRect, &rcChild, sizeof(RECT)); for (i=0;i<dat->childrenCount;i++) { if (dat->children[i] == dat->hwndActive) { MoveWindow(dat->children[i], rcChild.left, rcChild.top, rcChild.right-rcChild.left, rcChild.bottom - rcChild.top, TRUE); RedrawWindow(GetDlgItem(dat->children[i], IDC_LOG), NULL, NULL, RDW_INVALIDATE); } } if (dat->flags & SMF_SHOWSTATUSBAR) { RedrawWindow(dat->hwndStatus, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE); } } return FALSE; case WM_SETFOCUS: if (dat->hwndActive != NULL) { SetFocus(dat->hwndActive); } return TRUE; case WM_CLOSE: DestroyWindow(hwndDlg); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: //DestroyWindow(hwndDlg); return TRUE; } case WM_NOTIFY: { NMHDR* pNMHDR = (NMHDR*) lParam; if (pNMHDR->hwndFrom == dat->hwndTabs) { switch (pNMHDR->code) { case TCN_SELCHANGE: { TCITEM tci = {0}; int iSel = TabCtrl_GetCurSel(dat->hwndTabs); tci.mask = TCIF_PARAM; if (TabCtrl_GetItem(dat->hwndTabs, iSel, &tci)) { struct MessageWindowData * mdat = (struct MessageWindowData *) tci.lParam; ActivateChild(dat, mdat->hwnd); SetFocus(dat->hwndActive); } } break; case NM_RCLICK: { TCHITTESTINFO thinfo; int tabId, x, y; GetCursorPos(&thinfo.pt); x = thinfo.pt.x; y = thinfo.pt.y; ScreenToClient(dat->hwndTabs, &thinfo.pt); tabId = TabCtrl_HitTest(dat->hwndTabs, &thinfo); if (tabId != -1) { struct MessageWindowData * mwd = GetChildFromTab(dat->hwndTabs, tabId); //CallService(MS_USERINFO_SHOWDIALOG, (WPARAM) mwd->hContact, 0); HMENU hMenu = (HMENU) CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM) mwd->hContact, 0); TrackPopupMenu(hMenu, 0, x, y, 0, mwd->hwnd, NULL); DestroyMenu(hMenu); } } break; } } else if (pNMHDR->hwndFrom == dat->hwndStatus) { switch (pNMHDR->code) { case NM_CLICK: { NMMOUSE *nm=(NMMOUSE*)lParam; RECT rc; SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc); if (nm->pt.x >= rc.left) SendMessage(dat->hwndActive, DM_SWITCHUNICODE, 0, 0); } } break; } } break; case WM_DROPFILES: SendMessage(dat->hwndActive, WM_DROPFILES, wParam, lParam); break; case WM_TIMER: if (wParam == TIMERID_FLASHWND) { if ((dat->nFlash > dat->nFlashMax)) {// || ((GetActiveWindow() == hwndDlg) && (GetForegroundWindow() == hwndDlg))) { KillTimer(hwndDlg, TIMERID_FLASHWND); FlashWindow(hwndDlg, FALSE); } else if (dat->nFlash < dat->nFlashMax) { FlashWindow(hwndDlg, TRUE); dat->nFlash++; } } break; case WM_CONTEXTMENU: { if (dat->hwndStatus && dat->hwndStatus == (HWND) wParam) { RECT rc; POINT pt, pt2; GetCursorPos(&pt); pt2.x = pt.x; pt2.y = pt.y; ScreenToClient(dat->hwndStatus, &pt); SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc); if (pt.x >= rc.left && dat->hwndActive != NULL) { int codePage = (int) SendMessage(dat->hwndActive, DM_GETCODEPAGE, 0, 0); int i, iSel; for(i = 0; i < GetMenuItemCount(g_dat->hMenuANSIEncoding); i++) { CheckMenuItem (g_dat->hMenuANSIEncoding, i, MF_BYPOSITION | MF_UNCHECKED); } if(codePage == CP_ACP) { CheckMenuItem(g_dat->hMenuANSIEncoding, 0, MF_BYPOSITION | MF_CHECKED); } else { CheckMenuItem(g_dat->hMenuANSIEncoding, codePage, MF_BYCOMMAND | MF_CHECKED); } iSel = TrackPopupMenu(g_dat->hMenuANSIEncoding, TPM_RETURNCMD, pt2.x, pt2.y, 0, hwndDlg, NULL); if (iSel >= 500) { if (iSel == 500) iSel = CP_ACP; SendMessage(dat->hwndActive, DM_SETCODEPAGE, 0, iSel); } } else SendMessage(dat->hwndActive, WM_CONTEXTMENU, (WPARAM)hwndDlg, 0); } break; } case WM_ACTIVATE: if (LOWORD(wParam) == WA_INACTIVE) { ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED; ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0; SetWindowLong(hwndDlg , GWL_EXSTYLE , ws); if (dat->flags & SMF_USETRANSPARENCY) { pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA); // RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); } } if (LOWORD(wParam) != WA_ACTIVE) break; if (dat->hwndActive == NULL) { // do not set foreground window at all (always stay in the background !) // SendMessage(hwndDlg, DM_DEACTIVATE, 0, 0); } else { PostMessage(hwndDlg, WM_SETFOCUS, 0, 0); } case WM_MOUSEACTIVATE: if (KillTimer(hwndDlg, TIMERID_FLASHWND)) { FlashWindow(hwndDlg, FALSE); dat->nFlash = 0; } ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED; ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0; SetWindowLong(hwndDlg , GWL_EXSTYLE , ws); if (dat->flags & SMF_USETRANSPARENCY) { pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->activeAlpha), LWA_ALPHA); // RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); } break; case WM_LBUTTONDOWN: if (!IsZoomed(hwndDlg)) { POINT pt; GetCursorPos(&pt); // dat->mouseLBDown = 1; // GetCursorPos(&dat->mouseLBDownPos); return SendMessage(hwndDlg, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, MAKELPARAM(pt.x, pt.y)); // SetCapture(hwndDlg); } break; case WM_LBUTTONUP: //if (dat->mouseLBDown) { // dat->mouseLBDown = 0; // ReleaseCapture(); //} break; case WM_MOUSEMOVE:/* if (dat->mouseLBDown) { POINT pt; RECT rc; GetCursorPos(&pt); GetWindowRect(hwndDlg, &rc); SetWindowPos(hwndDlg, 0, rc.left - (dat->mouseLBDownPos.x - pt.x), rc.top - (dat->mouseLBDownPos.y - pt.y), 0, 0, SWP_NOZORDER | SWP_NOSIZE); dat->mouseLBDownPos = pt; }*/ break; case WM_MOVING: { int snapPixels = 10; RECT rcDesktop; RECT *pRect = (RECT *)lParam; POINT pt; SIZE szSize = {pRect->right-pRect->left,pRect->bottom-pRect->top}; GetCursorPos(&pt); SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0); pRect->left = pt.x-dat->mouseLBDownPos.x; pRect->top = pt.y-dat->mouseLBDownPos.y; pRect->right = pRect->left+szSize.cx; pRect->bottom = pRect->top+szSize.cy; if (!(GetAsyncKeyState(VK_CONTROL) & 0x8000)) { if(pRect->top < snapPixels && pRect->top > -snapPixels) { pRect->top = 0; pRect->bottom = szSize.cy; } if(pRect->left < snapPixels && pRect->left > -snapPixels) { pRect->left = 0; pRect->right = szSize.cx; } if(pRect->right < rcDesktop.right+snapPixels && pRect->right > rcDesktop.right-snapPixels) { pRect->right = rcDesktop.right; pRect->left = rcDesktop.right-szSize.cx; } if(pRect->bottom < rcDesktop.bottom+snapPixels && pRect->bottom > rcDesktop.bottom-snapPixels) { pRect->bottom = rcDesktop.bottom; pRect->top = rcDesktop.bottom-szSize.cy; } } } break; case WM_SYSCOMMAND: if ((wParam & 0xFFF0) == SC_MOVE) { RECT rc; GetWindowRect(hwndDlg, &rc); dat->mouseLBDownPos.x = LOWORD(lParam) - rc.left; dat->mouseLBDownPos.y = HIWORD(lParam) - rc.top; } break; case WM_DESTROY: { g_dat->hParent = NULL; SetWindowLong(hwndDlg, GWL_USERDATA, 0); WindowList_Remove(g_dat->hParentWindowList, hwndDlg); if (dat->children!=NULL) free (dat->children); free(dat->tabCtrlDat); free(dat); if (dat->flags & SMF_USETABS) { WINDOWPLACEMENT wp = { 0 }; wp.length = sizeof(wp); GetWindowPlacement(hwndDlg, &wp); DBWriteContactSettingDword(NULL, SRMMMOD, "x", wp.rcNormalPosition.left); DBWriteContactSettingDword(NULL, SRMMMOD, "y", wp.rcNormalPosition.top); DBWriteContactSettingDword(NULL, SRMMMOD, "width", wp.rcNormalPosition.right - wp.rcNormalPosition.left); DBWriteContactSettingDword(NULL, SRMMMOD, "height", wp.rcNormalPosition.bottom - wp.rcNormalPosition.top); } else { WINDOWPLACEMENT wp = { 0 }; HANDLE hContact; if (DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT)) hContact = dat->hContact; else hContact = NULL; wp.length = sizeof(wp); GetWindowPlacement(hwndDlg, &wp); if (!dat->windowWasCascaded) { DBWriteContactSettingDword(hContact, SRMMMOD, "x", wp.rcNormalPosition.left); DBWriteContactSettingDword(hContact, SRMMMOD, "y", wp.rcNormalPosition.top); } DBWriteContactSettingDword(hContact, SRMMMOD, "width", wp.rcNormalPosition.right - wp.rcNormalPosition.left); DBWriteContactSettingDword(hContact, SRMMMOD, "height", wp.rcNormalPosition.bottom - wp.rcNormalPosition.top); } } break; case DM_DEACTIVATE: SetForegroundWindow(dat->foregroundWindow); break; case DM_ERRORDECIDED: break; case DM_STARTFLASHING: if (GetActiveWindow() != hwndDlg || GetForegroundWindow() != hwndDlg) { dat->nFlash = 0; SetTimer(hwndDlg, TIMERID_FLASHWND, TIMEOUT_FLASHWND, NULL); } break; case DM_REMOVECHILD: { RemoveChild(dat, (HWND) lParam); if (dat->childrenCount != 0) { SetFocus(dat->hwndActive); } else { DestroyWindow(hwndDlg); } } return TRUE; case DM_ADDCHILD: { struct MessageWindowData * mdat = (struct MessageWindowData *) lParam; AddChild(dat, mdat); } return TRUE; case DM_ACTIVATECHILD: if((HWND) lParam != dat->hwndActive) { ActivateChild(dat, (HWND) lParam); } return TRUE; case DM_ACTIVATEPREV: ActivatePrevChild(dat, (HWND) lParam); SetFocus(dat->hwndActive); return TRUE; case DM_ACTIVATENEXT: ActivateNextChild(dat, (HWND) lParam); SetFocus(dat->hwndActive); return TRUE; case DM_SENDMESSAGE: { int i; for (i=0;i<dat->childrenCount;i++) { SendMessage(dat->children[i], DM_SENDMESSAGE, wParam, lParam); } } break; case DM_OPTIONSAPPLIED: { RECT rc; dat->flags = g_dat->flags; if (!(dat->flags & SMF_SHOWSTATUSBAR)) { ShowWindow(dat->hwndStatus, SW_HIDE); } else { ShowWindow(dat->hwndStatus, SW_SHOW); } ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION); if (dat->flags & SMF_SHOWTITLEBAR) { ws |= WS_CAPTION; } SetWindowLong(hwndDlg, GWL_STYLE, ws); ws = GetWindowLong(hwndDlg, GWL_EXSTYLE)& ~WS_EX_LAYERED; ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0; SetWindowLong(hwndDlg , GWL_EXSTYLE , ws); if (dat->flags & SMF_USETRANSPARENCY) { pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA); // RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); } ws = GetWindowLong(dat->hwndTabs, GWL_STYLE) & ~(TCS_BOTTOM); if (dat->flags & SMF_TABSATBOTTOM) { ws |= TCS_BOTTOM; } SetWindowLong(dat->hwndTabs, GWL_STYLE, ws); RedrawWindow(dat->hwndTabs, NULL, NULL, RDW_INVALIDATE); GetWindowRect(hwndDlg, &rc); SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING); SendMessage(hwndDlg, WM_SIZE, 0, 0); //RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); break; } case DM_UPDATETITLE: { struct MessageWindowData * mdat = (struct MessageWindowData *) lParam; TCITEM tci; int tabId; TCHAR *tContactName; if (mdat && mdat->hwnd == dat->hwndActive) { TCHAR *newtitle, oldtitle[256]; #if defined ( _UNICODE ) newtitle = GetWindowTitle(mdat->hContact, mdat->szProto); #else newtitle = GetWindowTitle(mdat->hContact, mdat->szProto); #endif GetWindowText(hwndDlg, oldtitle, sizeof(oldtitle)); if (lstrcmp(newtitle, oldtitle)) { //swt() flickers even if the title hasn't actually changed SetWindowText(hwndDlg, newtitle); //SendMessage(hwndDlg, WM_SIZE, 0, 0); } free(newtitle); } tabId = GetTabFromHWND(dat, mdat->hwnd); tContactName = GetTabName(mdat->hContact); tci.mask = TCIF_TEXT; tci.pszText = tContactName; TabCtrl_SetItem(dat->hwndTabs, tabId, &tci); free(tContactName); break; } case DM_UPDATEWINICON: { struct MessageWindowData * mdat = (struct MessageWindowData *) lParam; if (mdat) { if (mdat->szProto) { int i, icoIdx = 0; WORD wStatus; char *szProto = mdat->szProto; HANDLE hContact = mdat->hContact; if (strcmp(mdat->szProto, "MetaContacts") == 0 && DBGetContactSettingByte(NULL,"CLC","Meta",0) == 0) { hContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(UINT)mdat->hContact, 0); if (hContact != NULL) { szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(UINT)hContact,0); } else { hContact = mdat->hContact; } } wStatus = DBGetContactSettingWord(hContact, szProto, "Status", ID_STATUS_OFFLINE); mdat->wStatus = wStatus; if (mdat->hwnd == dat->hwndActive) { if (DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_STATUSICON, SRMSGDEFSET_STATUSICON)) { if (mdat->showTyping && (g_dat->flags&SMF_SHOWTYPINGWIN)) { SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) g_dat->hIcons[SMF_ICON_TYPING]); } else if (mdat->showUnread && (GetActiveWindow() != hwndDlg || GetForegroundWindow() != hwndDlg)) { SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedIcon(SKINICON_EVENT_MESSAGE)); } else { SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedProtoIcon(szProto, wStatus)); } } else { SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedIcon(SKINICON_EVENT_MESSAGE)); } } SendDlgItemMessage(mdat->hwnd, IDC_USERMENU, BM_SETIMAGE, IMAGE_ICON, (LPARAM) LoadSkinnedProtoIcon(szProto, wStatus)); icoIdx = 0; for (i = 0; i < g_dat->protoNum; i++) { if (!strcmp(g_dat->protoNames[i], szProto)) { icoIdx = wStatus - ID_STATUS_OFFLINE + (ID_STATUS_OUTTOLUNCH - ID_STATUS_OFFLINE + 1) * (i +1) + 2; break; } } if (mdat->hwnd != dat->hwndActive) { if (mdat->showTyping) { icoIdx = 1; } else if (mdat->showUnread & 1) { icoIdx = 0; } } i = GetTabFromHWND(dat, mdat->hwnd); if (i>=0) { TCITEM tci; tci.mask = TCIF_IMAGE; tci.iImage = icoIdx; TabCtrl_SetItem(dat->hwndTabs, i, &tci); } } } break; } case DM_UPDATESTATUSBAR: break; case DM_SWITCHSTATUSBAR: dat->flags ^= SMF_SHOWSTATUSBAR; if (!(dat->flags & SMF_SHOWSTATUSBAR)) { ShowWindow(dat->hwndStatus, SW_HIDE); } else { ShowWindow(dat->hwndStatus, SW_SHOW); } SendMessage(hwndDlg, WM_SIZE, 0, 0); break; case DM_SWITCHTOOLBAR: { int i; dat->flags ^= SMF_SHOWBTNS; for (i=0;i<dat->childrenCount;i++) { SendMessage(dat->children[i], DM_SWITCHTOOLBAR, 0, 0); } SendMessage(hwndDlg, WM_SIZE, 0, 0); } break; case DM_SWITCHTITLEBAR: { RECT rc; dat->flags ^= SMF_SHOWTITLEBAR; ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION); if (dat->flags & SMF_SHOWTITLEBAR) { ws |= WS_CAPTION; } SetWindowLong(hwndDlg, GWL_STYLE, ws); GetWindowRect(hwndDlg, &rc); SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING); // SendMessage(hwndDlg, WM_SIZE, 0, 0); RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); } break; case DM_CASCADENEWWINDOW: if ((HWND) wParam == hwndDlg) break; { RECT rcThis, rcNew; GetWindowRect(hwndDlg, &rcThis); GetWindowRect((HWND) wParam, &rcNew); if (abs(rcThis.left - rcNew.left) < 3 && abs(rcThis.top - rcNew.top) < 3) { int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME); SetWindowPos((HWND) wParam, 0, rcNew.left + offset, rcNew.top + offset, 0, 0, SWP_NOZORDER | SWP_NOSIZE); *(int *) lParam = 1; } } break; //case DM_MESSAGESENDING: // dat->messagesInProgress += wParam ? -1 : 1; // if (dat->messagesInProgress < 0) dat->messagesInProgress = 0; // break; } return FALSE; }
void DoMessageBox(char *str, int rows, int cols, BOOL error) { EnableWindow(GraphicsWnd, FALSE); EnableWindow(TextWnd, FALSE); HWND h = GetForegroundWindow(); // Register the window class for our dialog. WNDCLASSEX wc; memset(&wc, 0, sizeof(wc)); wc.cbSize = sizeof(wc); wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC)MessageProc; wc.hInstance = Instance; wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW; wc.lpszClassName = "MessageWnd"; wc.lpszMenuName = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), IMAGE_ICON, 32, 32, 0); wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000), IMAGE_ICON, 16, 16, 0); RegisterClassEx(&wc); // Create the window. MessageString = str; RECT r; GetWindowRect(GraphicsWnd, &r); char *title = error ? "SolveSpace - Error" : "SolveSpace - Message"; int width = cols*SS.TW.CHAR_WIDTH + 20, height = rows*SS.TW.LINE_HEIGHT + 60; MessageWnd = CreateWindowClient(0, "MessageWnd", title, WS_OVERLAPPED | WS_SYSMENU, r.left + 100, r.top + 100, width, height, NULL, NULL, Instance, NULL); OkButton = CreateWindowEx(0, WC_BUTTON, "OK", WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, (width - 70)/2, rows*SS.TW.LINE_HEIGHT + 20, 70, 25, MessageWnd, NULL, Instance, NULL); SendMessage(OkButton, WM_SETFONT, (WPARAM)FixedFont, TRUE); ShowWindow(MessageWnd, TRUE); SetFocus(OkButton); MSG msg; DWORD ret; MessageDone = FALSE; while((ret = GetMessage(&msg, NULL, 0, 0)) && !MessageDone) { if((msg.message == WM_KEYDOWN && (msg.wParam == VK_RETURN || msg.wParam == VK_ESCAPE)) || (msg.message == WM_KEYUP && (msg.wParam == VK_SPACE))) { MessageDone = TRUE; break; } TranslateMessage(&msg); DispatchMessage(&msg); } MessageString = NULL; EnableWindow(TextWnd, TRUE); EnableWindow(GraphicsWnd, TRUE); SetForegroundWindow(GraphicsWnd); DestroyWindow(MessageWnd); }
BOOL player_impl::full_screen(BOOL fullscreen) { HWND hparent = GetParent(m_hwnd); // 不支持非顶层窗口全屏操作. if (IsWindow(hparent)) return FALSE; // Save the current windows placement/placement to // restore when fullscreen is over WINDOWPLACEMENT window_placement; window_placement.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(m_hwnd, &window_placement); if (fullscreen && !m_full_screen) { m_full_screen = true; m_wnd_style = GetWindowLong(m_hwnd, GWL_STYLE); printf("entering fullscreen mode.\n"); SetWindowLong(m_hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_VISIBLE); if (IsWindow(hparent)) { // Retrieve current window position so fullscreen will happen // on the right screen HMONITOR hmon = MonitorFromWindow(hparent, MONITOR_DEFAULTTONEAREST); MONITORINFO mi; mi.cbSize = sizeof(MONITORINFO); if (::GetMonitorInfo(hmon, &mi)) ::SetWindowPos(m_hwnd, 0, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOZORDER | SWP_FRAMECHANGED); } else { // Maximize non embedded window ShowWindow(m_hwnd, SW_SHOWMAXIMIZED); } if (IsWindow(hparent)) { // Hide the previous window RECT rect; GetClientRect(m_hwnd, &rect); // SetParent(hwnd, hwnd); SetWindowPos(m_hwnd, 0, 0, 0, rect.right, rect.bottom, SWP_NOZORDER|SWP_FRAMECHANGED); HWND topLevelParent = GetAncestor(hparent, GA_ROOT); ShowWindow(topLevelParent, SW_HIDE); } SetForegroundWindow(m_hwnd); return TRUE; } if (!fullscreen && m_full_screen) { m_full_screen = FALSE; printf("leaving fullscreen mode.\n"); // Change window style, no borders and no title bar SetWindowLong(m_hwnd, GWL_STYLE, m_wnd_style); if (hparent) { RECT rect; GetClientRect(hparent, &rect); // SetParent(hwnd, hparent); SetWindowPos(m_hwnd, 0, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_FRAMECHANGED); HWND topLevelParent = GetAncestor(hparent, GA_ROOT); ShowWindow(topLevelParent, SW_SHOW); SetForegroundWindow(hparent); ShowWindow(m_hwnd, SW_HIDE); } else { // return to normal window for non embedded vout SetWindowPlacement(m_hwnd, &window_placement); ShowWindow(m_hwnd, SW_SHOWNORMAL); } return TRUE; } return FALSE; }
/** * Erstellt das Fenster mit entsprechenden Werten. * * @param[in] width Breite des Fensters * @param[in] height Höhe des Fensters * @param[in] fullscreen Vollbildmodus ja oder nein * * @return @p true bei Erfolg, @p false bei Fehler * * @bug Hardwarecursor ist bei Fenstermodus sichtbar, * Cursor deaktivieren ist fehlerhaft * * @author FloSoft */ bool VideoWinAPI::CreateScreen(unsigned short width, unsigned short height, const bool fullscreen) { char title[512]; if(!initialized) return false; LPWSTR wTitle; AnsiToUtf8(wTitle, GetWindowTitle()); WNDCLASSW wc; wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetModuleHandle(NULL); wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SYMBOL)); wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = wTitle; // Fensterklasse registrieren if (!RegisterClassW(&wc)) return false; DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; DWORD dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX; if(fullscreen) { dwExStyle = WS_EX_APPWINDOW; dwStyle = WS_POPUP; EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &dm_prev); } else { // Bei Fensteranwendung die Breiten und Hoehen der Fensterrahmen, Titelleiste draufaddieren width += 2 * GetSystemMetrics(SM_CXFIXEDFRAME); height += 2 * GetSystemMetrics(SM_CXFIXEDFRAME) + GetSystemMetrics(SM_CYCAPTION); } // Fenster erstellen screen = CreateWindowExW(dwExStyle, wTitle, wTitle, dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, GetModuleHandle(NULL), NULL); delete[] wTitle; if(screen == NULL) return false; SetClipboardViewer(screen); sprintf(title, "%s - v%s-%s", GetWindowTitle(), GetWindowVersion(), GetWindowRevisionShort()); AnsiToUtf8(wTitle, title); SetWindowTextW(screen, wTitle); SetWindowTextW(GetConsoleWindow(), wTitle); delete[] wTitle; // Pixelformat zuweisen GLuint PixelFormat; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 8, // 8 Bit 8, // red 0, 8, // green 0, 8, // blue 0, 8, // alpha 0, 0, 0, 0, 0, 0, 32, // 32 Bit 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; screen_dc = GetDC(screen); if(screen_dc == NULL) return false; // Pixelformat auswaehlen PixelFormat = ChoosePixelFormat(screen_dc, &pfd); if(PixelFormat == 0) return false; // Pixelformat zuweisen if(!SetPixelFormat(screen_dc, PixelFormat, &pfd)) return false; // Renderingkontext erstellen screen_rc = wglCreateContext(screen_dc); if(screen_rc == NULL) return false; // Renderingkontext aktivieren if(!wglMakeCurrent(screen_dc, screen_rc)) return false; // Mauscursor ausblenden ShowCursor(FALSE); // Bei Fullscreen Aufloesung umstellen if(fullscreen) { // Aktuelle Framerate holen und die spaeter dann benutzen DEVMODE prev; EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &prev); DEVMODE dm; memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); dm.dmFields = DM_DISPLAYFREQUENCY | DM_PELSWIDTH | DM_PELSHEIGHT; dm.dmDisplayFrequency = prev.dmDisplayFrequency; dm.dmPelsWidth = width; dm.dmPelsHeight = height; ChangeDisplaySettings(&dm, CDS_FULLSCREEN); } this->screenWidth = width; this->screenHeight = height; this->fullscreen = fullscreen; // Das Fenster anzeigen ShowWindow(screen, SW_SHOW); // Das Fenster in den Vordergrund rcken SetForegroundWindow(screen); // Dem Fenster den Eingabefokus geben SetFocus(screen); return true; }
BOOL CALLBACK Main_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp) { static UINT msgCheckTerminate = 0; if (msgCheckTerminate == 0) msgCheckTerminate = RegisterWindowMessage (TEXT("AfsCredsCheckTerminate")); if (msg == msgCheckTerminate) { Main_OnCheckTerminate(); } else switch (msg) { case WM_INITDIALOG: g.hMain = hDlg; Main_OnInitDialog (hDlg); break; case WM_DESTROY: Creds_CloseLibraries(); ChangeTrayIcon (NIM_DELETE); break; case WM_ACTIVATEAPP: if (wp) { Main_RepopulateTabs (FALSE); } break; case WM_COMMAND: switch (LOWORD(wp)) { case IDOK: case IDCANCEL: Main_Show (FALSE); break; case M_ACTIVATE: if (g.fIsWinNT || IsServiceRunning()) { if (!lp) // Got here from "/show" parameter? switch tabs. { HWND hTab = GetDlgItem (g.hMain, IDC_TABS); TabCtrl_SetCurSel (hTab, 0); Main_OnSelectTab(); } Main_Show (TRUE); } else { Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95); } break; case M_TERMINATE: if (g.fIsWinNT && IsServiceRunning()) ModalDialog (IDD_TERMINATE, NULL, (DLGPROC)Terminate_DlgProc); else if (g.fIsWinNT) ModalDialog (IDD_TERMINATE_SMALL, NULL, (DLGPROC)Terminate_DlgProc); else // (!g.fIsWinNT) ModalDialog (IDD_TERMINATE_SMALL_95, NULL, (DLGPROC)Terminate_DlgProc); break; case M_TERMINATE_NOW: Quit(); break; case M_REMIND: Main_OnCheckMenuRemind(); break; } break; case WM_TIMER: Main_OnRemindTimer(); break; case WM_NOTIFY: switch (((NMHDR*)lp)->code) { case TCN_SELCHANGE: Main_OnSelectTab(); break; } break; case WM_TRAYICON: switch (lp) { case WM_LBUTTONDOWN: if (IsServiceRunning() || !IsServiceConfigured()) Main_Show (TRUE); else if (!g.fIsWinNT) Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95); else ShowStartupWizard(); break; case WM_RBUTTONDOWN: HMENU hm; if ((hm = TaLocale_LoadMenu (MENU_TRAYICON)) != 0) { POINT pt; GetCursorPos(&pt); HMENU hmDummy = CreateMenu(); InsertMenu (hmDummy, 0, MF_POPUP, (UINT)hm, NULL); BOOL fRemind = FALSE; lock_ObtainMutex(&g.credsLock); for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (g.aCreds[ iCreds ].fRemind) fRemind = TRUE; } lock_ReleaseMutex(&g.credsLock); CheckMenuItem (hm, M_REMIND, MF_BYCOMMAND | ((fRemind) ? MF_CHECKED : MF_UNCHECKED)); SetForegroundWindow(hDlg); TrackPopupMenu (GetSubMenu (hmDummy, 0), TPM_RIGHTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, NULL, hDlg, NULL); PostMessage(hDlg, WM_NULL, 0, 0); DestroyMenu (hmDummy); } break; case WM_MOUSEMOVE: Main_OnMouseOver(); break; } break; case WM_OBTAIN_TOKENS: if ( InterlockedIncrement (&g.fShowingMessage) != 1 ) InterlockedDecrement (&g.fShowingMessage); else ShowObtainCreds (wp, (char *)lp); GlobalFree((void *)lp); break; case WM_START_SERVICE: { SC_HANDLE hManager; if ((hManager = OpenSCManager ( NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS)) != NULL) { SC_HANDLE hService; if ((hService = OpenService ( hManager, TEXT("TransarcAFSDaemon"), SERVICE_QUERY_STATUS | SERVICE_START)) != NULL) { if (StartService (hService, 0, 0)) TestAndDoMapShare(SERVICE_START_PENDING); if ( KFW_is_available() && KFW_AFS_wait_for_service_start() ) { #ifdef USE_MS2MIT KFW_import_windows_lsa(); #endif /* USE_MS2MIT */ KFW_AFS_renew_tokens_for_all_cells(); } CloseServiceHandle (hService); } CloseServiceHandle (hManager); } if (KFW_AFS_wait_for_service_start()) ObtainTokensFromUserIfNeeded(g.hMain); } break; } return FALSE; }
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { int idc; POINT pt; PCOPYDATASTRUCT pcds; switch (msg) { case WM_COMMAND: idc = LOWORD(wParam); switch (idc) { case IDM_OPEN: SelectAndLoadFile(); break; case IDM_STOP: StopPlayback(); break; case IDM_FILE_INFO: showInfoDialog(hInst, hWnd, current_filename, current_song); break; case IDM_SAVE_WAV: SaveWav(); break; case IDM_ABOUT: ShowAbout(); break; case IDM_EXIT: PostQuitMessage(0); break; default: if (idc >= IDM_SONG1 && idc < IDM_SONG1 + songs) LoadAndPlay(idc - IDM_SONG1); break; } break; case WM_DESTROY: PostQuitMessage(0); break; case MYWM_NOTIFYICON: if (opening) { SetForegroundWindow(GetLastActivePopup(hWnd)); break; } switch (lParam) { case WM_LBUTTONDOWN: SelectAndLoadFile(); break; case WM_MBUTTONDOWN: if (songs <= 1) break; /* FALLTHROUGH */ case WM_RBUTTONUP: GetCursorPos(&pt); SetForegroundWindow(hWnd); TrackPopupMenu(lParam == WM_MBUTTONDOWN ? hSongMenu : hTrayMenu, TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL); PostMessage(hWnd, WM_NULL, 0, 0); break; default: break; } break; case WM_COPYDATA: pcds = (PCOPYDATASTRUCT) lParam; if (pcds->dwData == 'O' && pcds->cbData <= sizeof(current_filename)) { if (errorShown) { HWND hChild = GetLastActivePopup(hWnd); if (hChild != hWnd) SendMessage(hChild, WM_CLOSE, 0, 0); } memcpy(current_filename, pcds->lpData, pcds->cbData); LoadAndPlay(-1); } break; default: if (msg == taskbarCreatedMessage) Shell_NotifyIcon(NIM_ADD, &nid); return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; }
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { GLuint PixelFormat; // 保存查找匹配的结果 WNDCLASS wc; // 窗口类结构 DWORD dwExStyle; // 扩展窗口风格 DWORD dwStyle; // 窗口风格 RECT WindowRect; // 取得矩形的左上角和右下角的坐标值 WindowRect.left=(long)0; // 将Left 设为 0 WindowRect.right=(long)width; // 将Right 设为要求的宽度 WindowRect.top=(long)0; // 将Top 设为 0 WindowRect.bottom=(long)height; // 将Bottom 设为要求的高度 fullscreen=fullscreenflag; // 设置全局全屏标志 hInstance = GetModuleHandle(NULL); // 取得我们窗口的实例 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // 移动时重画,并为窗口取得DC wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc处理消息 wc.cbClsExtra = 0; // 无额外窗口数据 wc.cbWndExtra = 0; // 无额外窗口数据 wc.hInstance = hInstance; // 设置实例 wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // 装入缺省图标 wc.hCursor = LoadCursor(NULL, IDC_ARROW); // 装入鼠标指针 wc.hbrBackground = NULL; // GL不需要背景 wc.lpszMenuName = NULL; // 不需要菜单 wc.lpszClassName = "OpenG"; // 设定类名字 if (!RegisterClass(&wc)) // 尝试注册窗口类 { MessageBox(NULL, "注册窗口失败", "错误",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 退出并返回FALSE } if (fullscreen) // 要尝试全屏模式吗? { DEVMODE dmScreenSettings; // 设备模式 memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // 确保内存清空为零 dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Devmode 结构的大小 dmScreenSettings.dmPelsWidth = width; // 所选屏幕宽度 dmScreenSettings.dmPelsHeight = height; // 所选屏幕高度 dmScreenSettings.dmBitsPerPel = bits; // 每象素所选的色彩深度 dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; // 尝试设置显示模式并返回结果。注: CDS_FULLSCREEN 移去了状态条。 if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { // 若模式失败,提供两个选项:退出或在窗口内运行。 if (MessageBox(NULL, "全屏模式在当前显卡上设置失败!\n使用窗口模式?", "NeHe G",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; // 选择窗口模式(Fullscreen=FALSE) } else { // 弹出一个对话框,告诉用户程序结束 MessageBox(NULL, "程序将被关闭", "错误",MB_OK|MB_ICONSTOP); return FALSE; // 退出并返回 FALSE } } } if (fullscreen) // 仍处于全屏模式吗? { dwExStyle=WS_EX_APPWINDOW; // 扩展窗体风格 dwStyle=WS_POPUP; // 窗体风格 ShowCursor(FALSE); // 隐藏鼠标指针 } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // 扩展窗体风格 dwStyle=WS_OVERLAPPEDWINDOW; // 窗体风格 } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // 调整窗口达到真正要求的大小 if (!(hWnd=CreateWindowEx( dwExStyle, // 扩展窗体风格 "OpenG", // 类名字 title, // 窗口标题 WS_CLIPSIBLINGS | // 必须的窗体风格属性 WS_CLIPCHILDREN | // 必须的窗体风格属性 dwStyle, // 选择的窗体属性 0, 0, // 窗口位置 WindowRect.right-WindowRect.left, // 计算调整好的窗口宽度 WindowRect.bottom-WindowRect.top, // 计算调整好的窗口高度 NULL, // 无父窗口 NULL, // 无菜单 hInstance, // 实例 NULL))) // 不向WM_CREATE传递任何东东 { KillGLWindow(); // 重置显示区 MessageBox(NULL, "不能创建一个窗口设备描述表", "错误",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 返回 FALSE } static PIXELFORMATDESCRIPTOR pfd= // /pfd 告诉窗口我们所希望的东东,即窗口使用的像素格式 { sizeof(PIXELFORMATDESCRIPTOR), // 上述格式描述符的大小 1, // 版本号 PFD_DRAW_TO_WINDOW | // 格式支持窗口 PFD_SUPPORT_OPENGL | // 格式必须支持OpenGL PFD_DOUBLEBUFFER, // 必须支持双缓冲 PFD_TYPE_RGBA, // 申请 RGBA 格式 bits, // 选定色彩深度 0, 0, 0, 0, 0, 0, // 忽略的色彩位 0, // 无Alpha缓存 0, // 忽略Shift Bit 0, // 无累加缓存 0, 0, 0, 0, // 忽略聚集位 16, // 16位 Z-缓存 (深度缓存) 0, // 无蒙板缓存 0, // 无辅助缓存 PFD_MAIN_PLANE, // 主绘图层 0, // Reserved 0, 0, 0 // 忽略层遮罩 }; if (!(hDC=GetDC(hWnd))) // 取得设备描述表了么? { KillGLWindow(); // 重置显示区 MessageBox(NULL, "不能创建一种相匹配的像素格式", "错误",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 返回 FALSE } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Windows 找到相应的象素格式了吗? { KillGLWindow(); // 重置显示区 MessageBox(NULL, "不能设置像素格式", "错误",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 返回 FALSE } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // 能够设置象素格式么? { KillGLWindow(); // 重置显示区 MessageBox(NULL, "不能设置像素格式", "错误",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 返回 FALSE } if (!(hRC=wglCreateContext(hDC))) // 能否取得着色描述表? { KillGLWindow(); // 重置显示区 MessageBox(NULL, "不能创建OpenGL渲染描述表", "错误",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 返回 FALSE } if (!(hRC=wglCreateContext(hDC))) // 能否取得着色描述表? { KillGLWindow(); // 重置显示区 MessageBox(NULL, "不能创建OpenGL渲染描述表", "错误",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 返回 FALSE } if(!wglMakeCurrent(hDC,hRC)) // 尝试激活着色描述表 { KillGLWindow(); // 重置显示区 MessageBox(NULL, "不能激活当前的OpenGL渲然描述表", "错误",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 返回 FALSE } ShowWindow(hWnd,SW_SHOW); // 显示窗口 SetForegroundWindow(hWnd); // 略略提高优先级 SetFocus(hWnd); // 设置键盘的焦点至此窗口 ReSizeGLScene(width, height); // 设置透视 GL 屏幕 if (!InitGL()) // 初始化新建的GL窗口 { KillGLWindow(); // 重置显示区 MessageBox(NULL, "Initialization Failed.", "ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // 返回 FALSE } return TRUE; // 成功 }
/* (Unix domain) socket support to replace the old FIFO code * (taken from Sylpheed, thanks) * Returns the created socket, -1 if an error occurred or -2 if another socket exists and files * were sent to it. */ gint socket_init(gint argc, gchar **argv) { gint sock; #ifdef G_OS_WIN32 HANDLE hmutex; HWND hwnd; socket_init_win32(); hmutex = CreateMutexA(NULL, FALSE, "Geany"); if (! hmutex) { geany_debug("cannot create Mutex\n"); return -1; } if (GetLastError() != ERROR_ALREADY_EXISTS) { /* To support multiple instances with different configuration directories (as we do on * non-Windows systems) we would need to use different port number s but it might be * difficult to get a port number which is unique for a configuration directory (path) * and which is unused. This port number has to be guessed by the first and new instance * and the only data is the configuration directory path. * For now we use one port number, that is we support only one instance at all. */ sock = socket_fd_open_inet(REMOTE_CMD_PORT); if (sock < 0) return 0; return sock; } sock = socket_fd_connect_inet(REMOTE_CMD_PORT); if (sock < 0) return -1; #else gchar *display_name = gdk_get_display(); gchar *hostname = utils_get_hostname(); gchar *p; if (display_name == NULL) display_name = g_strdup("NODISPLAY"); /* these lines are taken from dcopc.c in kdelibs */ if ((p = strrchr(display_name, '.')) > strrchr(display_name, ':') && p != NULL) *p = '\0'; /* remove characters that may not be acceptable in a filename */ for (p = display_name; *p; p++) { if (*p == ':' || *p == '/') *p = '_'; } if (socket_info.file_name == NULL) socket_info.file_name = g_strdup_printf("%s%cgeany_socket_%s_%s", app->configdir, G_DIR_SEPARATOR, hostname, display_name); g_free(display_name); g_free(hostname); /* check whether the real user id is the same as this of the socket file */ check_socket_permissions(); sock = socket_fd_connect_unix(socket_info.file_name); if (sock < 0) { remove_socket_link_full(); /* deletes the socket file and the symlink */ return socket_fd_open_unix(socket_info.file_name); } #endif /* remote command mode, here we have another running instance and want to use it */ #ifdef G_OS_WIN32 /* first we send a request to retrieve the window handle and focus the window */ socket_fd_write_all(sock, "window\n", 7); if (socket_fd_read(sock, (gchar *)&hwnd, sizeof(hwnd)) == sizeof(hwnd)) SetForegroundWindow(hwnd); #endif /* now we send the command line args */ if (argc > 1) { send_open_command(sock, argc, argv); } if (cl_options.list_documents) { socket_get_document_list(sock); } socket_fd_close(sock); return -2; }