コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: smacdo/Hailstorm
/**
 * Handles window events that come from Windows.
 */
LRESULT MainWindow::HandleMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
    HWND hWnd = WindowHandle();
    int wmId = 0, wmEvent = 0;

    switch (message)
    {
        case WM_COMMAND:
            wmId = LOWORD(wParam);
            wmEvent = HIWORD(wParam);

            // Parse the menu selections:
            switch (wmId)
            {
                case IDM_ABOUT:
                    ShowAboutBox();
                    break;
                case IDM_EXIT:
                    this->Exit();
                    break;
                default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;

        case WM_ACTIVATE:
            SetPaused(LOWORD(wParam) == WA_INACTIVE);
            break;

        case WM_SIZE:
            if (wParam == SIZE_MINIMIZED)
            {
                SetPaused(true);
                SetMinimized(true);
            }
            else if (wParam == SIZE_MAXIMIZED)
            {
                // Unpause if we are coming out of a minimize
                if (IsMinimized())
                {
                    SetPaused(false);
                    SetMinimized(false);
                }

                SetWindowResized(Size{ LOWORD(lParam), HIWORD(lParam) });
            }
            else
            {
                // Unpause if we are coming out of a minimize
                if (IsMinimized())
                {
                    SetPaused(false);
                    SetMinimized(false);
                }

                SetWindowResized(Size{ LOWORD(lParam), HIWORD(lParam) });
            }
            break;

        case WM_POWERBROADCAST:
            if (wParam == PBT_APMQUERYSUSPEND)
            {
                // The application is about to be suspended. We should prepare for
                // this event by saving any data and then pausing the game loop
                // until we come out of suspension
            }
            else if (wParam == PBT_APMRESUMESUSPEND)
            {
                // The application is being resumed from suspension. We should
                // reload any saved data and unpause the game loop
            }

        case WM_ENTERMENULOOP:
            // Pause while user is in menu
            SetPaused(true);
            break;

        case WM_EXITMENULOOP:
            // Unpause after user has exited menu
            SetPaused(false);
            break;

        case WM_ENTERSIZEMOVE:
            SetIsWindowResizing(true);
            SetPaused(true);
            break;

        case WM_EXITSIZEMOVE:
            SetIsWindowResizing(false);
            SetPaused(false);
            break;

        case WM_CLOSE:
            PostQuitMessage(0);
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }

    return 0;
}
コード例 #2
0
ファイル: framewnd.c プロジェクト: HBelusca/NasuTek-Odyssey
/*******************************************************************************
 *
 *  FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
 *
 *  PURPOSE:  Processes WM_COMMAND messages for the main frame window.
 *
 */
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HKEY hKeyRoot = 0, hKey = 0;
    LPCTSTR keyPath;
    LPCTSTR valueName;
    BOOL result = TRUE;
    REGSAM regsam = KEY_READ;
    LONG lRet;
    int item;

    UNREFERENCED_PARAMETER(lParam);
    UNREFERENCED_PARAMETER(message);

    switch (LOWORD(wParam))
    {
    case ID_REGISTRY_LOADHIVE:
        LoadHive(hWnd);
        return TRUE;
    case ID_REGISTRY_UNLOADHIVE:
        UnloadHive(hWnd);
        return TRUE;
    case ID_REGISTRY_IMPORTREGISTRYFILE:
        ImportRegistryFile(hWnd);
        return TRUE;
    case ID_REGISTRY_EXPORTREGISTRYFILE:
        ExportRegistryFile(hWnd);
        return TRUE;
    case ID_REGISTRY_CONNECTNETWORKREGISTRY:
    {
        IDsObjectPicker *ObjectPicker;
        TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
        HRESULT hRet;

        hRet = CoInitialize(NULL);
        if (SUCCEEDED(hRet))
        {
            hRet = InitializeRemoteRegistryPicker(&ObjectPicker);
            if (SUCCEEDED(hRet))
            {
                hRet = InvokeRemoteRegistryPickerDialog(ObjectPicker,
                                                        hWnd,
                                                        szComputerName,
                                                        sizeof(szComputerName) / sizeof(szComputerName[0]));
                if (hRet == S_OK)
                {
                    /* FIXME - connect to the registry */
                }

                FreeObjectPicker(ObjectPicker);
            }

            CoUninitialize();
        }

        return TRUE;
    }
    case ID_REGISTRY_DISCONNECTNETWORKREGISTRY:
        return TRUE;
    case ID_REGISTRY_PRINT:
        PrintRegistryHive(hWnd, _T(""));
        return TRUE;
    case ID_REGISTRY_EXIT:
        DestroyWindow(hWnd);
        return TRUE;
    case ID_VIEW_STATUSBAR:
        toggle_child(hWnd, LOWORD(wParam), hStatusBar);
        return TRUE;
    case ID_HELP_HELPTOPICS:
        WinHelp(hWnd, _T("regedit"), HELP_FINDER, 0);
        return TRUE;
    case ID_HELP_ABOUT:
        ShowAboutBox(hWnd);
        return TRUE;
    case ID_VIEW_SPLIT:
    {
        RECT rt;
        POINT pt, pts;
        GetClientRect(g_pChildWnd->hWnd, &rt);
        pt.x = rt.left + g_pChildWnd->nSplitPos;
        pt.y = (rt.bottom / 2);
        pts = pt;
        if(ClientToScreen(g_pChildWnd->hWnd, &pts))
        {
            SetCursorPos(pts.x, pts.y);
            SetCursor(LoadCursor(0, IDC_SIZEWE));
            SendMessage(g_pChildWnd->hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(pt.x, pt.y));
        }
        return TRUE;
    }
    case ID_EDIT_RENAME:
    case ID_EDIT_MODIFY:
    case ID_EDIT_MODIFY_BIN:
    case ID_EDIT_DELETE:
        regsam |= KEY_WRITE;
        break;
    }

    keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
    valueName = GetValueName(g_pChildWnd->hListWnd, -1);
    if (keyPath)
    {
        lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, regsam, &hKey);
        if (lRet != ERROR_SUCCESS) hKey = 0;
    }

    switch (LOWORD(wParam))
    {
    case ID_EDIT_MODIFY:
        if (valueName && ModifyValue(hWnd, hKey, valueName, FALSE))
            RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
        break;
    case ID_EDIT_MODIFY_BIN:
        if (valueName && ModifyValue(hWnd, hKey, valueName, TRUE))
            RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
        break;
    case ID_EDIT_RENAME:
        if (GetFocus() == g_pChildWnd->hListWnd)
        {
            if(ListView_GetSelectedCount(g_pChildWnd->hListWnd) == 1)
            {
                item = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
                if(item > -1)
                {
                    (void)ListView_EditLabel(g_pChildWnd->hListWnd, item);
                }
            }
        }
        else if (GetFocus() == g_pChildWnd->hTreeWnd)
        {
            /* Get focused entry of treeview (if any) */
            HTREEITEM hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
            if (hItem != NULL)
                (void)TreeView_EditLabel(g_pChildWnd->hTreeWnd, hItem);
        }
        break;
    case ID_EDIT_DELETE:
    {
        if (GetFocus() == g_pChildWnd->hListWnd)
        {
            UINT nSelected = ListView_GetSelectedCount(g_pChildWnd->hListWnd);
            if(nSelected >= 1)
            {
                TCHAR msg[128], caption[128];
                LoadString(hInst, IDS_QUERY_DELETE_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR));
                LoadString(hInst, (nSelected == 1 ? IDS_QUERY_DELETE_ONE : IDS_QUERY_DELETE_MORE), msg, sizeof(msg)/sizeof(TCHAR));
                if(MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) == IDYES)
                {
                    int ni, errs;

                    item = -1;
                    errs = 0;
                    while((ni = ListView_GetNextItem(g_pChildWnd->hListWnd, item, LVNI_SELECTED)) > -1)
                    {
                        valueName = GetValueName(g_pChildWnd->hListWnd, item);
                        if(RegDeleteValue(hKey, valueName) != ERROR_SUCCESS)
                        {
                            errs++;
                        }
                        item = ni;
                    }

                    RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
                    if(errs > 0)
                    {
                        LoadString(hInst, IDS_ERR_DELVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR));
                        LoadString(hInst, IDS_ERR_DELETEVALUE, msg, sizeof(msg)/sizeof(TCHAR));
                        MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONSTOP);
                    }
                }
            }
        }
        else if (GetFocus() == g_pChildWnd->hTreeWnd)
        {
            if (keyPath == 0 || *keyPath == 0)
            {
                MessageBeep(MB_ICONHAND);
            }
            else if (DeleteKey(hWnd, hKeyRoot, keyPath))
            {
                DeleteNode(g_pChildWnd->hTreeWnd, 0);
                RefreshTreeView(g_pChildWnd->hTreeWnd);
            }
        }
        break;
    }
    case ID_EDIT_NEW_STRINGVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_SZ);
        break;
    case ID_EDIT_NEW_BINARYVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_BINARY);
        break;
    case ID_EDIT_NEW_DWORDVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_DWORD);
        break;
    case ID_EDIT_NEW_MULTISTRINGVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_MULTI_SZ);
        break;
    case ID_EDIT_NEW_EXPANDABLESTRINGVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_EXPAND_SZ);
        break;
    case ID_EDIT_FIND:
        FindDialog(hWnd);
        break;
    case ID_EDIT_FINDNEXT:
        FindNext(hWnd);
        break;
    case ID_EDIT_COPYKEYNAME:
        CopyKeyName(hWnd, hKeyRoot, keyPath);
        break;
    case ID_EDIT_PERMISSIONS:
        RegKeyEditPermissions(hWnd, hKeyRoot, NULL, keyPath);
        break;
    case ID_REGISTRY_PRINTERSETUP:
        /*PRINTDLG pd;*/
        /*PrintDlg(&pd);*/
        /*PAGESETUPDLG psd;*/
        /*PageSetupDlg(&psd);*/
        break;
    case ID_REGISTRY_OPENLOCAL:
        break;

    case ID_VIEW_REFRESH:
        RefreshTreeView(g_pChildWnd->hTreeWnd);
        /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
        break;
        /*case ID_OPTIONS_TOOLBAR:*/
        /*	toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
        /*    break;*/
    case ID_EDIT_NEW_KEY:
        CreateNewKey(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd));
        break;
    default:
        if ((LOWORD(wParam) >= ID_FAVORITES_MIN) && (LOWORD(wParam) <= ID_FAVORITES_MAX))
        {
            HMENU hMenu;
            MENUITEMINFO mii;
            TCHAR szFavorite[512];

            hMenu = GetSubMenu(GetMenu(hWnd), FAVORITES_MENU_POSITION);

            memset(&mii, 0, sizeof(mii));
            mii.cbSize = sizeof(mii);
            mii.fMask = MIIM_TYPE;
            mii.fType = MFT_STRING;
            mii.dwTypeData = szFavorite;
            mii.cch = sizeof(szFavorite) / sizeof(szFavorite[0]);

            if (GetMenuItemInfo(hMenu, LOWORD(wParam) - ID_FAVORITES_MIN, TRUE, &mii))
            {
                ChooseFavorite(szFavorite);
            }
        }
        else
        {
            result = FALSE;
        }
        break;
    }

    if(hKey)
        RegCloseKey(hKey);
    return result;
}
コード例 #3
0
ファイル: Daemon.cpp プロジェクト: runsoftdev/ultravnc
// Process window messages
LRESULT CALLBACK Daemon::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
	// This is a static method, so we don't know which instantiation we're 
	// dealing with. We have stored a pseudo-this in the window user data, 
	// though.
    Daemon *_this = helper::SafeGetWindowUserData<Daemon>(hwnd);

	switch (iMsg) {

	case WM_CREATE:
		{
			return 0;
		}

	case WM_SOCKEVENT:
		{
			assert(HIWORD(lParam) == 0);
			// A new socket created by accept might send messages to
			// this procedure. We can ignore them.
			if(wParam != _this->m_deamon_sock) {
				return 0;
			}

			switch(lParam) {
			case FD_ACCEPT:
				{
					struct sockaddr_in incoming;
					int size_incoming=sizeof(incoming);
					memset(&incoming, 0, sizeof(incoming));


					SOCKET hNewSock;
					hNewSock = accept(_this->m_deamon_sock, (struct sockaddr *)&incoming,&size_incoming);
					WSAAsyncSelect(hNewSock, hwnd, 0, 0);
					unsigned long nbarg = 0;
					ioctlsocket(hNewSock, FIONBIO, &nbarg);
					// Phil Money @ Advantig, LLC 7-9-2005
					if (ListenMode){ 

						pApp->NewConnection(true,hNewSock);

					}else{ 
						closesocket(hNewSock); 
						hNewSock = INVALID_SOCKET;
					} 
					
					break;
				}
			case FD_READ:
				{
					unsigned long numbytes=0;
					ioctlsocket(_this->m_deamon_sock, FIONREAD, &numbytes);
					recv(_this->m_deamon_sock, _this->netbuf, numbytes, 0);
					break;
				}
			case FD_CLOSE:
				vnclog.Print(5, _T("Daemon connection closed\n"));
				DestroyWindow(hwnd);
				break;
			}
			
			return 0;
		}
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case ID_NEWCONN:
			pApp->NewConnection(false);
			break;
		case IDC_OPTIONBUTTON:
			pApp->m_options.DoDialog();
			break;
		// Phil Money @ Advantig, LLC 7-9-2005
		case ID_LISTEN_MODE:
			if (GetListenMode()){ 
				SetListenMode(false); 
			}else{ 
				SetListenMode(true); 
			} 
			_this->CheckTrayIcon(); 
			break;
		case ID_CLOSEAPP:
			PostQuitMessage(0);
			//DestroyWindow(hwnd);
			break;
		case ID_CLOSEDAEMON:
			//if (_this->m_sock!=NULL) shutdown(_this->m_sock, SD_BOTH);
			//if (_this->m_sock!=NULL) closesocket(_this->m_sock);
			//_this->m_sock=NULL;
			break;
		case IDD_APP_ABOUT:
			ShowAboutBox();
			break;
		}
		return 0;
	case WM_TRAYNOTIFY:
		{
			HMENU hSubMenu = GetSubMenu(_this->m_hmenu, 0);
			if (lParam==WM_LBUTTONDBLCLK) {
				// double click: execute first menu item
				::SendMessage(_this->m_nid.hWnd, WM_COMMAND, 
					GetMenuItemID(hSubMenu, 0), 0);
			} else if (lParam==WM_RBUTTONUP) {
				if (hSubMenu == NULL) { 
					vnclog.Print(2, _T("No systray submenu\n"));
					return 0;
				}
				// Make first menu item the default (bold font)
				::SetMenuDefaultItem(hSubMenu, 0, TRUE);
				/*if (_this->m_sock==NULL){
					MENUITEMINFO pItem;
					ZeroMemory( &pItem, sizeof(pItem) );
					pItem.cbSize		= sizeof(pItem);
					pItem.fMask			= MIIM_TYPE;
					pItem.fType			= MFT_STRING;
					pItem.dwTypeData	= (LPTSTR)"Deamon closed !!!";

					SetMenuItemInfo( hSubMenu, 5, TRUE, &pItem );
					::SetMenuDefaultItem(hSubMenu, 5, TRUE);
				}*/
				
				// Display the menu at the current mouse location. There's a "bug"
				// (Microsoft calls it a feature) in Windows 95 that requires calling
				// SetForegroundWindow. To find out more, search for Q135788 in MSDN.
				//
				POINT mouse;
				GetCursorPos(&mouse);
				::SetForegroundWindow(_this->m_nid.hWnd);
				::TrackPopupMenu(hSubMenu, 0, mouse.x, mouse.y, 0,
					_this->m_nid.hWnd, NULL);
				
			} 
			return 0;
		}
	case WM_TIMER:
		_this->CheckTrayIcon();
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	
	return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
