Example #1
0
void ViewPort::DrawActiveDomain( double pixel_size, double offset_x, double offset_y )
{
	Transform *transform;								// render all transforms in section
	HPEN pen, oldpen;
	HBRUSH brush, oldbrush;
	LOGBRUSH lbrush;
	int oldmode, i, x, y, numpts;
	Contour *contour, *c;
	Point *p;
	POINT *lpPoints;

	if ( section && viewDC )							// need a drawing surface for domain contour
	  if ( section->active )							// do only if have an active transform
		{
		transform = section->active;
		if ( transform->domain )						// do only if have domain
			{
			contour = transform->domain;
			if ( contour->points )
				{
				c = new Contour( *contour );					// copy the contour
																// if image, then contour is in pixels
				if ( transform->image ) c->Scale( transform->image->mag );
				c->InvNform( transform->nform );				// transform into section
				c->Shift( -offset_x, -offset_y );				// shift into view
				c->Scale( 1.0/pixel_size );						// scale to view's pixels
					
				numpts = c->points->Number();
				lpPoints = new POINT[ numpts ];					// create Window POINT array for drawing

				i = 0;
				p = c->points->first;
				while ( p != NULL )
					{
					lpPoints[i].x = (int)floor(p->x);
					lpPoints[i].y = height - (int)floor(p->y);
					i++;
					p = p->next;
					}
																// create pen for border of object
				pen = CreatePen( PS_SOLID, 1, c->border.ref() );
				oldpen = (HPEN)SelectObject( viewDC, pen );		// set pen into device context

				if ( c->mode < 0 )
					{
					brush = CreateSolidBrush( c->fill.ref() );	// interior will be filled
					oldbrush = (HBRUSH)SelectObject( viewDC, brush );
					SetROP2( viewDC, abs(c->mode) );			// using contour fill mode and color
					Polygon( viewDC, lpPoints, numpts );
					SelectObject( viewDC, oldbrush );			// clean up fill brush
					DeleteObject(brush);
					}

				SelectObject( viewDC, (HBRUSH)GetStockObject(NULL_BRUSH) );	// without coloring interior
				SetROP2( viewDC, R2_COPYPEN );								// draw contour border with pen
				if ( c->closed ) Polygon( viewDC, lpPoints, numpts );
				else Polyline( viewDC, lpPoints, numpts );
				
				SelectObject( viewDC, oldpen );					// clean up pen
				DeleteObject(pen);
				delete[] lpPoints;								// and dynamic memory
				delete c;
				}
			}
		}

}
Example #2
0
BOOL MusicUtils::SaveBitMapToFile(HBITMAP hBitmap, CString lpFileName)
{
	HDC		hDC;		//?????       
	int		iBits;		//?????????????????   
	WORD	wBitCount;	//????????????   
	DWORD	dwPaletteSize=0,//???????,?????????,??????,???????
		dwBmBitsSize,
		dwDIBSize,
		dwWritten;
	BITMAP	Bitmap;      
	BITMAPFILEHEADER	bmfHdr;	//??????
	BITMAPINFOHEADER	bi;		//???????                
	LPBITMAPINFOHEADER	lpbi;	//???????           
	HANDLE	fh,   hDib,   hPal,hOldPal=NULL;//?????????,????,??????,?????
	//???????????????   
	hDC = CreateDC(_T("DISPLAY"),NULL,NULL,NULL);   
	iBits = GetDeviceCaps(hDC,BITSPIXEL)*GetDeviceCaps(hDC,PLANES);   
	DeleteDC(hDC);
	if(iBits<=1)   
		wBitCount = 1;   
	else if(iBits<=4)   
		wBitCount = 4;   
	else if(iBits<=8)   
		wBitCount = 8;
	else if(iBits<=24)   
		wBitCount = 24;
	else
		wBitCount = 32;
	//???????   
	if(wBitCount<=8)   
		dwPaletteSize = (1<<wBitCount)*sizeof(RGBQUAD);   

	//?????????
	GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);   
	bi.biSize = sizeof(BITMAPINFOHEADER);
	bi.biWidth = Bitmap.bmWidth;   
	bi.biHeight = Bitmap.bmHeight;   
	bi.biPlanes = 1;   
	bi.biBitCount = wBitCount;   
	bi.biCompression = BI_RGB;   
	bi.biSizeImage = 0;   
	bi.biXPelsPerMeter = 0;   
	bi.biYPelsPerMeter = 0;   
	bi.biClrUsed = 0;   
	bi.biClrImportant = 0;   

	dwBmBitsSize = ((Bitmap.bmWidth*wBitCount+31)/32)*4*Bitmap.bmHeight;   

	//?????????   
	hDib = GlobalAlloc(GHND,dwBmBitsSize+dwPaletteSize+sizeof(BITMAPINFOHEADER));   
	lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);   
	*lpbi = bi;   

	//   ?????         
	hPal = GetStockObject(DEFAULT_PALETTE);   
	if(hPal)
	{   
		hDC = ::GetDC(NULL);   
		hOldPal = SelectPalette(hDC, (HPALETTE)hPal, FALSE);   
		RealizePalette(hDC);  
	}   

	//   ????????????   
	GetDIBits(hDC, hBitmap, 0, (UINT)Bitmap.bmHeight,
		(LPSTR)lpbi+sizeof(BITMAPINFOHEADER)+dwPaletteSize,
		(LPBITMAPINFO)lpbi,DIB_RGB_COLORS);   

	//?????         
	if(hOldPal)
	{
		SelectPalette(hDC,(HPALETTE)hOldPal,TRUE);
		RealizePalette(hDC);
		::ReleaseDC(NULL, hDC);
	}   

	//??????           
	fh = CreateFile(lpFileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL);

	if(fh==INVALID_HANDLE_VALUE)
		return   FALSE;

	//   ???????   
	bmfHdr.bfType = 0x4D42;//   "BM"   
	dwDIBSize = sizeof(BITMAPFILEHEADER)+
		sizeof(BITMAPINFOHEADER)+
		dwPaletteSize+dwBmBitsSize;
	bmfHdr.bfSize = dwDIBSize;
	bmfHdr.bfReserved1 = 0;
	bmfHdr.bfReserved2 = 0;
	bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER)+
		(DWORD)sizeof(BITMAPINFOHEADER)+dwPaletteSize;

	//   ???????
	WriteFile(fh,(LPSTR)&bmfHdr,sizeof(BITMAPFILEHEADER),&dwWritten,NULL);
	//   ??????????
	WriteFile(fh,(LPSTR)lpbi,dwDIBSize,&dwWritten,NULL);

	//??????
	GlobalUnlock(hDib);
	GlobalFree(hDib);
	CloseHandle(fh);
	return   TRUE;
}
/**
* Responsible for drawing each list item.
*/
void ToggleListView::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) {

	CListCtrl& ListCtrl=GetListCtrl();
	int nItem = lpDrawItemStruct->itemID;
	
	// get item data
	LV_ITEM lvi;
	_TCHAR szBuff[MAX_PATH];
	
	memset(&lvi, 0, sizeof(LV_ITEM));
	lvi.mask = LVIF_TEXT;
	lvi.iItem = nItem;
	lvi.pszText = szBuff;
	lvi.cchTextMax = sizeof(szBuff);
	ListCtrl.GetItem(&lvi);

	RECT rDraw;
	
	
	CopyRect ( &rDraw, &lpDrawItemStruct->rcItem );
	rDraw.right = rDraw.left + TOGGLELIST_ITEMHEIGHT;
	rDraw.top ++;

	rDraw.right ++;
	FrameRect ( lpDrawItemStruct->hDC, &rDraw, (HBRUSH)GetStockObject ( BLACK_BRUSH ) );
	rDraw.right --;

	FillRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_3DFACE ) );

	Draw3dRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_3DHILIGHT ), GetSysColorBrush ( COLOR_3DSHADOW ) );

	InflateRect ( &rDraw, -3, -3 );
	Draw3dRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_3DSHADOW ), GetSysColorBrush ( COLOR_3DHILIGHT ) );

	switch(GetToggleState(lvi.iItem)) {
		case TOGGLE_STATE_DISABLED:
			if(disabledIcon) {
				DrawIconEx ( lpDrawItemStruct->hDC, rDraw.left, rDraw.top, disabledIcon, 16, 16,0, NULL, DI_NORMAL );
			}
			break;
		case TOGGLE_STATE_ON:
			if(onIcon) {
				DrawIconEx ( lpDrawItemStruct->hDC, rDraw.left, rDraw.top, onIcon, 16, 16,0, NULL, DI_NORMAL );
			}
			break;
		case TOGGLE_STATE_OFF:
			if(offIcon) {
				DrawIconEx ( lpDrawItemStruct->hDC, rDraw.left, rDraw.top, offIcon, 16, 16,0, NULL, DI_NORMAL );
			}
			break;
	};
	
	CopyRect ( &rDraw, &lpDrawItemStruct->rcItem );
	rDraw.left += TOGGLELIST_ITEMHEIGHT;
	rDraw.left += 1;

	if ( lpDrawItemStruct->itemState & ODS_SELECTED ) {
		FillRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_HIGHLIGHT ) );			
	} else {
		FillRect ( lpDrawItemStruct->hDC, &rDraw, GetSysColorBrush ( COLOR_WINDOW ) ); 
	}

	rDraw.left += TEXT_OFFSET;

	int colorIndex = ( (lpDrawItemStruct->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT );
	SetTextColor ( lpDrawItemStruct->hDC, GetSysColor ( colorIndex ) );
	DrawText ( lpDrawItemStruct->hDC, szBuff, strlen(szBuff), &rDraw, DT_LEFT|DT_VCENTER|DT_SINGLELINE );

}
Example #4
0
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow)
{
    HWND hwnd;
    MSG msg;
    WNDCLASSEX wndclassex = {0};

    // Fill the WNDCLASSEX fields we care about
    wndclassex.cbSize = sizeof(WNDCLASSEX);
    wndclassex.style = CS_HREDRAW | CS_VREDRAW; // Redraw the window if it's position or size changes
    wndclassex.lpfnWndProc = WinProc;
    wndclassex.hInstance = hinstance;
    wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // Make the window background white
    wndclassex.lpszClassName = kClassName;
    wndclassex.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR,
                                            0, 0, LR_SHARED); // Load the default arrow cursor

    RegisterClassEx(&wndclassex); // Register the WNDCLASSEX with the OS

    // Here we set the style of the window
    // Notice how we use the style WS_VSCROLL, this creates the window with a
    // vertical scroll bar
    DWORD style = WS_SYSMENU | WS_VSCROLL;

    // Create the window
    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, // Our Window has a border with a sunken edge
                          kClassName,
                          "www.GameTutorials.com -- Vertical Scroll Bar",
                          style, // Style of window
                          CW_USEDEFAULT, // Windows picks upper-left X-pos of window
                          CW_USEDEFAULT, // Windows picks upper-left Y-pos of window
                          kWinWid,
                          kWinHgt,
                          NULL,
                          NULL,
                          hinstance,
                          NULL);

    // Error Check
    if(hwnd == NULL)
        return EXIT_FAILURE; // Couldn't create the window

    // Load a the text file for displaying
    if(!LoadTextFile("VerticalText.txt"))
        return EXIT_FAILURE; // No text file, no tutorial

    // Show and update the window
    ShowWindow(hwnd, ishow);
    UpdateWindow(hwnd);

    while(1)
    {
        // Checking for window messages -- If we get one we'll deal with it
        if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
            if(msg.message == WM_QUIT)
                break;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            // This is where the core of our application would go if we were writing one...
        }

    } // end of while(1)

    UnregisterClass(kClassName,hinstance); // Free up memory
    return msg.wParam;
}
Example #5
0
void InterfaceCreateTabControl(HWND hwnd) 
{ 
    TC_ITEM tie; 
    char s[100];
    HWND hwndCtl;
    LOGFONT lf;
    HFONT font;
    
    hwndTab = GetDlgItem(hwndMain,IDC_TAB_MAIN);
	
    tie.mask = TCIF_TEXT | TCIF_IMAGE; 
    tie.iImage = -1; 
    tie.pszText = s;
	
    tie.pszText = "&Status";
    TabCtrl_InsertItem(hwndTab,0, &tie);
    tie.pszText = "&Channels";
    TabCtrl_InsertItem(hwndTab,1, &tie);
    tie.pszText = "&Administration";
    TabCtrl_InsertItem(hwndTab,2, &tie);
	
    tab_pages[0] = CreateDialog(hInst,MAKEINTRESOURCE(IDD_TAB_PAGE_STATUS),hwndTab,
		InterfaceDialogTabPage);
    tab_pages[1] = CreateDialog(hInst,MAKEINTRESOURCE(IDD_TAB_PAGE_CHANNELS),hwndTab,
		InterfaceDialogTabPage);
    tab_pages[2] = CreateDialog(hInst,MAKEINTRESOURCE(IDD_TAB_PAGE_ADMINISTRATION),hwndTab,
		InterfaceDialogTabPage);
	
    /* keep about box page ready */
    tab_about = CreateDialog(hInst,MAKEINTRESOURCE(IDD_ABOUT),hwnd,
			     InterfaceDialogAbout);
	
	
    /* set admin page font */
    hwndCtl = GetDlgItem(HWND_ADMIN,IDC_ADMIN_RESPONSE);
    SendMessage(hwndCtl,WM_SETFONT,(WPARAM)GetStockObject(ANSI_FIXED_FONT),
		MAKELPARAM(TRUE,0));
	
    lf.lfHeight = 8;
    lf.lfWidth = 0;
    lf.lfEscapement = 0;
    lf.lfOrientation = 0;
    lf.lfWeight = 400;
    lf.lfItalic = 0; 
    lf.lfUnderline = 0;
    lf.lfStrikeOut = 0;
    lf.lfCharSet = 255;
    lf.lfOutPrecision = 1;
    lf.lfClipPrecision = 2;
    lf.lfQuality = 1;
    lf.lfPitchAndFamily = 49;
    strcpy(lf.lfFaceName,"Terminal");
    
    font = CreateFontIndirect(&lf);
    if (font != NULL)
    {
		SendMessage(hwndCtl,WM_SETFONT,(WPARAM)font,MAKELPARAM(TRUE,0));
    }

    /* Set text buffer to be large */
    SendMessage(hwndCtl, EM_EXLIMITTEXT, ADMIN_RESPONSE_SIZE, 0);
    
    lpfnDefAdminResponseProc = SubclassWindow(hwndCtl,InterfaceAdminResponseProc);
	
    hwndCtl = GetDlgItem(HWND_ADMIN,IDC_ADMIN_COMMAND);
    lpfnDefAdminInputProc = SubclassWindow(hwndCtl,InterfaceAdminInputProc);
	
    hwndTab_page = NULL;
	
    InterfaceTabChange();
}
Example #6
0
Bool
winCreateBoundingWindowWindowed(ScreenPtr pScreen)
{
    winScreenPriv(pScreen);
    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
    int iWidth = pScreenInfo->dwUserWidth;
    int iHeight = pScreenInfo->dwUserHeight;
    int iPosX;
    int iPosY;
    HWND *phwnd = &pScreenPriv->hwndScreen;
    WNDCLASSEX wc;
    RECT rcClient, rcWorkArea;
    DWORD dwWindowStyle;
    BOOL fForceShowWindow = FALSE;
    char szTitle[256];

    winDebug("winCreateBoundingWindowWindowed - User w: %d h: %d\n",
             (int) pScreenInfo->dwUserWidth, (int) pScreenInfo->dwUserHeight);
    winDebug("winCreateBoundingWindowWindowed - Current w: %d h: %d\n",
             (int) pScreenInfo->dwWidth, (int) pScreenInfo->dwHeight);

    /* Set the common window style flags */
    dwWindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;

    /* Decorated or undecorated window */
    if (pScreenInfo->fDecoration
#ifdef XWIN_MULTIWINDOWEXTWM
        && !pScreenInfo->fMWExtWM
#endif
        && !pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
        && !pScreenInfo->fMultiWindow
#endif
        ) {
        /* Try to handle startup via run.exe. run.exe instructs Windows to
         * hide all created windows. Detect this case and make sure the
         * window is shown nevertheless */
        STARTUPINFO startupInfo;

        GetStartupInfo(&startupInfo);
        if (startupInfo.dwFlags & STARTF_USESHOWWINDOW &&
            startupInfo.wShowWindow == SW_HIDE) {
            fForceShowWindow = TRUE;
        }
        dwWindowStyle |= WS_CAPTION;
        if (pScreenInfo->iResizeMode != notAllowed)
            dwWindowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
    }
    else
        dwWindowStyle |= WS_POPUP;

    /* Setup our window class */
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = winWindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = g_hInstance;
    wc.hIcon =
        (HICON) LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
                          GetSystemMetrics(SM_CXICON),
                          GetSystemMetrics(SM_CYICON), 0);
    wc.hCursor = 0;
    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = WINDOW_CLASS;
    wc.hIconSm =
        (HICON) LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
                          GetSystemMetrics(SM_CXSMICON),
                          GetSystemMetrics(SM_CYSMICON), LR_DEFAULTSIZE);
    RegisterClassEx(&wc);

    /* Get size of work area */
    winGetWorkArea(&rcWorkArea, pScreenInfo);

    /* Adjust for auto-hide taskbars */
    winAdjustForAutoHide(&rcWorkArea, pScreenInfo);

    /* Did the user specify a position? */
    if (pScreenInfo->fUserGavePosition) {
        iPosX = pScreenInfo->dwInitialX;
        iPosY = pScreenInfo->dwInitialY;
    }
    else {
        iPosX = rcWorkArea.left;
        iPosY = rcWorkArea.top;
    }

    /* Clean up the scrollbars flag, if necessary */
    if ((!pScreenInfo->fDecoration
#ifdef XWIN_MULTIWINDOWEXTWM
         || pScreenInfo->fMWExtWM
#endif
         || pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
         || pScreenInfo->fMultiWindow
#endif
        )
        && (pScreenInfo->iResizeMode == resizeWithScrollbars)) {
        /* We cannot have scrollbars if we do not have a window border */
        pScreenInfo->iResizeMode = notAllowed;
    }

    /* Did the user specify a height and width? */
    if (pScreenInfo->fUserGaveHeightAndWidth) {
        /* User gave a desired height and width, try to accomodate */
#if CYGDEBUG
        winDebug("winCreateBoundingWindowWindowed - User gave height "
                 "and width\n");
#endif

        /* Adjust the window width and height for borders and title bar */
        if (pScreenInfo->fDecoration
#ifdef XWIN_MULTIWINDOWEXTWM
            && !pScreenInfo->fMWExtWM
#endif
            && !pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
            && !pScreenInfo->fMultiWindow
#endif
            ) {
#if CYGDEBUG
            winDebug
                ("winCreateBoundingWindowWindowed - Window has decoration\n");
#endif

            /* Are we resizable */
            if (pScreenInfo->iResizeMode != notAllowed) {
#if CYGDEBUG
                winDebug
                    ("winCreateBoundingWindowWindowed - Window is resizable\n");
#endif

                iWidth += 2 * GetSystemMetrics(SM_CXSIZEFRAME);
                iHeight += 2 * GetSystemMetrics(SM_CYSIZEFRAME)
                    + GetSystemMetrics(SM_CYCAPTION);
            }
            else {
#if CYGDEBUG
                winDebug
                    ("winCreateBoundingWindowWindowed - Window is not resizable\n");
#endif

                iWidth += 2 * GetSystemMetrics(SM_CXFIXEDFRAME);
                iHeight += 2 * GetSystemMetrics(SM_CYFIXEDFRAME)
                    + GetSystemMetrics(SM_CYCAPTION);
            }
        }
    }
    else {
        /* By default, we are creating a window that is as large as possible */
#if CYGDEBUG
        winDebug("winCreateBoundingWindowWindowed - User did not give "
                 "height and width\n");
#endif
        /* Defaults are wrong if we have multiple monitors */
        if (pScreenInfo->fMultipleMonitors) {
            iWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
            iHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
        }
    }

    /* Make sure window is no bigger than work area */
    if (TRUE
#ifdef XWIN_MULTIWINDOWEXTWM
        && !pScreenInfo->fMWExtWM
#endif
#ifdef XWIN_MULTIWINDOW
        && !pScreenInfo->fMultiWindow
#endif
        ) {
        /* Trim window width to fit work area */
        if (iWidth > (rcWorkArea.right - rcWorkArea.left))
            iWidth = rcWorkArea.right - rcWorkArea.left;

        /* Trim window height to fit work area */
        if (iHeight >= (rcWorkArea.bottom - rcWorkArea.top))
            iHeight = rcWorkArea.bottom - rcWorkArea.top;

#if CYGDEBUG
        winDebug("winCreateBoundingWindowWindowed - Adjusted width: %d "
                 "height: %d\n", iWidth, iHeight);
#endif
    }

    /* Set display and screen-specific tooltip text */
    if (g_pszQueryHost != NULL)
        snprintf(szTitle,
                 sizeof(szTitle),
                 WINDOW_TITLE_XDMCP,
                 g_pszQueryHost, display, (int) pScreenInfo->dwScreen);
    else
        snprintf(szTitle,
                 sizeof(szTitle),
                 WINDOW_TITLE, display, (int) pScreenInfo->dwScreen);

    /* Create the window */
    *phwnd = CreateWindowExA(0, /* Extended styles */
                             WINDOW_CLASS,      /* Class name */
                             szTitle,   /* Window name */
                             dwWindowStyle, iPosX,      /* Horizontal position */
                             iPosY,     /* Vertical position */
                             iWidth,    /* Right edge */
                             iHeight,   /* Bottom edge */
                             (HWND) NULL,       /* No parent or owner window */
                             (HMENU) NULL,      /* No menu */
                             GetModuleHandle(NULL),     /* Instance handle */
                             pScreenPriv);      /* ScreenPrivates */
    if (*phwnd == NULL) {
        ErrorF("winCreateBoundingWindowWindowed - CreateWindowEx () failed\n");
        return FALSE;
    }

