// для GCC - другая int main() #endif { w = ImageWidth, h = ImageHeight; encode_start(); //memset(&CamImg, 0, sizeof(CamImg)); MSG msg; WNDCLASSA wcl; // 0. Регистрируем оконный класс wcl.hInstance = NULL; wcl.lpszClassName = szWinName; wcl.lpfnWndProc = MyFunc; wcl.style = 0; wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcl.hCursor = LoadCursor(NULL, IDC_ARROW); wcl.lpszMenuName = NULL; wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); if(!RegisterClassA(&wcl)) return 0; // 1. Создаём окно hWnd = CreateWindowA(szWinName, "Video", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 700, HWND_DESKTOP, NULL, NULL, NULL); HWND hStartRecord = CreateWindowA( "BUTTON", // Window class "Start", // Title WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 650, 200, 100, 50, hWnd, (HMENU)ID_START_BUTTON, // для WM_COMMAND NULL /*hThisInst*/, NULL ); HWND hStopRecord = CreateWindowA( "BUTTON", // Window class "Stop", // Title WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 650, 100, 100, 50, hWnd, (HMENU)ID_STOP_BUTTON, // для WM_COMMAND NULL /*hThisInst*/, NULL ); // 2. Отображаем окно на экран ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); // 3. Запускаем таймер (20 мсек, 50 кадров в секунду) SetTimer(hWnd, 1, 20, NULL); // 4. стартуем получение кадров с камеры InitVideo(); // 5. Стандартный цикл обработки событий while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
int WINAPI Notepad_WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow) { //recuperation de la taille de l'ecran int cxScreen, cyScreen ; cxScreen = GetSystemMetrics (SM_CXSCREEN); cyScreen = GetSystemMetrics (SM_CYSCREEN); #ifndef NOMAIN cxScreen = 800 ; cyScreen = 600 ; #endif HWND hwnd; MSG msg; WNDCLASS wc; HMENU hMenu, hSMFichier, hSMEdition, hSMApropos; #ifdef NOMAIN if( lpCmdLine!=NULL ) { if( strlen(lpCmdLine) > 0 ) { char *st = strstr( lpCmdLine, "|" ) ; if( st!=NULL ) { SavFile=(char*)malloc(strlen(st)+1); strcpy( SavFile, st+1 ) ; st[0]='\0'; IniFile=(char*)malloc(strlen(lpCmdLine)+1); strcpy( IniFile, lpCmdLine ) ; } } } TestIfParentIsKiTTY() ; #endif notepad_hinst = hinstance; HANDLE hAccel = LoadAccelerators (notepad_hinst, MAKEINTRESOURCE(NOTEPAD_IDR_ACCEL)) ; wc.style = 0; wc.lpfnWndProc = Notepad_WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = NULL; //wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIcon = LoadIcon(notepad_hinst, MAKEINTRESOURCE(NOTEPAD_IDI_MAINICON)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE); wc.lpszMenuName = NULL; wc.lpszClassName = Notepad_szprogname ; if(!RegisterClass(&wc)) return FALSE; //menu et sous menu hSMApropos = CreateMenu(); AppendMenu(hSMApropos, MF_STRING, NOTEPAD_IDM_ABOUT, Notepad_LoadString(NOTEPAD_STR_ABOUT)); hSMEdition = CreateMenu(); AppendMenu(hSMEdition, MF_STRING, NOTEPAD_IDM_CUT, Notepad_LoadString(NOTEPAD_STR_CUT)); AppendMenu(hSMEdition, MF_STRING, NOTEPAD_IDM_COPY, Notepad_LoadString(NOTEPAD_STR_COPY)); AppendMenu(hSMEdition, MF_STRING, NOTEPAD_IDM_PASTE, Notepad_LoadString(NOTEPAD_STR_PASTE)); AppendMenu(hSMEdition, MF_STRING, NOTEPAD_IDM_SELECTALL, Notepad_LoadString(NOTEPAD_STR_SELECTALL)); AppendMenu(hSMEdition, MF_STRING, NOTEPAD_IDM_UNDO, Notepad_LoadString(NOTEPAD_STR_UNDO)); AppendMenu(hSMEdition, MF_SEPARATOR, 0, NULL ); AppendMenu(hSMEdition, MF_STRING, NOTEPAD_IDM_SETFONT, Notepad_LoadString(NOTEPAD_STR_SETFONT)); hSMFichier = CreateMenu(); AppendMenu(hSMFichier, MF_STRING, NOTEPAD_IDM_NEW, Notepad_LoadString(NOTEPAD_STR_NEW)); AppendMenu(hSMFichier, MF_STRING, NOTEPAD_IDM_OPEN, Notepad_LoadString(NOTEPAD_STR_OPEN)); AppendMenu(hSMFichier, MF_STRING|MF_GRAYED|MF_DISABLED, NOTEPAD_IDM_SAVE, Notepad_LoadString(NOTEPAD_STR_SAVE)); AppendMenu(hSMFichier, MF_STRING, NOTEPAD_IDM_SAVEAS, Notepad_LoadString(NOTEPAD_STR_SAVEAS)); #ifdef NOMAIN AppendMenu(hSMFichier, MF_SEPARATOR, 0, NULL ); AppendMenu(hSMFichier, MF_STRING, NOTEPAD_IDM_LOAD_INI, TEXT("ini file")); AppendMenu(hSMFichier, MF_STRING, NOTEPAD_IDM_LOAD_SAV, TEXT("sav file")); if( ParentWindow!=NULL ) { AppendMenu(hSMFichier, MF_SEPARATOR, 0, NULL ); AppendMenu(hSMFichier, MF_STRING, NOTEPAD_IDM_RESIZE, TEXT("&Resize")); } #endif AppendMenu(hSMFichier, MF_SEPARATOR, 0, NULL ); AppendMenu(hSMFichier, MF_STRING, NOTEPAD_IDM_QUIT, Notepad_LoadString(NOTEPAD_STR_QUIT)); hMenu = CreateMenu(); AppendMenu(hMenu,MF_POPUP,(UINT)hSMFichier,Notepad_LoadString(NOTEPAD_STR_FILE)); AppendMenu(hMenu,MF_POPUP,(UINT)hSMEdition,Notepad_LoadString(NOTEPAD_STR_EDIT)); #ifdef NOMAIN HMENU hSMDelim = CreateMenu() ; AppendMenu(hSMDelim, MF_STRING|MF_CHECKED, NOTEPAD_IDM_CRLF, Notepad_LoadString(NOTEPAD_STR_CRLF)); AppendMenu(hSMDelim, MF_STRING|MF_CHECKED, NOTEPAD_IDM_SCOLON, Notepad_LoadString(NOTEPAD_STR_SCOLON)); AppendMenu(hSMDelim, MF_STRING|MF_UNCHECKED, NOTEPAD_IDM_SLASH, Notepad_LoadString(NOTEPAD_STR_SLASH)); AppendMenu(hMenu,MF_POPUP,(UINT)hSMDelim,Notepad_LoadString(NOTEPAD_STR_DELIM)); AppendMenu(hMenu,MF_STRING, NOTEPAD_IDM_SEND, Notepad_LoadString(NOTEPAD_STR_SEND)); #endif AppendMenu(hMenu,MF_POPUP,(UINT)hSMApropos,Notepad_LoadString(NOTEPAD_STR_HELP)); //hwnd = CreateWindow(Notepad_szprogname, Notepad_szprogname, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, cxScreen, cyScreen, NULL, hMenu, hinstance, NULL); hwnd = CreateWindowEx(WS_EX_ACCEPTFILES,Notepad_szprogname, Notepad_szprogname, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, cxScreen, cyScreen, NULL, hMenu, hinstance, NULL); if (!hwnd) return FALSE; ShowWindow(hwnd, nCmdShow) ; UpdateWindow(hwnd) ; #ifdef NOMAIN InitKiTTYNotepad( hwnd ) ; if( strstr( lpCmdLine, "-ed " ) == lpCmdLine ) if( strlen(lpCmdLine)>4 ) SendMessage( hwnd, WM_COMMAND, NOTEPAD_IDM_LOAD, (LPARAM)(lpCmdLine+4) ) ; #else if( strlen(lpCmdLine)>0 ) SendMessage( hwnd, WM_COMMAND, NOTEPAD_IDM_LOAD, (LPARAM)lpCmdLine ) ; #endif while (GetMessage(&msg, NULL, 0, 0)) { if(!TranslateAccelerator(hwnd, hAccel, &msg)){ TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; }
//int WINAPI void pvm_win_window_thread() { MSG Message; if(pvm_win_setup_window()) { init_err = 1; printf("pvm_win_setup_window failed\n"); return; } // Allocate enough memory for the BITMAPINFOHEADER and 256 RGBQUAD palette entries LPBITMAPINFO lpbi; lpbi = (LPBITMAPINFO) malloc(sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))); lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpbi->bmiHeader.biWidth = VSCREEN_WIDTH; lpbi->bmiHeader.biHeight = VSCREEN_HEIGHT; lpbi->bmiHeader.biPlanes = 1; lpbi->bmiHeader.biBitCount = 24; lpbi->bmiHeader.biCompression = BI_RGB; lpbi->bmiHeader.biSizeImage = 0; lpbi->bmiHeader.biXPelsPerMeter = 0; lpbi->bmiHeader.biYPelsPerMeter = 0; lpbi->bmiHeader.biClrUsed = 0; lpbi->bmiHeader.biClrImportant = 0; HDC hScreenDC = GetWindowDC(NULL); screenBitmap = CreateDIBSection( hScreenDC, lpbi, DIB_RGB_COLORS, (void*)&screen_image, 0, 0); // Assume hPaintDC is a variable of type HDC, and the dc we're rendering to //hBitmapDC = CreateCompatibleDC(hScreenDC); //HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBitmapDC, screenBitmap); ReleaseDC(NULL,hScreenDC); free(lpbi); int i; for( i = 0; i < VSCREEN_WIDTH * VSCREEN_HEIGHT * 3; i++) { screen_image[i] = 34; } drv_video_win32.screen = screen_image; drv_video_win32.xsize = VSCREEN_WIDTH; drv_video_win32.ysize = VSCREEN_HEIGHT; drv_video_win32.update = &drv_win_screen_update; #if 1 drv_video_win32.bitblt = &vid_bitblt_forw; drv_video_win32.winblt = &vid_win_winblt; drv_video_win32.readblt = &vid_readblt_forw; drv_video_win32.bitblt_part = &vid_bitblt_part_forw; #else drv_video_win32.bitblt = &drv_video_bitblt_rev; drv_video_win32.winblt = &drv_video_win_winblt_rev; drv_video_win32.readblt = &drv_video_readblt_rev; drv_video_win32.bitblt_part = &drv_video_bitblt_part_rev; #endif drv_video_win32.mouse_redraw_cursor = &vid_mouse_draw_deflt; drv_video_win32.mouse_set_cursor = &vid_mouse_set_cursor_deflt; drv_video_win32.mouse_disable = &vid_mouse_off_deflt; drv_video_win32.mouse_enable = &vid_mouse_on_deflt; init_ok = 1; #if HOVER { eventTrack.cbSize = sizeof(eventTrack); eventTrack.dwFlags = TME_HOVER; eventTrack.hwndTrack = hWnd; eventTrack.dwHoverTime = 5; if(0 == TrackMouseEvent(&eventTrack)) printf("Track error\n"); } #endif while(GetMessage(&Message, hWnd, 0, 0)) { TranslateMessage(&Message); DispatchMessage(&Message); } //return Message.wParam; //printf("Message loop end\n"); }
/* This function checks the windows message queue and DirectInput and returns 1 if there was input, 0 if there was no input, or -1 if the application has posted a quit message. */ static int DX5_CheckInput(_THIS, int timeout, BOOL processInput) { MSG msg; int i; HRESULT result; DWORD event; /* Check the normal windows queue (highest preference) */ posted = 0; while ( ! posted && PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { DispatchMessage(&msg); } else { return(-1); } } if ( posted ) { return(1); } /* Pump the DirectInput flow */ if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { for ( i=0; i<SDL_DIndev; ++i ) { result = IDirectInputDevice2_Poll(SDL_DIdev[i]); if ( (result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED) ) { if ( strcmp(inputs[i].name, "mouse") == 0 ) { mouse_lost = 1; } IDirectInputDevice2_Acquire(SDL_DIdev[i]); IDirectInputDevice2_Poll(SDL_DIdev[i]); } } } /* Wait for messages and input events */ event = MsgWaitForMultipleObjects(SDL_DIndev, SDL_DIevt, FALSE, timeout, QS_ALLEVENTS); if ((event >= WAIT_OBJECT_0) && (event < (WAIT_OBJECT_0+SDL_DIndev))) { DWORD numevents; DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE]; event -= WAIT_OBJECT_0; numevents = INPUT_QSIZE; result = IDirectInputDevice2_GetDeviceData( SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); if ( (result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED) ) { if ( strcmp(inputs[event].name, "mouse") == 0 ) { mouse_lost = 1; } IDirectInputDevice2_Acquire(SDL_DIdev[event]); result = IDirectInputDevice2_GetDeviceData( SDL_DIdev[event], sizeof(DIDEVICEOBJECTDATA), evtbuf, &numevents, 0); } /* Handle the events */ if ( result == DI_OK && processInput ) { /* Note: This can post multiple events to event queue */ (*SDL_DIfun[event])((int)numevents, evtbuf); return(1); } } if ( event != WAIT_TIMEOUT ) { /* Maybe there was a windows message? */ if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { if ( GetMessage(&msg, NULL, 0, 0) > 0 ) { DispatchMessage(&msg); } else { return(-1); } return(1); } } return(0); }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { WCHAR szWindowClass[] = L"ROSAPPMGR"; HANDLE hMutex = NULL; HACCEL KeyBrd; MSG Msg; InitializeAtlModule(hInstance, TRUE); switch (GetUserDefaultUILanguage()) { case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT): SetProcessDefaultLayout(LAYOUT_RTL); break; default: break; } hInst = hInstance; hMutex = CreateMutexW(NULL, FALSE, szWindowClass); if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS)) { /* If already started, it is found its window */ HWND hWindow = FindWindowW(szWindowClass, NULL); /* Activate window */ ShowWindow(hWindow, SW_SHOWNORMAL); SetForegroundWindow(hWindow); return 1; } if (!LoadSettings()) { FillDefaultSettings(&SettingsInfo); } InitLogs(); InitCommonControls(); hMainWnd = CreateMainWindow(); if (!hMainWnd) goto Exit; /* Maximize it if we must */ ShowWindow(hMainWnd, (SettingsInfo.bSaveWndPos && SettingsInfo.Maximized ? SW_MAXIMIZE : nShowCmd)); UpdateWindow(hMainWnd); if (SettingsInfo.bUpdateAtStart) UpdateAppsDB(); /* Load the menu hotkeys */ KeyBrd = LoadAccelerators(NULL, MAKEINTRESOURCE(HOTKEYS)); /* Message Loop */ while (GetMessage(&Msg, NULL, 0, 0)) { if (!TranslateAccelerator(hMainWnd, KeyBrd, &Msg)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } } Exit: if (hMutex) CloseHandle(hMutex); InitializeAtlModule(hInstance, FALSE); return 0; }
//---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- void MainLoop() { for(;;) { MSG msg; if (PeekMessage (&msg,NULL,0,0,PM_NOREMOVE)) { if( msg.message == WM_QUIT ) { return ; } GetMessage (&msg,NULL,0,0); TranslateMessage(&msg); DispatchMessage(&msg); } else { // フリップを行う g_manager->Flip(); // Updateと再生開始を並行で行う g_wait = false; if( g_timer % 30 == 0 ) { // エフェクトの再生 g_manager->Play( g_effect, rand() % 20 - 10, rand() % 20 - 10, rand() % 20 - 10 ); } // Update完了待ち while( !g_wait ) { Sleep(1); } g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 ); g_d3d_device->BeginScene(); // エフェクトの描画開始処理を行う。 g_renderer->BeginRendering(); // エフェクトの描画を行う。 g_manager->Draw(); // エフェクトの描画終了処理を行う。 g_renderer->EndRendering(); g_d3d_device->EndScene(); g_timer++; { HRESULT hr; hr = g_d3d_device->Present( NULL, NULL, NULL, NULL ); // デバイスロスト処理 switch ( hr ) { // デバイスロスト case D3DERR_DEVICELOST: while ( FAILED( hr = g_d3d_device->TestCooperativeLevel() ) ) { switch ( hr ) { // デバイスロスト case D3DERR_DEVICELOST: ::SleepEx( 1000, true ); break; // デバイスロスト:リセット可 case D3DERR_DEVICENOTRESET: // デバイスロストの処理を行う前に実行する g_renderer->OnLostDevice(); D3DPRESENT_PARAMETERS d3dp; ZeroMemory(&d3dp, sizeof(d3dp)); d3dp.BackBufferWidth = g_window_width; d3dp.BackBufferHeight = g_window_height; d3dp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dp.BackBufferCount = 1; d3dp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dp.Windowed = TRUE; d3dp.hDeviceWindow = g_window_handle; d3dp.EnableAutoDepthStencil = TRUE; d3dp.AutoDepthStencilFormat = D3DFMT_D16; g_d3d_device->Reset( &d3dp ); // デバイスロストの処理の後に実行する g_renderer->OnResetDevice(); break; } } break; } } } } }
int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) { Common::EnableCrashingOnCrashes(); char *token = szCmdLine; char fileToLoad[256] = ""; token = strtok(szCmdLine," "); g_Config.Load(); VFSRegister("", new DirectoryAssetReader("")); while (token) { if (strcmp(token,"-run")) { //run immediately } token = strtok(NULL," "); } //Windows, API init stuff INITCOMMONCONTROLSEX comm; comm.dwSize = sizeof(comm); comm.dwICC = ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES; InitCommonControlsEx(&comm); timeBeginPeriod(1); MainWindow::Init(_hInstance); HACCEL hAccelTable = LoadAccelerators(_hInstance, (LPCTSTR)IDR_ACCELS); g_hPopupMenus = LoadMenu(_hInstance, (LPCSTR)IDR_POPUPMENUS); MainWindow::Show(_hInstance, iCmdShow); host = new WindowsHost(MainWindow::GetHWND(), MainWindow::GetDisplayHWND()); HWND hwndMain = MainWindow::GetHWND(); HMENU menu = GetMenu(hwndMain); //initialize custom controls CtrlDisAsmView::init(); CtrlMemView::init(); CtrlRegisterList::init(); DialogManager::AddDlg(memoryWindow[0] = new CMemoryDlg(_hInstance, hwndMain, currentDebugMIPS)); DialogManager::AddDlg(vfpudlg = new CVFPUDlg(_hInstance, hwndMain, currentDebugMIPS)); MainWindow::Update(); MainWindow::UpdateMenus(); LogManager::Init(); bool hidden = false; #ifndef _DEBUG hidden = true; #endif LogManager::GetInstance()->GetConsoleListener()->Open(hidden, 150, 120, "PPSSPP Debug Console"); LogManager::GetInstance()->SetLogLevel(LogTypes::G3D, LogTypes::LERROR); if (strlen(fileToLoad)) { // TODO: load the thing } //so.. we're at the message pump of the GUI thread MSG msg; while (GetMessage(&msg, NULL, 0, 0)) //while no quit { //DSound_UpdateSound(); //hack to make it possible to get to main window from floating windows with Esc if (msg.hwnd != hwndMain && msg.message==WM_KEYDOWN && msg.wParam==VK_ESCAPE) BringWindowToTop(hwndMain); //Translate accelerators and dialog messages... if (!TranslateAccelerator(hwndMain, hAccelTable, &msg)) { if (!DialogManager::IsDialogMessage(&msg)) { //and finally translate and dispatch TranslateMessage(&msg); DispatchMessage(&msg); } } } LogManager::Shutdown(); DialogManager::DestroyAll(); timeEndPeriod(1); g_Config.Save(); delete host; return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX windowClass; // window class HWND hwnd; // window handle MSG msg; // message DWORD dwExStyle; // Window Extended Style DWORD dwStyle; // Window Style RECT windowRect; g_gameEngine = new GameEngine; g_glRender = new CGfxOpenGL(*g_gameEngine); g_gameStateMngr = new GameStateManager(*g_glRender, *g_gameEngine); windowRect.left=(long)0; // Set Left Value To 0 windowRect.right=(long)windowWidth; // Set Right Value To Requested Width windowRect.top=(long)0; // Set Top Value To 0 windowRect.bottom=(long)windowHeight; // Set Bottom Value To Requested Height // fill out the window class structure windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.style = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = MainWindowProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // default arrow windowClass.hbrBackground = NULL; // don't need background windowClass.lpszMenuName = NULL; // no menu windowClass.lpszClassName = "GLClass"; windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // windows logo small icon // register the windows class if (!RegisterClassEx(&windowClass)) return 0; if (fullscreen) // fullscreen? { DEVMODE dmScreenSettings; // device mode memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = windowWidth; // screen width dmScreenSettings.dmPelsHeight = windowHeight; // screen height dmScreenSettings.dmBitsPerPel = windowBits; // bits per pixel dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; // if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { // setting display mode failed, switch to windowed MessageBox(NULL, "Display mode failed", NULL, MB_OK); fullscreen = FALSE; } } if (fullscreen) // Are We Still In Fullscreen Mode? { dwExStyle=WS_EX_APPWINDOW; // Window Extended Style dwStyle=WS_POPUP; // Windows Style ShowCursor(FALSE); // Hide Mouse Pointer } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style } AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size // class registered, so now create our window hwnd = CreateWindowEx(NULL, // extended style "GLClass", // class name "BOGLGP - Chapter 2 - OpenGL Application", // app name dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, SCREEN_X,SCREEN_Y, // x,y coordinate windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, // width, height NULL, // handle to parent NULL, // handle to menu hInstance, // application instance NULL); // no extra params hDC = GetDC(hwnd); // check if window creation failed (hwnd would equal NULL) if (!hwnd) return 0; ShowWindow(hwnd, SW_SHOW); // display the window UpdateWindow(hwnd); // update the window g_gameStateMngr->initialize(); while (!exiting) { if( !g_paused ) g_gameStateMngr->process(); g_gameStateMngr->render(); Sleep(SLEEP_TIME); SwapBuffers(hDC); while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage (&msg, NULL, 0, 0)) { exiting = true; break; } TranslateMessage (&msg); DispatchMessage (&msg); } } delete g_gameStateMngr; delete g_gameEngine; delete g_glRender; if (fullscreen) { ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop ShowCursor(TRUE); // Show Mouse Pointer } return (int)msg.wParam; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; //wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); #if MENU_1 wc.hIcon = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_MYICON)); //icon on taskbar wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0); //icon on top left wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU); #endif #if MENU_2 wc.hIcon = NULL; wc.hIconSm = NULL; wc.lpszMenuName = NULL; #endif #if DIALOG_1 wc.hIcon = NULL; wc.hIconSm = NULL; wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU); #endif wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszClassName = g_szClassName; //register class if(!RegisterClassEx(&wc)) { MessageBox(NULL,"Window Registration failed!", "Error !", MB_ICONEXCLAMATION | MB_OK); } //create window hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_szClassName, "The title on my window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240,120, NULL,NULL,hInstance,NULL); //check if creating window fail if(hwnd == NULL) { MessageBox(hwnd,"WIndow creattion failed!","Error !", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0) > 0 ) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("Checker1"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("Checker1 Mouse Hit-Test Demo"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
void __declspec(dllexport) show(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { TCHAR fn[MAX_PATH]; TCHAR temp[64]; TCHAR *sleep=temp; EXDLL_INIT(); popstring(sleep); popstring(fn); sleep_val=0; while (*sleep >= _T('0') && *sleep <= _T('9')) { sleep_val*=10; sleep_val+=*sleep++-_T('0'); } if (fn[0] && sleep_val>0) { MSG msg; TCHAR classname[4]=_T("_sp"); static WNDCLASS wc; wc.lpfnWndProc = WndProc; wc.hInstance = g_hInstance; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.lpszClassName = classname; if (RegisterClass(&wc)) { TCHAR fn2[MAX_PATH]; lstrcpy(fn2,fn); lstrcat(fn,_T(".bmp")); lstrcat(fn2,_T(".wav")); g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE); if (g_hbm) { HWND myWnd; PlaySound(fn2,NULL,SND_ASYNC|SND_FILENAME|SND_NODEFAULT); myWnd = CreateWindowEx(WS_EX_TOOLWINDOW,classname,classname, 0,0,0,0,0,(HWND)hwndParent,NULL,g_hInstance,NULL); while (IsWindow(myWnd) && GetMessage(&msg,myWnd,0,0)) { DispatchMessage(&msg); } // Stop currently playing wave, we want to exit PlaySound(0,0,0); DeleteObject(g_hbm); UnregisterClass(classname, g_hInstance); } } } wsprintf(temp,_T("%d"),g_rv); pushstring(temp); }
void MMsgBox::AdjustSize() { int nLineCount = MMGetLineCount(m_pMessage->GetFont(),GetMessage(),MMSGBOX_W); SetBounds(MRECT(MMSGBOX_X, MMSGBOX_Y, MMSGBOX_W, MMSGBOX_H + nLineCount*m_pMessage->GetFont()->GetHeight())); }
const char* MMsgBox::GetText(void) { return GetMessage(); }
void * s_video_gdi_create_window (void *arg) { MSG msg; RECT rect; HDC mainwindow; WNDCLASSEX wndclass; char *szMainWndClass = "XynthWindowingSystem"; s_video_gdi_data_t *priv = (s_video_gdi_data_t *) xynth_server->driver->driver_data; memset(&wndclass, 0, sizeof(WNDCLASSEX)); wndclass.lpszClassName = szMainWndClass; wndclass.cbSize = sizeof(WNDCLASSEX); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = MainWndProc; wndclass.hInstance = priv->hinst; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); RegisterClassEx(&wndclass); priv->hwndMain = CreateWindow(szMainWndClass, "Xynth Windowing system", WS_POPUP | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, priv->hinst, NULL); rect.left = 0; rect.right = xynth_server->window->surface->width; rect.top = 0; rect.bottom = xynth_server->window->surface->height; AdjustWindowRect(&rect, GetWindowLong(priv->hwndMain, GWL_STYLE), FALSE); SetWindowPos(priv->hwndMain, HWND_TOP, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE); ShowWindow(priv->hwndMain, TRUE); UpdateWindow(priv->hwndMain); mainwindow = GetDC(priv->hwndMain); if (mainwindow == NULL) { debugf(DSER | DFAT, "What the f**k is this?"); return NULL; } priv->bpp_windows = GetDeviceCaps(mainwindow, BITSPIXEL); if (priv->bpp_windows == 24) { debugf(DSER | DFAT, "24 bitsperpixel modes are not supported by Xynth Windowing System. " "Try changing display mode from " "Display Properties -> Settings -> Color quality."); } while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (void *) msg.wParam; }
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ _T("Code::Blocks Template Windows App"), /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow (hwnd, nCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }
DWORD CSocketThreadManager::SocketThread(LPVOID lpParameter) { try { //Get the address of our data ThreadData* pData; pData=(ThreadData*)lpParameter; //Initialize the random seed srand(GetTickCount()+(unsigned long)pData->pEvent+(unsigned long)pData->hWindowHandle); //Create the window pData->hWindowHandle=CreateWindowEx(0, pData->sClassName.c_str(), SOCKET_WINDOW_NAME, WS_OVERLAPPED, 0, 0, 0, 0, 0, NULL, pData->hInstance, NULL); //Alert we are done pData->pEvent->Set(); //Check we have this window if (pData->hWindowHandle) { //Run a message map MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { //Translate and dispatch TranslateMessage(&msg); //Check if it's a timer if (msg.message==WM_TIMER) { //Lock the CS CCriticalAutoRelease aRelease(pData->pCSection); //Check is it our timer TOMap::iterator aTheIterator; aTheIterator=pData->pMap.find(msg.wParam); //Check if we have it if (aTheIterator!=pData->pMap.end()) { //Found it TimeoutData aData; aData=aTheIterator->second; //Do we need to delete it if (aData.bClearTimeout) { //Delete it KillTimer(pData->hWindowHandle, msg.wParam); //Do we have the data to reset ? if (aData.pTimer) memset(aData.pTimer, 0, sizeof(TimerID)); //Erase the timer pData->pMap.erase(aTheIterator); //Decrease the count --pData->iTimeoutCount; } //Exit the CS aRelease.Exit(); //Protect it try { //Dispatch the data (*(aData.pTimeoutProc))(aData.pData); } ERROR_HANDLER_STATIC(CSocketThreadManager_Class,"SocketThread - Proc") } else { //Release the data aRelease.Exit(); //Dispatch the message pData->pClass->ParseDispatchMessage(msg, pData); } }
static DWORD CALLBACK MMDevApiMsgProc(void *ptr) { ThreadRequest *req = ptr; IMMDeviceEnumerator *Enumerator; ALuint deviceCount = 0; MMDevApiData *data; ALCdevice *device; HRESULT hr, cohr; MSG msg; TRACE("Starting message thread\n"); cohr = CoInitialize(NULL); if(FAILED(cohr)) { WARN("Failed to initialize COM: 0x%08lx\n", cohr); req->result = cohr; SetEvent(req->FinishedEvt); return 0; } hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr); if(FAILED(hr)) { WARN("Failed to create IMMDeviceEnumerator instance: 0x%08lx\n", hr); CoUninitialize(); req->result = hr; SetEvent(req->FinishedEvt); return 0; } Enumerator = ptr; IMMDeviceEnumerator_Release(Enumerator); Enumerator = NULL; CoUninitialize(); req->result = S_OK; SetEvent(req->FinishedEvt); TRACE("Starting message loop\n"); while(GetMessage(&msg, NULL, 0, 0)) { TRACE("Got message %u\n", msg.message); switch(msg.message) { case WM_USER_OpenDevice: req = (ThreadRequest*)msg.wParam; device = (ALCdevice*)msg.lParam; data = device->ExtraData; hr = cohr = S_OK; if(++deviceCount == 1) hr = cohr = CoInitialize(NULL); if(SUCCEEDED(hr)) hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr); if(SUCCEEDED(hr)) { Enumerator = ptr; if(!data->devid) hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(Enumerator, eRender, eMultimedia, &data->mmdev); else hr = IMMDeviceEnumerator_GetDevice(Enumerator, data->devid, &data->mmdev); IMMDeviceEnumerator_Release(Enumerator); Enumerator = NULL; } if(SUCCEEDED(hr)) hr = IMMDevice_Activate(data->mmdev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, &ptr); if(SUCCEEDED(hr)) { data->client = ptr; device->DeviceName = get_device_name(data->mmdev); } if(FAILED(hr)) { if(data->mmdev) IMMDevice_Release(data->mmdev); data->mmdev = NULL; if(--deviceCount == 0 && SUCCEEDED(cohr)) CoUninitialize(); } req->result = hr; SetEvent(req->FinishedEvt); continue; case WM_USER_ResetDevice: req = (ThreadRequest*)msg.wParam; device = (ALCdevice*)msg.lParam; req->result = DoReset(device); SetEvent(req->FinishedEvt); continue; case WM_USER_StartDevice: req = (ThreadRequest*)msg.wParam; device = (ALCdevice*)msg.lParam; data = device->ExtraData; ResetEvent(data->NotifyEvent); hr = IAudioClient_SetEventHandle(data->client, data->NotifyEvent); if(FAILED(hr)) ERR("Failed to set event handle: 0x%08lx\n", hr); else { hr = IAudioClient_Start(data->client); if(FAILED(hr)) ERR("Failed to start audio client: 0x%08lx\n", hr); } if(SUCCEEDED(hr)) hr = IAudioClient_GetService(data->client, &IID_IAudioRenderClient, &ptr); if(SUCCEEDED(hr)) { data->render = ptr; data->thread = StartThread(MMDevApiProc, device); if(!data->thread) { if(data->render) IAudioRenderClient_Release(data->render); data->render = NULL; IAudioClient_Stop(data->client); ERR("Failed to start thread\n"); hr = E_FAIL; } } req->result = hr; SetEvent(req->FinishedEvt); continue; case WM_USER_StopDevice: req = (ThreadRequest*)msg.wParam; device = (ALCdevice*)msg.lParam; data = device->ExtraData; if(data->thread) { data->killNow = 1; StopThread(data->thread); data->thread = NULL; data->killNow = 0; IAudioRenderClient_Release(data->render); data->render = NULL; IAudioClient_Stop(data->client); } req->result = S_OK; SetEvent(req->FinishedEvt); continue; case WM_USER_CloseDevice: req = (ThreadRequest*)msg.wParam; device = (ALCdevice*)msg.lParam; data = device->ExtraData; IAudioClient_Release(data->client); data->client = NULL; IMMDevice_Release(data->mmdev); data->mmdev = NULL; if(--deviceCount == 0) CoUninitialize(); req->result = S_OK; SetEvent(req->FinishedEvt); continue; case WM_USER_Enumerate: req = (ThreadRequest*)msg.wParam; hr = cohr = S_OK; if(++deviceCount == 1) hr = cohr = CoInitialize(NULL); if(SUCCEEDED(hr)) hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr); if(SUCCEEDED(hr)) { EDataFlow flowdir; DevMap **devlist; ALuint *numdevs; ALuint i; Enumerator = ptr; if(msg.lParam == CAPTURE_DEVICE_PROBE) { flowdir = eCapture; devlist = &CaptureDeviceList; numdevs = &NumCaptureDevices; } else { flowdir = eRender; devlist = &PlaybackDeviceList; numdevs = &NumPlaybackDevices; } for(i = 0;i < *numdevs;i++) { free((*devlist)[i].name); free((*devlist)[i].devid); } free(*devlist); *devlist = NULL; *numdevs = 0; *devlist = ProbeDevices(Enumerator, flowdir, numdevs); IMMDeviceEnumerator_Release(Enumerator); Enumerator = NULL; } if(--deviceCount == 0 && SUCCEEDED(cohr)) CoUninitialize(); req->result = S_OK; SetEvent(req->FinishedEvt); continue; default: ERR("Unexpected message: %u\n", msg.message); continue; } } TRACE("Message loop finished\n"); return 0; }
void TrackPopup(duComboBox *pComboBox, HWND hwndOwner, HWND hwndListBox) { POINT pt; MSG msg; HWND hwndActive = NULL; while (GetMessage(&msg, NULL, 0, 0)) { if (pComboBox->IsEnd()) break; hwndActive = GetActiveWindow(); if (hwndActive != hwndOwner) break; switch (msg.message) { case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_RBUTTONDBLCLK: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MBUTTONDBLCLK: pt.x = (short)LOWORD(msg.lParam); pt.y = (short)HIWORD(msg.lParam); MapWindowPoints(msg.hwnd, hwndListBox, &pt, 1); msg.lParam = MAKELPARAM(pt.x, pt.y); msg.hwnd = hwndListBox; break; case WM_MOUSEWHEEL: msg.hwnd = hwndListBox; break; case WM_NCMOUSEMOVE: msg.hwnd = hwndListBox; break; case WM_NCLBUTTONDOWN: case WM_NCLBUTTONUP: case WM_NCLBUTTONDBLCLK: case WM_NCRBUTTONDOWN: case WM_NCRBUTTONUP: case WM_NCRBUTTONDBLCLK: case WM_NCMBUTTONDOWN: case WM_NCMBUTTONUP: case WM_NCMBUTTONDBLCLK: ::DestroyWindow(hwndListBox); return; case WM_KEYDOWN: case WM_KEYUP: case WM_CHAR: case WM_DEADCHAR: case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_SYSCHAR: case WM_SYSDEADCHAR: msg.hwnd = hwndListBox; break; } TranslateMessage(&msg); DispatchMessage(&msg); if (pComboBox->IsEnd()) break; hwndActive = GetActiveWindow(); if (hwndActive != hwndOwner) break; } ::DestroyWindow(hwndListBox); if (msg.message == WM_QUIT) { PostQuitMessage((int)msg.wParam); } }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(nCmdShow); SetDllDirectory(L""); ::OleInitialize(NULL); // we need some of the common controls INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_LINK_CLASS|ICC_LISTVIEW_CLASSES|ICC_PAGESCROLLER_CLASS |ICC_PROGRESS_CLASS|ICC_STANDARD_CLASSES|ICC_TAB_CLASSES|ICC_TREEVIEW_CLASSES |ICC_UPDOWN_CLASS|ICC_USEREX_CLASSES|ICC_WIN95_CLASSES; InitCommonControlsEx(&icex); apr_initialize(); setlocale(LC_ALL, ""); // to avoid that SASL will look for and load its plugin dlls all around the // system, we set the path here. // Note that SASL doesn't have to be initialized yet for this to work sasl_set_path(SASL_PATH_TYPE_PLUGIN, (LPSTR)(LPCSTR)CUnicodeUtils::StdGetUTF8(CAppUtils::GetAppDirectory()).c_str()); // first create a hidden window which serves as our main window for receiving // the window messages, starts the monitoring thread and handles the icon // in the tray area. MSG msg; msg.wParam = FALSE; HACCEL hAccelTable; hInst = hInstance; INITCOMMONCONTROLSEX used = { sizeof(INITCOMMONCONTROLSEX), ICC_BAR_CLASSES }; InitCommonControlsEx(&used); Snarl::SnarlInterface snarlIface; CCmdLineParser parser(lpCmdLine); if (parser.HasKey(_T("patchfile"))) { hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_CMVIEWER)); // in this case, we start another part of our application, not // the monitoring part. CDiffViewer viewer(hInst); if (parser.HasVal(_T("title"))) viewer.SetTitle(parser.GetVal(_T("title"))); if (viewer.RegisterAndCreateWindow()) { if (viewer.LoadFile(parser.GetVal(_T("patchfile")))) { ::ShowWindow(viewer.GetHWNDEdit(), SW_SHOW); ::SetFocus(viewer.GetHWNDEdit()); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(viewer, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } } } else { //only one instance of this application part allowed g_mutex = ::CreateMutex(NULL, FALSE, APPNAME_MUTEX); if (g_mutex != NULL) { if ((::GetLastError()==ERROR_ALREADY_EXISTS)&&(!parser.HasKey(_T("task")))) { //an instance of this app is already running HWND hWnd = FindWindow(ResString(hInst, IDS_APP_TITLE), NULL); //try finding the running instance of this app if (hWnd) { UINT COMMITMONITOR_SHOWDLGMSG = RegisterWindowMessage(_T("CommitMonitor_ShowDlgMsg")); PostMessage(hWnd, COMMITMONITOR_SHOWDLGMSG ,0 ,0); //open the window of the already running app SetForegroundWindow(hWnd); //set the window to front } apr_terminate(); return FALSE; } } CHiddenWindow hiddenWindow(hInst); hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_COMMITMONITOR)); if (hiddenWindow.RegisterAndCreateWindow()) { if ((snarlIface.GetVersionEx() != Snarl::M_FAILED)&&(Snarl::SnarlInterface::GetSnarlWindow() != NULL)) { std::wstring imgPath = CAppUtils::GetAppDataDir()+L"\\CM.png"; if (CAppUtils::ExtractBinResource(_T("PNG"), IDB_COMMITMONITOR, imgPath)) { // register with Snarl snarlIface.RegisterApp(_T("CommitMonitor"), imgPath.c_str(), imgPath.c_str(), hiddenWindow); snarlIface.RegisterAlert(_T("CommitMonitor"), ALERTTYPE_NEWPROJECTS); snarlIface.RegisterAlert(_T("CommitMonitor"), ALERTTYPE_NEWCOMMITS); snarlIface.RegisterAlert(_T("CommitMonitor"), ALERTTYPE_FAILEDCONNECT); } } if (parser.HasKey(_T("task"))) { hiddenWindow.SetTask(true); } else if (!parser.HasKey(_T("hidden"))) { hiddenWindow.ShowDialog(); } // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(hiddenWindow, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } if (!hiddenWindow.StopThread(2000)) { hiddenWindow.RemoveTrayIcon(); TerminateProcess(GetCurrentProcess(), 0); } } ::OleUninitialize(); sasl_done(); apr_terminate(); if ((snarlIface.GetVersionEx() != Snarl::M_FAILED)&&(Snarl::SnarlInterface::GetSnarlWindow() != NULL)) { // unregister with Snarl snarlIface.UnregisterApp(); } return (int) msg.wParam; }
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wcex; MSG nMsg; HFONT hfHelp; long lStyle; const char* lpWndClass = "CClock"; const char* lpTitle = ""; lWinWidth = 450; lWinHeight = 135; lDeskWidth = GetDeviceCaps(GetDC(GetDesktopWindow()), HORZRES); lDeskHeight = GetDeviceCaps(GetDC(GetDesktopWindow()), VERTRES); crWndColor = RGB(0, 0, 0); srand((unsigned)time(NULL)); // The WNDCLASSEX details wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_DROPSHADOW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = CreateSolidBrush(crWndColor); wcex.lpszMenuName = NULL; wcex.lpszClassName = lpWndClass; wcex.hIconSm = NULL; RegisterClassEx(&wcex); hWnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, lpWndClass, lpTitle, WS_POPUP, (lDeskWidth - lWinWidth)/2, (lDeskHeight - lWinHeight)/2, lWinWidth, lWinHeight, NULL, NULL, hInstance, NULL); hLblHelp = CreateWindowEx(WS_EX_TOOLWINDOW, "STATIC", "?", WS_CHILD | SS_NOTIFY, 440, -2, 25, 20, hWnd, NULL, hInstance, NULL); hfHelp = CreateFont(0, 6, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma"); SendMessage(hLblHelp, WM_SETFONT, (WPARAM)hfHelp, (LPARAM)TRUE); lOpacity = 255; lStyle = GetWindowLong(hWnd, GWL_EXSTYLE); SetWindowLong(hWnd, GWL_EXSTYLE, lStyle | WS_EX_LAYERED); SetLayeredWindowAttributes(hWnd, crWndColor, lOpacity, LWA_ALPHA); ShowWindow(hWnd, SW_SHOWNORMAL); ShowWindow(hLblHelp, SW_SHOWNORMAL); UpdateWindow(hWnd); SetTimer(hWnd, nIDTmr, 1000, TmrProc); fnParseTime(hWnd); while(GetMessage(&nMsg, NULL, 0, 0) > 0) { TranslateMessage(&nMsg); DispatchMessage(&nMsg); } DeleteObject(hfHelp); return nMsg.wParam; }
/* The main Win32 event handler */ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { extern int posted; switch (msg) { case WM_SYSKEYDOWN: case WM_KEYDOWN: { SDL_keysym keysym; #ifdef _WIN32_WCE // Drop GAPI artefacts if (wParam == 0x84 || wParam == 0x5B) return 0; // Rotate key if necessary if (this->hidden->orientation != SDL_ORIENTATION_UP) wParam = rotateKey(wParam, this->hidden->orientation); #endif /* Ignore repeated keys */ if ( lParam&REPEATED_KEYMASK ) { return(0); } switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ { Uint8 *state = SDL_GetKeyState(NULL); if (state[SDLK_LSHIFT] == SDL_RELEASED && (GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; } else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { /* Win9x */ int sc = HIWORD(lParam) & 0xFF; if (sc == 0x2A) wParam = VK_LSHIFT; else if (sc == 0x36) wParam = VK_RSHIFT; else wParam = VK_LSHIFT; } } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } #ifdef NO_GETKEYBOARDSTATE /* this is the workaround for the missing ToAscii() and ToUnicode() in CE (not necessary at KEYUP!) */ if ( SDL_TranslateUNICODE ) { MSG m; m.hwnd = hwnd; m.message = msg; m.wParam = wParam; m.lParam = lParam; m.time = 0; if ( TranslateMessage(&m) && PeekMessage(&m, hwnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) { GetMessage(&m, hwnd, 0, WM_USER); wParam = m.wParam; } } #endif /* NO_GETKEYBOARDSTATE */ posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } return(0); case WM_SYSKEYUP: case WM_KEYUP: { SDL_keysym keysym; #ifdef _WIN32_WCE // Drop GAPI artifacts if (wParam == 0x84 || wParam == 0x5B) return 0; // Rotate key if necessary if (this->hidden->orientation != SDL_ORIENTATION_UP) wParam = rotateKey(wParam, this->hidden->orientation); #endif switch (wParam) { case VK_CONTROL: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RCONTROL; else wParam = VK_LCONTROL; break; case VK_SHIFT: /* EXTENDED trick doesn't work here */ { Uint8 *state = SDL_GetKeyState(NULL); if (state[SDLK_LSHIFT] == SDL_PRESSED && !(GetKeyState(VK_LSHIFT) & 0x8000)) { wParam = VK_LSHIFT; } else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) { wParam = VK_RSHIFT; } else { /* Win9x */ int sc = HIWORD(lParam) & 0xFF; if (sc == 0x2A) wParam = VK_LSHIFT; else if (sc == 0x36) wParam = VK_RSHIFT; else wParam = VK_LSHIFT; } } break; case VK_MENU: if ( lParam&EXTENDED_KEYMASK ) wParam = VK_RMENU; else wParam = VK_LMENU; break; } /* Windows only reports keyup for print screen */ if ( wParam == VK_SNAPSHOT && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED ) { posted = SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(wParam,HIWORD(lParam),&keysym,1)); } posted = SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(wParam,HIWORD(lParam),&keysym,0)); } return(0); #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER) case WM_SYSCOMMAND: { const DWORD val = (DWORD) (wParam & 0xFFF0); if ((val == SC_SCREENSAVE) || (val == SC_MONITORPOWER)) { if (!this->hidden->allow_screensaver) { /* Note that this doesn't stop anything on Vista if the screensaver has a password. */ return(0); } } } /* Fall through to default processing */ #endif /* SC_SCREENSAVE && SC_MONITORPOWER */ default: { /* Only post the event if we're watching for it */ if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) { SDL_SysWMmsg wmmsg; SDL_VERSION(&wmmsg.version); wmmsg.hwnd = hwnd; wmmsg.msg = msg; wmmsg.wParam = wParam; wmmsg.lParam = lParam; posted = SDL_PrivateSysWMEvent(&wmmsg); /* DJM: If the user isn't watching for private messages in her SDL event loop, then pass it along to any win32 specific window proc. */ } else if (userWindowProc) { return CallWindowProc(userWindowProc, hwnd, msg, wParam, lParam); } } break; } return(DefWindowProc(hwnd, msg, wParam, lParam)); }
static LONG WINAPI exceptionPrinter( LPEXCEPTION_POINTERS ep ) { EnumWindows( enumWindowsForDisable,GetCurrentProcessId() ); #define DWARFSTACK_DIALOG_CLASS TEXT("dwarfstack_exception_dialog") WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = exceptionWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = DLGWINDOWEXTRA; wc.hInstance = GetModuleHandle( NULL ); wc.hIcon = NULL; wc.hCursor = LoadCursor( NULL,IDC_ARROW ); wc.hbrBackground = (HBRUSH)( COLOR_BTNFACE+1 ); wc.lpszMenuName = NULL; wc.lpszClassName = DWARFSTACK_DIALOG_CLASS; RegisterClass( &wc ); int sw = GetSystemMetrics( SM_CXSCREEN ); int sh = GetSystemMetrics( SM_CYSCREEN ); #define DLG_W 500 #define DLG_H 500 HWND hwnd = CreateWindow( DWARFSTACK_DIALOG_CLASS,TEXT("application crashed"), WS_CAPTION,(sw-DLG_W)/2,(sh-DLG_H)/2,DLG_W,DLG_H, NULL,NULL,GetModuleHandle(NULL),NULL ); RECT rect; GetClientRect( hwnd,&rect ); int w = rect.right - rect.left; int h = rect.bottom - rect.top; HWND textHwnd = CreateWindow( TEXT("edit"),TEXT(""), WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_BORDER|WS_HSCROLL|WS_VSCROLL| ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_READONLY, 0,0,w,h-32,hwnd,NULL,NULL,NULL ); CreateWindow( TEXT("button"),TEXT("OK"), WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_DEFPUSHBUTTON, (w-50)/2,h-28,50,24, hwnd,(HMENU)IDCANCEL,NULL,NULL ); #ifdef DWST_SHARED // needs -lgdi32 -> only in shared library HFONT font = GetStockObject( ANSI_FIXED_FONT ); if( font ) SendMessage( textHwnd,WM_SETFONT,(WPARAM)font,FALSE ); #endif { TCHAR exeName[MAX_PATH]; if( GetModuleFileName(GetModuleHandle(NULL),exeName,MAX_PATH) ) { Edit_ReplaceSel( textHwnd,TEXT("application:\r\n") ); Edit_ReplaceSel( textHwnd,exeName ); Edit_ReplaceSel( textHwnd,TEXT("\r\n\r\n") ); } } if( myExtraInfo ) { Edit_ReplaceSel( textHwnd,TEXT("extra information:\r\n") ); Edit_ReplaceSel( textHwnd,myExtraInfo ); Edit_ReplaceSel( textHwnd,TEXT("\r\n\r\n") ); } DWORD code = ep->ExceptionRecord->ExceptionCode; const TCHAR *desc = NULL; switch( code ) { #define EX_DESC( name ) \ case EXCEPTION_##name: desc = TEXT(" (") #name ")"; \ break EX_DESC( ACCESS_VIOLATION ); EX_DESC( ARRAY_BOUNDS_EXCEEDED ); EX_DESC( BREAKPOINT ); EX_DESC( DATATYPE_MISALIGNMENT ); EX_DESC( FLT_DENORMAL_OPERAND ); EX_DESC( FLT_DIVIDE_BY_ZERO ); EX_DESC( FLT_INEXACT_RESULT ); EX_DESC( FLT_INVALID_OPERATION ); EX_DESC( FLT_OVERFLOW ); EX_DESC( FLT_STACK_CHECK ); EX_DESC( FLT_UNDERFLOW ); EX_DESC( ILLEGAL_INSTRUCTION ); EX_DESC( IN_PAGE_ERROR ); EX_DESC( INT_DIVIDE_BY_ZERO ); EX_DESC( INT_OVERFLOW ); EX_DESC( INVALID_DISPOSITION ); EX_DESC( NONCONTINUABLE_EXCEPTION ); EX_DESC( PRIV_INSTRUCTION ); EX_DESC( SINGLE_STEP ); EX_DESC( STACK_OVERFLOW ); } TCHAR hexNum[20]; Edit_ReplaceSel( textHwnd,TEXT("code: 0x") ); _stprintf( hexNum,TEXT("%08lX"),code ); Edit_ReplaceSel( textHwnd,hexNum ); if( desc ) Edit_ReplaceSel( textHwnd,desc ); Edit_ReplaceSel( textHwnd,TEXT("\r\n") ); if( code==EXCEPTION_ACCESS_VIOLATION && ep->ExceptionRecord->NumberParameters==2 ) { ULONG_PTR flag = ep->ExceptionRecord->ExceptionInformation[0]; ULONG_PTR addr = ep->ExceptionRecord->ExceptionInformation[1]; Edit_ReplaceSel( textHwnd, flag==8?TEXT("data execution prevention"): (flag?TEXT("write access"):TEXT("read access")) ); Edit_ReplaceSel( textHwnd,TEXT(" violation at 0x") ); _stprintf( hexNum,TEXT("%p"),(void*)addr ); Edit_ReplaceSel( textHwnd,hexNum ); Edit_ReplaceSel( textHwnd,TEXT("\r\n") ); } Edit_ReplaceSel( textHwnd,TEXT("\r\n") ); struct dialog_info di = { 0,textHwnd,NULL }; dwstOfException( ep->ContextRecord,&dlgPrint,&di ); SendMessage( hwnd,WM_NEXTDLGCTL,(WPARAM)textHwnd,TRUE ); Edit_SetSel( textHwnd,0,0 ); ShowWindow( hwnd,SW_SHOW ); UpdateWindow( hwnd ); MSG msg; while( GetMessage(&msg,NULL,0,0) ) { if( IsDialogMessage(hwnd,&msg) ) continue; TranslateMessage( &msg ); DispatchMessage( &msg ); } return( EXCEPTION_EXECUTE_HANDLER ); }
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) { lpCmdLine = GetCommandLine(); // この行は _ATL_MIN_CRT のために必要です #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); #else HRESULT hRes = CoInitialize(NULL); #endif _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance, &LIBID_ATLDEVICEMANAGERLib); _Module.dwThreadID = GetCurrentThreadId(); TCHAR szTokens[] = _T("-/"); int nRet = 0; BOOL bRun = TRUE; LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, _T("UnregServer"))==0) { _Module.UpdateRegistryFromResource(IDR_ATLDeviceManager, FALSE); nRet = _Module.UnregisterServer(TRUE); bRun = FALSE; break; } if (lstrcmpi(lpszToken, _T("RegServer"))==0) { _Module.UpdateRegistryFromResource(IDR_ATLDeviceManager, TRUE); nRet = _Module.RegisterServer(TRUE); bRun = FALSE; break; } lpszToken = FindOneOf(lpszToken, szTokens); } if (bRun) { HWND dummy_dialog_handle = NULL; //::AllocConsole(); ProcessInstance = hInstance; dummy_dialog_handle = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DUMMYDIALOG), NULL, DummyDialogProc); ShowWindow(dummy_dialog_handle, SW_HIDE); _Module.StartMonitor(); #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); _ASSERTE(SUCCEEDED(hRes)); hRes = CoResumeClassObjects(); #else hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); #endif _ASSERTE(SUCCEEDED(hRes)); MSG msg; while (GetMessage(&msg, 0, 0, 0)) DispatchMessage(&msg); _Module.RevokeClassObjects(); Sleep(dwPause); //スレッドが終了するまで待ちます if(dummy_dialog_handle != NULL) ::DestroyWindow(dummy_dialog_handle); ::FreeConsole(); } _Module.Term(); CoUninitialize(); return nRet; }
int WINAPI WinMain3(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdToShow) { WNDCLASSEX wex = {0}; HWND hwnd; MSG msg; // Register the window class wex.cbSize = sizeof(WNDCLASSEX); wex.style = 0; wex.lpfnWndProc = WndProc; wex.cbClsExtra = 0; //extra data per class wex.cbWndExtra = 0; //extra data per window of this class wex.hInstance = hInst; //handle to app instance wex.hIcon = LoadIcon(hInst, IDI_APPLICATION); wex.hCursor = LoadCursor(NULL, IDC_ARROW); wex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wex.lpszMenuName = NULL; wex.lpszClassName = g_szClassName; wex.hIconSm = LoadIcon(hInst, IDI_APPLICATION); if (!RegisterClassEx(&wex)) { //first argument null: no owner window MessageBox(NULL, L"Window registration failed", L"Error", MB_ICONEXCLAMATION | MB_OK); return -1; } // Create the window hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, // client area has sunken border g_szClassName, L"Sample window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, //hWndParent: a handle to parent or owner window NULL, //hMenu: can be NULL if class menu is used hInst, NULL); //pointer to window creation data (rarely used) if (hwnd == NULL) { MessageBox(NULL, L"Create window failed", L"", MB_ICONEXCLAMATION | MB_OK); return -1; } ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd); // Handle message loop //if hWnd (second parameter) is NULL, it retrieves messages for any window //belonging to current thread or any message on the current thread with hwnd value of NULL //if hwnd is -1, then only thread messages while (GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } //while (GetMessage(&msg, NULL, 0, 0) > 0) //{ // WNDPROC fWndProc = (WNDPROC)GetWindowLong(msg.hwnd, GWL_WNDPROC); // if (fWndProc != NULL) fWndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); //} // set by PostQuitMessage. return msg.wParam; }
int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) { setCurrentThreadName("Main"); // Windows Vista and above: alert Windows that PPSSPP is DPI aware, // so that we don't flicker in fullscreen on some PCs. MakePPSSPPDPIAware(); // FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM (fixed in SP1). Just disable it. #ifdef _M_X64 _set_FMA3_enable(0); #endif EnableCrashingOnCrashes(); wchar_t modulePath[MAX_PATH]; GetModuleFileName(NULL, modulePath, MAX_PATH); for (size_t i = wcslen(modulePath) - 1; i > 0; i--) { if (modulePath[i] == '\\') { modulePath[i] = 0; break; } } SetCurrentDirectory(modulePath); // GetCurrentDirectory(MAX_PATH, modulePath); // for checking in the debugger #ifndef _DEBUG bool showLog = false; #else bool showLog = false; #endif VFSRegister("", new DirectoryAssetReader("assets/")); VFSRegister("", new DirectoryAssetReader("")); wchar_t lcCountry[256]; // LOCALE_SNAME is only available in WinVista+ // Really should find a way to do this in XP too :/ if (0 != GetLocaleInfo(LOCALE_NAME_USER_DEFAULT, LOCALE_SNAME, lcCountry, 256)) { langRegion = ConvertWStringToUTF8(lcCountry); for (size_t i = 0; i < langRegion.size(); i++) { if (langRegion[i] == '-') langRegion[i] = '_'; } } else { langRegion = "en_US"; } osName = GetWindowsVersion() + " " + GetWindowsSystemArchitecture(); char configFilename[MAX_PATH] = { 0 }; const std::wstring configOption = L"--config="; char controlsConfigFilename[MAX_PATH] = { 0 }; const std::wstring controlsOption = L"--controlconfig="; std::vector<std::wstring> wideArgs = GetWideCmdLine(); for (size_t i = 1; i < wideArgs.size(); ++i) { if (wideArgs[i][0] == L'\0') continue; if (wideArgs[i][0] == L'-') { if (wideArgs[i].find(configOption) != std::wstring::npos && wideArgs[i].size() > configOption.size()) { const std::wstring tempWide = wideArgs[i].substr(configOption.size()); const std::string tempStr = ConvertWStringToUTF8(tempWide); std::strncpy(configFilename, tempStr.c_str(), MAX_PATH); } if (wideArgs[i].find(controlsOption) != std::wstring::npos && wideArgs[i].size() > controlsOption.size()) { const std::wstring tempWide = wideArgs[i].substr(configOption.size()); const std::string tempStr = ConvertWStringToUTF8(tempWide); std::strncpy(configFilename, tempStr.c_str(), MAX_PATH); } } } // On Win32 it makes more sense to initialize the system directories here // because the next place it was called was in the EmuThread, and it's too late by then. InitSysDirectories(); // Load config up here, because those changes below would be overwritten // if it's not loaded here first. g_Config.AddSearchPath(""); g_Config.AddSearchPath(GetSysDirectory(DIRECTORY_SYSTEM)); g_Config.SetDefaultPath(GetSysDirectory(DIRECTORY_SYSTEM)); g_Config.Load(configFilename, controlsConfigFilename); bool debugLogLevel = false; // The rest is handled in NativeInit(). for (size_t i = 1; i < wideArgs.size(); ++i) { if (wideArgs[i][0] == L'\0') continue; if (wideArgs[i][0] == L'-') { switch (wideArgs[i][1]) { case L'l': showLog = true; g_Config.bEnableLogging = true; break; case L's': g_Config.bAutoRun = false; g_Config.bSaveSettings = false; break; case L'd': debugLogLevel = true; break; } if (wideArgs[i] == L"--fullscreen") g_Config.bFullScreen = true; if (wideArgs[i] == L"--windowed") g_Config.bFullScreen = false; } } #ifdef _DEBUG g_Config.bEnableLogging = true; #endif LogManager::Init(); // Consider at least the following cases before changing this code: // - By default in Release, the console should be hidden by default even if logging is enabled. // - By default in Debug, the console should be shown by default. // - The -l switch is expected to show the log console, REGARDLESS of config settings. // - It should be possible to log to a file without showing the console. LogManager::GetInstance()->GetConsoleListener()->Init(showLog, 150, 120, "PPSSPP Debug Console"); if (debugLogLevel) LogManager::GetInstance()->SetAllLogLevels(LogTypes::LDEBUG); //Windows, API init stuff INITCOMMONCONTROLSEX comm; comm.dwSize = sizeof(comm); comm.dwICC = ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES; InitCommonControlsEx(&comm); timeBeginPeriod(1); MainWindow::Init(_hInstance); g_hPopupMenus = LoadMenu(_hInstance, (LPCWSTR)IDR_POPUPMENUS); MainWindow::Show(_hInstance); HWND hwndMain = MainWindow::GetHWND(); HWND hwndDisplay = MainWindow::GetDisplayHWND(); //initialize custom controls CtrlDisAsmView::init(); CtrlMemView::init(); CtrlRegisterList::init(); CGEDebugger::Init(); DialogManager::AddDlg(vfpudlg = new CVFPUDlg(_hInstance, hwndMain, currentDebugMIPS)); host = new WindowsHost(hwndMain, hwndDisplay); host->SetWindowTitle(0); MainWindow::CreateDebugWindows(); // Emu thread is always running! EmuThread_Start(); InputDevice::BeginPolling(); HACCEL hAccelTable = LoadAccelerators(_hInstance, (LPCTSTR)IDR_ACCELS); HACCEL hDebugAccelTable = LoadAccelerators(_hInstance, (LPCTSTR)IDR_DEBUGACCELS); //so.. we're at the message pump of the GUI thread for (MSG msg; GetMessage(&msg, NULL, 0, 0); ) // for no quit { if (msg.message == WM_KEYDOWN) { //hack to enable/disable menu command accelerate keys MainWindow::UpdateCommands(); //hack to make it possible to get to main window from floating windows with Esc if (msg.hwnd != hwndMain && msg.wParam == VK_ESCAPE) BringWindowToTop(hwndMain); } //Translate accelerators and dialog messages... HWND wnd; HACCEL accel; switch (g_activeWindow) { case WINDOW_MAINWINDOW: wnd = hwndMain; accel = hAccelTable; break; case WINDOW_CPUDEBUGGER: wnd = disasmWindow[0] ? disasmWindow[0]->GetDlgHandle() : 0; accel = hDebugAccelTable; break; case WINDOW_GEDEBUGGER: default: wnd = 0; accel = 0; break; } if (!TranslateAccelerator(wnd, accel, &msg)) { if (!DialogManager::IsDialogMessage(&msg)) { //and finally translate and dispatch TranslateMessage(&msg); DispatchMessage(&msg); } } } VFSShutdown(); InputDevice::StopPolling(); EmuThread_Stop(); MainWindow::DestroyDebugWindows(); DialogManager::DestroyAll(); timeEndPeriod(1); delete host; g_Config.Save(); LogManager::Shutdown(); return 0; }
int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil) { MSG messages; globallog = new char[1];globallog[0]=32; globallogsize=1; backbar=0; // globallog = (char*)Mrealloc(2); wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon( hThisInstance, "A" ); wincl.hIconSm = wincl.hIcon; wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; memset(¬e,0,sizeof(note)); note.cbSize=sizeof(NOTIFYICONDATA); note.hWnd=hwnd; note.uID=0; note.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP; note.hIcon=wincl.hIcon; note.uCallbackMessage=WM_USER+5; lstrcpy(note.szTip,szClassName); if (!RegisterClassEx (&wincl)) return 0; RECT lp; GetWindowRect(GetDesktopWindow(),&lp); int w=GetSystemMetrics(SM_CXSCREEN); int h=GetSystemMetrics(SM_CYSCREEN); hwnd =CreateWindowEx (0,szClassName,"patterns",WS_CAPTION|WS_MINIMIZEBOX|WS_VISIBLE|WS_SYSMENU,lp.right-414,0,414,670,HWND_DESKTOP,NULL,hThisInstance,NULL);//CW_USEDEFAULT hlog =CreateWindowEx (0,"Edit","",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_NOHIDESEL|WS_VSCROLL,0,0,438,630,hwnd,NULL,hThisInstance,NULL); // hcmd =CreateWindowEx (0,"Edit","",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_NOHIDESEL|WS_VSCROLL,0,310,538,20,hwnd,NULL,hThisInstance,NULL); // hcmd =CreateWindowEx (WS_EX_CLIENTEDGE,"ListBox","",WS_CHILD|WS_VISIBLE|WS_VSCROLL|LVS_REPORT | LVS_SHAREIMAGELISTS,0,260,538,70,hwnd,NULL,hThisInstance,NULL); hpro =CreateWindowEx (0,"Static"," ",WS_CHILD | WS_VISIBLE,0,630,380,20,hwnd,NULL,hThisInstance,NULL); /* SendMessage( hcmd, LVM_FIRST+54, 0, 32 | 16 | 2 | 1); ListView_SetTextColor(hcmd,0x00000000); SendMessage( hcmd, LVM_SETTEXTBKCOLOR, 0, 0x00ffffef); ListView_SetBkColor(hcmd,0xffffef); ListBox_InsertString(hcmd,0,"MMCIS-Real"); ListBox_InsertString(hcmd,0,"MMCIS-Demo"); LV_ITEM lvi;//memset(&lvi,0,sizeof(LV_ITEM)); LV_COLUMN lvc; lvc.pszText="dfg"; lvc.cx=44; lvc.iSubItem=0; ListView_InsertColumn(hcmd,1,&lvc); ListBox_SetColumnWidth(hcmd,41); lvi.cchTextMax=22; lvi.iItem=0; lvi.lParam=0; lvi.iSubItem=1; lvi.mask=LVIF_PARAM; lstrcat(lvi.pszText," subitem "); //ListBox_InsertItemData(hcmd,0,&lvi); SendMessage(hcmd, LVM_SETITEM, 0, (LPARAM)&lvi); // lvi.mask=LVIF_TEXT; lvi.cchTextMax=12; lvi.iItem=0; lvi.lParam=1; lvi.iSubItem=1; // lstrcat(lvi.pszText," subitem "); ListBox_InsertItemData(hcmd,0,&lvi); SendMessage(hcmd, LVM_SETTEXTCOLOR, 0, (LPARAM)(COLORREF)0xff0f00ff); ListView_Update(hcmd,0); ListView_RedrawItems(hcmd,0,3); */ //mysqltest(); if(find(lpszArgument,"/quit"))ShowWindow (hwnd, SW_HIDE); else ShowWindow (hwnd, nFunsterStil); UpdateWindow(hwnd); srand(time(0)); if(find(lpszArgument,"/opt"))action=optimizing;else if(find(lpszArgument,"/test")){ action=testing; hbup =CreateWindowEx (0,"Button"," ",WS_CHILD | WS_VISIBLE,40,630,10,10,hwnd,NULL,hThisInstance,NULL); hbdn =CreateWindowEx (0,"Button"," ",WS_CHILD | WS_VISIBLE,40,640,10,10,hwnd,NULL,hThisInstance,NULL); hbackbar =CreateWindowEx (0,"Static"," ",WS_CHILD | WS_VISIBLE,20,630,20,20,hwnd,NULL,hThisInstance,NULL);title(whbackbar,intToStr(backbar)); }else if(find(lpszArgument,"/debug"))action=debuging; if(find(lpszArgument,"/1t"))period=1;else if(find(lpszArgument,"/5t"))period=5;else if(find(lpszArgument,"/15t"))period=15;else if(find(lpszArgument,"/60t"))period=60;else if(find(lpszArgument,"/240t"))period=240;else if(find(lpszArgument,"/1440t"))period=1440;else if(find(lpszArgument,"/10080t"))period=10080;else if(find(lpszArgument,"/43200t"))period=43200; mode=999; if(find2(lpszArgument,"/MMCIS-Demo"))mode=light;else if(find2(lpszArgument,"/MMCIS-Real"))mode=medium;else if(find2(lpszArgument,"/InstaForex-Demo.com"))mode=hard; if(find(lpszArgument,"/quit")){PostMessageA(hwnd,WM_SIZE,SIZE_MINIMIZED,0);GetMessage (&messages, NULL, 0, 0);TranslateMessage(&messages);DispatchMessage(&messages);} // server = new Server; // if(action==optimizing)server->on(false);else server->on(); if(mode==999)wlog("Optimization: patterns.exe /MMCIS-Demo /opt /1440t\r\nTesting: patterns.exe /MMCIS-Demo /test /1440t\r\nDebuging: patterns.exe /MMCIS-Demo /debug /1440t\r\n\r\naction: /opt,/test,/debug\r\nperiod: /1t,/5t,/15t,/60t,/240t,/1440t,/10080t,/43200t\r\nmode: /MMCIS-Demo,/MMCIS-Real,/InstaForex-Demo.com\r\n\r\nExample: mt5\\bases\\MetaQuotes-Demo\\history\\patterns.exe /MMCIS-Demo /opt /1440t\r\n"); else if(action!=optimizing)decode(action,period,mode,donottradecurrentbar,backbar); else decode(action,period,mode,tradecurrentbar,backbar); InvalidateRect(hwnd,0,true); if(!find(lpszArgument,"/quit")) while (GetMessage (&messages, NULL, 0, 0)) {if((messages.hwnd==hcmd)&&(messages.message==WM_KEYUP)&&messages.wParam==VK_RETURN)wcmd(cmdmain); if((messages.hwnd==hcmd)&&(messages.message==WM_LBUTTONDBLCLK))wlog(intToStr(ListBox_GetCurSel(hcmd) )); if((messages.hwnd==hbup)&&(messages.message==WM_LBUTTONUP)){backbar++;if(backbar>21)backbar=21;else title(whbackbar,intToStr(backbar));decode(action,period,mode,donottradecurrentbar,backbar);InvalidateRect(hwnd,0,true);} if((messages.hwnd==hbdn)&&(messages.message==WM_LBUTTONUP)){backbar--;if(backbar<-1)backbar=-1;else title(whbackbar,intToStr(backbar));decode(action,period,mode,donottradecurrentbar,backbar);InvalidateRect(hwnd,0,true);} TranslateMessage(&messages); DispatchMessage(&messages); } wlogsave(); if(find(lpszArgument,"/quit")){Shell_NotifyIcon(NIM_DELETE,¬e);GetMessage (&messages, NULL, 0, 0);TranslateMessage(&messages);DispatchMessage(&messages);} delete[] globallog; return messages.wParam; }
NOEXPORT int gui_loop() { #ifdef _WIN32_WCE WNDCLASS wc; #else WNDCLASSEX wc; #endif MSG msg; LPTSTR classname=TEXT("stunnel_main_window_class"); /* register the class */ #ifndef _WIN32_WCE wc.cbSize=sizeof wc; #endif wc.style=CS_VREDRAW|CS_HREDRAW; wc.lpfnWndProc=window_proc; wc.cbClsExtra=wc.cbWndExtra=0; wc.hInstance=ghInst; wc.hIcon=LoadIcon(ghInst, MAKEINTRESOURCE(IDI_STUNNEL_MAIN)); wc.hCursor=LoadCursor(NULL, IDC_ARROW); wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName=NULL; wc.lpszClassName=classname; #ifdef _WIN32_WCE RegisterClass(&wc); #else /* load 16x16 icon */ wc.hIconSm=LoadImage(ghInst, MAKEINTRESOURCE(IDI_STUNNEL_MAIN), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); RegisterClassEx(&wc); #endif /* create main window */ #ifdef _WIN32_WCE hwnd=CreateWindow(classname, win32_name, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, ghInst, NULL); #else main_menu_handle=LoadMenu(ghInst, MAKEINTRESOURCE(IDM_MAINMENU)); if(main_menu_handle && cmdline.service) { /* block unsafe operations in the service mode */ EnableMenuItem(main_menu_handle, IDM_EDIT_CONFIG, MF_GRAYED); EnableMenuItem(main_menu_handle, IDM_SAVE_LOG, MF_GRAYED); } hwnd=CreateWindow(classname, win32_name, WS_TILEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, main_menu_handle, ghInst, NULL); #endif /* auto-reset, non-signaled events */ main_initialized=CreateEvent(NULL, FALSE, FALSE, NULL); config_ready=CreateEvent(NULL, FALSE, FALSE, NULL); /* hwnd needs to be initialized before _beginthread() */ _beginthread(daemon_thread, DEFAULT_STACK_SIZE, NULL); WaitForSingleObject(main_initialized, INFINITE); /* logging subsystem is now available */ /* setup periodic event to trigger update_logs() */ SetTimer(NULL, 0, 1000, timer_proc); /* run callback once per second */ s_log(LOG_DEBUG, "GUI message loop initialized"); for(;;) switch(GetMessage(&msg, NULL, 0, 0)) { case -1: ioerror("GetMessage"); return 0; case 0: s_log(LOG_DEBUG, "GUI message loop terminated"); return (int)msg.wParam; default: TranslateMessage(&msg); DispatchMessage(&msg); } }
LONG WINAPI ImageView_CreateWindow(HWND hwnd, LPWSTR szFileName) { struct GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; WNDCLASS WndClass = {0}; TCHAR szBuf[512]; HWND hMainWnd; MSG msg; if (!ImageView_LoadSettings()) { shiSettings.Maximized = FALSE; shiSettings.Left = 0; shiSettings.Top = 0; shiSettings.Right = 520; shiSettings.Bottom = 400; } // Initialize GDI+ gdiplusStartupInput.GdiplusVersion = 1; gdiplusStartupInput.DebugEventCallback = NULL; gdiplusStartupInput.SuppressBackgroundThread = FALSE; gdiplusStartupInput.SuppressExternalCodecs = FALSE; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); pLoadImage(szFileName); // Create the window WndClass.lpszClassName = _T("shimgvw_window"); WndClass.lpfnWndProc = (WNDPROC)ImageView_WndProc; WndClass.hInstance = hInstance; WndClass.style = CS_HREDRAW | CS_VREDRAW; WndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); WndClass.hCursor = LoadCursor(hInstance, IDC_ARROW); WndClass.hbrBackground = (HBRUSH)COLOR_WINDOW; if (!RegisterClass(&WndClass)) return -1; LoadString(hInstance, IDS_APPTITLE, szBuf, sizeof(szBuf) / sizeof(TCHAR)); hMainWnd = CreateWindow(_T("shimgvw_window"), szBuf, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL); // Show it ShowWindow(hMainWnd, SW_SHOW); UpdateWindow(hMainWnd); // Message Loop while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessageW(&msg); } if (image) GdipDisposeImage(image); GdiplusShutdown(gdiplusToken); return -1; }
static void processEventsAndTimeouts(void) { do { #if defined(_WIN32) MSG event; if(!GetMessage(&event, NULL, 0, 0)) /* bail if no more messages */ exit(0); TranslateMessage(&event); /* translate virtual-key messages */ DispatchMessage(&event); /* call the window proc */ /* see win32_event.c for event (message) processing procedures */ #else static int mappedMenuButton; GLUTeventParser *parser; XEvent event, ahead; GLUTwindow *window; GLUTkeyboardCB keyboard; GLUTspecialCB special; int gotEvent, width, height; gotEvent = interruptibleXNextEvent(__glutDisplay, &event); if (gotEvent) { switch (event.type) { case MappingNotify: XRefreshKeyboardMapping((XMappingEvent *) & event); break; case ConfigureNotify: window = __glutGetWindow(event.xconfigure.window); if (window) { if (window->win != event.xconfigure.window) { /* Ignore ConfigureNotify sent to the overlay planes. GLUT could get here because overlays select for StructureNotify events to receive DestroyNotify. */ break; } width = event.xconfigure.width; height = event.xconfigure.height; if (width != window->width || height != window->height) { if (window->overlay) { XResizeWindow(__glutDisplay, window->overlay->win, width, height); } window->width = width; window->height = height; __glutSetWindow(window); /* Do not execute OpenGL out of sequence with respect to the XResizeWindow request! */ glXWaitX(); window->reshape(width, height); window->forceReshape = False; /* A reshape should be considered like posting a repair; this is necessary for the "Mesa glXSwapBuffers to repair damage" hack to operate correctly. Without it, there's not an initial back buffer render from which to blit from when damage happens to the window. */ __glutPostRedisplay(window, GLUT_REPAIR_WORK); } } break; case Expose: /* compress expose events */ while (XEventsQueued(__glutDisplay, QueuedAfterReading) > 0) { XPeekEvent(__glutDisplay, &ahead); if (ahead.type != Expose || ahead.xexpose.window != event.xexpose.window) { break; } XNextEvent(__glutDisplay, &event); } if (event.xexpose.count == 0) { GLUTmenu *menu; if (__glutMappedMenu && (menu = __glutGetMenu(event.xexpose.window))) { __glutPaintMenu(menu); } else { window = __glutGetWindow(event.xexpose.window); if (window) { if (window->win == event.xexpose.window) { __glutPostRedisplay(window, GLUT_REPAIR_WORK); } else if (window->overlay && window->overlay->win == event.xexpose.window) { __glutPostRedisplay(window, GLUT_OVERLAY_REPAIR_WORK); } } } } else { /* there are more exposes to read; wait to redisplay */ } break; case ButtonPress: case ButtonRelease: if (__glutMappedMenu && event.type == ButtonRelease && mappedMenuButton == event.xbutton.button) { /* Menu is currently popped up and its button is released. */ __glutFinishMenu(event.xbutton.window, event.xbutton.x, event.xbutton.y); } else { window = __glutGetWindow(event.xbutton.window); /* added button check for mice with > 3 buttons */ if (window) { GLUTmenu *menu; int menuNum; if (event.xbutton.button <= GLUT_MAX_MENUS) menuNum = window->menu[event.xbutton.button - 1]; else menuNum = 0; /* Make sure that __glutGetMenuByNum is only called if there really is a menu present. */ if ((menuNum > 0) && (menu = __glutGetMenuByNum(menuNum))) { if (event.type == ButtonPress && !__glutMappedMenu) { __glutStartMenu(menu, window, event.xbutton.x_root, event.xbutton.y_root, event.xbutton.x, event.xbutton.y); mappedMenuButton = event.xbutton.button; } else { /* Ignore a release of a button with a menu attatched to it when no menu is popped up, or ignore a press when another menu is already popped up. */ } } else if (window->mouse) { __glutSetWindow(window); __glutModifierMask = event.xbutton.state; window->mouse(event.xbutton.button - 1, event.type == ButtonRelease ? GLUT_UP : GLUT_DOWN, event.xbutton.x, event.xbutton.y); __glutModifierMask = ~0; } else { /* Stray mouse events. Ignore. */ } } else { /* Window might have been destroyed and all the events for the window may not yet be received. */ } } break; case MotionNotify: if (!__glutMappedMenu) { window = __glutGetWindow(event.xmotion.window); if (window) { /* If motion function registered _and_ buttons held * down, call motion function... */ if (window->motion && event.xmotion.state & (Button1Mask | Button2Mask | Button3Mask)) { __glutSetWindow(window); window->motion(event.xmotion.x, event.xmotion.y); } /* If passive motion function registered _and_ buttons not held down, call passive motion function... */ else if (window->passive && ((event.xmotion.state & (Button1Mask | Button2Mask | Button3Mask)) == 0)) { __glutSetWindow(window); window->passive(event.xmotion.x, event.xmotion.y); } } } else { /* Motion events are thrown away when a pop up menu is active. */ } break; case KeyPress: case KeyRelease: window = __glutGetWindow(event.xkey.window); if (!window) { break; } if (event.type == KeyPress) { keyboard = window->keyboard; } else { /* If we are ignoring auto repeated keys for this window, check if the next event in the X event queue is a KeyPress for the exact same key (and at the exact same time) as the key being released. The X11 protocol will send auto repeated keys as such KeyRelease/KeyPress pairs. */ if (window->ignoreKeyRepeat) { if (XEventsQueued(__glutDisplay, QueuedAfterReading)) { XPeekEvent(__glutDisplay, &ahead); if (ahead.type == KeyPress && ahead.xkey.window == event.xkey.window && ahead.xkey.keycode == event.xkey.keycode && ahead.xkey.time == event.xkey.time) { /* Pop off the repeated KeyPress and ignore the auto repeated KeyRelease/KeyPress pair. */ XNextEvent(__glutDisplay, &event); break; } } } keyboard = window->keyboardUp; } if (keyboard) { char tmp[1]; int rc; rc = XLookupString(&event.xkey, tmp, sizeof(tmp), NULL, NULL); if (rc) { __glutSetWindow(window); __glutModifierMask = event.xkey.state; keyboard(tmp[0], event.xkey.x, event.xkey.y); __glutModifierMask = ~0; break; } } if (event.type == KeyPress) { special = window->special; } else { special = window->specialUp; } if (special) { KeySym ks; int key; /* Introduced in X11R6: (Partial list of) Keypad Functions. Define in place in case compiling against an older pre-X11R6 X11/keysymdef.h file. */ #ifndef XK_KP_Home #define XK_KP_Home 0xFF95 #endif #ifndef XK_KP_Left #define XK_KP_Left 0xFF96 #endif #ifndef XK_KP_Up #define XK_KP_Up 0xFF97 #endif #ifndef XK_KP_Right #define XK_KP_Right 0xFF98 #endif #ifndef XK_KP_Down #define XK_KP_Down 0xFF99 #endif #ifndef XK_KP_Prior #define XK_KP_Prior 0xFF9A #endif #ifndef XK_KP_Next #define XK_KP_Next 0xFF9B #endif #ifndef XK_KP_End #define XK_KP_End 0xFF9C #endif #ifndef XK_KP_Insert #define XK_KP_Insert 0xFF9E #endif #ifndef XK_KP_Delete #define XK_KP_Delete 0xFF9F #endif ks = XLookupKeysym((XKeyEvent *) & event, 0); /* XXX Verbose, but makes no assumptions about keysym layout. */ switch (ks) { /* *INDENT-OFF* */ /* function keys */ case XK_F1: key = GLUT_KEY_F1; break; case XK_F2: key = GLUT_KEY_F2; break; case XK_F3: key = GLUT_KEY_F3; break; case XK_F4: key = GLUT_KEY_F4; break; case XK_F5: key = GLUT_KEY_F5; break; case XK_F6: key = GLUT_KEY_F6; break; case XK_F7: key = GLUT_KEY_F7; break; case XK_F8: key = GLUT_KEY_F8; break; case XK_F9: key = GLUT_KEY_F9; break; case XK_F10: key = GLUT_KEY_F10; break; case XK_F11: key = GLUT_KEY_F11; break; case XK_F12: key = GLUT_KEY_F12; break; /* directional keys */ case XK_KP_Left: case XK_Left: key = GLUT_KEY_LEFT; break; case XK_KP_Up: /* Introduced in X11R6. */ case XK_Up: key = GLUT_KEY_UP; break; case XK_KP_Right: /* Introduced in X11R6. */ case XK_Right: key = GLUT_KEY_RIGHT; break; case XK_KP_Down: /* Introduced in X11R6. */ case XK_Down: key = GLUT_KEY_DOWN; break; /* *INDENT-ON* */ case XK_KP_Prior: /* Introduced in X11R6. */ case XK_Prior: /* XK_Prior same as X11R6's XK_Page_Up */ key = GLUT_KEY_PAGE_UP; break; case XK_KP_Next: /* Introduced in X11R6. */ case XK_Next: /* XK_Next same as X11R6's XK_Page_Down */ key = GLUT_KEY_PAGE_DOWN; break; case XK_KP_Home: /* Introduced in X11R6. */ case XK_Home: key = GLUT_KEY_HOME; break; #ifdef __hpux case XK_Select: #endif case XK_KP_End: /* Introduced in X11R6. */ case XK_End: key = GLUT_KEY_END; break; #ifdef __hpux case XK_InsertChar: #endif case XK_KP_Insert: /* Introduced in X11R6. */ case XK_Insert: key = GLUT_KEY_INSERT; break; #ifdef __hpux case XK_DeleteChar: #endif case XK_KP_Delete: /* Introduced in X11R6. */ /* The Delete character is really an ASCII key. */ __glutSetWindow(window); assert(keyboard); keyboard(127, /* ASCII Delete character. */ event.xkey.x, event.xkey.y); goto skip; default: goto skip; } __glutSetWindow(window); __glutModifierMask = event.xkey.state; special(key, event.xkey.x, event.xkey.y); __glutModifierMask = ~0; skip:; } break; case EnterNotify: case LeaveNotify: if (event.xcrossing.mode != NotifyNormal || event.xcrossing.detail == NotifyNonlinearVirtual || event.xcrossing.detail == NotifyVirtual) { /* Careful to ignore Enter/LeaveNotify events that come from the pop-up menu pointer grab and ungrab. Also, ignore "virtual" Enter/LeaveNotify events since they represent the pointer passing through the window hierarchy without actually entering or leaving the actual real estate of a window. */ break; } if (__glutMappedMenu) { GLUTmenuItem *item; int num; item = __glutGetMenuItem(__glutMappedMenu, event.xcrossing.window, &num); if (item) { __glutMenuItemEnterOrLeave(item, num, event.type); break; } } window = __glutGetWindow(event.xcrossing.window); if (window) { if (window->entry) { if (event.type == EnterNotify) { /* With overlays established, X can report two enter events for both the overlay and normal plane window. Do not generate a second enter callback if we reported one without an intervening leave. */ if (window->entryState != EnterNotify) { int num = window->num; Window xid = window->win; window->entryState = EnterNotify; __glutSetWindow(window); window->entry(GLUT_ENTERED); if (__glutMappedMenu) { /* Do not generate any passive motion events when menus are in use. */ } else { /* An EnterNotify event can result in a "compound" callback if a passive motion callback is also registered. In this case, be a little paranoid about the possibility the window could have been destroyed in the entry callback. */ window = __glutWindowList[num]; if (window && window->passive && window->win == xid) { __glutSetWindow(window); window->passive(event.xcrossing.x, event.xcrossing.y); } } } } else { if (window->entryState != LeaveNotify) { /* When an overlay is established for a window already mapped and with the pointer in it, the X server will generate a leave/enter event pair as the pointer leaves (without moving) from the normal plane X window to the newly mapped overlay X window (or vice versa). This enter/leave pair should not be reported to the GLUT program since the pair is a consequence of creating (or destroying) the overlay, not an actual leave from the GLUT window. */ if (XEventsQueued(__glutDisplay, QueuedAfterReading)) { XPeekEvent(__glutDisplay, &ahead); if (ahead.type == EnterNotify && __glutGetWindow(ahead.xcrossing.window) == window) { XNextEvent(__glutDisplay, &event); break; } } window->entryState = LeaveNotify; __glutSetWindow(window); window->entry(GLUT_LEFT); } } } else if (window->passive) { __glutSetWindow(window); window->passive(event.xcrossing.x, event.xcrossing.y); } } break; case UnmapNotify: /* MapNotify events are not needed to maintain visibility state since VisibilityNotify events will be delivered when a window becomes visible from mapping. However, VisibilityNotify events are not delivered when a window is unmapped (for the window or its children). */ window = __glutGetWindow(event.xunmap.window); if (window) { if (window->win != event.xconfigure.window) { /* Ignore UnmapNotify sent to the overlay planes. GLUT could get here because overlays select for StructureNotify events to receive DestroyNotify. */ break; } markWindowHidden(window); } break; case VisibilityNotify: window = __glutGetWindow(event.xvisibility.window); if (window) { /* VisibilityUnobscured+1 = GLUT_FULLY_RETAINED, VisibilityPartiallyObscured+1 = GLUT_PARTIALLY_RETAINED, VisibilityFullyObscured+1 = GLUT_FULLY_COVERED. */ int visState = event.xvisibility.state + 1; if (visState != window->visState) { if (window->windowStatus) { window->visState = visState; __glutSetWindow(window); window->windowStatus(visState); } } } break; case ClientMessage: if (event.xclient.data.l[0] == __glutWMDeleteWindow) exit(0); break; case DestroyNotify: purgeStaleWindow(event.xdestroywindow.window); break; case CirculateNotify: case CreateNotify: case GravityNotify: case ReparentNotify: /* Uninteresting to GLUT (but possible for GLUT to receive). */ break; default: /* Pass events not directly handled by the GLUT main event loop to any event parsers that have been registered. In this way, X Input extension events are passed to the correct handler without forcing all GLUT programs to support X Input event handling. */ parser = eventParserList; while (parser) { if (parser->func(&event)) break; parser = parser->next; } break; } } #endif /* _WIN32 */ if (__glutTimerList) { handleTimeouts(); } } while (XPending(__glutDisplay)); }
int waitkeyinput_inter(bool direction_, bool immedity_) { if(immedity_) { if(isKeyinput()) return 1; else return 0; } MSG msg; if(game_over) throw 0; while(GetMessage(&msg,0,0,0)) { if(msg.message == WM_CHAR) { if(msg.wParam == 1) //A+컨트롤 { //if(shift_check) return 0x8B; //0x8B은 컨트롤A } if(msg.wParam == 16) //p+컨트롤 { //if(shift_check) return 0x88; //0x88은 컨트롤p } else if(msg.wParam == 17 ) //Q+컨트롤 { //if(shift_check) return 0x89; //0x89은 컨트롤Q } else if(msg.wParam == 19) //S+컨트롤 { //if(shift_check) return 0x8A; //0x8A은 컨트롤S } return msg.wParam; //엔터13 esc 27 } else if(msg.message == WM_KEYDOWN) { switch(msg.wParam) { case '8': if(direction_ || shift_check) break; //원래는 if(direction_)만있었는데 뭔가 꼬임 return (shift_check)?'*':'j'; case VK_UP: case VK_NUMPAD8: if(direction_) return VK_UP; return 'j'; break; case '4': if(direction_ || shift_check) break; return (shift_check)?'$':'h'; case VK_LEFT: case VK_NUMPAD4: if(direction_) return VK_LEFT; return 'h'; break; case '6': if(direction_ || shift_check) break; return (shift_check)?'^':'l'; case VK_RIGHT: case VK_NUMPAD6: if(direction_) return VK_RIGHT; return 'l'; break; case '2': if(direction_ || shift_check) break; return (shift_check)?'@':'k'; case VK_DOWN: case VK_NUMPAD2: if(direction_) return VK_DOWN; return 'k'; break; case '1': if(direction_ || shift_check) break; return (shift_check)?'!':'b'; case VK_NUMPAD1: case 35: return 'b'; case '3': if(direction_ || shift_check) break; return (shift_check)?'#':'n'; case 34: if(direction_) return 34; case VK_NUMPAD3: return 'n'; case '7': if(direction_ || shift_check) break; return (shift_check)?'&':'y'; case VK_NUMPAD7: case 36: return 'y'; case '9': if(direction_ || shift_check) break; return (shift_check)?'(':'u'; case 33: if(direction_) return 33; case VK_NUMPAD9: return 'u'; default: break; } if(msg.wParam == VK_SHIFT) shift_check = true; if(msg.wParam == VK_CONTROL) ctrl_check = true; } else if(msg.message == WM_KEYUP) { if(msg.wParam == VK_SHIFT) shift_check = false; if(msg.wParam == VK_CONTROL) ctrl_check = false; } } if(msg.message == WM_QUIT) { throw 0; } return 0; }