コード例 #4
0
ファイル: WinConsole.cpp プロジェクト: sanderjo/nzbget
void WinConsole::ShowMenu()
{
	POINT curPoint;
	GetCursorPos(&curPoint);
	SetForegroundWindow(m_trayWindow);

	UINT itemId = TrackPopupMenu(m_menu, TPM_RETURNCMD | TPM_NONOTIFY, curPoint.x, curPoint.y, 0, m_trayWindow, nullptr);

	switch(itemId)
	{
		case ID_SHOWWEBUI:
			ShowWebUI();
			break;

		case ID_SHOW_DESTDIR:
			ShowInExplorer(g_Options->GetDestDir());
			break;

		case ID_SHOW_INTERDIR:
			ShowInExplorer(g_Options->GetInterDir());
			break;

		case ID_SHOW_NZBDIR:
			ShowInExplorer(g_Options->GetNzbDir());
			break;

		case ID_SHOW_CONFIGFILE:
			ShowInExplorer(g_Options->GetConfigFilename());
			break;

		case ID_SHOW_LOGFILE:
			ShowInExplorer(g_Options->GetLogFile());
			break;

		case ID_SHOW_SCRIPTDIR:
			{
				CString firstScriptDir = g_Options->GetScriptDir();
				// Taking the first path from the list
				if (char* p = strpbrk(firstScriptDir, ";,")) *p = '\0';
				ShowInExplorer(firstScriptDir);
				break;
			}

		case ID_INFO_HOMEPAGE:
			ShellExecute(0, "open", "http://nzbget.net", nullptr, nullptr, SW_SHOWNORMAL);
			break;

		case ID_INFO_DOWNLOADS:
			ShellExecute(0, "open", "http://nzbget.net/download", nullptr, nullptr, SW_SHOWNORMAL);
			break;

		case ID_INFO_FORUM:
			ShellExecute(0, "open", "http://nzbget.net/forum", nullptr, nullptr, SW_SHOWNORMAL);
			break;

		case ID_ABOUT:
			ShowAboutBox();
			break;

		case ID_PREFERENCES:
			ShowPrefsDialog();
			break;

		case ID_EXIT:
			ExitProc();
			break;

		case ID_TROUBLESHOOTING_RESTART:
			mayStartBrowser = true;
			Reload();
			break;

		case ID_TROUBLESHOOTING_OPENCONFIG:
			OpenConfigFileInTextEdit();
			break;

		case ID_TROUBLESHOOTING_FACTORYRESET:
			ShowFactoryResetDialog();
			break;
	}

	if (itemId >= ID_SHOW_DESTDIR + 1000 && itemId < ID_SHOW_DESTDIR + 2000)
	{
		ShowCategoryDir(itemId - (ID_SHOW_DESTDIR + 1000));
	}
}
コード例 #5
0
ファイル: igra.c プロジェクト: borancar/ZTris
LRESULT CALLBACK TetrisWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	static DWORD start;
	HDC hDC;
	RECT izmjena;
	PAINTSTRUCT ps;
	tetris_data *data;
	char proc;

	data = (tetris_data *) (LONG_PTR)GetWindowLongPtr(hWnd, GWLP_USERDATA);

	switch(Msg)
	{
		case WM_ACTIVATE:
			{
				BOOL fActive;

				fActive = LOWORD(wParam);

				if(fActive == WA_ACTIVE || fActive == WA_CLICKACTIVE)
					SendMessage(hWnd, TET_PAUSE, 0, 0);

				if(fActive == WA_INACTIVE && !data->gover)
					SendMessage(hWnd, TET_PAUSE, 1, 0);
			}
			break;

		case TET_ODABERI_NIVO:
			{
				data->level = (int)wParam;
				if(data->bodlevel_prozor)
					SendMessage(data->bodlevel_prozor, BODLEVEL_POKAZI, (WPARAM) data->level, (LPARAM) data->bodovi);
				PokreniTimer(data, hWnd);
			}
			break;

		case TET_IDUCA_PROZOR:
			data->iduca_prozor = (HWND) wParam;
			break;

		case TET_BODLEVEL_PROZOR:
			data->bodlevel_prozor = (HWND) wParam;
			break;

		case TET_RESET:
			break;

		case TET_BODOVI:
			return data->bodovi;

		case TET_BODOVI_RETKA:
			data->bodovi_retka = (int)wParam;
			break;

		case TET_POCETNI_REDOVI:
			data->zapuni_redove = (int)wParam;
			brisi_polje(data);
			break;

		case TET_PADA_SA_SREDINE:
			data->pad_sa_sredine = !!wParam;
			break;

		case TET_ROTACIJA:
			if(wParam == ROTACIJA_CW)
				data->rotiraj = rot_figuru_cw;
			else if(wParam == ROTACIJA_CCW)
				data->rotiraj = rot_figuru_ccw;
			break;

		case TET_START:
			data->tfigure = rand() % NFIGURA + 1;
			data->iduca = rand() % NFIGURA + 1;

			pokazi_iducu(data);

			odaberi_figuru(data, data->tfigure);

			brisi_polje(data);

			if(data->bodlevel_prozor)
				SendMessage(data->bodlevel_prozor, BODLEVEL_POKAZI, (WPARAM) data->level, (LPARAM) data->bodovi);

			crtaj_polje(data);
			crtaj_figuru(data, data->rfigure, data->sfigure);
			break;

		case TET_STOP:
			KillTimer(hWnd, TIMER);
			break;

		case TET_IDUCA:
			return data->iduca;

		case TET_PAUSE:
			if (data->paused && !wParam) {
				PokreniTimer(data, hWnd);
				crtaj_polje(data);
				crtaj_figuru(data, data->rfigure, data->sfigure);
			} else if (!data->paused && wParam) {
				KillTimer(hWnd, TIMER);
				data->paused=1;
				ClearBuffer(data);

				BitBlt(data->hdcBuffer,
						(VELBLOKA*SPOLJA-data->bmPause.bmWidth)/2, (VELBLOKA*VPOLJA-data->bmPause.bmHeight)/2,
						data->bmPause.bmWidth, data->bmPause.bmHeight, data->hdcPause, 0, 0, SRCCOPY);
			}

			izmjena.left=0;
			izmjena.top=0;
			izmjena.right=VELBLOKA*SPOLJA;
			izmjena.bottom=VELBLOKA*VPOLJA;

			InvalidateRect(hWnd, &izmjena, FALSE);
			break;

		case TET_SLIKA_POZADINA:
			LoadBGImg(data, (wchar_t*)wParam);
			break;

		case TET_SLIKA_FIGURE:
			LoadFigureImg(data, (wchar_t*)wParam);
			break;

		case TET_SLIKA_PAUZE:
			LoadPauseImg(data, (wchar_t*)wParam);
			break;

		case TET_GAMEOVE_HANDLER:
			data->game_over_handler = (void(*)(int))wParam;
			break;

		case WM_LBUTTONDOWN:
#ifdef WINCE
			SendMessage(hWnd, TET_PAUSE, !data->paused, 0);
#else
			SendMessage(hWnd, TET_PAUSE, 0, 0);
#endif
			break;

#ifndef WINCE
		case WM_MOVING:
			{
				RECT *pos, offset;

				if(!data->gover && !data->paused)
					SendMessage(hWnd, TET_PAUSE, 1, 0);

				pos = (RECT *) lParam;

				SetWindowPos(data->iduca_prozor, HWND_NOTOPMOST, pos->right, pos->top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);

				GetWindowRect(data->iduca_prozor, &offset);

				SetWindowPos(data->bodlevel_prozor, HWND_NOTOPMOST, offset.left, offset.bottom, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
			}
			break;
#endif

		case WM_MOVE:
			{
				RECT offset;
				
				if(!data->gover && !data->paused)
					SendMessage(hWnd, TET_PAUSE, 1, 0);
			
				GetWindowRect(hWnd, &offset);

				SetWindowPos(data->iduca_prozor, HWND_NOTOPMOST, offset.right, offset.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);

				GetWindowRect(data->iduca_prozor, &offset);

				SetWindowPos(data->bodlevel_prozor, HWND_NOTOPMOST, offset.left, offset.bottom, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
			
				InvalidateRect(data->iduca_prozor, NULL, FALSE);
			}
			break;

		case WM_CREATE:
			{
				CREATESTRUCT *ccs;
				HBITMAP hbm = NULL;
				HDC hdcWindow = NULL;
				
				ccs = (CREATESTRUCT *) lParam;

				SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG)(LONG_PTR)ccs->lpCreateParams);

				data = ccs->lpCreateParams;

				hdcWindow = GetDC(hWnd);

				data->hdcBuffer = CreateCompatibleDC(hdcWindow);
				DeleteObject(SelectObject(data->hdcBuffer, CreateCompatibleBitmap(hdcWindow, SPOLJA * VELBLOKA, VPOLJA * VELBLOKA)));

				data->hdcPause = CreateCompatibleDC(hdcWindow);
				data->hdcFigure = CreateCompatibleDC(hdcWindow);
				data->hdcBackground = CreateCompatibleDC(hdcWindow);

				LoadBGImg(data, NULL);
				LoadFigureImg(data, NULL);
				LoadPauseImg(data, NULL);

				ReleaseDC(hWnd, hdcWindow);

				data->bodovi_retka = 10;
				data->level=1;
			}
			break;

		case WM_KEYDOWN:
			proc = 1;

			switch (wParam) {
				case 'P':
					if(!data->gover)
						SendMessage(hWnd, TET_PAUSE, !data->paused, 0);
					break;

				case 'A': {
					char biopauz;
					biopauz = data->paused;
					SendMessage(hWnd, TET_PAUSE, 1 && !data->gover, 0);
					ShowAboutBox(hWnd);
					SendMessage(hWnd, TET_PAUSE, biopauz && !data->gover, 0);
					break;
					}

				case 'R': {
					char biopauz;
					biopauz = data->paused;
					SendMessage(hWnd, TET_PAUSE, 1, 0);
					ShowRang(hWnd);
					SendMessage(hWnd, TET_PAUSE, biopauz, 0);
					break;
					}

				case VK_ESCAPE:
					SendMessage(hWnd, WM_CLOSE, 0, 0);
					break;

				default:
					proc=0;
					break;
			}

			if (proc || data->gover || data->paused) break;

			switch(wParam)
			{
				case VK_LEFT:
					if(stavi_figuru(data, data->rfigure, data->sfigure-1))
					{
						data->sfigure--;

						izmjena.left = data->sfigure * VELBLOKA;
						izmjena.right = (data->sfigure + (SFIGURA + 1)) * VELBLOKA;
						izmjena.top = data->rfigure;
						izmjena.bottom = (data->rfigure + RFIGURA) * VELBLOKA;
						
						InvalidateRect(hWnd, &izmjena, FALSE);
					}
					break;

				case VK_RIGHT:
					if(stavi_figuru(data, data->rfigure, data->sfigure+1))
					{
						data->sfigure++;

						izmjena.left = (data->sfigure - 1) * VELBLOKA;
						izmjena.right = (data->sfigure + SFIGURA) * VELBLOKA;
						izmjena.top = data->rfigure;
						izmjena.bottom = (data->rfigure + RFIGURA) * VELBLOKA;
						
						InvalidateRect(hWnd, &izmjena, FALSE);
					}
					break;

				case VK_DOWN:
					if(stavi_figuru(data, data->rfigure+1, data->sfigure))
					{
						data->rfigure++;

						izmjena.left = data->sfigure * VELBLOKA;
						izmjena.right = (data->sfigure + SFIGURA) * VELBLOKA;
						izmjena.top = data->rfigure;
						izmjena.bottom = (data->rfigure + RFIGURA) * VELBLOKA;
					
						InvalidateRect(hWnd, &izmjena, FALSE);					
					}
					else
						if(!dodaj_figuru(data, hWnd, data->rfigure, data->sfigure))
							game_over(data, hWnd);

					break;

#ifndef WINCE
				case VK_SPACE:
#else
				case VK_RETURN:
#endif
					{
						izmjena.left = data->sfigure * VELBLOKA;
						izmjena.right = (data->sfigure + SFIGURA) * VELBLOKA;
						izmjena.top = data->rfigure * VELBLOKA;
						izmjena.bottom = (data->rfigure + RFIGURA) * VELBLOKA;

						InvalidateRect(hWnd, &izmjena, FALSE);

						for(; stavi_figuru(data, data->rfigure+1, data->sfigure); data->rfigure++);

						izmjena.top = data->rfigure * VELBLOKA;
						izmjena.bottom = (data->rfigure + RFIGURA) * VELBLOKA;

						InvalidateRect(hWnd, &izmjena, FALSE);

						if(!dodaj_figuru(data, hWnd, data->rfigure, data->sfigure))
							game_over(data, hWnd);
					}
					break;

				case VK_UP:
					if(data->rotiraj(data, data->rfigure, data->sfigure))
					{
						izmjena.left = data->sfigure * VELBLOKA;
						izmjena.right = (data->sfigure + SFIGURA) * VELBLOKA;
						izmjena.top = data->rfigure * VELBLOKA;
						izmjena.bottom = (data->rfigure + RFIGURA) * VELBLOKA;

						InvalidateRect(hWnd, &izmjena, FALSE);
					}
					break;
			}

			if (!data->paused) {
				crtaj_polje(data);
				crtaj_figuru(data, data->rfigure, data->sfigure);
			}

#ifdef WINCE
			UpdateWindow(hWnd);
#endif		

			if(GetTickCount() - start <= data->spid)
				break;

		case WM_TIMER:
			{
				if(stavi_figuru(data, data->rfigure+1, data->sfigure))
					data->rfigure++;
				else
					if(!dodaj_figuru(data, hWnd, data->rfigure, data->sfigure))
					{
						game_over(data, hWnd);
						break;
					}

				izmjena.left = data->sfigure * VELBLOKA;
				izmjena.right = (data->sfigure + SFIGURA) * VELBLOKA;
				izmjena.top = data->rfigure-2;
				izmjena.bottom = (data->rfigure + (RFIGURA+1)) * VELBLOKA;

				InvalidateRect(hWnd, &izmjena, FALSE);

				crtaj_polje(data);
				crtaj_figuru(data, data->rfigure, data->sfigure);
				
				if(data->bodlevel_prozor)
					SendMessage(data->bodlevel_prozor, BODLEVEL_POKAZI, (WPARAM) data->level, (LPARAM) data->bodovi);

				start = GetTickCount();

#ifdef WINCE
				UpdateWindow(hWnd);
#endif		
			}
			break;

		case WM_PAINT:
			hDC = BeginPaint(hWnd, &ps);

			BitBlt(hDC, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left,
				ps.rcPaint.bottom - ps.rcPaint.top, data->hdcBuffer, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);
			
			EndPaint(hWnd, &ps);
			break;

		case WM_DESTROY:
			DestroyWindow(data->iduca_prozor);
			DestroyWindow(data->bodlevel_prozor);
			DeleteDC(data->hdcBuffer);
			DeleteDC(data->hdcFigure);
			DeleteDC(data->hdcPause);
			KillTimer(hWnd, TIMER);
			GlobalFree((HGLOBAL)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_USERDATA));
			PostQuitMessage(EXIT_SUCCESS);
			break;

		default:
			return DefWindowProc(hWnd, Msg, wParam, lParam);
	}

	return 0;
}
コード例 #6
0
ファイル: Daemon.cpp プロジェクト: bk138/CollabTool
// Process window messages
LRESULT CALLBACK Daemon::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
	// This is a static method, so we don't know which instantiation we're 
	// dealing with. We have stored a pseudo-this in the window user data, 
	// though.
	Daemon *_this = (Daemon *) GetWindowLong(hwnd, GWL_USERDATA);

	switch (iMsg) {

	case WM_CREATE:
		{
			return 0;
		}

	case WM_SOCKEVENT:
		{
			assert(HIWORD(lParam) == 0);
			// A new socket created by accept might send messages to
			// this procedure. We can ignore them.
			if(wParam != _this->m_sock) {
				return 0;
			}

			switch(lParam) {
			case FD_ACCEPT:
				{
					SOCKET hNewSock;
					hNewSock = accept(_this->m_sock, NULL, NULL);
					WSAAsyncSelect(hNewSock, hwnd, 0, 0);
					unsigned long nbarg = 0;
					ioctlsocket(hNewSock, FIONBIO, &nbarg);

					pApp->NewConnection(hNewSock);
					
					break;
				}
			case FD_READ:
				{
					unsigned long numbytes;
					ioctlsocket(_this->m_sock, FIONREAD, &numbytes);
					recv(_this->m_sock, _this->netbuf, numbytes, 0);
					break;
				}
			case FD_CLOSE:
				vnclog.Print(5, _T("Daemon connection closed\n"));
				DestroyWindow(hwnd);
				break;
			}
			
			return 0;
		}
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case ID_NEWCONN:
			pApp->NewConnection();
			break;
		case IDC_OPTIONBUTTON:
			pApp->m_options.DoDialog();
			pApp->m_options.SaveOpt(".listen", KEY_VNCVIEWER_HISTORI);
			break;
		case ID_CLOSEDAEMON:
			PostQuitMessage(0);
			break;
		case IDD_APP_ABOUT:
			ShowAboutBox();
			break;
		}
		return 0;
	case WM_TRAYNOTIFY:
		{
			HMENU hSubMenu = GetSubMenu(_this->m_hmenu, 0);
			if (lParam==WM_LBUTTONDBLCLK) {
				// double click: execute first menu item
				::SendMessage(_this->m_nid.hWnd, WM_COMMAND, 
					GetMenuItemID(hSubMenu, 0), 0);
			} else if (lParam==WM_RBUTTONUP) {
				if (hSubMenu == NULL) { 
					vnclog.Print(2, _T("No systray submenu\n"));
					return 0;
				}
				// Make first menu item the default (bold font)
				::SetMenuDefaultItem(hSubMenu, 0, TRUE);
				
				// Display the menu at the current mouse location. There's a "bug"
				// (Microsoft calls it a feature) in Windows 95 that requires calling
				// SetForegroundWindow. To find out more, search for Q135788 in MSDN.
				//
				POINT mouse;
				GetCursorPos(&mouse);
				::SetForegroundWindow(_this->m_nid.hWnd);
				::TrackPopupMenu(hSubMenu, 0, mouse.x, mouse.y, 0,
					_this->m_nid.hWnd, NULL);
				
			} 
			return 0;
		}
	case WM_TIMER:
		_this->CheckTrayIcon();
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	
	return DefWindowProc(hwnd, iMsg, wParam, lParam);
}