#if CYGDEBUG
    winDebug("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n");
#endif

    if (fForceShowWindow) {
        ErrorF
            ("winCreateBoundingWindowWindowed - Setting normal windowstyle\n");
        ShowWindow(*phwnd, SW_SHOW);
    }

    /* Get the client area coordinates */
    if (!GetClientRect(*phwnd, &rcClient)) {
        ErrorF("winCreateBoundingWindowWindowed - GetClientRect () "
               "failed\n");
        return FALSE;
    }

    winDebug("winCreateBoundingWindowWindowed - WindowClient "
             "w %d  h %d r %d l %d b %d t %d\n",
             (int)(rcClient.right - rcClient.left),
             (int)(rcClient.bottom - rcClient.top),
             (int)rcClient.right, (int)rcClient.left,
             (int)rcClient.bottom, (int)rcClient.top);

    /* We adjust the visual size if the user did not specify it */
    if (!
        ((pScreenInfo->iResizeMode == resizeWithScrollbars) &&
         pScreenInfo->fUserGaveHeightAndWidth)) {
        /*
         * User did not give a height and width with scrollbars enabled,
         * so we will resize the underlying visual to be as large as
         * the initial view port (page size).  This way scrollbars will
         * not appear until the user shrinks the window, if they ever do.
         *
         * NOTE: We have to store the viewport size here because
         * the user may have an autohide taskbar, which would
         * cause the viewport size to be one less in one dimension
         * than the viewport size that we calculated by subtracting
         * the size of the borders and caption.
         */
        pScreenInfo->dwWidth = rcClient.right - rcClient.left;
        pScreenInfo->dwHeight = rcClient.bottom - rcClient.top;
    }

#if 0
    /*
     * NOTE: For the uninitiated, the page size is the number of pixels
     * that we can display in the x or y direction at a time and the
     * range is the total number of pixels in the x or y direction that we
     * have available to display.  In other words, the page size is the
     * size of the window area minus the space the caption, borders, and
     * scrollbars (if any) occupy, and the range is the size of the
     * underlying X visual.  Notice that, contrary to what some of the
     * MSDN Library arcticles lead you to believe, the windows
     * ``client area'' size does not include the scrollbars.  In other words,
     * the whole client area size that is reported to you is drawable by
     * you; you do not have to subtract the size of the scrollbars from
     * the client area size, and if you did it would result in the size
     * of the scrollbars being double counted.
     */

    /* Setup scrollbar page and range, if scrollbars are enabled */
    if (pScreenInfo->fScrollbars) {
        SCROLLINFO si;

        /* Initialize the scrollbar info structure */
        si.cbSize = sizeof(si);
        si.fMask = SIF_RANGE | SIF_PAGE;
        si.nMin = 0;

        /* Setup the width range and page size */
        si.nMax = pScreenInfo->dwWidth - 1;
        si.nPage = rcClient.right - rcClient.left;
        winDebug("winCreateBoundingWindowWindowed - HORZ nMax: %d nPage :%d\n",
                 si.nMax, si.nPage);
        SetScrollInfo(*phwnd, SB_HORZ, &si, TRUE);

        /* Setup the height range and page size */
        si.nMax = pScreenInfo->dwHeight - 1;
        si.nPage = rcClient.bottom - rcClient.top;
        winDebug("winCreateBoundingWindowWindowed - VERT nMax: %d nPage :%d\n",
                 si.nMax, si.nPage);
        SetScrollInfo(*phwnd, SB_VERT, &si, TRUE);
    }
#endif

    /* Show the window */
    if (FALSE
#ifdef XWIN_MULTIWINDOWEXTWM
        || pScreenInfo->fMWExtWM
#endif
#ifdef XWIN_MULTIWINDOW
        || pScreenInfo->fMultiWindow
#endif
        ) {
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
        pScreenPriv->fRootWindowShown = FALSE;
#endif
        ShowWindow(*phwnd, SW_HIDE);
    }
    else
        ShowWindow(*phwnd, SW_SHOWNORMAL);
    if (!UpdateWindow(*phwnd)) {
        ErrorF("winCreateBoundingWindowWindowed - UpdateWindow () failed\n");
        return FALSE;
    }

    /* Attempt to bring our window to the top of the display */
    if (TRUE
#ifdef XWIN_MULTIWINDOWEXTWM
        && !pScreenInfo->fMWExtWM
#endif
        && !pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
        && !pScreenInfo->fMultiWindow
#endif
        ) {
        if (!BringWindowToTop(*phwnd)) {
            ErrorF("winCreateBoundingWindowWindowed - BringWindowToTop () "
                   "failed\n");
            return FALSE;
        }
    }

    winDebug("winCreateBoundingWindowWindowed -  Returning\n");

    return TRUE;
}
Example #7
0
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow)
{  
	HWND hwnd;
    MSG msg;
    WNDCLASSEX wndclassex = {0};

	SDBuffer doubleBuff = {0}; // This is our "double buffer" struct

	// Fill the fields we care about
	wndclassex.cbSize = sizeof(WNDCLASSEX);
    wndclassex.style = CS_HREDRAW | CS_VREDRAW;
    wndclassex.lpfnWndProc = WinProc;
    wndclassex.hInstance = hinstance;
    wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclassex.lpszClassName = class_name;
    wndclassex.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR,
											0, 0, LR_SHARED); // Load the default arrow cursor

    RegisterClassEx(&wndclassex); // Register the window

    hwnd = CreateWindowEx(NULL, // No extra window attributes
						  class_name,
						  "www.GameTutorials.com -- Double Buffering",
						  WS_OVERLAPPEDWINDOW,
						  CW_USEDEFAULT, // Window will receive a default x pos on screen
						  CW_USEDEFAULT, // Window will receive a default y pos on screen
						  WIN_WID,
						  WIN_HGT,
						  NULL,
						  NULL,
						  hinstance,
						  NULL);

		// Error check
		if(!hwnd)
			return EXIT_FAILURE; // Something really bad happened!
		
	doubleBuff.win_hwnd = hwnd; // Set the HWND of our double buffer struct

	// Attempt to initialize our double buffering
	if(!InitDoubleBuffer(doubleBuff))
		return EXIT_FAILURE; // Couldn't set up double buffering
	
	// Here we'll load up our bitmap
	HBITMAP img_bmp = (HBITMAP)LoadImage(hinstance,"AnImage.bmp",IMAGE_BITMAP,
										 0,0,LR_LOADFROMFILE);

		// Error Check
		if(!img_bmp)
			return EXIT_FAILURE; // Couldn't load our image
		
	// Create a compatible HDC so that we can draw our "img_bmp"
	HDC img_dc = CreateCompatibleDC(doubleBuff.win_dc);
		
		if(!img_dc)
			return EXIT_FAILURE;
		
	// Select our "img_bmp" into the "img_dc"
	HBITMAP old_bmp = (HBITMAP)SelectObject(img_dc,img_bmp);

    ShowWindow(hwnd, ishow);
    UpdateWindow(hwnd);
  
    while(1)
	{
		// Check message(s) if there are any
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
				
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else if(LockFrameRate())
		{
			#if DOUBLE_BUFFER // If we are using double buffering

				// First we fill our back buffer to solid white (the same color as the
				// background color of our window)
				FillRect(doubleBuff.back_dc,&doubleBuff.rect,(HBRUSH)GetStockObject(WHITE_BRUSH));

				// Next we'll draw the bitmap to our back buffer
				BitBlt(doubleBuff.back_dc,gXPos,gYPos,gXPos + IMG_WID,
					   gYPos + IMG_HGT,img_dc,0,0,SRCCOPY);

				// Then we draw the back buffer to the front buffer (our window)
				BitBlt(doubleBuff.win_dc,0,0,doubleBuff.rect.right,
					   doubleBuff.rect.bottom,doubleBuff.back_dc,0,0,SRCCOPY);

			#else // No double buffering in use

				// We fill our window with solid white so we can clear away the "old"
				// position of the image
				FillRect(doubleBuff.win_dc,&doubleBuff.rect,(HBRUSH)GetStockObject(WHITE_BRUSH));

				// Blit the image to the window
				BitBlt(doubleBuff.win_dc,gXPos,gYPos,gXPos + IMG_WID,
					   gYPos + IMG_HGT,img_dc,0,0,SRCCOPY);

				// **NOTE** Do not be mislead by the use of the "doubleBuff" variable.
				//			We are ONLY using this to access the window's HDC.  Absolutely
				//			no double buffering goes on in the between the #else and the 
				//			#endif.  Be sure to look at how worse it looks without double
				//			buffering.

			#endif
		}

	}

	// Free up our image memory
	SelectObject(img_dc,old_bmp);
	DeleteDC(img_dc);

	// Free up all the memory associated with our back buffer
	FreeDoubleBuffer(doubleBuff);

	UnregisterClass(class_name,hinstance); // Free up WNDCLASSEX
		return msg.wParam;
}
Example #8
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

	static POINT apt[4] ;

	HDC          hdc ;

	int          cxClient, cyClient ;

	PAINTSTRUCT  ps ;


	switch (message)

	{

	case WM_SIZE:

		cxClient = LOWORD (lParam) ;

		cyClient = HIWORD (lParam) ;



		apt[0].x = cxClient / 4 ;

		apt[0].y = cyClient / 2 ;



		apt[1].x = cxClient / 2 ;

		apt[1].y = cyClient / 4 ;



		apt[2].x = cxClient / 2 ;

		apt[2].y = 3 * cyClient / 4 ;



		apt[3].x = 3 * cxClient / 4 ;

		apt[3].y = cyClient / 2 ;



		return 0 ;


	case WM_LBUTTONDOWN:

	case WM_RBUTTONDOWN:

	case WM_MOUSEMOVE:

		if (wParam & MK_LBUTTON || wParam & MK_RBUTTON)

		{

			hdc = GetDC (hwnd) ;

			SelectObject (hdc, GetStockObject (WHITE_PEN)) ;

			DrawBezier (hdc, apt) ;



			if (wParam & MK_LBUTTON)

			{

				apt[1].x = LOWORD (lParam) ;

				apt[1].y = HIWORD (lParam) ;

			}



			if (wParam & MK_RBUTTON)

			{

				apt[2].x = LOWORD (lParam) ;

				apt[2].y = HIWORD (lParam) ;

			}



			SelectObject (hdc, GetStockObject (BLACK_PEN)) ;

			DrawBezier (hdc, apt) ;

			ReleaseDC (hwnd, hdc) ;

		}

		return 0 ;

	case   WM_PAINT:

		InvalidateRect (hwnd, NULL, TRUE) ;



		hdc = BeginPaint (hwnd, &ps) ;



		DrawBezier (hdc, apt) ;



		EndPaint (hwnd, &ps) ;

		return 0 ;



	case WM_DESTROY:

		PostQuitMessage (0) ;

		return 0 ;

	}

	return DefWindowProc (hwnd, message, wParam, lParam) ;

}
Example #9
0
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

	PSTR szCmdLine, int iCmdShow)

{

	static TCHAR szAppName[] = TEXT ("Bezier") ;

	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 ("Bezier Splines"),

		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 ;

}
Example #10
0
void debugview_info::draw_contents(HDC windc)
{
	debug_view_char const *viewdata = m_view->viewdata();
	debug_view_xy const visarea = m_view->visible_size();

	// get the client rect
	RECT client;
	GetClientRect(m_wnd, &client);

	// create a compatible DC and an offscreen bitmap
	HDC const dc = CreateCompatibleDC(windc);
	if (dc == nullptr)
		return;
	HBITMAP const bitmap = CreateCompatibleBitmap(windc, client.right, client.bottom);
	if (bitmap == nullptr)
	{
		DeleteDC(dc);
		return;
	}
	HGDIOBJ const oldbitmap = SelectObject(dc, bitmap);

	// set the font
	HGDIOBJ const oldfont = SelectObject(dc, metrics().debug_font());
	COLORREF const oldfgcolor = GetTextColor(dc);
	int const oldbkmode = GetBkMode(dc);
	SetBkMode(dc, TRANSPARENT);

	// iterate over rows and columns
	for (UINT32 row = 0; row < visarea.y; row++)
	{
		// loop twice; once to fill the background and once to draw the text
		for (int iter = 0; iter < 2; iter++)
		{
			COLORREF fgcolor;
			COLORREF bgcolor = RGB(0xff,0xff,0xff);
			HBRUSH bgbrush = nullptr;
			int last_attrib = -1;
			TCHAR buffer[256];
			int count = 0;
			RECT bounds;

			// initialize the text bounds
			bounds.left = bounds.right = 0;
			bounds.top = row * metrics().debug_font_height();
			bounds.bottom = bounds.top + metrics().debug_font_height();

			// start with a brush on iteration #0
			if (iter == 0)
				bgbrush = CreateSolidBrush(bgcolor);

			// iterate over columns
			for (UINT32 col = 0; col < visarea.x; col++)
			{
				// if the attribute changed, adjust the colors
				if (viewdata[col].attrib != last_attrib)
				{
					COLORREF oldbg = bgcolor;

					// reset to standard colors
					fgcolor = RGB(0x00,0x00,0x00);
					bgcolor = RGB(0xff,0xff,0xff);

					// pick new fg/bg colors
					if (viewdata[col].attrib & DCA_VISITED) bgcolor = RGB(0xc6, 0xe2, 0xff);
					if (viewdata[col].attrib & DCA_ANCILLARY) bgcolor = RGB(0xe0,0xe0,0xe0);
					if (viewdata[col].attrib & DCA_SELECTED) bgcolor = RGB(0xff,0x80,0x80);
					if (viewdata[col].attrib & DCA_CURRENT) bgcolor = RGB(0xff,0xff,0x00);
					if ((viewdata[col].attrib & DCA_SELECTED) && (viewdata[col].attrib & DCA_CURRENT)) bgcolor = RGB(0xff,0xc0,0x80);
					if (viewdata[col].attrib & DCA_CHANGED) fgcolor = RGB(0xff,0x00,0x00);
					if (viewdata[col].attrib & DCA_INVALID) fgcolor = RGB(0x00,0x00,0xff);
					if (viewdata[col].attrib & DCA_DISABLED) fgcolor = RGB((GetRValue(fgcolor) + GetRValue(bgcolor)) / 2, (GetGValue(fgcolor) + GetGValue(bgcolor)) / 2, (GetBValue(fgcolor) + GetBValue(bgcolor)) / 2);
					if (viewdata[col].attrib & DCA_COMMENT) fgcolor = RGB(0x00,0x80,0x00);

					// flush any pending drawing
					if (count > 0)
					{
						bounds.right = bounds.left + (count * metrics().debug_font_width());
						if (iter == 0)
							FillRect(dc, &bounds, bgbrush);
						else
							ExtTextOut(dc, bounds.left, bounds.top, 0, nullptr, buffer, count, nullptr);
						bounds.left = bounds.right;
						count = 0;
					}

					// set the new colors
					if (iter == 0 && oldbg != bgcolor)
					{
						DeleteObject(bgbrush);
						bgbrush = CreateSolidBrush(bgcolor);
					}
					else if (iter == 1)
						SetTextColor(dc, fgcolor);
					last_attrib = viewdata[col].attrib;
				}

				// add this character to the buffer
				buffer[count++] = viewdata[col].byte;
			}

			// flush any remaining stuff
			if (count > 0)
			{
				bounds.right = bounds.left + (count * metrics().debug_font_width());
				if (iter == 0)
					FillRect(dc, &bounds, bgbrush);
				else
					ExtTextOut(dc, bounds.left, bounds.top, 0, nullptr, buffer, count, nullptr);
			}

			// erase to the end of the line
			if (iter == 0)
			{
				bounds.left = bounds.right;
				bounds.right = client.right;
				FillRect(dc, &bounds, bgbrush);
				DeleteObject(bgbrush);
			}
		}

		// advance viewdata
		viewdata += visarea.x;
	}

	// erase anything beyond the bottom with white
	GetClientRect(m_wnd, &client);
	client.top = visarea.y * metrics().debug_font_height();
	FillRect(dc, &client, (HBRUSH)GetStockObject(WHITE_BRUSH));

	// reset the font
	SetBkMode(dc, oldbkmode);
	SetTextColor(dc, oldfgcolor);
	SelectObject(dc, oldfont);

	// blit the final results
	BitBlt(windc, 0, 0, client.right, client.bottom, dc, 0, 0, SRCCOPY);

	// undo the offscreen stuff
	SelectObject(dc, oldbitmap);
	DeleteObject(bitmap);
	DeleteDC(dc);
}
Example #11
0
HRESULT CGifSmileyCtrl::OnDrawSmiley(ATL_DRAWINFO& di, bool bCustom=false)
{
	USES_CONVERSION;
	if (di.dwDrawAspect != DVASPECT_CONTENT)
	{
		return E_FAIL;
	}
	if ( bCustom && !IsVisible(di))
	{
		return S_OK;
	}
	if (!m_pGifImage)
	{
		return E_FAIL;
	}
	RECT& rc = *(RECT*)di.prcBounds;

	HRGN hOldRgn, hNewRgn;

	if (!IsRectEmpty(&m_rectPos))
	{   //strange workaround for drawing zoom out smileys (look MS calculate it one pix larger than exactly)
		if (rc.bottom-rc.top-1 == m_rectPos.bottom-m_rectPos.top 
			&& rc.right-rc.left== m_rectPos.right-m_rectPos.left)
			rc.top+=1;
	}

	if ( bCustom )SelectSmileyClipRgn(di.hdcDraw, rc, hOldRgn, hNewRgn, TRUE);

	InflateRect(&rc,-1,0); //border offset to fix blinked cursor painting
	if ( (m_dwFlags&REO_INVERTEDSELECT) == 0 || !bCustom || m_bTransparent)
		DoDrawSmiley(di.hdcDraw, rc, rc.right-rc.left,rc.bottom-rc.top, m_nFrameSize.Width, m_nFrameSize.Height);
	else
	{
		Bitmap bmp(rc.right-rc.left,rc.bottom-rc.top, PixelFormat32bppARGB);
		Graphics g(&bmp);
		COLORREF col=(COLORREF)(m_clrBackColor);
		SolidBrush brush(Color(GetRValue(col),GetGValue(col),GetBValue(col)));
		g.FillRectangle( &brush, 0 ,0, rc.right-rc.left, rc.bottom-rc.top);
		HDC hdc=g.GetHDC();
		RECT mrc={0};
		mrc.right=rc.right-rc.left;
		mrc.bottom=rc.bottom-rc.top;
		DoDrawSmiley(hdc, mrc, mrc.right-mrc.left,mrc.bottom-mrc.top, m_nFrameSize.Width, m_nFrameSize.Height);
		InvertRect(hdc, &mrc);
		BitBlt(di.hdcDraw, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, SRCCOPY );
		g.ReleaseHDC(hdc);       
	}
	if ((m_dwFlags&REO_SELECTED) == REO_SELECTED && bCustom)
	{
		//Draw frame around
		HBRUSH oldBrush=(HBRUSH)SelectObject(di.hdcDraw, GetStockObject(NULL_BRUSH)); 
		HPEN oldPen=(HPEN)SelectObject(di.hdcDraw, GetStockObject(BLACK_PEN));
		::Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom );
		SelectObject(di.hdcDraw, oldBrush);
		SelectObject(di.hdcDraw, oldPen);
	}
	AdvanceFrame();
	if (!bCustom) 
		m_bPaintValid=false;
	ResetClip(di.hdcDraw, hOldRgn, hNewRgn);

	return S_OK;
}
Example #12
0
LRESULT DisViewBox_OnPaint(HWND hwnd, disview_struct *win, WPARAM wParam, LPARAM lParam)
{
    HDC          hdc;
    PAINTSTRUCT  ps;
    SIZE fontsize;
    TCHAR text[100];
    TCHAR txt[100];
    RECT rect;
    int lg;
    int ht;
    HDC mem_dc;
    HBITMAP mem_bmp;
    u32  nbligne;

    GetClientRect(hwnd, &rect);
    lg = rect.right - rect.left;
    ht = rect.bottom - rect.top;

    hdc = BeginPaint(hwnd, &ps);

    mem_dc = CreateCompatibleDC(hdc);
    mem_bmp = CreateCompatibleBitmap(hdc, lg, ht);
    SelectObject(mem_dc, mem_bmp);

    FillRect(mem_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));

    SelectObject(mem_dc, GetStockObject(SYSTEM_FIXED_FONT));

    GetTextExtentPoint32(mem_dc, "0", 1, &fontsize);

    nbligne = ht/fontsize.cy;

    SetTextColor(mem_dc, RGB(0,0,0));

    if((win->mode==1) || ((win->mode==0) && (win->cpu->CPSR.bits.T == 0)))
    {
        u32 i;
        u32 adr;

        if (win->autoup||win->autogo)
            win->curr_ligne = (win->cpu->instruct_adr >> 2);
        adr = win->curr_ligne*4;

        for(i = 0; i < nbligne; ++i)
        {
            u32 ins = _MMU_read32(win->cpu->proc_ID, MMU_AT_DEBUG, adr);
            des_arm_instructions_set[INDEX(ins)](adr, ins, txt);
            sprintf(text, "%04X:%04X  %08X  %s", (int)(adr>>16), (int)(adr&0xFFFF), (int)ins, txt);
            DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX);
            rect.top+=fontsize.cy;
            adr += 4;
        }



        if(((win->cpu->instruct_adr&0x0FFFFFFF) >= (win->curr_ligne<<2))&&((win->cpu->instruct_adr&0x0FFFFFFF) <= (win->curr_ligne+(nbligne<<2))))
        {
            HBRUSH brjaune = CreateSolidBrush(RGB(255, 255, 0));
            SetBkColor(mem_dc, RGB(255, 255, 0));
            rect.top = (((win->cpu->instruct_adr&0x0FFFFFFF)>>2) - win->curr_ligne)*fontsize.cy;
            rect.bottom = rect.top + fontsize.cy;
            FillRect(mem_dc, &rect, brjaune);
            des_arm_instructions_set[INDEX(win->cpu->instruction)](win->cpu->instruct_adr, win->cpu->instruction, txt);
            sprintf(text, "%04X:%04X  %08X  %s", (int)((win->cpu->instruct_adr&0x0FFFFFFF)>>16), (int)(win->cpu->instruct_adr&0xFFFF), (int)win->cpu->instruction, txt);
            DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX);
            DeleteObject(brjaune);
        }
Example #13
0
/*============================================
 *  BasicWindow::registWC__()
 *  WNDCLASS登録 & WNDCLASS名を返す
 *  同じ内容のWNDCLASSの二重登録を阻止する
 *==========================================*/
std::wstring urania::BasicWindow::registWC__
(const urania::BasicWindow::WC_& wc)
{
  std::vector<WC_>::iterator it = std::find(vwc_S.begin(), vwc_S.end(), wc);
  if (it == vwc_S.end())
  {
    ////////////////////////////////////////////////////////
    // WNDCLASSの登録とvectorへの追加
    ////////////////////////////////////////////////////////

    // クラス名をWC_に設定
    WC_ wc2 = wc;
    //std::wostringstream tmp;
    std::basic_ostringstream<wchar_t> tmp;
    tmp << vwc_S.size();

    wc2.wcname_ = std::wstring(L"GPWNDCLASS") + tmp.str();

    // WNDCLASS Structure
    WNDCLASS wndcls =
    {
      CS_HREDRAW | CS_VREDRAW,
      wc2.proc_,
      0,
      sizeof(Window*),
      getHI__(),
      NULL,
      NULL,
      NULL,
      nullptr,
      wc2.wcname_.c_str()
    };

    // Icon の設定
    if (wc2.icon_id_ != DEFAULT_RC)
      wndcls.hIcon = LoadIcon(getHI__(), MAKEINTRESOURCE(wc2.icon_id_));
    else
      wndcls.hIcon = LoadIcon(0, IDI_APPLICATION);

    // Cursor の設定
    if (wc2.cursor_id_ != DEFAULT_RC)
      wndcls.hCursor = LoadCursor(getHI__(), MAKEINTRESOURCE(wc2.cursor_id_));
    else
      wndcls.hCursor = LoadCursor(0, IDC_ARROW);


    // 背景色の設定
    switch (wc2.bkcolor_)
    {
    case BG_WHITE:
      wndcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
      break;

    case BG_BLACK:
      wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
      break;

    case BG_GRAY:
      wndcls.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
      break;

    case BG_LTGRAY:
      wndcls.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
      break;

    case BG_DKGRAY:
      wndcls.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
      break;

    case BG_APPWORKSPACE:
      wndcls.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
      break;

    case BG_BKWINDOW:
      wndcls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
      break;

    default:
      wndcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
      break;
    }

    // 実際に登録
    ::RegisterClass(&wndcls);

    vwc_S.push_back(wc2);
    return wc2.wcname_;
  }
  else
    return it->wcname_; // WNDCLASS名を返す
}
Example #14
0
NTSTATUS
EnumerateFonts(
    DWORD Flags)
{
    TEXTMETRIC tmi;
    HDC hDC;
    PFACENODE pFN;
    ULONG ulOldEnumFilter;
    DWORD FontIndex;
    DWORD dwFontType = 0;

    DBGFONTS(("EnumerateFonts %lx\n", Flags));

    dwFontType = (EF_TTFONT|EF_OEMFONT|EF_DEFFACE) & Flags;

    if (FontInfo == NULL) {
        //
        // allocate memory for the font array
        //
        NumberOfFonts = 0;

        FontInfo = (PFONT_INFO)HeapAlloc(pConHeap,MAKE_TAG( FONT_TAG ),sizeof(FONT_INFO) * INITIAL_FONTS);
        if (FontInfo == NULL)
            return STATUS_NO_MEMORY;
        FontInfoLength = INITIAL_FONTS;
    }

    hDC = CreateDCW(L"DISPLAY",NULL,NULL,NULL);

    // Before enumeration, turn off font enumeration filters.
    ulOldEnumFilter = SetFontEnumeration(0);
    // restore all the other flags
    SetFontEnumeration(ulOldEnumFilter & ~FE_FILTER_TRUETYPE);

    if (Flags & EF_DEFFACE) {
        SelectObject(hDC,GetStockObject(OEM_FIXED_FONT));

        if (GetTextMetricsW(hDC, &tmi)) {
            DefaultFontSize.X = (SHORT)(tmi.tmMaxCharWidth);
            DefaultFontSize.Y = (SHORT)(tmi.tmHeight+tmi.tmExternalLeading);
            DefaultFontFamily = tmi.tmPitchAndFamily;
        }
        GetTextFaceW(hDC, LF_FACESIZE, DefaultFaceName);
        DBGFONTS(("Default (OEM) Font %ls (%d,%d)\n", DefaultFaceName,
                DefaultFontSize.X, DefaultFontSize.Y));

        // Make sure we are going to enumerate the OEM face.
        pFN = AddFaceNode(&gpFaceNames, DefaultFaceName);
        pFN->dwFlag |= EF_DEFFACE | EF_OEMFONT;
    }

    // Use DoFontEnum to get all fonts from the system.  Our FontEnum
    // proc puts just the ones we want into an array
    //
    for (pFN = gpFaceNames; pFN; pFN = pFN->pNext) {
        DBGFONTS(("\"%ls\" is %s%s%s%s%s%s\n", pFN->awch,
            pFN->dwFlag & EF_NEW        ? "NEW "        : " ",
            pFN->dwFlag & EF_OLD        ? "OLD "        : " ",
            pFN->dwFlag & EF_ENUMERATED ? "ENUMERATED " : " ",
            pFN->dwFlag & EF_OEMFONT    ? "OEMFONT "    : " ",
            pFN->dwFlag & EF_TTFONT     ? "TTFONT "     : " ",
            pFN->dwFlag & EF_DEFFACE    ? "DEFFACE "    : " "));

        if ((pFN->dwFlag & dwFontType) == 0) {
            // not the kind of face we want
            continue;
        }
        if (pFN->dwFlag & EF_ENUMERATED) {
            // we already enumerated this face
            continue;
        }

        DoFontEnum(hDC, pFN->awch, DefaultFontSize.Y);
        pFN->dwFlag |= EF_ENUMERATED;
    }


    // After enumerating fonts, restore the font enumeration filter.
    SetFontEnumeration(ulOldEnumFilter);

    DeleteDC(hDC);

    // Make sure the default font is set correctly
    if (NumberOfFonts > 0 && DefaultFontSize.X == 0 && DefaultFontSize.Y == 0) {
        DefaultFontSize.X = FontInfo[0].Size.X;
        DefaultFontSize.Y = FontInfo[0].Size.Y;
        DefaultFontFamily = FontInfo[0].Family;
    }

    for (FontIndex = 0; FontIndex < NumberOfFonts; FontIndex++) {
        if (FontInfo[FontIndex].Size.X == DefaultFontSize.X &&
            FontInfo[FontIndex].Size.Y == DefaultFontSize.Y &&
            FontInfo[FontIndex].Family == DefaultFontFamily) {
            break;
        }
    }
    ASSERT(FontIndex < NumberOfFonts);
    if (FontIndex < NumberOfFonts) {
        DefaultFontIndex = FontIndex;
    } else {
        DefaultFontIndex = 0;
    }
    DBGFONTS(("EnumerateFonts : DefaultFontIndex = %ld\n", DefaultFontIndex));

    return STATUS_SUCCESS;
}
Example #15
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst,
	LPSTR lpszCmdLine, int nCmdShow)
{
	MSG msg;
	WNDCLASS myProg;


	if(!hPreInst)
	{
		myProg.style=CS_HREDRAW|CS_VREDRAW;
		myProg.lpfnWndProc=WndProc;
		myProg.cbClsExtra=0;	
		myProg.cbWndExtra=0;
		myProg.hInstance=hInstance;
		myProg.hIcon=NULL;
		myProg.hCursor=LoadCursor(NULL,IDC_ARROW);
		myProg.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
		myProg.lpszMenuName=NULL;
		myProg.lpszClassName = _T("クラスネーム");
		if(!RegisterClass(&myProg))
			return FALSE;
	}

	hWnd = CreateWindow(
		myProg.lpszClassName,
		_T("ballaction"),
		WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_CLIPCHILDREN,	//ウィンドウスタイル
		CW_USEDEFAULT, CW_USEDEFAULT,	//ウィンドウ座標
		WINDOW_WIDTH, WINDOW_HEIGHT,	//ウィンドウサイズ
		NULL,
		NULL,
		hInstance,
		NULL);


	//CreateWindowで設定した幅と高さの値は、タイトルバーや枠のサイズも含めたものになってしまうので
	//クライアント領域を取得し、ウィンドウサイズを設定し直す。
	RECT wRect, cRect;  // ウィンドウ全体の矩形、クライアント領域の矩形
	int ww, wh;         // ウィンドウ全体の幅、高さ
	int cw, ch;         // クライアント領域の幅、高さ

	// ウィンドウ全体の幅・高さを計算
	GetWindowRect(hWnd, &wRect);
	ww = wRect.right - wRect.left;
	wh = wRect.bottom - wRect.top;
	// クライアント領域の幅・高さを計算
	GetClientRect(hWnd, &cRect);
	cw = cRect.right - cRect.left;
	ch = cRect.bottom - cRect.top;
	// クライアント領域以外に必要なサイズを計算
	ww = ww - cw;
	wh = wh - ch;
	// ウィンドウ全体に必要なサイズを計算
	ww = WINDOW_WIDTH + ww;
	wh = WINDOW_HEIGHT + wh;
	// 計算した幅と高さをウィンドウに設定
	SetWindowPos(hWnd, HWND_TOP, 0, 0, ww, wh, SWP_NOMOVE);

	ShowWindow(hWnd,nCmdShow);
	UpdateWindow(hWnd);

	srand((UINT)time(NULL));	//乱数初期化


	//タスクリスト初期化(最初のタスクも作成しておく)
	TaskGM::InitTaskList();
	game_manager = new GameManager2(hWnd, WINDOW_WIDTH, WINDOW_HEIGHT);
	//タイマー作成
	game_manager->createTimer();
	new ballaction(game_manager);

  

	while(true)
	{
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if(msg.message==WM_QUIT) break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			Task::RunTask();		// 値の更新
		}
	}
	return(msg.wParam);
}
Example #16
0
static HWND
InitInstance(HINSTANCE hInst)
{
    WCHAR       szClass[] = L"CharMap";
    WCHAR       szTitle[256];
    WNDCLASSEXW wc;
    HWND        hWnd;

    LoadStringW(hInst, IDS_TITLE, szTitle, SIZEOF(szTitle));

    hSmIcon = LoadImage(hInstance,
                        MAKEINTRESOURCE(IDI_ICON),
                        IMAGE_ICON,
                        16,
                        16,
                        0);

    hBgIcon = LoadImage(hInstance,
                        MAKEINTRESOURCE(IDI_ICON),
                        IMAGE_ICON,
                        32,
                        32,
                        0);

    // Create workspace
    ZeroMemory(&wc, sizeof(wc));

    wc.cbSize        = sizeof(wc);
    wc.lpfnWndProc   = PanelWndProc;
    wc.hInstance     = hInst;
    wc.hIcon         = hBgIcon;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = szClass;
    wc.hIconSm       = hSmIcon;

    RegisterClassExW(&wc);

    hWnd = CreateWindowW(
            szClass,
            szTitle,
            WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            NULL,
            NULL,
            hInst,
            NULL);

    if (hWnd != NULL)
    {
        LoadSettings();
        ShowWindow(hWnd, SW_SHOW);
        UpdateWindow(hWnd);
    }

    return hWnd;
}
// WINMAIN ////////////////////////////////////////////////
int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)
{

WNDCLASSEX winclass; // this will hold the class we create
HWND	   hwnd;	 // generic window handle
MSG		   msg;		 // generic message

// first fill in the window class stucture
winclass.cbSize         = sizeof(WNDCLASSEX);
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW); 
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL;
winclass.lpszClassName	= WINDOW_CLASS_NAME;
winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

// save hinstance in global
hinstance_app = hinstance;

// register the window class
if (!RegisterClassEx(&winclass))
	return(0);

// create the window
if (!(hwnd = CreateWindowEx(NULL,                  // extended style
                            WINDOW_CLASS_NAME,     // class
						    "GDI Text Printing Demo", // title
						    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
					 	    0,0,	  // initial x,y
						    400,400,  // initial width, height
						    NULL,	  // handle to parent 
						    NULL,	  // handle to menu
						    hinstance,// instance of this application
						    NULL)))	// extra creation parms
return(0);

// save main window handle
main_window_handle = hwnd;

// get the dc and hold it
HDC hdc = GetDC(hwnd);

// enter main event loop, but this time we use PeekMessage()
// instead of GetMessage() to retrieve messages
while(TRUE)
	{
    // test if there is a message in queue, if so get it
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	   { 
	   // test if this is a quit
       if (msg.message == WM_QUIT)
           break;
	
	   // translate any accelerator keys
	   TranslateMessage(&msg);

	   // send the message to the window proc
	   DispatchMessage(&msg);
	   } // end if
    
    // main game processing goes here
    
    // set the foreground color to random
    SetTextColor(hdc, RGB(rand()%256,rand()%256,rand()%256));

    // set the background color to black
    SetBkColor(hdc, RGB(0,0,0));

    // finally set the transparency mode to transparent
    SetBkMode(hdc, TRANSPARENT);

    // draw some text at a random location
    TextOut(hdc,rand()%400,rand()%400, "GDI Text Demo!", strlen("GDI Text Demo!"));

    Sleep(10);
	
	} // end while

// release the dc
ReleaseDC(hwnd,hdc);

// return to Windows like this
return(msg.wParam);

} // end WinMain
Example #18
0
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF));

	WNDCLASS wc;
	wc.cbClsExtra = 0; 
	wc.cbWndExtra = 0; 
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.hCursor= NULL; 
	wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION); 
	wc.hInstance = hInstance; 
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = WIN32_CLASS_NAME; 
	wc.lpszMenuName = NULL;
	wc.style = CS_HREDRAW | CS_VREDRAW;

	DWORD style = WS_OVERLAPPEDWINDOW;
	POINT pt = { CW_USEDEFAULT, CW_USEDEFAULT };
	SIZE sz = { CW_USEDEFAULT, CW_USEDEFAULT };

	RegisterClass(&wc);

#ifndef IN_EDITOR
	sz.cx = 1280;
	sz.cy = 720;
#endif

	HWND hWnd = CreateWindow(WIN32_CLASS_NAME, "Window", style, 
		pt.x, pt.y, sz.cx, sz.cy,
		NULL, NULL, hInstance, NULL);

	ShowWindow(hWnd, SW_SHOW);

	RECT rc;
	GetClientRect(hWnd, &rc);
	int width = rc.right - rc.left;
	int height = rc.bottom - rc.top;

	try {

		gCursor = new MGUI::Cursor;

		CreateApplication(&gApp);
		d_assert (gApp != NULL);

		gApp->SetCachePath("Cache");

		gApp->Init(hInstance, hWnd, width, height);

		MSG msg;
		memset(&msg,0,sizeof(msg));
		while(msg.message != WM_QUIT)
		{
			if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			else
			{
				gApp->Update();
			}
		}

		gApp->Shutdown();
		delete gApp;

		delete gCursor;
	}
	catch(...) {
		d_assert(0);
	}

	UnregisterClass(WIN32_CLASS_NAME, hInstance);

	return 0;
}
Example #19
0
void PaintTransparentRect(HDC hdc, LPRECT paintr, COLORREF color, int alpha) {
	BLENDFUNCTION blend;
	RECT rect;

	HDC memdc    	= CreateCompatibleDC(NULL);
	HBITMAP hBitmap = CreateCompatibleBitmap(hdc, 1, 1);
	HBRUSH hBrush   = CreateSolidBrush(color);
	HGDIOBJ hOld    = SelectObject(memdc, hBitmap);
	
	rect.left   = 0;
	rect.top    = 0;
	rect.bottom = 1;
	rect.right  = 1;
	
	SetPixel(memdc, 0, 0, color); 

	//HGDIOBJ hOldFont = SelectObject(hdc0, hFontBold);
	paintr->right = paintr->left + 80 + CalcRectWidth(hdc);

	blend.BlendOp			  = AC_SRC_OVER;
	blend.BlendFlags		  = 0;
	blend.SourceConstantAlpha = alpha;
	blend.AlphaFormat		  = 0;
	AlphaBlend(hdc, paintr->left, paintr->top, paintr->right - paintr->left,
		paintr->bottom - paintr->top, memdc, 0, 0, 1, 1, blend);

	SelectObject(memdc, hOld);
	DeleteObject(hBrush);
	DeleteObject(hBitmap);
	DeleteDC(memdc);
	
#if 0
	FrameRect(hdc0, paintr, hBrush);
	SetBkMode(hdc0, TRANSPARENT);
	SetTextColor(hdc0, 0xD0D0D0);
	TextOut(hdc0, paintr->left + 30, paintr->top + 7, "QuickSwitch", 11);
	SelectObject(hdc0, hFont);
	for (int i = 0; i != numbots; i++) {
		DrawIconEx(hdc0, paintr->left + 30, paintr->top + 30 + (i * 22), 
			stateicons[0], 16, 16, 0, NULL, DI_NORMAL); 
		if (curnewprof == i) {
			rect.left   = paintr->left + 28;
			rect.top    = paintr->top  + 28 + (i * 22);
			rect.right  = paintr->left + 56 + (strlen(bot[i]->profilename) * 6);
			rect.bottom = paintr->top  + 47 + (i * 22);
			FrameRect(hdc0, &rect, (HBRUSH)GetStockObject(GRAY_BRUSH));///////////
			SetTextColor(hdc0, vbWhite);
		} else {
			SetTextColor(hdc0, 0xF0A0A0);
		}
		TextOut(hdc0, paintr->left + 52, paintr->top + 30 + (i * 22),
			bot[i]->profilename, strlen(bot[i]->profilename));
	}
	SelectObject(hdc0, hOldFont);
	SelectObject(hdc, hOld);
	DeleteDC(hdc);
	ReleaseDC(0, hdc0);
	DeleteObject(hBitmap);
	DeleteObject(hBrush);
#endif
}
Example #20
0
    int
gui_mch_dialog(
    int		 type,
    char_u	*title,
    char_u	*message,
    char_u	*buttons,
    int		 dfltbutton,
    char_u	*textfield,
    int		ex_cmd)
{
    FARPROC	dp;
    LPWORD	p, pnumitems;
    int		numButtons;
    int		*buttonWidths, *buttonPositions;
    int		buttonYpos;
    int		nchar, i;
    DWORD	lStyle;
    int		dlgwidth = 0;
    int		dlgheight;
    int		editboxheight;
    int		horizWidth;
    int		msgheight;
    char_u	*pstart;
    char_u	*pend;
    char_u	*tbuffer;
    RECT	rect;
    HWND	hwnd;
    HDC		hdc;
    HFONT	oldFont;
    TEXTMETRIC	fontInfo;
    int		fontHeight;
    int		textWidth, minButtonWidth, messageWidth;
    int		maxDialogWidth;
    int		vertical;
    int		dlgPaddingX;
    int		dlgPaddingY;
    HGLOBAL	hglbDlgTemp;

#ifndef NO_CONSOLE
    /* Don't output anything in silent mode ("ex -s") */
    if (silent_mode)
	return dfltbutton;   /* return default option */
#endif

    /* If there is no window yet, open it. */
    if (s_hwnd == NULL && gui_mch_init() == FAIL)
	return dfltbutton;

    if ((type < 0) || (type > VIM_LAST_TYPE))
	type = 0;

    /* allocate some memory for dialog template */
    /* TODO should compute this really*/

    hglbDlgTemp = GlobalAlloc(GHND,  DLG_ALLOC_SIZE);
    if (hglbDlgTemp == NULL)
	return -1;

    p = (LPWORD) GlobalLock(hglbDlgTemp);

    if (p == NULL)
	return -1;

    /*
     * make a copy of 'buttons' to fiddle with it.  compiler grizzles because
     * vim_strsave() doesn't take a const arg (why not?), so cast away the
     * const.
     */
    tbuffer = vim_strsave(buttons);
    if (tbuffer == NULL)
	return -1;

    --dfltbutton;   /* Change from one-based to zero-based */

    /* Count buttons */
    numButtons = 1;
    for (i = 0; tbuffer[i] != '\0'; i++)
    {
	if (tbuffer[i] == DLG_BUTTON_SEP)
	    numButtons++;
    }
    if (dfltbutton >= numButtons)
	dfltbutton = 0;

    /* Allocate array to hold the width of each button */
    buttonWidths = (int *) lalloc(numButtons * sizeof(int), TRUE);
    if (buttonWidths == NULL)
	return -1;

    /* Allocate array to hold the X position of each button */
    buttonPositions = (int *) lalloc(numButtons * sizeof(int), TRUE);
    if (buttonPositions == NULL)
	return -1;

    /*
     * Calculate how big the dialog must be.
     */
    hwnd = GetDesktopWindow();
    hdc = GetWindowDC(hwnd);
    oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT));
    dlgPaddingX = DLG_OLD_STYLE_PADDING_X;
    dlgPaddingY = DLG_OLD_STYLE_PADDING_Y;

    GetTextMetrics(hdc, &fontInfo);
    fontHeight = fontInfo.tmHeight;

    /* Minimum width for horizontal button */
    minButtonWidth = GetTextWidth(hdc, "Cancel", 6);

    /* Maximum width of a dialog, if possible */
    GetWindowRect(s_hwnd, &rect);
    maxDialogWidth = rect.right - rect.left
		     - GetSystemMetrics(SM_CXFRAME) * 2;
    if (maxDialogWidth < DLG_MIN_MAX_WIDTH)
	maxDialogWidth = DLG_MIN_MAX_WIDTH;

    /* Set dlgwidth to width of message */
    pstart = message;
    messageWidth = 0;
    msgheight = 0;
    do
    {
	pend = vim_strchr(pstart, DLG_BUTTON_SEP);
	if (pend == NULL)
	    pend = pstart + STRLEN(pstart);	/* Last line of message. */
	msgheight += fontHeight;
	textWidth = GetTextWidth(hdc, pstart, pend - pstart);
	if (textWidth > messageWidth)
	    messageWidth = textWidth;
	pstart = pend + 1;
    } while (*pend != NUL);
    dlgwidth = messageWidth;

    /* Add width of icon to dlgwidth, and some space */
    dlgwidth += DLG_ICON_WIDTH + 3 * dlgPaddingX;

    if (msgheight < DLG_ICON_HEIGHT)
	msgheight = DLG_ICON_HEIGHT;

    /*
     * Check button names.  A long one will make the dialog wider.
     */
	 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
    if (!vertical)
    {
	// Place buttons horizontally if they fit.
	horizWidth = dlgPaddingX;
	pstart = tbuffer;
	i = 0;
	do
	{
	    pend = vim_strchr(pstart, DLG_BUTTON_SEP);
	    if (pend == NULL)
		pend = pstart + STRLEN(pstart);	// Last button name.
	    textWidth = GetTextWidth(hdc, pstart, pend - pstart);
	    if (textWidth < minButtonWidth)
		textWidth = minButtonWidth;
	    textWidth += dlgPaddingX;	    /* Padding within button */
	    buttonWidths[i] = textWidth;
	    buttonPositions[i++] = horizWidth;
	    horizWidth += textWidth + dlgPaddingX; /* Pad between buttons */
	    pstart = pend + 1;
	} while (*pend != NUL);

	if (horizWidth > maxDialogWidth)
	    vertical = TRUE;	// Too wide to fit on the screen.
	else if (horizWidth > dlgwidth)
	    dlgwidth = horizWidth;
    }

    if (vertical)
    {
	// Stack buttons vertically.
	pstart = tbuffer;
	do
	{
	    pend = vim_strchr(pstart, DLG_BUTTON_SEP);
	    if (pend == NULL)
		pend = pstart + STRLEN(pstart);	// Last button name.
	    textWidth = GetTextWidth(hdc, pstart, pend - pstart);
	    textWidth += dlgPaddingX;		/* Padding within button */
	    textWidth += DLG_VERT_PADDING_X * 2; /* Padding around button */
	    if (textWidth > dlgwidth)
		dlgwidth = textWidth;
	    pstart = pend + 1;
	} while (*pend != NUL);
    }

    if (dlgwidth < DLG_MIN_WIDTH)
	dlgwidth = DLG_MIN_WIDTH;	/* Don't allow a really thin dialog!*/

    /* start to fill in the dlgtemplate information.  addressing by WORDs */
    lStyle = DS_MODALFRAME | WS_CAPTION | WS_VISIBLE ;

    add_long(lStyle);
    pnumitems = p;	/*save where the number of items must be stored*/
    add_byte(0);	// NumberOfItems(will change later)
    add_word(10);	// x
    add_word(10);	// y
    add_word(PixelToDialogX(dlgwidth));

    // Dialog height.
    if (vertical)
	dlgheight = msgheight + 2 * dlgPaddingY +
			      DLG_VERT_PADDING_Y + 2 * fontHeight * numButtons;
    else
	dlgheight = msgheight + 3 * dlgPaddingY + 2 * fontHeight;

    // Dialog needs to be taller if contains an edit box.
    editboxheight = fontHeight + dlgPaddingY + 4 * DLG_VERT_PADDING_Y;
    if (textfield != NULL)
	dlgheight += editboxheight;

    add_word(PixelToDialogY(dlgheight));

    add_byte(0);	//menu
    add_byte(0);	//class

    /* copy the title of the dialog */
    add_string(title ? title : ("Vim"VIM_VERSION_MEDIUM));

    buttonYpos = msgheight + 2 * dlgPaddingY;

    if (textfield != NULL)
	buttonYpos += editboxheight;

    pstart = tbuffer; //dflt_text
    horizWidth = (dlgwidth - horizWidth) / 2;	/* Now it's X offset */
    for (i = 0; i < numButtons; i++)
    {
	/* get end of this button. */
	for (	pend = pstart;
		*pend && (*pend != DLG_BUTTON_SEP);
		pend++)
	    ;

	if (*pend)
	    *pend = '\0';

	/*
	 * NOTE:
	 * setting the BS_DEFPUSHBUTTON style doesn't work because Windows sets
	 * the focus to the first tab-able button and in so doing makes that
	 * the default!! Grrr.  Workaround: Make the default button the only
	 * one with WS_TABSTOP style. Means user can't tab between buttons, but
	 * he/she can use arrow keys.
	 *
	 * NOTE (Thore): Setting BS_DEFPUSHBUTTON works fine when it's the
	 * first one, so I changed the correct button to be this style. This
	 * is necessary because when an edit box is added, we need a button to
	 * be default.  The edit box will be the default control, and when the
	 * user presses enter from the edit box we want the default button to
	 * be pressed.
	 */
	if (vertical)
	{
	    p = add_dialog_element(p,
		    ((i == dfltbutton || dfltbutton < 0) && textfield != NULL
			    ?  BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP,
		    PixelToDialogX(DLG_VERT_PADDING_X),
		    PixelToDialogY(buttonYpos /* TBK */
				   + 2 * fontHeight * i),
		    PixelToDialogX(dlgwidth - 2 * DLG_VERT_PADDING_X),
		    (WORD)(PixelToDialogY(2 * fontHeight) - 1),
		    (WORD)(IDCANCEL + 1 + i), (BYTE)0x80, pstart);
	}
	else
	{
	    p = add_dialog_element(p,
		    ((i == dfltbutton || dfltbutton < 0) && textfield != NULL
			     ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP,
		    PixelToDialogX(horizWidth + buttonPositions[i]),
		    PixelToDialogY(buttonYpos), /* TBK */
		    PixelToDialogX(buttonWidths[i]),
		    (WORD)(PixelToDialogY(2 * fontHeight) - 1),
		    (WORD)(IDCANCEL + 1 + i), (BYTE)0x80, pstart);
	}

	pstart = pend + 1;	/*next button*/

    }
    *pnumitems += numButtons;

    /* Vim icon */
    p = add_dialog_element(p, SS_ICON,
	    PixelToDialogX(dlgPaddingX),
	    PixelToDialogY(dlgPaddingY),
	    PixelToDialogX(DLG_ICON_WIDTH),
	    PixelToDialogY(DLG_ICON_HEIGHT),
	    DLG_NONBUTTON_CONTROL + 0, (BYTE)0x82,
	    &dlg_icons[type]);


    /* Dialog message */
    p = add_dialog_element(p, SS_LEFT,
	    PixelToDialogX(2 * dlgPaddingX + DLG_ICON_WIDTH),
	    PixelToDialogY(dlgPaddingY),
	    (WORD)(PixelToDialogX(messageWidth) + 1),
	    PixelToDialogY(msgheight),
	    DLG_NONBUTTON_CONTROL + 1, (BYTE)0x82, message);

    /* Edit box */
    if (textfield != NULL)
    {
	p = add_dialog_element(p, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP | WS_BORDER,
		PixelToDialogX(2 * dlgPaddingX),
		PixelToDialogY(2 * dlgPaddingY + msgheight),
		PixelToDialogX(dlgwidth - 4 * dlgPaddingX),
		PixelToDialogY(fontHeight + dlgPaddingY),
		DLG_NONBUTTON_CONTROL + 2, (BYTE)0x81, textfield);
	*pnumitems += 1;
    }

    *pnumitems += 2;

    SelectFont(hdc, oldFont);
    ReleaseDC(hwnd, hdc);
    dp = MakeProcInstance((FARPROC)dialog_callback, s_hinst);


    /* Let the dialog_callback() function know which button to make default
     * If we have an edit box, make that the default. We also need to tell
     * dialog_callback() if this dialog contains an edit box or not. We do
     * this by setting s_textfield if it does.
     */
    if (textfield != NULL)
    {
	dialog_default_button = DLG_NONBUTTON_CONTROL + 2;
	s_textfield = textfield;
    }
    else
    {
	dialog_default_button = IDCANCEL + 1 + dfltbutton;
	s_textfield = NULL;
    }

    /*show the dialog box modally and get a return value*/
    nchar = DialogBoxIndirect(
	    s_hinst,
	    (HGLOBAL) hglbDlgTemp,
	    s_hwnd,
	    (DLGPROC)dp);

    FreeProcInstance( dp );
    GlobalUnlock(hglbDlgTemp);
    GlobalFree(hglbDlgTemp);
    vim_free(tbuffer);
    vim_free(buttonWidths);
    vim_free(buttonPositions);


    return nchar;
}
Example #21
0
LRESULT CALLBACK NewStatusBarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	POINT pt;

	switch (msg) {
	case WM_SETCURSOR:
		GetCursorPos(&pt);

		SendMessage(GetParent(hwnd), msg, wParam, lParam);
		if (pt.x == ptMouse.x && pt.y == ptMouse.y)
			return 1;

		ptMouse = pt;
		if (tooltip_active){
			KillTimer(hwnd, TIMERID_HOVER);
			if (!NotifyEventHooks(hStatusBarHideToolTipEvent, 0, 0))
				CallService("mToolTip/HideTip", 0, 0);
			tooltip_active = FALSE;
		}
		KillTimer(hwnd, TIMERID_HOVER);
		SetTimer(hwnd, TIMERID_HOVER, 750, 0);
		break;

	case WM_NCHITTEST:
		{
			LRESULT lr = SendMessage(GetParent(hwnd), WM_NCHITTEST, wParam, lParam);
			if (lr == HTLEFT || lr == HTRIGHT || lr == HTBOTTOM || lr == HTTOP || lr == HTTOPLEFT || lr == HTTOPRIGHT
				|| lr == HTBOTTOMLEFT || lr == HTBOTTOMRIGHT)
				return HTTRANSPARENT;
		}
		break;

	case WM_ERASEBKGND:
		if (cfg::dat.bSkinnedStatusBar)
			return 1;
		return mir_callNextSubclass(hwnd, NewStatusBarWndProc, msg, wParam, lParam);

	case WM_LBUTTONDOWN:
	case WM_RBUTTONDOWN:
		KillTimer(hwnd, TIMERID_HOVER);
		if (!NotifyEventHooks(hStatusBarHideToolTipEvent, 0, 0))
			CallService("mToolTip/HideTip", 0, 0);
		tooltip_active = FALSE;
		break;

	case WM_PAINT:
		if (cfg::shutDown || arStatusItems.getCount() == 0)
			return 0;

		if (cfg::dat.bSkinnedStatusBar) {
			PAINTSTRUCT ps;
			HDC hdc = BeginPaint(hwnd, &ps);
			HDC hdcMem = CreateCompatibleDC(hdc);
			RECT rcClient, rcWindow;
			DRAWITEMSTRUCT dis = {0};
			BYTE windowStyle = cfg::getByte("CLUI", "WindowStyle", SETTING_WINDOWSTYLE_DEFAULT);
			LONG b_offset = cfg::dat.bClipBorder + (windowStyle == SETTING_WINDOWSTYLE_NOBORDER ? 2 : (windowStyle == SETTING_WINDOWSTYLE_THINBORDER ? 1 : 0));

			GetClientRect(hwnd, &rcClient);
			GetWindowRect(hwnd, &rcWindow);
			pt.x = rcWindow.left;
			pt.y = rcWindow.top;
			ScreenToClient(pcli->hwndContactList, &pt);

			HBITMAP hbmMem = CreateCompatibleBitmap(hdc, rcClient.right, rcClient.bottom);
			HBITMAP hbmOld = reinterpret_cast<HBITMAP>(SelectObject(hdcMem, hbmMem));
			SetBkMode(hdcMem, TRANSPARENT);
			HFONT hOldFont = reinterpret_cast<HFONT>(SelectObject(hdcMem, GetStockObject(DEFAULT_GUI_FONT)));
			BitBlt(hdcMem, 0, 0, rcClient.right, rcClient.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);
			StatusItems_t *item = arStatusItems[ID_EXTBKSTATUSBAR - ID_STATUS_OFFLINE];
			if (!item->IGNORED) {
				RECT rc = rcClient;
				rc.left += item->MARGIN_LEFT;
				rc.right -= item->MARGIN_RIGHT;
				rc.top += item->MARGIN_TOP;
				rc.bottom -= item->MARGIN_BOTTOM;
				DrawAlpha(hdcMem, &rc, item->COLOR, item->ALPHA, item->COLOR2, item->COLOR2_TRANSPARENT, item->GRADIENT,
					item->CORNER, item->BORDERSTYLE, item->imageItem);
				SetTextColor(hdcMem, item->TEXTCOLOR);
			}
			else
				SetTextColor(hdcMem, GetSysColor(COLOR_BTNTEXT));

			dis.hwndItem = hwnd;
			dis.hDC = hdcMem;
			dis.CtlType = 0;
			int nParts = SendMessage(hwnd, SB_GETPARTS, 0, 0);
			for (int i = 0; i < nParts; i++) {
				SendMessage(hwnd, SB_GETRECT, i, (LPARAM)&dis.rcItem);
				OffsetRect(&dis.rcItem, 0, -b_offset);
				dis.itemData = SendMessage(hwnd, SB_GETTEXTA, i, 0);
				SendMessage(pcli->hwndContactList, WM_DRAWITEM, 0, (LPARAM)&dis);
			}
			BitBlt(hdc, 0, 0, rcClient.right, rcClient.bottom, hdcMem, 0, 0, SRCCOPY);
			if (hOldFont)
				SelectObject(hdcMem, hOldFont);
			SelectObject(hdcMem, hbmOld);
			DeleteObject(hbmMem);
			DeleteDC(hdcMem);
			EndPaint(hwnd, &ps);
			return 0;
		}
		break;

	case WM_TIMER:
		if (wParam == TIMERID_HOVER) {
			KillTimer(hwnd, TIMERID_HOVER);

			GetCursorPos(&pt);
			if (pt.x == ptMouse.x && pt.y == ptMouse.y) {
				ScreenToClient(hwnd, &pt);
				int nParts = SendMessage(hwnd, SB_GETPARTS, 0, 0);
				for (int i = 0; i < nParts; i++) {
					RECT rc;
					SendMessage(hwnd, SB_GETRECT, i, (LPARAM)&rc);
					if (PtInRect(&rc,pt)) {
						ProtocolData *PD = (ProtocolData *)SendMessageA(hwnd, SB_GETTEXTA, i, 0);
						if (PD == NULL)
							continue;

						if (NotifyEventHooks(hStatusBarShowToolTipEvent, (WPARAM)PD->RealName, 0) > 0) // a plugin handled this event
							tooltip_active = TRUE;
						else if (cfg::getDword("mToolTip", "ShowStatusTip", 0)) {
							WORD wStatus = (WORD)CallProtoService(PD->RealName, PS_GETSTATUS, 0, 0);
							BYTE isLocked = cfg::getByte(PD->RealName, "LockMainStatus", 0);

							TCHAR szTipText[256];
							mir_sntprintf(szTipText, SIZEOF(szTipText), _T("<b>%s</b>: %s%s"),
								PD->RealName, pcli->pfnGetStatusModeDescription(wStatus, 0), isLocked ? _T("  (LOCKED)") : _T(""));

							CLCINFOTIP ti = { sizeof(ti) };
							ti.isTreeFocused = (GetFocus() == pcli->hwndContactList);
							CallService("mToolTip/ShowTipW", (WPARAM)szTipText, (LPARAM)&ti);
						}
						break;
					}
				}
			}
		}
		break;
	}

	return mir_callNextSubclass(hwnd, NewStatusBarWndProc, msg, wParam, lParam);
}
Example #22
0
// ----------------------------------------------------------------------
//  Windows proc for the one and only window in this app.
//
// ----------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HBRUSH   hbrLit = NULL;
    static HBRUSH   hbrUnlit = NULL;
    static HFONT    hFont = NULL;
    static UINT_PTR nTimerId = 101;

    switch (message)
    {
        case WM_CREATE:
        {
            // Make BLACK the transparency color
            SetLayeredWindowAttributes(hWnd, RGB(0,0,0), 0, LWA_COLORKEY);

            // Initialize the DPI scalar.
            InitializeDPIScale(hWnd);

            // Create brushes and font that will be used in WM_PAINT
            hbrLit = CreateSolidBrush(RGB(0,128,255));
            hbrUnlit = CreateSolidBrush(RGB(0,64,128));
            hFont = CreateFont(DPIScale(64), 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, 0, 0, 0, 0, 0, L"Segoe UI");

            // Position at the center of the primary monitor
            POINT const ptZeroZero = {};
            HMONITOR hMonitor = MonitorFromPoint(ptZeroZero, MONITOR_DEFAULTTOPRIMARY);
            MONITORINFO mi = {sizeof(mi)};
            GetMonitorInfo(hMonitor, &mi);

            SIZE const size = { g_currentVolume.cSteps * DPIScale(10), DPIScale(60) };

            POINT const pt = 
            {
                mi.rcMonitor.left + (mi.rcMonitor.left + mi.rcMonitor.right - size.cx) / 2, 
                mi.rcMonitor.top + (mi.rcMonitor.top + mi.rcMonitor.bottom - size.cy) / 2
            };

            SetWindowPos(hWnd, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, SWP_SHOWWINDOW);

            break;
        }

        case WM_DESTROY:
        {
            DeleteObject(hbrLit);
            DeleteObject(hbrUnlit);
            DeleteObject(hFont);

            PostQuitMessage(0);
            return 0;
        }

        case WM_ERASEBKGND:
        {
            // Don't do any erasing here.  It's done in WM_PAINT to avoid flicker.
            return 1;
        }

        case WM_VOLUMECHANGE:
        {
            // get the new volume level
            g_pVolumeMonitor->GetLevelInfo(&g_currentVolume);

            // make window visible for 2 seconds
            ShowWindow(hWnd, SW_SHOW);
            InvalidateRect(hWnd, NULL, TRUE);

            nTimerId = SetTimer(hWnd, 101, 2000, NULL);

            return 0;
        }

        case WM_ENDPOINTCHANGE:
        {
            g_pVolumeMonitor->ChangeEndpoint();
            return 0;
        }

        case WM_TIMER:
        {
            // make the window go away
            ShowWindow(hWnd, SW_HIDE);
            KillTimer(hWnd, nTimerId);

            return 0;
        }

        case WM_PAINT:
        {
            PAINTSTRUCT     ps;
            HPAINTBUFFER    hBufferedPaint = NULL;
            RECT            rc;

            GetClientRect(hWnd, &rc);
            HDC hdc = BeginPaint(hWnd, &ps);

            if (g_bDblBuffered)
            {
                // Get doublebuffered DC
                HDC hdcMem;
                hBufferedPaint = BeginBufferedPaint(hdc, &rc, BPBF_COMPOSITED, NULL, &hdcMem);
                if (hBufferedPaint)
                {
                    hdc = hdcMem;
                }
            }

            // black background (transparency color)
            FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));

            // Draw LEDs
            for (UINT i = 0; i < (g_currentVolume.cSteps-1); i++)
            {
                RECT const rcLed = { DPIScale(i * 10), DPIScale(10), DPIScale(i * 10 + 8), rc.bottom-DPIScale(15) };

                if ((i < g_currentVolume.nStep) && (!g_currentVolume.bMuted))
                    FillRect(hdc, &rcLed, hbrLit);
                else
                    FillRect(hdc, &rcLed, hbrUnlit);
            }

            if (g_currentVolume.bMuted)
            {
                HGDIOBJ hof = SelectObject(hdc, hFont);
                SetBkMode(hdc, TRANSPARENT);
                SetTextColor(hdc, RGB(255, 64, 64));
                RECT rcText = rc;
                rcText.bottom -= DPIScale(11);
                DrawText(hdc, L"MUTED", -1, &rcText, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
                SelectObject(hdc, hof);
            }

            if (hBufferedPaint)
            {
                // end painting
                BufferedPaintMakeOpaque(hBufferedPaint, NULL);
                EndBufferedPaint(hBufferedPaint, TRUE);
            }

            EndPaint(hWnd, &ps);
            return 0;
        }
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}
Example #23
0
static int winDialogBaseProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result)
{
  if (iupwinBaseContainerMsgProc(ih, msg, wp, lp, result))
    return 1;

  iupwinMenuDialogProc(ih, msg, wp, lp);

  switch (msg)
  {
  case WM_GETMINMAXINFO:
    {
      if (winDialogCheckMinMaxInfo(ih, (MINMAXINFO*)lp))
      {
        *result = 0;
        return 1;
      }
      break;
    }
  case WM_MOVE:
    {
      IFnii cb = (IFnii)IupGetCallback(ih, "MOVE_CB");
      int x, y;
      /* ignore LPARAM because they are the clientpos */
      iupdrvDialogGetPosition(ih, NULL, &x, &y);
      if (cb) cb(ih, x, y);
      break;
    }
  case WM_SIZE:
    {
      if (ih->data->ignore_resize)
        break;

      switch(wp)
      {
      case SIZE_MINIMIZED:
        {
          if (ih->data->show_state != IUP_MINIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            ih->data->show_state = IUP_MINIMIZE;
            if (show_cb && show_cb(ih, IUP_MINIMIZE) == IUP_CLOSE)
              IupExitLoop();
          }
          break;
        }
      case SIZE_MAXIMIZED:
        {
          if (ih->data->show_state != IUP_MAXIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            ih->data->show_state = IUP_MAXIMIZE;
            if (show_cb && show_cb(ih, IUP_MAXIMIZE) == IUP_CLOSE)
              IupExitLoop();
          }

          winDialogResize(ih, LOWORD(lp), HIWORD(lp));

          if (iupAttribGetBoolean(ih, "MDICHILD"))
          {
            /* WORKAROUND: when a child MDI dialog is maximized, 
               its title is displayed inside the MDI client area.
               So we force a MDI client size update */
            RECT rect;
            Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE");
            GetClientRect(client->handle, &rect);
            PostMessage(client->handle, WM_SIZE, (WPARAM)SIZE_RESTORED, MAKELPARAM(rect.right-rect.left, rect.bottom-rect.top));
          }
          break;
        }
      case SIZE_RESTORED:
        {
          if (ih->data->show_state == IUP_MAXIMIZE || ih->data->show_state == IUP_MINIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            ih->data->show_state = IUP_RESTORE;
            if (show_cb && show_cb(ih, IUP_RESTORE) == IUP_CLOSE)
              IupExitLoop();
          }

          winDialogResize(ih, LOWORD(lp), HIWORD(lp));
          break;
        }
      }

      if (iupAttribGetBoolean(ih, "MDIFRAME"))
      {
        /* We are going to manually position the MDI client, 
           so abort MDI frame processing. */
        *result = 0;
        return 1;
      }
      else
        break;
    }
  case WM_USER+IUPWIN_TRAY_NOTIFICATION:
    {
      int dclick  = 0;
      int button  = 0;
      int pressed = 0;

      switch (lp)
      {
      case WM_LBUTTONDOWN:
        pressed = 1;
        button  = 1;
        break;
      case WM_MBUTTONDOWN:
        pressed = 1;
        button  = 2;
        break;
      case WM_RBUTTONDOWN:
        pressed = 1;
        button  = 3;
        break;
      case WM_LBUTTONDBLCLK:
        dclick = 1;
        button = 1;
        break;
      case WM_MBUTTONDBLCLK:
        dclick = 1;
        button = 2;
        break;
      case WM_RBUTTONDBLCLK:
        dclick = 1;
        button = 3;
        break;
      case WM_LBUTTONUP:
        button = 1;
        break;
      case WM_MBUTTONUP:
        button = 2;
        break;
      case WM_RBUTTONUP:
        button = 3;
        break;
      }

      if (button != 0)
      {
        IFniii cb = (IFniii)IupGetCallback(ih, "TRAYCLICK_CB");
        if (cb && cb(ih, button, pressed, dclick) == IUP_CLOSE)
          IupExitLoop();
      }

      break;
    }
  case WM_CLOSE:
    {
      Icallback cb = IupGetCallback(ih, "CLOSE_CB");
      if (cb)
      {
        int ret = cb(ih);
        if (ret == IUP_IGNORE)
        {
          *result = 0;
          return 1;
        }
        if (ret == IUP_CLOSE)
          IupExitLoop();
      }

      /* child mdi is automatically destroyed */
      if (iupAttribGetBoolean(ih, "MDICHILD"))
        IupDestroy(ih);
      else
      {
        if (!winDialogMDICloseChildren(ih))
        {
          *result = 0;
          return 1;
        }

        IupHide(ih); /* IUP default processing */
      }

      *result = 0;
      return 1;
    }
  case WM_COPYDATA:  
    {
      IFnsi cb = (IFnsi)IupGetCallback(ih, "COPYDATA_CB");
      if (cb)
      {
        COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lp;
        char* iup_id = (char*)cds->dwData;

        /* from SetGlobal("SINGLEINSTANCE") */
        if (iup_id && iup_id[0] == 'I' &&
                      iup_id[1] == 'U' &&
                      iup_id[2] == 'P')
        {
          char* data = iupwinStrFromSystem((TCHAR*)cds->lpData);
          cb(ih, data, (int)strlen(data)+1);
        }
      }
      break; 
    }
  case WM_ERASEBKGND:
    {
      HBITMAP hBitmap = (HBITMAP)iupAttribGet(ih, "_IUPWIN_BACKGROUND_BITMAP");
      if (hBitmap) 
      {
        RECT rect;
        HDC hdc = (HDC)wp;

        HBRUSH hBrush = CreatePatternBrush(hBitmap);
        GetClientRect(ih->handle, &rect); 
        FillRect(hdc, &rect, hBrush); 
        DeleteObject(hBrush);

        /* return non zero value */
        *result = 1;
        return 1; 
      }
      else
      {
        unsigned char r, g, b;
        char* color = iupAttribGet(ih, "_IUPWIN_BACKGROUND_COLOR");
        if (iupStrToRGB(color, &r, &g, &b))
        {
          RECT rect;
          HDC hdc = (HDC)wp;

          SetDCBrushColor(hdc, RGB(r,g,b));
          GetClientRect(ih->handle, &rect); 
          FillRect(hdc, &rect, (HBRUSH)GetStockObject(DC_BRUSH)); 

          /* return non zero value */
          *result = 1;
          return 1;
        }
      }
      break;
    }
  case WM_DESTROY:
    {
      /* Since WM_CLOSE changed the Windows default processing                            */
      /* WM_DESTROY is NOT received by IupDialogs                                         */
      /* Except when they are children of other IupDialogs and the parent is destroyed.   */
      /* So we have to destroy the child dialog.                                          */
      /* The application is responsible for destroying the children before this happen.   */
      IupDestroy(ih);
      break;
    }
  case WM_DPICHANGED:
    {
      IupRefresh(ih);
      break;
    }
  }

  if (msg == (UINT)WM_HELPMSG)
  {
    Ihandle* child = NULL;
    DWORD* struct_ptr = (DWORD*)lp;
    if (*struct_ptr == sizeof(CHOOSECOLOR))
    {
      CHOOSECOLOR* choosecolor = (CHOOSECOLOR*)lp;
      child = (Ihandle*)choosecolor->lCustData;
    }
    else if (*struct_ptr == sizeof(CHOOSEFONT))
    {
      CHOOSEFONT* choosefont = (CHOOSEFONT*)lp;
      child = (Ihandle*)choosefont->lCustData;
    }

    if (child)
    {
      Icallback cb = IupGetCallback(child, "HELP_CB");
      if (cb && cb(child) == IUP_CLOSE)
        EndDialog((HWND)iupAttribGet(child, "HWND"), IDCANCEL);
    }
  }

  return 0;
}
Example #24
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    // register window class
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);


    if (!RegisterClassEx(&wcex))
        return 0;

    // create main window
    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "SOIL Sample",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          512,
                          512,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    //	check my error handling
    /*
    SOIL_load_OGL_texture( "img_test.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0 );
    std::cout << "'" << SOIL_last_result() << "'" << std::endl;
    */


    // enable OpenGL for the window
    EnableOpenGL(hwnd, &hDC, &hRC);

    glEnable( GL_BLEND );
    //glDisable( GL_BLEND );
    //	straight alpha
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    //	premultiplied alpha (remember to do the same in glColor!!)
    //glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );

    //	do I want alpha thresholding?
    glEnable( GL_ALPHA_TEST );
    glAlphaFunc( GL_GREATER, 0.5f );

    //	log what the use is asking us to load
    std::string load_me = lpCmdLine;
    if( load_me.length() > 2 )
    {
		//load_me = load_me.substr( 1, load_me.length() - 2 );
		load_me = load_me.substr( 0, load_me.length() - 0 );
    } else
    {
    	//load_me = "img_test_uncompressed.dds";
    	//load_me = "img_test_indexed.tga";
    	//load_me = "img_test.dds";
    	load_me = "img_test.png";
    	//load_me = "odd_size.jpg";
    	//load_me = "img_cheryl.jpg";
    	//load_me = "oak_odd.png";
    	//load_me = "field_128_cube.dds";
    	//load_me = "field_128_cube_nomip.dds";
    	//load_me = "field_128_cube_uc.dds";
    	//load_me = "field_128_cube_uc_nomip.dds";
    	//load_me = "Goblin.dds";
    	//load_me = "parquet.dds";
    	//load_me = "stpeters_probe.hdr";
    	//load_me = "VeraMoBI_sdf.png";

    	//	for testing the texture rectangle code
    	//load_me = "test_rect.png";
    }
	std::cout << "'" << load_me << "'" << std::endl;

	//	1st try to load it as a single-image-cubemap
	//	(note, need DDS ordered faces: "EWUDNS")
	GLuint tex_ID;
    int time_me;

    std::cout << "Attempting to load as a cubemap" << std::endl;
    time_me = clock();
	tex_ID = SOIL_load_OGL_single_cubemap(
			load_me.c_str(),
			SOIL_DDS_CUBEMAP_FACE_ORDER,
			SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID,
			SOIL_FLAG_POWER_OF_TWO
			| SOIL_FLAG_MIPMAPS
			//| SOIL_FLAG_COMPRESS_TO_DXT
			//| SOIL_FLAG_TEXTURE_REPEATS
			//| SOIL_FLAG_INVERT_Y
			| SOIL_FLAG_DDS_LOAD_DIRECT
			);
	time_me = clock() - time_me;
	std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;
    if( tex_ID > 0 )
    {
    	glEnable( GL_TEXTURE_CUBE_MAP );
		glEnable( GL_TEXTURE_GEN_S );
		glEnable( GL_TEXTURE_GEN_T );
		glEnable( GL_TEXTURE_GEN_R );
		glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glBindTexture( GL_TEXTURE_CUBE_MAP, tex_ID );
		//	report
		std::cout << "the loaded single cube map ID was " << tex_ID << std::endl;
		//std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;
    } else
    {
    	std::cout << "Attempting to load as a HDR texture" << std::endl;
		time_me = clock();
		tex_ID = SOIL_load_OGL_HDR_texture(
				load_me.c_str(),
				//SOIL_HDR_RGBE,
				//SOIL_HDR_RGBdivA,
				SOIL_HDR_RGBdivA2,
				0,
				SOIL_CREATE_NEW_ID,
				SOIL_FLAG_POWER_OF_TWO
				| SOIL_FLAG_MIPMAPS
				//| SOIL_FLAG_COMPRESS_TO_DXT
				);
		time_me = clock() - time_me;
		std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;

		//	did I fail?
		if( tex_ID < 1 )
		{
			//	loading of the single-image-cubemap failed, try it as a simple texture
			std::cout << "Attempting to load as a simple 2D texture" << std::endl;
			//	load the texture, if specified
			time_me = clock();
			tex_ID = SOIL_load_OGL_texture(
					load_me.c_str(),
					SOIL_LOAD_AUTO,
					SOIL_CREATE_NEW_ID,
					SOIL_FLAG_POWER_OF_TWO
					| SOIL_FLAG_MIPMAPS
					//| SOIL_FLAG_MULTIPLY_ALPHA
					//| SOIL_FLAG_COMPRESS_TO_DXT
					| SOIL_FLAG_DDS_LOAD_DIRECT
					//| SOIL_FLAG_NTSC_SAFE_RGB
					//| SOIL_FLAG_CoCg_Y
					//| SOIL_FLAG_TEXTURE_RECTANGLE
					);
			time_me = clock() - time_me;
			std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;
		}

		if( tex_ID > 0 )
		{
			//	enable texturing
			glEnable( GL_TEXTURE_2D );
			//glEnable( 0x84F5 );// enables texture rectangle
			//  bind an OpenGL texture ID
			glBindTexture( GL_TEXTURE_2D, tex_ID );
			//	report
			std::cout << "the loaded texture ID was " << tex_ID << std::endl;
			//std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;
		} else
		{
			//	loading of the texture failed...why?
			glDisable( GL_TEXTURE_2D );
			std::cout << "Texture loading failed: '" << SOIL_last_result() << "'" << std::endl;
		}
    }

    // program main loop
    const float ref_mag = 0.1f;
    while (!bQuit)
    {
        // check for messages
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // handle or dispatch messages
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            // OpenGL animation code goes here
            theta = clock() * 0.1;

            float tex_u_max = 1.0f;//0.2f;
            float tex_v_max = 1.0f;//0.2f;

            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT);

            glPushMatrix();
            glScalef( 0.8f, 0.8f, 0.8f );
            //glRotatef(-0.314159f*theta, 0.0f, 0.0f, 1.0f);
			glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
			glNormal3f( 0.0f, 0.0f, 1.0f );
            glBegin(GL_QUADS);
				glNormal3f( -ref_mag, -ref_mag, 1.0f );
                glTexCoord2f( 0.0f, tex_v_max );
                glVertex3f( -1.0f, -1.0f, -0.1f );

                glNormal3f( ref_mag, -ref_mag, 1.0f );
                glTexCoord2f( tex_u_max, tex_v_max );
                glVertex3f( 1.0f, -1.0f, -0.1f );

                glNormal3f( ref_mag, ref_mag, 1.0f );
                glTexCoord2f( tex_u_max, 0.0f );
                glVertex3f( 1.0f, 1.0f, -0.1f );

                glNormal3f( -ref_mag, ref_mag, 1.0f );
                glTexCoord2f( 0.0f, 0.0f );
                glVertex3f( -1.0f, 1.0f, -0.1f );
            glEnd();
            glPopMatrix();

			tex_u_max = 1.0f;
            tex_v_max = 1.0f;
            glPushMatrix();
            glScalef( 0.8f, 0.8f, 0.8f );
            glRotatef(theta, 0.0f, 0.0f, 1.0f);
			glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
			glNormal3f( 0.0f, 0.0f, 1.0f );
            glBegin(GL_QUADS);
                glTexCoord2f( 0.0f, tex_v_max );		glVertex3f( 0.0f, 0.0f, 0.1f );
                glTexCoord2f( tex_u_max, tex_v_max );		glVertex3f( 1.0f, 0.0f, 0.1f );
                glTexCoord2f( tex_u_max, 0.0f );		glVertex3f( 1.0f, 1.0f, 0.1f );
                glTexCoord2f( 0.0f, 0.0f );		glVertex3f( 0.0f, 1.0f, 0.1f );
            glEnd();
            glPopMatrix();

            {
				/*	check for errors	*/
				GLenum err_code = glGetError();
				while( GL_NO_ERROR != err_code )
				{
					printf( "OpenGL Error @ %s: %i", "drawing loop", err_code );
					err_code = glGetError();
				}
			}

            SwapBuffers(hDC);

            Sleep (1);
        }
    }

    //	and show off the screenshot capability
    /*
    load_me += "-screenshot.tga";
    SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_TGA, 0, 0, 512, 512 );
    //*/
    //*
    load_me += "-screenshot.bmp";
    SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_BMP, 0, 0, 512, 512 );
    //*/
    /*
    load_me += "-screenshot.dds";
    SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_DDS, 0, 0, 512, 512 );
    //*/

    // shutdown OpenGL
    DisableOpenGL(hwnd, hDC, hRC);

    // destroy the window explicitly
    DestroyWindow(hwnd);

    return msg.wParam;
}
Example #25
0
File: grid.c Project: UIKit0/mctrl
static void
grid_paint(void* control, HDC dc, RECT* dirty, BOOL erase)
{
    grid_t* grid = (grid_t*) control;
    RECT client;
    RECT rect;
    int header_w, header_h;
    int old_dc_state;
    int col0, row0;
    int x0, y0;
    int col, row;
    int col_count = grid->col_count;
    int row_count = grid->row_count;
    table_t* table = grid->table;
    table_cell_t* cell;

    GRID_TRACE("grid_paint(%p, %d, %d, %d, %d)", grid,
               dirty->left, dirty->top, dirty->right, dirty->bottom);

    if(table == NULL  &&  !(grid->style & MC_GS_OWNERDATA))
        return;

    old_dc_state = SaveDC(dc);
    GetClientRect(grid->win, &client);
    header_w = grid_header_width(grid);
    header_h = grid_header_height(grid);

    if(grid->font != NULL)
        SelectObject(dc, grid->font);
    SetBkMode(dc, TRANSPARENT);
    SetTextColor(dc, RGB(0,0,0));
    SelectObject(dc, GetStockObject(BLACK_PEN));

    /* Find 1st visible column */
    rect.left = header_w - grid->scroll_x;
    for(col = 0; col < col_count; col++) {
        rect.right = rect.left + grid_col_width(grid, col);
        if(rect.right > header_w) {
            col0 = col;
            x0 = rect.left;
            break;
        }
        rect.left = rect.right;
    }

    /* Find 1st visible row */
    rect.top = header_h - grid->scroll_y;
    for(row = 0; row < row_count; row++) {
        rect.bottom = rect.top + grid_row_height(grid, row);
        if(rect.bottom > header_h) {
            row0 = row;
            y0 = rect.top;
            break;
        }
        rect.top = rect.bottom;
    }

    /* If needed, send MC_GN_ODCACHEHINT */
    if(grid->style & MC_GS_OWNERDATA) {
        WORD col1, row1;

        rect.right = x0;
        for(col1 = col0; col1+1 < grid->col_count; col1++) {
            rect.right += grid_col_width(grid, col1);
            if(rect.right >= client.right)
                break;
        }

        rect.bottom = y0;
        for(row1 = row0; row1+1 < grid->row_count; row1++) {
            rect.bottom += grid_row_height(grid, row1);
            if(rect.bottom >= client.bottom)
                break;
        }

        if(col0 != grid->cache_hint[0] || row0 != grid->cache_hint[1] ||
           col1 != grid->cache_hint[2] || row1 != grid->cache_hint[3]) {
            MC_NMGCACHEHINT hint;

            hint.hdr.hwndFrom = grid->win;
            hint.hdr.idFrom = GetWindowLong(grid->win, GWL_ID);
            hint.hdr.code = MC_GN_ODCACHEHINT;
            hint.wColumnFrom = col0;
            hint.wRowFrom = row0;
            hint.wColumnTo = col1;
            hint.wRowTo = row1;
            GRID_TRACE("grid_paint: Sending MC_GN_ODCACHEHINT (%hu, %hu, %hu, %hu)",
                       col0, row0, col1, row1);
            MC_SEND(grid->notify_win, WM_NOTIFY, hint.hdr.idFrom, &hint);

            grid->cache_hint[0] = col0;
            grid->cache_hint[1] = row0;
            grid->cache_hint[2] = col1;
            grid->cache_hint[3] = row1;
        }
    }

    /* Paint the "dead" top left header cell */
    if(header_w > 0  &&  header_h > 0  &&
       dirty->left < header_w  &&  dirty->top < header_h)
    {
        mc_rect_set(&rect, 0, 0, grid->header_width, grid->header_height);
        mc_clip_set(dc, 0, 0, MC_MIN(header_w, client.right), MC_MIN(header_h, client.bottom));
        grid_paint_header_cell(grid, MC_TABLE_HEADER, MC_TABLE_HEADER, NULL, dc, &rect, -1, 0);
    }

    /* Paint column headers */
    if(header_h > 0  &&  dirty->top < header_h) {
        rect.left = x0;
        rect.top = 0;
        rect.bottom = header_h;

        for(col = col0; col < col_count; col++) {
            rect.right = rect.left + grid_col_width(grid, col);
            mc_clip_set(dc, MC_MAX(header_w, rect.left), rect.top,
                        MC_MIN(rect.right, client.right), MC_MIN(rect.bottom, client.bottom));
            grid_paint_header_cell(grid, col, MC_TABLE_HEADER, (table ? &table->cols[col] : NULL),
                                   dc, &rect, col, (grid->style & MC_GS_COLUMNHEADERMASK));
            rect.left = rect.right;
            if(rect.right >= client.right)
                break;
        }
    }

    /* Paint row headers */
    if(header_w > 0  &&  dirty->left <= header_w) {
        rect.left = 0;
        rect.top = y0;
        rect.right = header_w;

        for(row = row0; row < row_count; row++) {
            rect.bottom = rect.top + grid_row_height(grid, row);
            mc_clip_set(dc, rect.left, MC_MAX(header_h, rect.top),
                        MC_MIN(rect.right, client.right), MC_MIN(rect.bottom, client.bottom));
            grid_paint_header_cell(grid, MC_TABLE_HEADER, row, (table ? &table->rows[row] : NULL),
                                   dc, &rect, row, (grid->style & MC_GS_ROWHEADERMASK));
            rect.top = rect.bottom;
            if(rect.bottom >= client.bottom)
                break;
        }
    }

    /* Paint grid lines */
    if(!(grid->style & MC_GS_NOGRIDLINES)) {
        HPEN pen, old_pen;
        int x, y;

        mc_clip_set(dc, header_w, header_h, client.right, client.bottom);
        pen = CreatePen(PS_SOLID, 0, mcGetThemeSysColor(grid->theme_listview, COLOR_3DFACE));
        old_pen = SelectObject(dc, pen);

        x = x0;
        y = header_h + grid->scroll_y_max - grid->scroll_y;
        for(col = col0; col < col_count; col++) {
            x += grid_col_width(grid, col);
            MoveToEx(dc, x-1, header_h, NULL);
            LineTo(dc, x-1, y);
            if(x >= client.right)
                break;
        }

        x = header_w + grid->scroll_x_max - grid->scroll_x;
        y = y0;
        for(row = 0; row < row_count; row++) {
            y += grid_row_height(grid, row);
            MoveToEx(dc, header_w, y-1, NULL);
            LineTo(dc, x, y-1);
            if(y >= client.bottom)
                break;
        }

        SelectObject(dc, old_pen);
        DeleteObject(pen);
    }

    /* Paint grid cells */
    rect.top = y0;
    for(row = row0; row < row_count; row++) {
        rect.bottom = rect.top + grid_row_height(grid, row);
        rect.left = x0;
        for(col = col0; col < col_count; col++) {
            if(table != NULL)
                cell = table_cell(table, col, row);
            else
                cell = NULL;
            rect.right = rect.left + grid_col_width(grid, col);
            grid_paint_cell(grid, col, row, cell, dc, &rect);
            if(rect.right >= client.right)
                break;
            rect.left = rect.right;
        }
        if(rect.bottom >= client.bottom)
            break;
        rect.top = rect.bottom;
    }

    RestoreDC(dc, old_dc_state);
}
Example #26
0
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        
                   PSTR szCmdLine, int iCmdShow)
        
{
        
    static TCHAR szAppName[] = TEXT ("HelloWin") ;
        
    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 ("This program requires Windows NT!"),
        
                                  szAppName, MB_ICONERROR) ;
        
            return 0 ;
        
    }
        
    hwnd = CreateWindow( szAppName,      // window class name
        
                   TEXT ("The Hello Program"),   // window caption
        
                   WS_OVERLAPPEDWINDOW,  // window style
        
                   CW_USEDEFAULT,// initial x position
        
                   CW_USEDEFAULT,// initial y position
        
                   CW_USEDEFAULT,// initial x size
        
                   CW_USEDEFAULT,// initial y size
        
                   NULL,                 // parent window handle
        
               NULL,            // window menu handle
        
               hInstance,   // program instance handle
        
               NULL) ;      // creation parameters
        
   
        
    ShowWindow (hwnd, iCmdShow) ;
        
    UpdateWindow (hwnd) ;
        
   
        
    while (GetMessage (&msg, NULL, 0, 0))
        
    {
        
            TranslateMessage (&msg) ;
        
          DispatchMessage (&msg) ;
        
    }
        
    return msg.wParam ;
        
}
Example #27
0
File: draw.c Project: GYGit/reactos
static BOOL
MyIntDrawRectEdge(HDC hdc, LPRECT rc, UINT uType, UINT uFlags, COLOR_SCHEME *scheme)
{
    signed char LTInnerI, LTOuterI;
    signed char RBInnerI, RBOuterI;
    HPEN LTInnerPen, LTOuterPen;
    HPEN RBInnerPen, RBOuterPen;
    RECT InnerRect = *rc;
    POINT SavePoint;
    HPEN SavePen;
    int LBpenplus = 0;
    int LTpenplus = 0;
    int RTpenplus = 0;
    int RBpenplus = 0;
    HBRUSH hbr;

    /* Init some vars */
    LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN);
    SavePen = (HPEN)SelectObject(hdc, LTInnerPen);

    /* Determine the colors of the edges */
    LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
    LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
    RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
    RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];

    if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT)
        LBpenplus = 1;
    if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT)
        RTpenplus = 1;
    if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT)
        RBpenplus = 1;
    if((uFlags & BF_TOPLEFT) == BF_TOPLEFT)
        LTpenplus = 1;

    if((uFlags & MY_BF_ACTIVEBORDER))
        hbr = CreateSolidBrush(scheme->crColor[COLOR_ACTIVEBORDER]);
    else
        hbr = CreateSolidBrush(scheme->crColor[COLOR_BTNFACE]);

    FillRect(hdc, &InnerRect, hbr);
    DeleteObject(hbr);

    MoveToEx(hdc, 0, 0, &SavePoint);

    /* Draw the outer edge */
    if(LTOuterI != -1)
    {
        LTOuterPen = GetStockObject(DC_PEN);
        SelectObject(hdc, LTOuterPen);
        SetDCPenColor(hdc, scheme->crColor[LTOuterI]);
        if(uFlags & BF_TOP)
        {
            MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
            LineTo(hdc, InnerRect.right, InnerRect.top);
        }
        if(uFlags & BF_LEFT)
        {
            MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
            LineTo(hdc, InnerRect.left, InnerRect.bottom);
        }
    }

    if(RBOuterI != -1)
    {
        RBOuterPen = GetStockObject(DC_PEN);
        SelectObject(hdc, RBOuterPen);
        SetDCPenColor(hdc, scheme->crColor[RBOuterI]);
        if(uFlags & BF_BOTTOM)
        {
            MoveToEx(hdc, InnerRect.left, InnerRect.bottom-1, NULL);
            LineTo(hdc, InnerRect.right, InnerRect.bottom-1);
        }
        if(uFlags & BF_RIGHT)
        {
            MoveToEx(hdc, InnerRect.right-1, InnerRect.top, NULL);
            LineTo(hdc, InnerRect.right-1, InnerRect.bottom);
        }
    }

    /* Draw the inner edge */
    if(LTInnerI != -1)
    {
        LTInnerPen = GetStockObject(DC_PEN);
        SelectObject(hdc, LTInnerPen);
        SetDCPenColor(hdc, scheme->crColor[LTInnerI]);
        if(uFlags & BF_TOP)
        {
            MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
            LineTo(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
        }
        if(uFlags & BF_LEFT)
        {
            MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
            LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
        }
    }

    if(RBInnerI != -1)
    {
        RBInnerPen = GetStockObject(DC_PEN);
        SelectObject(hdc, RBInnerPen);
        SetDCPenColor(hdc, scheme->crColor[RBInnerI]);
        if(uFlags & BF_BOTTOM)
        {
            MoveToEx(hdc, InnerRect.left+LBpenplus, InnerRect.bottom-2, NULL);
            LineTo(hdc, InnerRect.right-RBpenplus, InnerRect.bottom-2);
        }
        if(uFlags & BF_RIGHT)
        {
            MoveToEx(hdc, InnerRect.right-2, InnerRect.top+RTpenplus, NULL);
            LineTo(hdc, InnerRect.right-2, InnerRect.bottom-RBpenplus);
        }
    }

    if (uFlags & BF_ADJUST)
    {
        int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
                      + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);

        if(uFlags & BF_LEFT)
            InnerRect.left += add;
        if(uFlags & BF_RIGHT)
            InnerRect.right -= add;
        if(uFlags & BF_TOP)
            InnerRect.top += add;
        if(uFlags & BF_BOTTOM)
            InnerRect.bottom -= add;

        if(uFlags & BF_ADJUST)
            *rc = InnerRect;
    }

    /* Cleanup */
    SelectObject(hdc, SavePen);
    MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
    return TRUE;
}
Example #28
0
		}";

	/*
		Step 0 - Create a EGLNativeWindowType that we can use for OpenGL ES output
	*/
	// Register the windows class
	WNDCLASS sWC;
    sWC.style = CS_HREDRAW | CS_VREDRAW;
	sWC.lpfnWndProc = WndProc;
    sWC.cbClsExtra = 0;
    sWC.cbWndExtra = 0;
    sWC.hInstance = hInstance;
    sWC.hIcon = 0;
    sWC.hCursor = 0;
    sWC.lpszMenuName = 0;
	sWC.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    sWC.lpszClassName = WINDOW_CLASS;
	unsigned int nWidth = WINDOW_WIDTH;
	unsigned int nHeight = WINDOW_HEIGHT;

	ATOM registerClass = RegisterClass(&sWC);
	if (!registerClass)
	{
		MessageBox(0, _T("Failed to register the window class"), _T("Error"), MB_OK | MB_ICONEXCLAMATION);
	}

	int screenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
	int screenHeight = GetSystemMetrics(SM_CYFULLSCREEN);

	// Create the eglWindow
	RECT	sRect;
Example #29
0
File: pugl_win.cpp Project: EQ4/lad
PuglView*
puglCreate(PuglNativeWindow parent,
           const char*      title,
           int              width,
           int              height,
           bool             resizable)
{
	PuglView*      view = (PuglView*)calloc(1, sizeof(PuglView));
	PuglInternals* impl = (PuglInternals*)calloc(1, sizeof(PuglInternals));
	if (!view || !impl) {
		return NULL;
	}

	view->impl   = impl;
	view->width  = width;
	view->height = height;

	WNDCLASS wc;
	wc.style         = CS_OWNDC;
	wc.lpfnWndProc   = wndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = 0;
	wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = "Pugl";
	RegisterClass(&wc);

	impl->hwnd = CreateWindow(
		"Pugl", title,
		WS_VISIBLE | (parent ? WS_CHILD : (WS_POPUPWINDOW | WS_CAPTION)),
		0, 0, width, height,
		(HWND)parent, NULL, NULL, NULL);
	if (!impl->hwnd) {
		free(impl);
		free(view);
		return NULL;
	}
		
	SetWindowLongPtr(impl->hwnd, GWL_USERDATA, (LONG)view);

	impl->hdc = GetDC(impl->hwnd);

	PIXELFORMATDESCRIPTOR pfd;
	ZeroMemory(&pfd, sizeof(pfd));
	pfd.nSize      = sizeof(pfd);
	pfd.nVersion   = 1;
	pfd.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 24;
	pfd.cDepthBits = 16;
	pfd.iLayerType = PFD_MAIN_PLANE;

	int format = ChoosePixelFormat(impl->hdc, &pfd);
	SetPixelFormat(impl->hdc, format, &pfd);

	impl->hglrc = wglCreateContext(impl->hdc);
	wglMakeCurrent(impl->hdc, impl->hglrc);

	view->width  = width;
	view->height = height;

	return view;
}
Example #30
0
void ViewPort::DrawContours( double pixel_size, double offset_x, double offset_y )
{
	Transform *transform;								// render all transforms in section
	HPEN pen, oldpen;
	HBRUSH brush, oldbrush;
	LOGBRUSH lbrush;
	int oldmode, i, x, y, numpts;
	Contour *contour, *c;
	Point *p;
	POINT *lpPoints;

//startTime3 = GetTickCount();

	if ( section && viewDC )							// do only if section and drawing surface are defined
	  if ( section->transforms )							// render all contours in all transforms
		{
		transform = section->transforms->first;
		while ( transform )									// render all contours in this transform
			{	
			if ( transform->contours )						// do only if have contours
				{
				contour = transform->contours->first;
															// do each contour in list
				while ( contour )
					{
					if ( contour->points && !contour->hidden )		// don't draw hidden contours
						{
						c = new Contour( *contour );					// copy the contour
						c->InvNform( transform->nform );				// transform into section
						c->Shift( -offset_x, -offset_y );				// shift into view
						c->Scale( 1.0/pixel_size );						// scale to view's pixels

						numpts = c->points->Number();
						lpPoints = new POINT[ numpts ];					// create Window POINT array for drawing

						i = 0;
						p = c->points->first;
						while ( p != NULL )
							{
							lpPoints[i].x = (int)floor(p->x);
							lpPoints[i].y = height - (int)floor(p->y);
							i++;
							p = p->next;
							}
																		// create pen for border of object
						if ( transform->isActive ) pen = CreatePen( PS_DOT, 1, c->border.ref() );
						else pen = CreatePen( PS_SOLID, 1, c->border.ref() );
						oldpen = (HPEN)SelectObject( viewDC, pen );		// set pen into device context

						if ( c->closed && ((transform->isActive && (c->mode > 0))
												|| (!transform->isActive && (c->mode < 0))) )
							{
							brush = CreateSolidBrush( c->fill.ref() );	// interior will be filled
							oldbrush = (HBRUSH)SelectObject( viewDC, brush );
							SetROP2( viewDC, abs(c->mode) );			// using contour fill mode and color
							Polygon( viewDC, lpPoints, numpts );
							SelectObject( viewDC, oldbrush );			// clean up fill brush
							DeleteObject(brush);
							}

						SelectObject( viewDC, (HBRUSH)GetStockObject(NULL_BRUSH) );	// without coloring interior
						SetROP2( viewDC, R2_COPYPEN );								// draw contour border with pen
						if ( c->closed ) Polygon( viewDC, lpPoints, numpts );
						else Polyline( viewDC, lpPoints, numpts );
						
						SelectObject( viewDC, oldpen );					// clean up pen
						DeleteObject(pen);
						delete[] lpPoints;								// and dynamic memory
						delete c;
						}
					contour = contour->next;					// do next contour in list
					}
				}

			transform = transform->next;					// do next transform in list
			}
		}		// end if ( section->transforms )

//totalTime3 += GetTickCount() - startTime3;			// debugging
//nTime3++;

}