コード例 #1
0
ファイル: appearance.c プロジェクト: Moteesh/reactos
static INT_PTR
AppearancePage_OnInit(HWND hwndDlg)
{
    INT iListIndex;
    HWND hwndTheme;
    GLOBALS *g;
    RECT rcPreview;
    HDC hdcScreen;
    PTHEME pTheme;

    g = (GLOBALS*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBALS));
    if (g == NULL)
        return FALSE;

    SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);

    g->bInitializing = TRUE;

    if (!LoadCurrentScheme(&g->Scheme))
        return FALSE;

    g->pThemes = LoadThemes();
    if (g->pThemes)
    {
        BOOL bLoadedTheme = FALSE;

        if (g_GlobalData.pwszAction && 
            g_GlobalData.pwszFile && 
            wcscmp(g_GlobalData.pwszAction, L"OpenMSTheme") == 0)
        {
            bLoadedTheme = FindOrAppendTheme(g->pThemes, 
                                             g_GlobalData.pwszFile,
                                             NULL,
                                             NULL,
                                             &g->ActiveTheme);
        }

        if (bLoadedTheme)
        {
            g->bThemeChanged = TRUE;
            g->bSchemeChanged = TRUE;

            PostMessageW(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);

            AppearancePage_LoadSelectedScheme(hwndDlg, g);
        }
        else
        {
            if (!GetActiveTheme(g->pThemes, &g->ActiveTheme))
            {
                g->ActiveTheme.ThemeActive = FALSE;
            }
        }

        /*
         * Keep a copy of the selected classic theme in order to select this
         * when user selects the classic theme (and not a horrible random theme )
         */
        if (!GetActiveClassicTheme(g->pThemes, &g->ClassicTheme))
        {
            g->ClassicTheme.Theme = g->pThemes;
            g->ClassicTheme.Color = g->pThemes->ColoursList;
            g->ClassicTheme.Size = g->ClassicTheme.Color->ChildStyle;
        }

        if (g->ActiveTheme.ThemeActive == FALSE)
            g->ActiveTheme = g->ClassicTheme;

        GetClientRect(GetDlgItem(hwndDlg, IDC_APPEARANCE_PREVIEW), &rcPreview);

        hdcScreen = GetDC(NULL);
        g->hbmpThemePreview = CreateCompatibleBitmap(hdcScreen, rcPreview.right, rcPreview.bottom);
        g->hdcThemePreview = CreateCompatibleDC(hdcScreen);
        SelectObject(g->hdcThemePreview, g->hbmpThemePreview);
        ReleaseDC(NULL, hdcScreen);

        hwndTheme = GetDlgItem(hwndDlg, IDC_APPEARANCE_VISUAL_STYLE);

        for (pTheme = g->pThemes; pTheme; pTheme = pTheme->NextTheme)
        {
            iListIndex = SendMessage(hwndTheme, CB_ADDSTRING, 0, (LPARAM)pTheme->DisplayName);
            SendMessage(hwndTheme, CB_SETITEMDATA, iListIndex, (LPARAM)pTheme);
            if (pTheme == g->ActiveTheme.Theme)
            {
                SendMessage(hwndTheme, CB_SETCURSEL, (WPARAM)iListIndex, 0);
            }
        }

        if (g->ActiveTheme.Theme)
        {
            AppearancePage_ShowColorSchemes(hwndDlg, g);
            AppearancePage_ShowSizes(hwndDlg, g);
            AppearancePage_UpdateThemePreview(hwndDlg, g);
        }
    }
    g->bInitializing = FALSE;

    return FALSE;
}
コード例 #2
0
ファイル: dibutil.c プロジェクト: russlank/WinBGI
HDIB ChangeDIBFormat(HDIB hDIB, WORD wBitCount, DWORD dwCompression)
{
    HDC                hDC;             // Handle to DC
    HBITMAP            hBitmap;         // Handle to bitmap
    BITMAP             Bitmap;          // BITMAP data structure
    BITMAPINFOHEADER   bi;              // Bitmap info header
    LPBITMAPINFOHEADER lpbi;            // Pointer to bitmap info
    HDIB               hNewDIB = NULL;  // Handle to new DIB
    HPALETTE           hPal, hOldPal;   // Handle to palette, prev pal
    WORD               DIBBPP, NewBPP;  // DIB bits per pixel, new bpp
    DWORD              DIBComp, NewComp;// DIB compression, new compression

    // Check for a valid DIB handle

    if (!hDIB)
        return NULL;

    // Get the old DIB's bits per pixel and compression format

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
    DIBBPP = ((LPBITMAPINFOHEADER)lpbi)->biBitCount;
    DIBComp = ((LPBITMAPINFOHEADER)lpbi)->biCompression;
    GlobalUnlock(hDIB);

    // Validate wBitCount and dwCompression
    // They must match correctly (i.e., BI_RLE4 and 4 BPP or
    // BI_RLE8 and 8BPP, etc.) or we return failure
    if (wBitCount == 0)
    {
        NewBPP = DIBBPP;
        if ((dwCompression == BI_RLE4 && NewBPP == 4) ||
                (dwCompression == BI_RLE8 && NewBPP == 8) ||
                (dwCompression == BI_RGB))
            NewComp = dwCompression;
        else
            return NULL;
    }
    else if (wBitCount == 1 && dwCompression == BI_RGB)
    {
        NewBPP = wBitCount;
        NewComp = BI_RGB;
    }
    else if (wBitCount == 4)
    {
        NewBPP = wBitCount;
        if (dwCompression == BI_RGB || dwCompression == BI_RLE4)
            NewComp = dwCompression;
        else
            return NULL;
    }
    else if (wBitCount == 8)
    {
        NewBPP = wBitCount;
        if (dwCompression == BI_RGB || dwCompression == BI_RLE8)
            NewComp = dwCompression;
        else
            return NULL;
    }
    else if (wBitCount == 24 && dwCompression == BI_RGB)
    {
        NewBPP = wBitCount;
        NewComp = BI_RGB;
    }
    else
        return NULL;

    // Save the old DIB's palette

    hPal = CreateDIBPalette(hDIB);
    if (!hPal)
        return NULL;

    // Convert old DIB to a bitmap

    hBitmap = DIBToBitmap(hDIB, hPal);
    if (!hBitmap)
    {
        DeleteObject(hPal);
        return NULL;
    }

    // Get info about the bitmap
    GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);

    // Fill in the BITMAPINFOHEADER appropriately

    bi.biSize               = sizeof(BITMAPINFOHEADER);
    bi.biWidth              = Bitmap.bmWidth;
    bi.biHeight             = Bitmap.bmHeight;
    bi.biPlanes             = 1;
    bi.biBitCount           = NewBPP;
    bi.biCompression        = NewComp;
    bi.biSizeImage          = 0;
    bi.biXPelsPerMeter      = 0;
    bi.biYPelsPerMeter      = 0;
    bi.biClrUsed            = 0;
    bi.biClrImportant       = 0;

    // Go allocate room for the new DIB

    hNewDIB = AllocRoomForDIB(bi, hBitmap);
    if (!hNewDIB)
        return NULL;

    // Get a pointer to the new DIB

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hNewDIB);

    // Get a DC and select/realize our palette in it

    hDC  = GetDC(NULL);
    hOldPal = SelectPalette(hDC, hPal, FALSE);
    RealizePalette(hDC);

    // Call GetDIBits and get the new DIB bits

    if (!GetDIBits(hDC, hBitmap, 0, (UINT) lpbi->biHeight,
            (LPSTR)lpbi + (WORD)lpbi->biSize + PaletteSize((LPSTR)lpbi),
            (LPBITMAPINFO)lpbi, DIB_RGB_COLORS))
    {
        GlobalUnlock(hNewDIB);
        GlobalFree(hNewDIB);
        hNewDIB = NULL;
    }

    // Clean up and return

    SelectPalette(hDC, hOldPal, TRUE);
    RealizePalette(hDC);
    ReleaseDC(NULL, hDC);

    // Unlock the new DIB's memory block
    if (hNewDIB)
        GlobalUnlock(hNewDIB);

    DeleteObject(hBitmap);
    DeleteObject(hPal);

    return hNewDIB;
}
コード例 #3
0
//-----------------------------------WinProc-----------------------------
//
//-----------------------------------------------------------------------
LRESULT CALLBACK WindowProc(HWND hwnd, 
						                UINT msg, 
                            WPARAM wparam, 
                            LPARAM lparam)
{
	//these hold the dimensions of the client window area
	static int cxClient, cyClient;

	//used to create the back buffer
	static HDC		  hdcBackBuffer;
	static HBITMAP	hBitmap;
	static HBITMAP	hOldBitmap; 


	switch(msg)
	{	
		case WM_CREATE: 
		{
			//seed the random number generator
			srand((unsigned) time(NULL));

			//get the size of the client window
			RECT rect;
			GetClientRect(hwnd, &rect);

			cxClient = rect.right/2;
			cyClient = rect.bottom/2;

			//setup the controller
			g_pController = new CController(hwnd);

				//create a surface for us to render to(backbuffer)
			hdcBackBuffer = CreateCompatibleDC(NULL);

			HDC hdc = GetDC(hwnd);

			hBitmap = CreateCompatibleBitmap(hdc,
											                cxClient,
											                cyClient);
			ReleaseDC(hwnd, hdc);

			hOldBitmap = (HBITMAP)SelectObject(hdcBackBuffer, hBitmap); 
		} 
			
		break;
		
		//check key press messages
		case WM_KEYUP:
		{
			switch(wparam)
			{

				case VK_ESCAPE:
				{
					PostQuitMessage(0);
				}

				break;

				case 'F':
					{
						g_pController->FastRenderToggle();
					}
					
					break;

        //reset the demo
        case 'R':
          {
             if (g_pController)
             {
               delete g_pController;
             }

             //setup the new controller
			       g_pController = new CController(hwnd);
          }

          break;

			}//end WM_KEYUP switch
		}

		break;

		//has the user resized the client area?
		case WM_SIZE:
		{
 			cxClient = LOWORD(lparam);
			cyClient = HIWORD(lparam);

			//resize the backbuffer accordingly
			SelectObject(hdcBackBuffer, hOldBitmap);

			HDC hdc = GetDC(hwnd);

			hBitmap = CreateCompatibleBitmap(hdc,
											                 cxClient,
											                 cyClient);
			ReleaseDC(hwnd, hdc);
			
			hOldBitmap = (HBITMAP)SelectObject(hdcBackBuffer, hBitmap); 
		} 

		break;

		case WM_PAINT: 
		{
      PAINTSTRUCT ps;
      
		  BeginPaint(hwnd, &ps);
			//fill our backbuffer with white
			BitBlt(hdcBackBuffer,
             0,
             0,
             cxClient,
             cyClient,
             NULL,
             NULL,
             NULL,
             WHITENESS);
			
			//render the mines and sweepers
			g_pController->Render(hdcBackBuffer);
			
			//now blit backbuffer to front
			BitBlt(ps.hdc, 0, 0, cxClient, cyClient, hdcBackBuffer, 0, 0, SRCCOPY); 

			EndPaint(hwnd, &ps);
		} 
			
		break;

		case WM_DESTROY: 
		{
			SelectObject(hdcBackBuffer, hOldBitmap);
			
			//clean up our backbuffer objects
			DeleteDC(hdcBackBuffer);
			DeleteObject(hBitmap); 

      // kill the application, this sends a WM_QUIT message 
			PostQuitMessage(0);
 		} 
			
		break;

		default:break;

	}//end switch

	// default msg handler 
	return (DefWindowProc(hwnd, msg, wparam, lparam));

}//end WinProc
コード例 #4
0
ファイル: MainDlg.cpp プロジェクト: junehappylove/GitHub
void CMainDlg::DrawPhoto()
{
	if (m_BitmapEx.IsValid())
	{

		//CBitmapEx m_PhotoBitmapEx;

		//int tX,tY;
		
		CDC *pDC = m_ctl_photo.GetDC();

		CDC memDC;
		memDC.CreateCompatibleDC(pDC);

		CBitmap bmp;
		bmp.CreateCompatibleBitmap(pDC, m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight());
		memDC.SelectObject(bmp);

		CRect rect(0,0,m_PhotoBitmapEx.GetWidth(),m_PhotoBitmapEx.GetHeight());
		CBrush bBlack(GetSysColor(COLOR_3DFACE));

		memDC.FillRect(&rect, &bBlack);
		m_PhotoBitmapEx.Draw(memDC);

		pDC->FillRect(&m_PhotoRect, &bBlack);

		pDC->SetStretchBltMode(HALFTONE);
		pDC->StretchBlt(0,0,m_PhotoRect.Width(), m_PhotoRect.Height(),
			&memDC, 
			0,0,
			m_CutRect.Width(), m_CutRect.Height(),
			SRCCOPY);

		/*CDC *pDC = m_ctl_photo.GetDC();

		CDC memDC;
		memDC.CreateCompatibleDC(pDC);

		CBitmap bmp;
		bmp.CreateCompatibleBitmap(pDC, m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight());
		memDC.SelectObject(bmp);

		CRect rect(0,0,m_PhotoBitmapEx.GetWidth(),m_PhotoBitmapEx.GetHeight());
		CBrush bBlack(GetSysColor(COLOR_3DFACE));

		memDC.FillRect(&rect, &bBlack);

		m_PhotoBitmapEx.Draw(memDC);

		pDC->FillRect(&m_PhotoRect, &bBlack);

		pDC->SetStretchBltMode(HALFTONE);
		pDC->StretchBlt(0,0,m_PhotoRect.Width(), m_PhotoRect.Height(),
			&memDC, 
			0,0,
			m_PhotoBitmapEx.GetWidth(), m_PhotoBitmapEx.GetHeight(),
			SRCCOPY);*/

		memDC.DeleteDC();
		ReleaseDC(pDC);
	}
	else
	{
		CDC *pDC = m_ctl_photo.GetDC();
		CBrush bBlack(GetSysColor(COLOR_3DFACE));
		pDC->FillRect(m_PhotoRect,&bBlack);
	}
}
コード例 #5
0
ファイル: dibutil.c プロジェクト: russlank/WinBGI
HDIB ChangeBitmapFormat(HBITMAP hBitmap, WORD wBitCount, DWORD dwCompression,
        HPALETTE hPal)
{
    HDC                hDC;          // Screen DC
    HDIB               hNewDIB=NULL; // Handle to new DIB
    BITMAP             Bitmap;       // BITMAP data structure
    BITMAPINFOHEADER   bi;           // Bitmap info. header
    LPBITMAPINFOHEADER lpbi;         // Pointer to bitmap header
    HPALETTE           hOldPal=NULL; // Handle to palette
    WORD               NewBPP;       // New bits per pixel
    DWORD              NewComp;      // New compression format

    // Check for a valid bitmap handle

    if (!hBitmap)
        return NULL;

    // Validate wBitCount and dwCompression
    // They must match correctly (i.e., BI_RLE4 and 4 BPP or
    // BI_RLE8 and 8BPP, etc.) or we return failure
    
    if (wBitCount == 0)
    {
        NewComp = dwCompression;
        if (NewComp == BI_RLE4)
            NewBPP = 4;
        else if (NewComp == BI_RLE8)
            NewBPP = 8;
        else // Not enough info */
            return NULL;
    }
    else if (wBitCount == 1 && dwCompression == BI_RGB)
    {
        NewBPP = wBitCount;
        NewComp = BI_RGB;
    }
    else if (wBitCount == 4)
    {
        NewBPP = wBitCount;
        if (dwCompression == BI_RGB || dwCompression == BI_RLE4)
            NewComp = dwCompression;
        else
            return NULL;
    }
    else if (wBitCount == 8)
    {
        NewBPP = wBitCount;
        if (dwCompression == BI_RGB || dwCompression == BI_RLE8)
            NewComp = dwCompression;
        else
            return NULL;
    }
    else if (wBitCount == 24 && dwCompression == BI_RGB)
    {
        NewBPP = wBitCount;
        NewComp = BI_RGB;
    }
    else
        return NULL;

    // Get info about the bitmap

    GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);

    // Fill in the BITMAPINFOHEADER appropriately

    bi.biSize               = sizeof(BITMAPINFOHEADER);
    bi.biWidth              = Bitmap.bmWidth;
    bi.biHeight             = Bitmap.bmHeight;
    bi.biPlanes             = 1;
    bi.biBitCount           = NewBPP;
    bi.biCompression        = NewComp;
    bi.biSizeImage          = 0;
    bi.biXPelsPerMeter      = 0;
    bi.biYPelsPerMeter      = 0;
    bi.biClrUsed            = 0;
    bi.biClrImportant       = 0;

    // Go allocate room for the new DIB

    hNewDIB = AllocRoomForDIB(bi, hBitmap);
    if (!hNewDIB)
        return NULL;

    // Get a pointer to the new DIB

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hNewDIB);

    // If we have a palette, get a DC and select/realize it

    if (hPal)
    {
        hDC  = GetDC(NULL);
        hOldPal = SelectPalette(hDC, hPal, FALSE);
        RealizePalette(hDC);
    }

    // Call GetDIBits and get the new DIB bits

    if (!GetDIBits(hDC, hBitmap, 0, (UINT) lpbi->biHeight, (LPSTR)lpbi +
            (WORD)lpbi->biSize + PaletteSize((LPSTR)lpbi), (LPBITMAPINFO)lpbi,
            DIB_RGB_COLORS))
    {
        GlobalUnlock(hNewDIB);
        GlobalFree(hNewDIB);
        hNewDIB = NULL;
    }

    // Clean up and return

    if (hOldPal)
    {
        SelectPalette(hDC, hOldPal, TRUE);
        RealizePalette(hDC);
        ReleaseDC(NULL, hDC);
    }

    // Unlock the new DIB's memory block

    if (hNewDIB)
        GlobalUnlock(hNewDIB);

    return hNewDIB;
}
コード例 #6
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT Message,
                          WPARAM wParam, LPARAM lParam)
{
	int response;
	HDC hdc;
	PAINTSTRUCT paintstruct;
	static unsigned k = 0;

	switch (Message)
	{
		case WM_COMMAND:
			switch (LOWORD (wParam))
			{
          		case IDM_COM1:
            		cc.dwSize = sizeof(COMMCONFIG);
					cc.wVersion = 0x100;
					GetCommConfig (hComm, &cc, &cc.dwSize);
            		if (!CommConfigDialog (lpszCommName, hwnd, &cc))
               			break;
				break;
				case IDM_COM2:
					cc.dwSize = sizeof(COMMCONFIG);
					cc.wVersion = 0x100;
					GetCommConfig (hComm, &cc, &cc.dwSize);
            		if (!CommConfigDialog (lpszCommName, hwnd, &cc))
               			break;
				break;
			}
		break;
   		case WM_RBUTTONDOWN:		// Process right button
      		response = MessageBox (hwnd, "Press One:", "Right Button",
         							  MB_ABORTRETRYIGNORE);
			switch (response)
			{
         		case IDABORT:
            		MessageBox (hwnd, "", "Abort", MB_OK);
				break;
				case IDRETRY:
            		MessageBox (hwnd, "", "Retry", MB_OK);
				break;
				case IDIGNORE:
					MessageBox (hwnd, "", "Ignore", MB_OK);
				break;
			}
		break;

		case WM_LBUTTONDOWN:		// Process left button
      		response = MessageBox (hwnd, "Conitnue?", "Left Button",
         							  MB_ICONHAND | MB_YESNO);
			switch (response)
			{
         		case IDYES:
            		MessageBox (hwnd, "Press Button", "Yes", MB_OK);
				break;
				case IDNO:
            		MessageBox (hwnd, "Press Button", "No", MB_OK);
				break;
			}
		break;
		
		case WM_CHAR:	// Process keystroke
			hdc = GetDC (hwnd);			 // get device context
			sprintf (str, "%c", (char) wParam); // Convert char to string
			TextOut (hdc, 10*k, 0, str, strlen (str)); // output character	
			k++; // increment the screen x-coordinate
			ReleaseDC (hwnd, hdc); // Release device context
		break;
		
		case WM_PAINT:		// Process a repaint message
			hdc = BeginPaint (hwnd, &paintstruct); // Acquire DC
			TextOut (hdc, 0, 0, str, strlen (str)); // output character
			EndPaint (hwnd, &paintstruct); // Release DC
		break;

		case WM_DESTROY:	// Terminate program
      		PostQuitMessage (0);
		break;
		default:
			return DefWindowProc (hwnd, Message, wParam, lParam);
	}
	return 0;
}
コード例 #7
0
ファイル: mhrip.c プロジェクト: jpka/UnNetHack
void mswin_display_RIP_window (HWND hWnd)
{
    MSG msg;
    RECT rt;
    PNHRIPWindow data;
    HWND mapWnd;
    RECT riprt;
    RECT clientrect;
    RECT textrect;
    HDC hdc;
    HFONT OldFont;

    data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA);

    GetNHApp()->hPopupWnd = hWnd;
    mapWnd = mswin_hwnd_from_winid(WIN_MAP);
    if( !IsWindow(mapWnd) ) mapWnd = GetNHApp()->hMainWnd;
    GetWindowRect(mapWnd, &rt);
    GetWindowRect(hWnd, &riprt);
    GetClientRect (hWnd, &clientrect);
    textrect = clientrect;
    textrect.top += RIP_OFFSET_Y;
    textrect.left += RIP_OFFSET_X;
    textrect.right -= RIP_OFFSET_X;
    if (data->window_text)
    {
        hdc = GetDC (hWnd);
        OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
        DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
                  DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
        SelectObject (hdc, OldFont);
        ReleaseDC(hWnd, hdc);
    }
    if (textrect.right - textrect.left > RIP_WIDTH)
        clientrect.right = textrect.right + RIP_OFFSET_X - clientrect.right;
    else
        clientrect.right = textrect.left + 2 * RIP_OFFSET_X + RIP_WIDTH - clientrect.right;
    clientrect.bottom = textrect.bottom + RIP_HEIGHT + RIP_OFFSET_Y - clientrect.bottom;
    GetWindowRect (GetDlgItem(hWnd, IDOK), &textrect);
    textrect.right -= textrect.left;
    textrect.bottom -= textrect.top;
    clientrect.bottom += textrect.bottom + RIP_OFFSET_Y;
    riprt.right -= riprt.left;
    riprt.bottom -= riprt.top;
    riprt.right += clientrect.right;
    riprt.bottom += clientrect.bottom;
    rt.left += (rt.right - rt.left - riprt.right) / 2;
    rt.top += (rt.bottom - rt.top - riprt.bottom) / 2;

    MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE);
    GetClientRect (hWnd, &clientrect);
    MoveWindow (GetDlgItem(hWnd, IDOK),
                (clientrect.right - clientrect.left - textrect.right) / 2,
                clientrect.bottom - textrect.bottom - RIP_OFFSET_Y, textrect.right, textrect.bottom, TRUE);
    ShowWindow(hWnd, SW_SHOW);

    while( IsWindow(hWnd) &&
            GetMessage(&msg, NULL, 0, 0)!=0 ) {
        if( !IsDialogMessage(hWnd, &msg) ) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    GetNHApp()->hPopupWnd = NULL;
}
コード例 #8
0
ファイル: print.c プロジェクト: GYGit/reactos
LRESULT CALLBACK preview_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CREATE:
        {
            HWND hMainWnd = GetParent(hWnd);
            HWND hEditorWnd = GetDlgItem(hMainWnd, IDC_EDITOR);
            FORMATRANGE fr;
            GETTEXTLENGTHEX gt = {GTL_DEFAULT, 1200};
            HDC hdc = GetDC(hWnd);
            HDC hdcTarget = make_dc();

            fr.rc = preview.rcPage = get_print_rect(hdcTarget);
            preview.rcPage.bottom += margins.bottom;
            preview.rcPage.right += margins.right;
            preview.rcPage.top = preview.rcPage.left = 0;
            fr.rcPage = preview.rcPage;

            preview.bmSize.cx = twips_to_pixels(preview.rcPage.right, GetDeviceCaps(hdc, LOGPIXELSX));
            preview.bmSize.cy = twips_to_pixels(preview.rcPage.bottom, GetDeviceCaps(hdc, LOGPIXELSY));

            preview.textlength = SendMessageW(hEditorWnd, EM_GETTEXTLENGTHEX, (WPARAM)&gt, 0);

            fr.hdc = CreateCompatibleDC(hdc);
            fr.hdcTarget = hdcTarget;
            fr.chrg.cpMin = 0;
            fr.chrg.cpMax = preview.textlength;
            DeleteDC(fr.hdc);
            DeleteDC(hdcTarget);
            ReleaseDC(hWnd, hdc);

            update_preview_sizes(hWnd, TRUE);
            update_preview(hMainWnd);
            break;
        }

        case WM_PAINT:
            return print_preview(hWnd);

        case WM_SIZE:
        {
            update_preview_sizes(hWnd, FALSE);
            InvalidateRect(hWnd, NULL, FALSE);
            break;
        }

        case WM_VSCROLL:
        case WM_HSCROLL:
        {
            SCROLLINFO si;
            RECT rc;
            int nBar = (msg == WM_VSCROLL) ? SB_VERT : SB_HORZ;
            int origPos;

            GetClientRect(hWnd, &rc);
            si.cbSize = sizeof(si);
            si.fMask = SIF_ALL;
            GetScrollInfo(hWnd, nBar, &si);
            origPos = si.nPos;
            switch(LOWORD(wParam))
            {
                case SB_TOP: /* == SB_LEFT */
                    si.nPos = si.nMin;
                    break;
                case SB_BOTTOM: /* == SB_RIGHT */
                    si.nPos = si.nMax;
                    break;
                case SB_LINEUP: /* == SB_LINELEFT */
                    si.nPos -= si.nPage / 10;
                    break;
                case SB_LINEDOWN: /* == SB_LINERIGHT */
                    si.nPos += si.nPage / 10;
                    break;
                case SB_PAGEUP: /* == SB_PAGELEFT */
                    si.nPos -= si.nPage;
                    break;
                case SB_PAGEDOWN: /* SB_PAGERIGHT */
                    si.nPos += si.nPage;
                    break;
                case SB_THUMBTRACK:
                    si.nPos = si.nTrackPos;
                    break;
            }
            si.fMask = SIF_POS;
            SetScrollInfo(hWnd, nBar, &si, TRUE);
            GetScrollInfo(hWnd, nBar, &si);
            if (si.nPos != origPos)
            {
                int amount = origPos - si.nPos;
                if (msg == WM_VSCROLL)
                    ScrollWindow(hWnd, 0, amount, NULL, NULL);
                else
                    ScrollWindow(hWnd, amount, 0, NULL, NULL);
            }
            return 0;
        }

        case WM_SETCURSOR:
        {
            POINT pt;
            RECT rc;
            int bHittest = 0;
            DWORD messagePos = GetMessagePos();
            pt.x = (short)LOWORD(messagePos);
            pt.y = (short)HIWORD(messagePos);
            ScreenToClient(hWnd, &pt);

            GetClientRect(hWnd, &rc);
            if (PtInRect(&rc, pt))
            {
                pt.x += GetScrollPos(hWnd, SB_HORZ);
                pt.y += GetScrollPos(hWnd, SB_VERT);
                bHittest = preview_page_hittest(pt);
            }

            if (bHittest)
                SetCursor(LoadCursorW(GetModuleHandleW(0),
                                      MAKEINTRESOURCEW(IDC_ZOOM)));
            else
                SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_ARROW));

            return TRUE;
        }

        case WM_LBUTTONDOWN:
        {
            int page;
            POINT pt;
            pt.x = (short)LOWORD(lParam) + GetScrollPos(hWnd, SB_HORZ);
            pt.y = (short)HIWORD(lParam) + GetScrollPos(hWnd, SB_VERT);
            if ((page = preview_page_hittest(pt)) > 0)
            {
                HWND hMainWnd = GetParent(hWnd);

                /* Convert point from client coordinate to unzoomed page
                 * coordinate. */
                pt.x -= preview.spacing.cx;
                if (page > 1)
                    pt.x -= preview.bmScaledSize.cx + preview.spacing.cx;
                pt.y -= preview.spacing.cy;
                pt.x /= preview.zoomratio;
                pt.y /= preview.zoomratio;

                if (preview.zoomlevel == 0)
                    preview.saved_pages_shown = preview.pages_shown;
                preview.zoomlevel = (preview.zoomlevel + 1) % 3;
                preview.zoomratio = 0;
                if (preview.zoomlevel == 0 && preview.saved_pages_shown > 1)
                {
                    toggle_num_pages(hMainWnd);
                } else if (preview.pages_shown > 1) {
                    if (page >= 2) preview.page++;
                    toggle_num_pages(hMainWnd);
                } else {
                    update_preview_sizes(hWnd, TRUE);
                    InvalidateRect(hWnd, NULL, FALSE);
                    update_preview_buttons(hMainWnd);
                }

                if (preview.zoomlevel > 0) {
                    SCROLLINFO si;
                    /* Convert the coordinate back to client coordinate. */
                    pt.x *= preview.zoomratio;
                    pt.y *= preview.zoomratio;
                    pt.x += preview.spacing.cx;
                    pt.y += preview.spacing.cy;
                    /* Scroll to center view at that point on the page */
                    si.cbSize = sizeof(si);
                    si.fMask = SIF_PAGE;
                    GetScrollInfo(hWnd, SB_HORZ, &si);
                    pt.x -= si.nPage / 2;
                    SetScrollPos(hWnd, SB_HORZ, pt.x, TRUE);
                    GetScrollInfo(hWnd, SB_VERT, &si);
                    pt.y -= si.nPage / 2;
                    SetScrollPos(hWnd, SB_VERT, pt.y, TRUE);
                }
            }
        }

        default:
            return DefWindowProcW(hWnd, msg, wParam, lParam);
    }

    return 0;
}
コード例 #9
0
std::unique_ptr<os::Viewport> MFCGraphicsOperations::createViewport(const os::ViewPortProperties& props)
{
	int PixelFormat;
	PIXELFORMATDESCRIPTOR pfd_test;
	PIXELFORMATDESCRIPTOR GL_pfd;

	mprintf(("  Initializing WGL...\n"));

	memset(&GL_pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
	memset(&pfd_test, 0, sizeof(PIXELFORMATDESCRIPTOR));

	GL_pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
	GL_pfd.nVersion = 1;
	GL_pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
	if (props.enable_opengl)
	{
		GL_pfd.dwFlags |= PFD_SUPPORT_OPENGL;
	}

	GL_pfd.iPixelType = PFD_TYPE_RGBA;
	GL_pfd.cColorBits = (BYTE)(props.pixel_format.red_size + props.pixel_format.green_size + props.pixel_format.blue_size + props.pixel_format.alpha_size);
	GL_pfd.cRedBits = (BYTE)(props.pixel_format.red_size);
	GL_pfd.cGreenBits = (BYTE)(props.pixel_format.green_size);
	GL_pfd.cBlueBits = (BYTE)(props.pixel_format.blue_size);
	GL_pfd.cAlphaBits = (BYTE)(props.pixel_format.alpha_size);
	GL_pfd.cDepthBits = (BYTE)(props.pixel_format.depth_size);
	GL_pfd.cStencilBits = (BYTE)(props.pixel_format.stencil_size);

	Assert(_windowHandle != NULL);

	auto device_context = GetDC(_windowHandle);

	if (!device_context)
	{
		mprintf(("Unable to get device context for OpenGL W32!\n"));
		return nullptr;
	}

	PixelFormat = ChoosePixelFormat(device_context, &GL_pfd);

	if (!PixelFormat)
	{
		mprintf(("Unable to choose pixel format for OpenGL W32!\n"));
		ReleaseDC(_windowHandle, device_context);
		return nullptr;
	}
	else
	{
		DescribePixelFormat(device_context, PixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd_test);
	}

	if (!SetPixelFormat(device_context, PixelFormat, &GL_pfd))
	{
		mprintf(("Unable to set pixel format for OpenGL W32!\n"));
		ReleaseDC(_windowHandle, device_context);
		return nullptr;
	}

	mprintf(("  Requested SDL Video values = R: %d, G: %d, B: %d, depth: %d, stencil: %d\n",
		props.pixel_format.red_size, props.pixel_format.green_size, props.pixel_format.blue_size,
		props.pixel_format.depth_size, props.pixel_format.stencil_size));

	return std::unique_ptr<os::Viewport>(new MFCViewport(_windowHandle, device_context));
}
コード例 #10
0
//运行函数
bool CFlowerEffectThread::OnEventThreadRun()
{
	//加载图片
	CPngImage ImageFlower;
	CString strInfo=TEXT("GIFT_"),strImage;
	strImage.Format(TEXT("%s%ld"),strInfo,m_wFlowerID/2+1);
	ImageFlower.LoadImage(GetModuleHandle(PROPERTY_MODULE_DLL_NAME),strImage);
	if(ImageFlower.IsNull())return false;

	//窗体大小
	CRect ClientRect;
	::GetWindowRect(m_hFlowerEffectControl, &ClientRect);

	//绘画大小
	int nCartoonWidth = 150;
	int nCartoonCount = ImageFlower.GetWidth() / nCartoonWidth;

	//过虑散频
	MoveWindow(m_hFlowerEffectControl,0,0,0,0,false);
	::ShowWindow(m_hFlowerEffectControl, SW_SHOW);

	//绘画图片
	for ( int nCartoonIndex=0; nCartoonIndex < nCartoonCount; ++nCartoonIndex )
	{		
		//设备句柄
		HDC hDC=GetDC(m_hFlowerEffectControl);
		if ( hDC==NULL ) return false;

		//系上D C
		CDC	TempDC;
		TempDC.Attach(hDC);

		//内存设备
		CDC *pMemoryDC = CDC::FromHandle(m_ImageBuffer.GetDC());
		CDC *pScreenDC = CDC::FromHandle(m_ImageBufferScreen.GetDC());

		//绘画背景
		pMemoryDC->BitBlt(0,0,ClientRect.Width(),ClientRect.Height(),pScreenDC,0,0,SRCCOPY);

		//绘画礼物
		ImageFlower.DrawImage(pMemoryDC, 0, 0, ClientRect.Width(), ClientRect.Height(),
			nCartoonWidth * nCartoonIndex,0,nCartoonWidth, ImageFlower.GetHeight());

		TempDC.BitBlt(0, 0, ClientRect.Width(), ClientRect.Height(), pMemoryDC, 0, 0, SRCCOPY);

		//显示窗体
		if (nCartoonIndex==0) MoveWindow(m_hFlowerEffectControl,ClientRect.left,ClientRect.top,ClientRect.Width(),ClientRect.Height(),false);

		//释放设备
		TempDC.Detach();
		ReleaseDC(m_hFlowerEffectControl, hDC);
		hDC=NULL;
		m_ImageBuffer.ReleaseDC();
		m_ImageBufferScreen.ReleaseDC();
		pMemoryDC=NULL;

		//线程睡眠
		Sleep(120);
	}

	//隐藏窗体
	::ShowWindow(m_hFlowerEffectControl, SW_HIDE);

	return false;
}
コード例 #11
0
LRESULT CBeikeSafeSoftmgrNecessHandler::OnListBoxGetDispInfo( LPNMHDR pnmh )
{
	BKLBMGETDISPINFO* pdi = (BKLBMGETDISPINFO*)pnmh;

	if ( pdi->nListItemID >= m_arrRightList.GetSize() )
		return 0;

	NECESS_SOFT_LIST_DATA&	datalist = m_arrRightList[pdi->nListItemID];

	if (datalist.bTitle)
	{
		// 标题的绘制

		pdi->nHeight = SOFT_LIST_TITLE_HEIGHT;

		m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_TITLE,TRUE);
		m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_ITEM,FALSE);

		m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_TITLE_NAME,datalist.strTitleName);
	}
	else
	{
		// 里面软件list的绘制

		pdi->nHeight = SOFT_LIST_ITEM_HEIGHT;
		m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_TITLE,FALSE);
		m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_ITEM,TRUE);

		m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_DIV_ITEM,"crbg",pdi->bSelect?"EBF5FF":"FFFFFF");

		CSoftListItemData* pSoftData = GetSoftDataByID(datalist.strSoftId);

		int nPosX = 0;
		Gdiplus::Image *pImage = NULL;
		{
			CDC dcx = GetDC(m_pMainDlg->m_hWnd);
			HFONT			hFntTmp;

			int nTypeWidth = 0;
			if (m_bShowType)
			{
				hFntTmp = dcx.SelectFont(BkFontPool::GetFont(BKF_DEFAULTFONT));
				CRect rcType;
				CString strType;
				strType.Format(L"[%s]", pSoftData->m_strTypeShort);
				dcx.DrawText(strType, -1, &rcType, DT_VCENTER | DT_SINGLELINE | DT_CALCRECT);
				nTypeWidth = rcType.Width();
				dcx.SelectFont(hFntTmp);
			}

			hFntTmp = dcx.SelectFont(BkFontPool::GetFont(BKF_BOLDFONT));
			CRect rcProb;
			dcx.DrawText(pSoftData->m_strName, -1, &rcProb, DT_VCENTER | DT_SINGLELINE | DT_CALCRECT);
			dcx.SelectFont(hFntTmp);

			ReleaseDC(m_pMainDlg->m_hWnd, dcx);

			CRect rcWin;
			GetWindowRect(m_necessList->m_hWnd, &rcWin);

			int nLablesWidth = 0;
			if ((pSoftData->m_attri&SA_Green) == SA_Green)
			{
				pImage = BkPngPool::Get(IDP_SOFTMGR_GREEN_SOFT);
				nLablesWidth += pImage->GetWidth();
			}
			if (pSoftData->m_bCharge == TRUE)
			{
				if (nLablesWidth != 0)
					nLablesWidth += 2;
				pImage = BkPngPool::Get(IDP_SOFTMGR_CHARGE_SOFT);
				nLablesWidth += pImage->GetWidth();
			}
			if (pSoftData->m_bPlug == TRUE)
			{
				if (nLablesWidth != 0)
					nLablesWidth += 2;
				pImage = BkPngPool::Get(IDP_SOFTMGR_PLUGIN_SOFT);
				nLablesWidth += pImage->GetWidth();
			}
			if ((pSoftData->m_attri&SA_New) == SA_New)
			{
				if (nLablesWidth != 0)
					nLablesWidth += 2;
				pImage = BkPngPool::Get(IDP_SOFTMGR_NEW_SOFT);
				nLablesWidth += pImage->GetWidth();
			}

			int nLeft = 50 + nTypeWidth;
			nPosX = rcWin.Width() - 310 - nLablesWidth;
			if (rcProb.Width() < rcWin.Width() - 310 - nLablesWidth - nLeft)
				nPosX = nLeft + rcProb.Width();
		
			CStringA strPosA;
			strPosA.Format("%d,12,%d,27", nLeft, nPosX);
			m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TITLE, "pos", strPosA);

			if (m_bShowType)
			{
				CString strTypeShort;
				strTypeShort.Format(L"[%s]", pSoftData->m_strTypeShort);
				m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TYPE, strTypeShort);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TYPE,TRUE);
			}
			else
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TYPE,FALSE);
		}

		m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_GREEN,FALSE);
		m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_CHARGE,FALSE);
		m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PLUGIN,FALSE);
		m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_NEW,FALSE);
		int nPosY = 10;
		if ((pSoftData->m_attri&SA_Green) == SA_Green)
		{
			nPosX += 2;
			CStringA strPosA;
			strPosA.Format("%d,%d", nPosX, nPosY);
			m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_GREEN, "pos", strPosA);
			m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_GREEN,TRUE);
			nPosX += 45;
		}
		if (pSoftData->m_bCharge == TRUE)
		{
			nPosX += 2;
			CStringA strPosA;
			strPosA.Format("%d,%d", nPosX, nPosY);
			m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_CHARGE, "pos", strPosA);
			m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_CHARGE,TRUE);
			nPosX += 45;
		}
		if (pSoftData->m_bPlug == TRUE)
		{
			nPosX += 2;
			CStringA strPosA;
			strPosA.Format("%d,%d", nPosX, nPosY);
			m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_PLUGIN, "pos", strPosA);
			m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PLUGIN,TRUE);
			nPosX += 45;
		}
		if ((pSoftData->m_attri&SA_New) == SA_New)
		{
			nPosX += 2;
			CStringA strPosA;
			strPosA.Format("%d,%d", nPosX, nPosY);
			m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_NEW, "pos", strPosA);
			m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_NEW,TRUE);
		}

		if (pSoftData != NULL)
		{
			// 图标的绘制
			if (TRUE)
			{
				CStringA	strMem;
				strMem.Format("%d",pSoftData->m_pImage);
				m_necessList->SetItemAttribute( IDC_SOFTMGR_LISTTMP_ICON_SOFT, "mempointer",strMem );
			}
			
			//画评分
			for (int i = IDC_SOFTMGR_LISTTMP_STAR_ONE; i <= IDC_SOFTMGR_LISTTMP_STAR_FIVE; i++)
			{
				CStringA strSkin;
				if ((i - IDC_SOFTMGR_LISTTMP_STAR_ONE + 1)*2 <= pSoftData->m_fMark)
					strSkin = "star";
				else if ((i - IDC_SOFTMGR_LISTTMP_STAR_ONE + 1)*2 - 1 <= pSoftData->m_fMark)
					strSkin = "star_half";
				else
					strSkin = "star_off";
				
				m_necessList->SetItemAttribute(i, "skin", strSkin);
			}

			CString strMark;
			strMark.Format(L"%.1f分 投票", pSoftData->m_fMark);
			m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_MARK, strMark);

			// 下载图标
			if (!pSoftData->m_bIcon)
				m_pSoftMgrMainUI->OnDownLoadIcon( pSoftData->m_strSoftID );

			// 标题,描述,大小
			m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TITLE, pSoftData->m_strName);
			m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_DESC, pSoftData->m_strDescription);
			m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_SIZE, pSoftData->m_strSize);
			m_necessList->SetItemStringAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_DESC,"tip",pSoftData->m_strDescription);
			m_necessList->SetItemStringAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_TITLE,"tip",BkString::Get(IDS_SOFTMGR_8100));
			m_necessList->SetItemStringAttribute(IDC_SOFTMGR_LISTTMP_ICON_SOFT,"tip",BkString::Get(IDS_SOFTMGR_8100));

			if (pSoftData->m_bUpdate)
			{
				CDC dcx = GetDC(m_pMainDlg->m_hWnd);
				HFONT			hFntTmp;
				hFntTmp = dcx.SelectFont(BkFontPool::GetFont(BKF_DEFAULTFONT));

				CRect rcProb;
				dcx.DrawText(pSoftData->m_strDescription, -1, &rcProb, DT_VCENTER | DT_SINGLELINE | DT_CALCRECT);

				dcx.SelectFont(hFntTmp);
				ReleaseDC(m_pMainDlg->m_hWnd, dcx);

				CRect rcWin;
				GetWindowRect(m_necessList->m_hWnd, &rcWin);

				int nPos = 0;
				CStringA strPosDes;
				CStringA strPosNew;
				if (rcProb.Width() > rcWin.Width() - 50 - 310 - 50 - 2)
				{
					strPosDes = "50,32,-52,47";
					strPosNew = "-50,32,-0,47";
				}
				else
				{
					strPosDes.Format("50,32,%d,47", 50 + rcProb.Width());
					strPosNew.Format("%d,32,-0,47", 50 + rcProb.Width() + 2);
				}
				m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_DESC, "pos", strPosDes);
				m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_NEW, "pos", strPosNew);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_NEW,TRUE);
			}
			else
			{
				m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_TXT_SOFT_DESC, "pos", "50,32,-0,47");
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_NEW,FALSE);
			}

			if ( /*!pSoftData->m_bSetup && */pSoftData->m_bDownloading && !pSoftData->m_bWaitDownload && !pSoftData->m_bUsingForOneKey )
			{
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_SIZE,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_MARK,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_MARK,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_DOWN,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_UPDATE,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_REINST,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_USE_ONKEY,FALSE);

				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PROG_DOWN_DOWNING,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWN,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWNED,FALSE);

				CStringA	strProg;
				strProg.Format("%d",pSoftData->m_dwProgress);
				m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_PROG_DOWN_DOWNING,"value",strProg);

				if (pSoftData->m_bLinking)
				{				 
					if (pSoftData->m_bLinkFailed)
						m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,BkString::Get(IDS_SOFTMGR_8089));
					else
						m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,BkString::Get(IDS_SOFTMGR_8090));				
				}
				else
				{
					strProg += "%";
					m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG, CA2W(strProg) );
				}

				if ( !pSoftData->m_bDownLoad )
				{
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PROG_DOWN_DOWNING,TRUE);
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,TRUE);
					// 正在下载中的
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWN,TRUE);

					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_LNK_SOFT_RETRY,FALSE);
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_FEEDBACK,FALSE);
					if (pSoftData->m_bLinking)
					{
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_STATE,FALSE);
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_PAUSE,FALSE);
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_CONTINUE,FALSE);

						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_STOP,!pSoftData->m_bLinkFailed);
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_LNK_SOFT_RETRY,pSoftData->m_bLinkFailed);
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_FEEDBACK,pSoftData->m_bLinkFailed);
					}
					else
					{
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_STATE,TRUE);
						if (pSoftData->m_bPause)
							m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_STATE,BkString::Get(IDS_SOFTMGR_8091));				
						else 
							m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_DOWN_STATE,pSoftData->m_strSpeed);
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_PAUSE,!pSoftData->m_bPause);
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWN_CONTINUE,pSoftData->m_bPause);
					}
				}
				else
				{
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_SIZE,TRUE);
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_MARK,TRUE);
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_MARK,TRUE);

					// 已下载完毕的
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWNED,TRUE);

					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWNED_INSTALL,FALSE);
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_INST_STATE,TRUE);

					if (pSoftData->m_bWaitInstall)
						m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_INST_STATE,BkString::Get(IDS_SOFTMGR_8102));
					else if (pSoftData->m_bInstalling)
						m_necessList->SetItemText(IDC_SOFTMGR_LISTTMP_TXT_SOFT_INST_STATE,BkString::Get(IDS_SOFTMGR_8085));
					else
					{
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_INST_STATE,FALSE);
						m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_DOWNED_INSTALL,TRUE);
					}

					if ((pSoftData->m_attri&SA_Green) == SA_Green)
					{
						m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_BTN_DOWNED_INSTALL, "class", "btndetaildownloaded");
					}
					else
					{
						m_necessList->SetItemAttribute(IDC_SOFTMGR_LISTTMP_BTN_DOWNED_INSTALL, "class", "btndetaildown");
					}
				}
			}
			else
			{
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_SIZE,TRUE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_MARK,TRUE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_MARK,TRUE);

				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_PROG_DOWN_DOWNING,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_DOWN_PROG,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWN,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_DIV_SOFT_DOWNING_DOWNED,FALSE);

				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_DOWN,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_UPDATE,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_REINST,FALSE);
				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_USE_ONKEY,FALSE);

				if (!pSoftData->m_bUsingForOneKey)
				{
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_DOWN,!pSoftData->m_bUpdate&&!pSoftData->m_bSetup);
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_UPDATE,pSoftData->m_bUpdate);
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_BTN_SOFT_REINST,pSoftData->m_bSetup&&!pSoftData->m_bUpdate);
				}
				else
				{
					m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_USE_ONKEY,TRUE);
				}

				m_necessList->SetItemVisible(IDC_SOFTMGR_LISTTMP_TXT_SOFT_CHARGE,FALSE);
			}
		}	
	}
	

	return 0;
}
コード例 #12
0
ファイル: win_syscon.cpp プロジェクト: DaTa-/cnq3x
/*
** Sys_CreateConsole
*/
void Sys_CreateConsole( void )
{
	HDC hDC;
	WNDCLASS wc;
	RECT rect;
	const char *DEDCLASS = "Q3 WinConsole";
	int nHeight;
	int swidth, sheight;
	int DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX;

	memset( &wc, 0, sizeof( wc ) );

	wc.style         = 0;
	wc.lpfnWndProc   = (WNDPROC) ConWndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = g_wv.hInstance;
	wc.hIcon         = LoadIcon( g_wv.hInstance, MAKEINTRESOURCE(IDI_ICON1));
	wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszMenuName  = 0;
	wc.lpszClassName = DEDCLASS;

	if ( !RegisterClass (&wc) )
		return;

	rect.left = 0;
	rect.right = 540;
	rect.top = 0;
	rect.bottom = 450;
	AdjustWindowRect( &rect, DEDSTYLE, FALSE );

	hDC = GetDC( GetDesktopWindow() );
	swidth = GetDeviceCaps( hDC, HORZRES );
	sheight = GetDeviceCaps( hDC, VERTRES );
	ReleaseDC( GetDesktopWindow(), hDC );

	s_wcd.windowWidth = rect.right - rect.left + 1;
	s_wcd.windowHeight = rect.bottom - rect.top + 1;

	s_wcd.hWnd = CreateWindowEx( 0,
							   DEDCLASS,
							   CONSOLE_WINDOW_TITLE,
							   DEDSTYLE,
							   ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1,
							   NULL,
							   NULL,
							   g_wv.hInstance,
							   NULL );

	if ( s_wcd.hWnd == NULL )
	{
		return;
	}

	//
	// create fonts
	//
	hDC = GetDC( s_wcd.hWnd );
	nHeight = -MulDiv( 8, GetDeviceCaps( hDC, LOGPIXELSY), 72);

	s_wcd.hfBufferFont = CreateFont( nHeight,
									  0,
									  0,
									  0,
									  FW_LIGHT,
									  0,
									  0,
									  0,
									  DEFAULT_CHARSET,
									  OUT_DEFAULT_PRECIS,
									  CLIP_DEFAULT_PRECIS,
									  DEFAULT_QUALITY,
									  FF_MODERN | FIXED_PITCH,
									  "Courier New" );

	ReleaseDC( s_wcd.hWnd, hDC );

	//
	// create the input line
	//
	s_wcd.hwndInputLine = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | 
												ES_LEFT | ES_AUTOHSCROLL,
												6, 400, 528, 20,
												s_wcd.hWnd, 
												( HMENU ) INPUT_ID,	// child window ID
												g_wv.hInstance, NULL );

	//
	// create the buttons
	//
	s_wcd.hwndButtonCopy = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												5, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) COPY_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonCopy, WM_SETTEXT, 0, ( LPARAM ) "copy" );

	s_wcd.hwndButtonClear = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												82, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) CLEAR_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonClear, WM_SETTEXT, 0, ( LPARAM ) "clear" );

	s_wcd.hwndButtonQuit = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												462, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) QUIT_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonQuit, WM_SETTEXT, 0, ( LPARAM ) "quit" );


	//
	// create the scrollbuffer
	//
	s_wcd.hwndBuffer = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | 
												ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
												6, 40, 526, 354,
												s_wcd.hWnd, 
												( HMENU ) EDIT_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, ( long ) InputLineWndProc );
	SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT);
	UpdateWindow( s_wcd.hWnd );
	SetForegroundWindow( s_wcd.hWnd );
	SetFocus( s_wcd.hwndInputLine );

	s_wcd.visLevel = 1;
}
コード例 #13
0
ファイル: richutil.c プロジェクト: raoergsls/miranda
static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	TRichUtil *ru;
	
	EnterCriticalSection(&csRich);
	ru = rlist_find(slist, hwnd);
	LeaveCriticalSection(&csRich);
	switch(msg) {
		case WM_THEMECHANGED:
		case WM_STYLECHANGED:
		{
			RichUtil_ClearUglyBorder(ru);
			break;
		}
		case WM_NCPAINT:
		{
			LRESULT ret = CallWindowProc(ru->origProc, hwnd, msg, wParam, lParam);
			if (ru->hasUglyBorder&&MyIsThemeActive()) {
				HANDLE hTheme = MyOpenThemeData(ru->hwnd, L"EDIT");

				if (hTheme) {
					RECT rcBorder;
					RECT rcClient;
					int nState;
					HDC hdc = GetWindowDC(ru->hwnd);

					GetWindowRect(hwnd, &rcBorder);
					rcBorder.right -= rcBorder.left; rcBorder.bottom -= rcBorder.top;
					rcBorder.left = rcBorder.top = 0;
					CopyRect(&rcClient, &rcBorder);
					rcClient.left += ru->rect.left;
					rcClient.top += ru->rect.top;
					rcClient.right -= ru->rect.right;
					rcClient.bottom -= ru->rect.bottom;
					ExcludeClipRect(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
					if(MyIsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL))
						MyDrawThemeParentBackground(hwnd, hdc, &rcBorder);
					if(!IsWindowEnabled(hwnd))
						nState = ETS_DISABLED;
					else if(SendMessage(hwnd, EM_GETOPTIONS, 0, 0) & ECO_READONLY)
						nState = ETS_READONLY;
					else nState = ETS_NORMAL;
					MyDrawThemeBackground(hTheme, hdc, EP_EDITTEXT, nState, &rcBorder, NULL);
					MyCloseThemeData(hTheme);
					ReleaseDC(hwnd, hdc);
					return 0;
				}
			}
			return ret;
		}
		case WM_NCCALCSIZE:
		{
			LRESULT ret = CallWindowProc(ru->origProc, hwnd, msg, wParam, lParam);
			NCCALCSIZE_PARAMS *ncsParam = (NCCALCSIZE_PARAMS*)lParam;
			
			if (ru->hasUglyBorder&&MyIsThemeActive()) {
				HANDLE hTheme = MyOpenThemeData(hwnd, L"EDIT");

				if (hTheme) {
					RECT rcClient; 
					HDC hdc = GetDC(GetParent(hwnd));

					ZeroMemory(&rcClient, sizeof(RECT));
					if(MyGetThemeBackgroundContentRect(hTheme, hdc, EP_EDITTEXT, ETS_NORMAL, &ncsParam->rgrc[0], &rcClient) == S_OK) {
						ru->rect.left = rcClient.left-ncsParam->rgrc[0].left;
						ru->rect.top = rcClient.top-ncsParam->rgrc[0].top;
						ru->rect.right = ncsParam->rgrc[0].right-rcClient.right;
						ru->rect.bottom = ncsParam->rgrc[0].bottom-rcClient.bottom;
						CopyRect(&ncsParam->rgrc[0], &rcClient);
						MyCloseThemeData(hTheme);
						ReleaseDC(GetParent(hwnd), hdc);
						return WVR_REDRAW;
					}
					ReleaseDC(GetParent(hwnd), hdc);
					MyCloseThemeData(hTheme);
				}
			}
			return ret;
		}
		case WM_ENABLE:
			RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_NOCHILDREN|RDW_UPDATENOW|RDW_FRAME);
			break;
		case WM_DESTROY:
		{
			LRESULT ret = CallWindowProc(ru->origProc, hwnd, msg, wParam, lParam);

			if(IsWindow(hwnd)) {
				if((WNDPROC)GetWindowLongPtr(hwnd, GWLP_WNDPROC) == &RichUtil_Proc)
					SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)ru->origProc);
			}
			EnterCriticalSection(&csRich);
			slist = rlist_remove(slist, ru);
			LeaveCriticalSection(&csRich);
			if (ru) free(ru);
			return ret;
		}
	}
	return CallWindowProc(ru->origProc, hwnd, msg, wParam, lParam);
}
コード例 #14
0
ファイル: startwin.game.c プロジェクト: Plagman/jfduke3d
static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static HBITMAP hbmp = NULL;
	HDC hdc;
	
	switch (uMsg) {
		case WM_INITDIALOG: {
			HWND hwnd;
			RECT r, rdlg, chrome, rtab, rcancel, rstart;
			int xoffset = 0, yoffset = 0;

			// Fetch the positions (in screen coordinates) of all the windows we need to tweak
			ZeroMemory(&chrome, sizeof(chrome));
			AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE);
			GetWindowRect(hwndDlg, &rdlg);
			GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab);
			GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel);
			GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart);

			// Knock off the non-client area of the main dialogue to give just the client area
			rdlg.left -= chrome.left; rdlg.top -= chrome.top;
			rdlg.right -= chrome.right; rdlg.bottom -= chrome.bottom;

			// Translate them to client-relative coordinates wrt the main dialogue window
			rtab.right -= rtab.left - 1; rtab.bottom -= rtab.top - 1;
			rtab.left  -= rdlg.left; rtab.top -= rdlg.top;

			rcancel.right -= rcancel.left - 1; rcancel.bottom -= rcancel.top - 1;
			rcancel.left -= rdlg.left; rcancel.top -= rdlg.top;

			rstart.right -= rstart.left - 1; rstart.bottom -= rstart.top - 1;
			rstart.left -= rdlg.left; rstart.top -= rdlg.top;

			// And then convert the main dialogue coordinates to just width/length
			rdlg.right -= rdlg.left - 1; rdlg.bottom -= rdlg.top - 1;
			rdlg.left = 0; rdlg.top = 0;

			// Load the bitmap into the bitmap control and fetch its dimensions
			hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP));
			hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP);
			SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);
			GetClientRect(hwnd, &r);
			xoffset = r.right;
			yoffset = r.bottom - rdlg.bottom;

			// Shift and resize the controls that require it
			rtab.left += xoffset; rtab.bottom += yoffset;
			rcancel.left += xoffset; rcancel.top += yoffset;
			rstart.left += xoffset; rstart.top += yoffset;
			rdlg.right += xoffset;
			rdlg.bottom += yoffset;

			// Move the controls to their new positions
			MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE);
			MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE);
			MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE);

			// Move the main dialogue to the centre of the screen
			hdc = GetDC(NULL);
			rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2;
			rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2;
			ReleaseDC(NULL, hdc);
			MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left,
				rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE);

			// Add tabs to the tab control
			{
				TCITEM tab;
				
				hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL);

				ZeroMemory(&tab, sizeof(tab));
				tab.mask = TCIF_TEXT;
				tab.pszText = TEXT("Configuration");
				SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab);
				tab.mask = TCIF_TEXT;
				tab.pszText = TEXT("Game");
				SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_GAME, (LPARAM)&tab);
				tab.mask = TCIF_TEXT;
				tab.pszText = TEXT("Messages");
				SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab);

				// Work out the position and size of the area inside the tab control for the pages
				ZeroMemory(&r, sizeof(r));
				GetClientRect(hwnd, &r);
				SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r);
				r.right -= r.left-1;
				r.bottom -= r.top-1;
				r.top += rtab.top;
				r.left += rtab.left;

				// Create the pages and position them in the tab control, but hide them
				pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(),
					MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc);
				pages[TAB_GAME] = CreateDialog((HINSTANCE)win_gethinstance(),
					MAKEINTRESOURCE(WIN_STARTWINPAGE_GAME), hwndDlg, GamePageProc);
				pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES);
				SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
				SetWindowPos(pages[TAB_GAME], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
				SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);

				// Tell the editfield acting as the console to exclude the width of the scrollbar
				GetClientRect(pages[TAB_MESSAGES],&r);
				r.right -= GetSystemMetrics(SM_CXVSCROLL)+4;
				r.left = r.top = 0;
				SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r);

				// Set a tab stop in the game data listbox
				{
				DWORD tabs[1] = { 150 };
				ListBox_SetTabStops(GetDlgItem(pages[TAB_GAME], IDGDATA), 1, tabs);
				}

				SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START));
				SetWindowText(hwndDlg, apptitle);
			}
			return FALSE;
		}

		case WM_NOTIFY: {
			LPNMHDR nmhdr = (LPNMHDR)lParam;
			int cur;
			if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break;
			cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0);
			switch (nmhdr->code) {
				case TCN_SELCHANGING: {
					if (cur < 0 || !pages[cur]) break;
					ShowWindow(pages[cur],SW_HIDE);
					return TRUE;
				}
				case TCN_SELCHANGE: {
					if (cur < 0 || !pages[cur]) break;
					ShowWindow(pages[cur],SW_SHOW);
					return TRUE;
				}
			}
			break;
		}

		case WM_CLOSE:
			if (mode == TAB_CONFIG) done = 0;
			else quitevent++;
			return TRUE;

		case WM_DESTROY:
			if (hbmp) {
				DeleteObject(hbmp);
				hbmp = NULL;
			}

			if (pages[TAB_GAME]) {
				DestroyWindow(pages[TAB_GAME]);
				pages[TAB_GAME] = NULL;
			}

			if (pages[TAB_CONFIG]) {
				DestroyWindow(pages[TAB_CONFIG]);
				pages[TAB_CONFIG] = NULL;
			}

			startupdlg = NULL;
			return TRUE;

		case WM_COMMAND:
			switch (LOWORD(wParam)) {
				case WIN_STARTWIN_CANCEL:
					if (mode == TAB_CONFIG) done = 0;
					else quitevent++;
					return TRUE;
				case WIN_STARTWIN_START: done = 1; return TRUE;
			}
			return FALSE;

		case WM_CTLCOLORSTATIC:
			if ((HWND)lParam == pages[TAB_MESSAGES])
				return (BOOL)GetSysColorBrush(COLOR_WINDOW);
			break;

		default: break;
	}

	return FALSE;
}
コード例 #15
0
static void test_Render(void)
{
    IPicture *pic;
    HRESULT hres;
    short type;
    PICTDESC desc;
    OLE_XSIZE_HIMETRIC pWidth;
    OLE_YSIZE_HIMETRIC pHeight;
    COLORREF result, expected;
    HDC hdc = GetDC(0);

    /* test IPicture::Render return code on uninitialized picture */
    OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic);
    hres = IPicture_get_Type(pic, &type);
    ok(hres == S_OK, "IPicture_get_Type does not return S_OK, but 0x%08x\n", hres);
    ok(type == PICTYPE_UNINITIALIZED, "Expected type = PICTYPE_UNINITIALIZED, got = %d\n", type);
    /* zero dimensions */
    hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 0, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 10, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 0, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 0, 10, 0, 0, 10, 10, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 0, 0, 0, 10, 10, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 10, 10, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    /* nonzero dimensions, PICTYPE_UNINITIALIZED */
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 10, NULL);
    ole_expect(hres, S_OK);
    IPicture_Release(pic);

    desc.cbSizeofstruct = sizeof(PICTDESC);
    desc.picType = PICTYPE_ICON;
    desc.u.icon.hicon = LoadIcon(NULL, IDI_APPLICATION);
    if(!desc.u.icon.hicon){
        win_skip("LoadIcon failed. Skipping...\n");
        ReleaseDC(NULL, hdc);
        return;
    }

    OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE, (VOID**)&pic);
    /* zero dimensions, PICTYPE_ICON */
    hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 0, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 10, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 0, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 0, 10, 0, 0, 10, 10, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 10, 0, 0, 0, 10, 10, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
    hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 10, 10, NULL);
    ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);

    /* Check if target size and position is respected */
    IPicture_get_Width(pic, &pWidth);
    IPicture_get_Height(pic, &pHeight);

    SetPixelV(hdc, 0, 0, 0x00F0F0F0);
    SetPixelV(hdc, 5, 5, 0x00F0F0F0);
    SetPixelV(hdc, 10, 10, 0x00F0F0F0);
    expected = GetPixel(hdc, 0, 0);

    hres = IPicture_Render(pic, hdc, 1, 1, 9, 9, 0, 0, pWidth, -pHeight, NULL);
    ole_expect(hres, S_OK);

    if(hres != S_OK) {
        IPicture_Release(pic);
        ReleaseDC(NULL, hdc);
        return;
    }

    /* Evaluate the rendered Icon */
    result = GetPixel(hdc, 0, 0);
    ok(result == expected,
       "Color at 0,0 should be unchanged 0x%06X, but was 0x%06X\n", expected, result);
    result = GetPixel(hdc, 5, 5);
    ok(result != expected ||
        broken(result == expected), /* WinNT 4.0 and older may claim they drew */
                                    /* the icon, even if they didn't. */
       "Color at 5,5 should have changed, but still was 0x%06X\n", expected);
    result = GetPixel(hdc, 10, 10);
    ok(result == expected,
       "Color at 10,10 should be unchanged 0x%06X, but was 0x%06X\n", expected, result);

    IPicture_Release(pic);
    ReleaseDC(NULL, hdc);
}
コード例 #16
0
ファイル: NtGdiGetRandomRgn.c プロジェクト: hoangduit/reactos
INT
Test_NtGdiGetRandomRgn(PTESTINFO pti)
{
    HWND hWnd;
    HDC hDC;
    HRGN hrgn, hrgn2;

    /* Create a window */
    hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                         CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
                         NULL, NULL, g_hInstance, 0);
//	UpdateWindow(hWnd);
    hDC = GetDC(hWnd);

    ASSERT(hDC != NULL);

    hrgn = CreateRectRgn(0,0,0,0);
    hrgn2 = CreateRectRgn(3,3,10,10);
    SetLastError(ERROR_SUCCESS);
    RTEST(NtGdiGetRandomRgn(0, hrgn, 0) == -1);
    RTEST(GetLastError() == ERROR_INVALID_HANDLE);

    SetLastError(ERROR_SUCCESS);
    RTEST(NtGdiGetRandomRgn((HDC)2345, hrgn, 1) == -1);
    RTEST(GetLastError() == ERROR_INVALID_HANDLE);

    SetLastError(ERROR_SUCCESS);
    RTEST(NtGdiGetRandomRgn((HDC)2345, hrgn, 10) == -1);
    RTEST(GetLastError() == ERROR_INVALID_HANDLE);

    SetLastError(ERROR_SUCCESS);
    RTEST(NtGdiGetRandomRgn((HDC)2345, (HRGN)10, 10) == -1);
    RTEST(GetLastError() == ERROR_INVALID_HANDLE);

    SetLastError(ERROR_SUCCESS);
    RTEST(NtGdiGetRandomRgn((HDC)2345, 0, 1) == -1);
    RTEST(GetLastError() == ERROR_INVALID_HANDLE);

    SetLastError(ERROR_SUCCESS);
    RTEST(NtGdiGetRandomRgn(hDC, 0, 0) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, 0, 1) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, (HRGN)-5, 0) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, (HRGN)-5, 1) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 0) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 1) == 0);
    TEST(NtGdiGetRandomRgn(hDC, hrgn, 2) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 3) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 4) == 1);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 5) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 10) == 0);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, -10) == 0);
    RTEST(GetLastError() == ERROR_SUCCESS);

    SelectClipRgn(hDC, hrgn2);
    RTEST(NtGdiGetRandomRgn(hDC, 0, 1) == -1);
    RTEST(GetLastError() == ERROR_SUCCESS);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 1) == 1);
    RTEST(CombineRgn(hrgn, hrgn, hrgn, RGN_OR) == SIMPLEREGION);
    RTEST(CombineRgn(hrgn, hrgn, hrgn2, RGN_XOR) == NULLREGION);

    SetRectRgn(hrgn2,0,0,0,0);
    SelectClipRgn(hDC, hrgn2);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 1) == 1);

    RTEST(CombineRgn(hrgn2, hrgn, hrgn2, RGN_XOR) == NULLREGION);
    RTEST(CombineRgn(hrgn2, hrgn, hrgn, RGN_OR) == NULLREGION);

    SelectClipRgn(hDC, NULL);
    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 1) == 0);


    RTEST(NtGdiGetRandomRgn(hDC, hrgn, 4) == 1);

    RTEST(GetLastError() == ERROR_SUCCESS);

    ReleaseDC(hWnd, hDC);
    DestroyWindow(hWnd);

    return APISTATUS_NORMAL;
}
コード例 #17
0
ファイル: main.cpp プロジェクト: gvsurenderreddy/winswitch
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

	static BOOL s_fConfirmActive = FALSE;
	static UINT s_uTaskbarCreated = 0;

	switch (uMsg) {

		case WM_HOTKEY: {

			switch (wParam) {

				case IDH_NEXTTASK:
				case IDH_PREVTASK:
				case IDH_WINNEXTTASK:
				case IDH_WINPREVTASK:
				case IDH_INSTNEXT:
				case IDH_INSTPREV:
				case IDH_STNEXTTASK:
				case IDH_STINEXTTASK:
					ShowTaskSwitchWnd((UINT)wParam);
					break;

				case IDH_MINIMIZETRAY:
					FlipToTray(GetForegroundWindow());
					break;

				case IDH_RESTORETRAY:
					if (g_cWti > 0)
						_UnflipFromTray(g_cWti - 1);
					break;

				case IDH_SHOWHIDE:
					ShowTrayIcon(!(g_dwFlags & TSF_SHOWTRAYICON));
					break;

				case IDH_CONFIG:
					ConfigTaskSwitchXP();
					break;
				case IDH_ALTAPPLIST:
					//MessageBox (0, L"This must display alternative task switching window\r\n"
					//	L"(or the same window but in alternative mode)", L"klvov says:", MB_OK);
					//ShowAltTSWindow();
					//OutputDebugString(L"IDH_ALTAPPLIST message received\n");
					ShowTaskSwitchWnd((UINT)wParam);
					break;

				case IDH_EXIT:
					if (!(g_dwFlags & TSF_NOCONFIRMEXIT)) {
						if (s_fConfirmActive) { // activate confirm dialog
#pragma FIX_LATER(multiple exit confirmations)
							break;
							/*HWND hwndMsg = FindWindowEx(NULL, NULL, L"#32770", L"TaskSwitchXP confirmation");
							if (hwndMsg) {
								SetForegroundWindow(hwndMsg);
								break;
							}*/
						}

						s_fConfirmActive = TRUE;
						if (ConfirmMessage(IDS_CONFIRM_EXIT))
							DestroyWindow(hwnd);
						s_fConfirmActive = FALSE;
					} else 
						DestroyWindow(hwnd);
					break;
			}
			break;
							}

		case WM_TIMER:
			if (wParam == TIMER_RIGHTUP) {
				KillTimer(hwnd, TIMER_RIGHTUP);
				mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_RIGHTUP, 
					_ptRClick.x, _ptRClick.y, _dwRData, _dwRExtraInfo);
			} else if (wParam == TIMER_SETANIMATION) {
				KillTimer(hwnd, TIMER_SETANIMATION);
				ANIMATIONINFO ai;
				ai.cbSize = sizeof(ANIMATIONINFO);
				ai.iMinAnimate = TRUE;
				SystemParametersInfo(SPI_SETANIMATION, sizeof(ANIMATIONINFO), &ai, FALSE);
			} else if (wParam == TIMER_CHECKTRAYWND) {
				for (UINT i = 0; i < g_cWti; i++) {
					if (!IsWindow(g_pWti[i].hwnd) || IsWindowVisible(g_pWti[i].hwnd))
						_UnflipFromTray(i, SC_MINIMIZE);
				}
			} else if (wParam == TIMER_RELOADICONS) {
				if (!(g_dwFlags & TSF_RELOADICONS))
					KillTimer(hwnd, TIMER_RELOADICONS);
				ReloadTsTrayIcons();
			} else if (wParam == TIMER_CHECKCOLORS) {
				KillTimer(hwnd, TIMER_CHECKCOLORS);
				if (CheckColorTheme())
					CheckDefaultColors();
			} else if (wParam == TIMER_CLOSEDESK) {
				if (WaitForSingleObject(g_hThreadTs, 0) == WAIT_OBJECT_0) {
					KillTimer(hwnd, TIMER_CLOSEDESK);
					//_RPT0(_CRT_WARN, "close desk\n");
					if (g_hThreadTs) {
						CloseHandle(g_hThreadTs);
						g_hThreadTs = NULL;
					}
					if (g_hDesk) {
						CloseDesktop(g_hDesk);
						g_hDesk = NULL;
					}
				}
			}
			break;

		case WM_REMOTECMD:
			SwitchToThisWindow(hwnd, TRUE);
			if (wParam & CCLF_ESCAPE) {
				if (g_hwndTs)
					PostMessage(g_hwndTs, WM_TASKSWITCH, IDH_ESCAPE, 0);
			} else if (wParam & CCLF_STINEXTTASK) {
				ShowTaskSwitchWnd(IDH_STINEXTTASK);
			} else if (wParam & CCLF_STNEXTTASK) {
				ShowTaskSwitchWnd(IDH_STNEXTTASK);
			}
			break;

		case WM_MYTRAYMSG:
			if (wParam == IDI_TASKSWITCHXP) {
				if ((UINT)lParam == g_uTrayMenu) {
					ShowTrayMenu();
				} else if ((UINT)lParam == g_uTrayConfig) {
					ConfigTaskSwitchXP();
				} else if ((UINT)lParam == g_uTrayNext) {
					ShowTaskSwitchWnd(IDH_STTRAYNEXT);
				} else if ((UINT)lParam == g_uTrayPrev) {
					ShowTaskSwitchWnd(IDH_STITRAYNEXT);
				}
			} else {
				if (lParam == WM_LBUTTONUP) {
                    UnflipFromTrayID((UINT)wParam);
				} else if (lParam == WM_RBUTTONUP) {
					ShowFlippedSystemMenu((UINT)wParam);
				} else if (lParam == WM_MBUTTONUP)
					UnflipFromTrayID((UINT)wParam, 0);
			}
			break;

		case WM_EXTMOUSE:
			if (wParam == HTMINBUTTON) {
				FlipToTray((HWND)lParam);
			} else if (wParam == HTMAXBUTTON) {
				HWND h = (HWND)lParam;
				DWORD dwExStyle = GetWindowLongPtr(h, GWL_EXSTYLE);
				SetWindowPos(h, ((dwExStyle & WS_EX_TOPMOST) 
					? HWND_NOTOPMOST : HWND_TOPMOST), 0, 0, 0, 0, 
					SWP_NOSIZE | SWP_NOMOVE);
			}
			break;

		case WM_FLIPTOTRAY:
			return(FlipToTray((HWND)wParam));
			//break;

		case WM_UNFLIPFROMTRAY:
			UnflipFromTray((HWND)wParam, (UINT)lParam);
			break;

		case WM_GETTRAYWINDOWS:
			if (wParam) {
				HWND *phWnd = (HWND*)wParam;
				int cWti = 0;
				while (cWti < MIN((int)lParam, (int)g_cWti)) {
					phWnd[cWti] = g_pWti[cWti].hwnd;
					cWti++;
				}
				return(cWti);
			} else 
				return(g_cWti);
			break;

		case WM_RELOADSETTINGS:
			if (!LoadSettings()) {
				ReportError(IDS_ERR_LOADSETTINGS);
				DestroyWindow(hwnd);
			}
			break;

		case WM_THEMECHANGED:
			if (CheckColorTheme())
				CheckDefaultColors();
			SetTimer(hwnd, TIMER_CHECKCOLORS, 1000, NULL);
			break;

		case WM_CREATE: {

			s_uTaskbarCreated = RegisterWindowMessage(L"TaskbarCreated");
			g_hwndMain = hwnd;

			SendMessage(hwnd, WM_SETICON, ICON_BIG, 
				(LONG)(LONG_PTR)LoadImage(g_hinstExe, MAKEINTRESOURCE(IDI_TASKSWITCHXP), IMAGE_ICON, 
				GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR));
			SendMessage(hwnd, WM_SETICON, ICON_SMALL, 
				(LONG)(LONG_PTR)LoadImage(g_hinstExe, MAKEINTRESOURCE(IDI_TASKSWITCHXP), IMAGE_ICON, 
				GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR));

			if (!LoadSettings()) {
				ReportError(IDS_ERR_LOADSETTINGS);
				return(-1);
			}
			if (!InitPreviewThread())
				return(-1);

			// Weird huh? I cannot understand this...
			if (g_dwShowDelay && g_dwFlagsPv & TSFPV_DESKTOP && g_dwFlagsPv & TSFPV_TASKBAR) {

				RECT rcPvEx;
				rcPvEx.left = rcPvEx.top = 0;
				rcPvEx.right = 102;
				rcPvEx.bottom = 76;
				HDC hdcScreen = GetDC(NULL);
				HDC hdcMem = CreateCompatibleDC(hdcScreen);
				HBITMAP hbitmapMem = CreateCompatibleBitmap(hdcScreen, 
					rcPvEx.right - rcPvEx.left, rcPvEx.bottom - rcPvEx.top);
				ReleaseDC(NULL, hdcScreen);

				if (hbitmapMem) {
					HBITMAP hbitmapOld = (HBITMAP)SelectObject(hdcMem, hbitmapMem);

					SetForegroundWindow(g_hwndMain);
					MyPrintWindow(FindWindow(L"Shell_TrayWnd", L""), 
						hdcMem, &rcPvEx, &rcPvEx, MPW_NOCHECKPOS);

					SelectObject(hdcMem, hbitmapOld);
					DeleteObject(hbitmapMem);
				}
				DeleteDC(hdcMem);
			}
			SetTimer(hwnd, TIMER_CHECKTRAYWND, 1000, NULL);

			if (g_dwCmdLine & CCLF_STINEXTTASK) {
				ShowTaskSwitchWnd(IDH_STINEXTTASK);
			} else if (g_dwCmdLine & CCLF_STNEXTTASK) {
				ShowTaskSwitchWnd(IDH_STNEXTTASK);
			}
			break;
						}

		case WM_CLOSE:
			break;

		case WM_DESTROY:
			KillTimer(hwnd, TIMER_CHECKTRAYWND);
			DestroySettings();
			DestroyPreviewThread();
			for (int i = (int)g_cWti - 1; i >= 0; i--)
				_UnflipFromTray((UINT)i, 0);
			PostQuitMessage(0);
			break;

		default:
			if (uMsg == s_uTaskbarCreated) {
				ReloadTsTrayIcons();
			} else 
				return(DefWindowProc(hwnd, uMsg, wParam, lParam));
			break;
	}
	return(0);
}
コード例 #18
0
ファイル: wglinfo.c プロジェクト: DX-MON/gtkGLExt2
HWND
CreateOpenGLWindow(char* title, int x, int y, int width, int height, 
		   BYTE type, DWORD flags)
{
    int         pf;
    HDC         hDC;
    HWND        hWnd;
    WNDCLASS    wc;
    PIXELFORMATDESCRIPTOR pfd;
    static HINSTANCE hInstance = 0;

    /* only register the window class once - use hInstance as a flag. */
    if (!hInstance) {
	hInstance = GetModuleHandle(NULL);
	wc.style         = CS_OWNDC;
	wc.lpfnWndProc   = (WNDPROC)WindowProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = "OpenGL";

	if (!RegisterClass(&wc)) {
	    MessageBox(NULL, "RegisterClass() failed:  "
		       "Cannot register window class.", "Error", MB_OK);
	    return NULL;
	}
    }

    hWnd = CreateWindow("OpenGL", title, WS_OVERLAPPEDWINDOW |
			WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
			x, y, width, height, NULL, NULL, hInstance, NULL);

    if (hWnd == NULL) {
	MessageBox(NULL, "CreateWindow() failed:  Cannot create a window.",
		   "Error", MB_OK);
	return NULL;
    }

    hDC = GetDC(hWnd);

    /* there is no guarantee that the contents of the stack that become
       the pfd are zeroed, therefore _make sure_ to clear these bits. */
    memset(&pfd, 0, sizeof(pfd));
    pfd.nSize        = sizeof(pfd);
    pfd.nVersion     = 1;
    pfd.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | flags;
    pfd.iPixelType   = type;
    pfd.cColorBits   = 32;

    pf = ChoosePixelFormat(hDC, &pfd);
    if (pf == 0) {
	MessageBox(NULL, "ChoosePixelFormat() failed:  "
		   "Cannot find a suitable pixel format.", "Error", MB_OK); 
	return 0;
    } 
 
    if (SetPixelFormat(hDC, pf, &pfd) == FALSE) {
	MessageBox(NULL, "SetPixelFormat() failed:  "
		   "Cannot set format specified.", "Error", MB_OK);
	return 0;
    } 

    DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

    ReleaseDC(hWnd, hDC);

    return hWnd;
}    
コード例 #19
0
ファイル: mhrip.c プロジェクト: jpka/UnNetHack
BOOL CALLBACK NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PNHRIPWindow data;

    data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA);
    switch (message)
    {
    case WM_INITDIALOG:
        /* set text control font */
        hdc = GetDC(hWnd);
        SendMessage(hWnd, WM_SETFONT,
                    (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
        ReleaseDC(hWnd, hdc);

        SetFocus(GetDlgItem(hWnd, IDOK));
        return FALSE;

    case WM_MSNH_COMMAND:
        onMSNHCommand(hWnd, wParam, lParam);
        break;

    case WM_PAINT:
    {
        int bitmap_offset;
        RECT clientrect;
        RECT textrect;
        HDC hdcBitmap;
        HANDLE OldBitmap;
        PAINTSTRUCT ps;
        HFONT OldFont;

        hdc = BeginPaint (hWnd, &ps);
        OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
        hdcBitmap = CreateCompatibleDC(hdc);
        SetBkMode (hdc, TRANSPARENT);
        GetClientRect (hWnd, &clientrect);
        textrect = clientrect;
        textrect.top += RIP_OFFSET_Y;
        textrect.left += RIP_OFFSET_X;
        textrect.right -= RIP_OFFSET_X;
        if (data->window_text)
        {
            DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
                      DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
            DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
                      DT_LEFT | DT_NOPREFIX);
        }
        OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip);
        SetBkMode (hdc, OPAQUE);
        bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2;
        BitBlt (hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH,
                RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY);
        SetBkMode (hdc, TRANSPARENT);
        if (data->rip_text)
        {
            textrect.left += RIP_GRAVE_X + bitmap_offset;
            textrect.top = textrect.bottom + RIP_GRAVE_Y;
            textrect.right = textrect.left + RIP_GRAVE_WIDTH;
            textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT;
            DrawText (hdc, data->rip_text, strlen(data->rip_text), &textrect,
                      DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK);
        }
        SelectObject (hdcBitmap, OldBitmap);
        SelectObject (hdc, OldFont);
        DeleteDC (hdcBitmap);
        EndPaint (hWnd, &ps);
    }
    break;

    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDOK:
            mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
            if( GetNHApp()->hMainWnd==hWnd )
                GetNHApp()->hMainWnd=NULL;
            DestroyWindow(hWnd);
            SetFocus(GetNHApp()->hMainWnd);
            return TRUE;
        }
        break;

    case WM_CLOSE:
        /* if we get this here, we saved the bones so we can just force a quit */

        mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
        if( GetNHApp()->hMainWnd==hWnd )
            GetNHApp()->hMainWnd=NULL;
        DestroyWindow(hWnd);
        SetFocus(GetNHApp()->hMainWnd);
        program_state.stopprint++;
        return TRUE;

    case WM_DESTROY:
        if( data ) {
            if( data->window_text ) free(data->window_text);
            if( data->rip_text ) free(data->rip_text);
            if (data->rip_bmp != NULL) DeleteObject(data->rip_bmp);
            free(data);
            SetWindowLong(hWnd, GWL_USERDATA, (LONG)0);
        }
        break;

    }
    return FALSE;
}
コード例 #20
0
ファイル: wglinfo.c プロジェクト: DX-MON/gtkGLExt2
int 
main(int argc, char** argv)
{
    HDC hDC;				/* device context */
    HGLRC hRC;				/* opengl context */
    HWND  hWnd;				/* window */
    MSG   msg;				/* message */
    int   i;
    char* s;
    char  t[80];
    char* p;
    int verbose = 0;

    while (--argc) {
	if (strcmp("-h", argv[argc]) == 0) {
	    printf("Usage: wglinfo [-v] [-t] [-m] [-h] [-dispay <dname>] [-nfbc] [-fpcinfo]\n");
	    printf("        -v: Print visuals info in verbose form.\n");
	    printf("        -t: Print verbose table (not implemented on Win32)\n");
	    printf("        -m: Don't print mid table headers (in long tables). (not on Win32)\n");
	    printf("        -display <dname>: Print GLX visuals on specified server. (not on Win32)\n");
	    printf("        -nfbc: Don't use fbconfig extension (not available on Win32)\n");
	    printf("        -fbcinfo: print out additional fbconfig information (not on Win32)\n");
	    printf("        -h: This screen.\n");
	    exit(0);
	} else if (strcmp("-v", argv[argc]) == 0) {
	    verbose = 1;
	}
    }

    hWnd = CreateOpenGLWindow("wglinfo", 0, 0, 100, 100, PFD_TYPE_RGBA, 0);
    if (hWnd == NULL)
	exit(1);

    hDC = GetDC(hWnd);
    hRC = wglCreateContext(hDC);
    wglMakeCurrent(hDC, hRC);

    ShowWindow(hWnd, SW_HIDE);

    /* output header information */
    printf("display: N/A\n");
    printf("server wgl vendor string: N/A\n");
    printf("server wgl version string: N/A\n");
    printf("server wgl extensions (WGL_): N/A\n");
    printf("client wgl version: N/A\n");
    printf("client wgl extensions (WGL_): none\n");
    printf("OpenGL vendor string: %s\n", glGetString(GL_VENDOR));
    printf("OpenGL renderer string: %s\n", glGetString(GL_RENDERER));
    printf("OpenGL version string: %s\n", glGetString(GL_VERSION));
    printf("OpenGL extensions (GL_): \n");

    /* do the magic to separate all extensions with comma's, except
       for the last one that _may_ terminate in a space. */
    i = 0;
    s = (char*)glGetString(GL_EXTENSIONS);
    t[79] = '\0';
    p = &t[0];
    while(*s) {
	t[i++] = *s;
	if(*s == ' ') {
	    if (*(s+1) != '\0') {
		t[i-1] = ',';
		t[i] = ' ';
		p = &t[i++];
	    } else {	       /* zoinks! last one terminated in a space! */
		t[i-1] = '\0';
	    }
	}
	if(i > 80 - 5) {
	    *p = t[i] = '\0';
	    printf("    %s\n", t);
	    p++;
	    i = strlen(p);
	    strcpy(t, p);
	}
	s++;
    }
    t[i] = '\0';
    printf("    %s.\n\n", t);

    /* enumerate all the formats */
    VisualInfo(hDC, verbose);

    PostQuitMessage(0);
    while(GetMessage(&msg, hWnd, 0, 0)) {
	TranslateMessage(&msg);
	DispatchMessage(&msg);
    }

    wglMakeCurrent(NULL, NULL);
    ReleaseDC(hWnd, hDC);
    wglDeleteContext(hRC);
    DestroyWindow(hWnd);

    return msg.wParam;
}
コード例 #21
0
ファイル: MainDlg.cpp プロジェクト: junehappylove/GitHub
void CMainDlg::DrawPicture()
{
	int tX,tY;
	if (m_SBitmapEx.IsValid())
	{
		m_BitmapEx.Create(m_SBitmapEx.GetWidth(),m_SBitmapEx.GetHeight());
		m_BitmapEx.Draw(0,0,m_SBitmapEx.GetWidth(),m_SBitmapEx.GetHeight(),m_SBitmapEx,0,0);
		m_BitmapEx.Scale(m_nScale,m_nScale);

		CDC *pDC = m_ctl_image.GetDC();

		CDC memDC,memDC1;
		memDC.CreateCompatibleDC(pDC);
		memDC1.CreateCompatibleDC(pDC);

		CBitmap bmp;
		bmp.CreateCompatibleBitmap(pDC, m_BitmapEx.GetWidth(), m_BitmapEx.GetHeight());
		memDC.SelectObject(bmp);
		m_BitmapEx.Draw(memDC);

		CBitmap bmp1;
		bmp1.CreateCompatibleBitmap(pDC, m_ImageRect.Width(), m_ImageRect.Height());
		memDC1.SelectObject(bmp1);

		CPen pen;
		CPen* pOldPen;
		CFont wFont,wFont1;
		CFont *pOldFont;
		CString title;

		//清除背景
		CRgn rgn;
		rgn.CreateRectRgn(0,0,m_ImageRect.Width(),m_ImageRect.Height());
		CBrush bBlack(GetSysColor(COLOR_3DFACE));
		memDC1.FillRgn(&rgn, &bBlack);

		//memDC1.SetStretchBltMode(HALFTONE);
		tX = (m_ImageRect.Width() - m_BitmapEx.GetWidth())/2;
		tY = (m_ImageRect.Height() - m_BitmapEx.GetHeight())/2;

		memDC1.BitBlt(tX,tY,m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight(),&memDC,m_pLeft,m_pTop,SRCCOPY);

		pen.CreatePen(PS_SOLID, 1, RGB (255, 0, 0));

		pOldPen = memDC1.SelectObject (&pen);
		memDC1.MoveTo(m_CutRect.left,m_CutRect.top);
		memDC1.LineTo(m_CutRect.right,m_CutRect.top);
		memDC1.LineTo(m_CutRect.right,m_CutRect.bottom);
		memDC1.LineTo(m_CutRect.left,m_CutRect.bottom);
		memDC1.LineTo(m_CutRect.left,m_CutRect.top);
		memDC1.SelectObject (pOldPen);

		/*
		if (m_PicEditStatus)
		{
			//清除背景
			
			if (m_DrawRect.left > 0)
			{
				CRgn rGap1,rGap2,rGap3,rGap4;
				rGap1.CreateRectRgn(0, 0, m_DrawRect.left+10,m_ImageRect.Height());
				rGap2.CreateRectRgn(m_DrawRect.right-10, 0, m_ImageRect.right,m_ImageRect.Height());
				rGap3.CreateRectRgn(0, 0, m_ImageRect.Width(),m_DrawRect.top+10);
				rGap4.CreateRectRgn(0, m_DrawRect.bottom-10, m_ImageRect.Width(),m_ImageRect.bottom);

				rGap1.CombineRgn(&rGap1,&rGap2,RGN_OR);
				rGap1.CombineRgn(&rGap1,&rGap3,RGN_OR);
				rGap1.CombineRgn(&rGap1,&rGap4,RGN_OR);

				CBrush bBlack(GetSysColor(COLOR_3DFACE));
				memDC1.FillRgn(&rGap1, &bBlack);
			}

			memDC1.SetStretchBltMode(HALFTONE);

			if (m_Factor>=0)
			{
				memDC1.StretchBlt(0,0,m_ImageRect.Width(), m_ImageRect.Height(),
					&memDC, 
					(m_BitmapEx.GetWidth())*m_Factor/2,(m_BitmapEx.GetHeight())*m_Factor/2
					,(m_BitmapEx.GetWidth())*(1-m_Factor), (m_BitmapEx.GetHeight())*(1-m_Factor)
					,SRCCOPY);
				m_DrawRect = m_ImageRect;
			}
			else
			{
				memDC1.StretchBlt((m_ImageRect.Width())*(-m_Factor)/2,(m_ImageRect.Height())*(-m_Factor)/2
					,(m_ImageRect.Width())*(1+m_Factor), (m_ImageRect.Height())*(1+m_Factor)
					,&memDC, 
					0,0,m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight()
					,SRCCOPY);
				m_DrawRect.left = (m_ImageRect.Width())*(-m_Factor)/2;
				m_DrawRect.top = (m_ImageRect.Height())*(-m_Factor)/2;
				m_DrawRect.right = 
					(m_ImageRect.Width())*(-m_Factor)/2 + (m_ImageRect.Width())*(1+m_Factor) - 1;
				m_DrawRect.bottom = 
					(m_ImageRect.Height())*(-m_Factor)/2 + (m_ImageRect.Height())*(1+m_Factor) - 1; 
			}


			pen.CreatePen(PS_SOLID, 1, RGB (255, 0, 0));
			pOldPen = memDC1.SelectObject (&pen);
			memDC1.MoveTo(m_CutRect.left,m_CutRect.top);
			memDC1.LineTo(m_CutRect.right,m_CutRect.top);
			memDC1.LineTo(m_CutRect.right,m_CutRect.bottom);
			memDC1.LineTo(m_CutRect.left,m_CutRect.bottom);
			memDC1.LineTo(m_CutRect.left,m_CutRect.top);
			memDC1.SelectObject (pOldPen);

			
			title.Format(_T("%d*%d"),
				m_Factor>=0 ? (int)(((double)m_BitmapEx.GetWidth()*(1-m_Factor)) * ((double)m_CutRect.Width()/m_ImageRect.Width())) 
					: (int)(((double)m_BitmapEx.GetWidth()/(1+m_Factor)) * ((double)m_CutRect.Width()/m_ImageRect.Width())),
				m_Factor>=0 ? (int)(((double)m_BitmapEx.GetHeight()*(1-m_Factor)) * ((double)m_CutRect.Height()/m_ImageRect.Height()))  
					: (int)(((double)m_BitmapEx.GetHeight()/(1+m_Factor)) * ((double)m_CutRect.Height()/m_ImageRect.Height())));
			wFont1.CreateFont(12, 0, 0, 0, 0,
				0, 0, 0,
				0, 0, 0, 0,
				VARIABLE_PITCH | FF_SWISS, _T("MS Sans Serif"));
			pOldFont = memDC1.SelectObject(&wFont1);
			memDC1.SetTextColor(RGB(255,0,0));
			memDC1.SetBkMode(TRANSPARENT);
			memDC1.TextOut(m_CutRect.left+2,m_CutRect.top+2, title);
			memDC1.SelectObject(pOldFont);

			
			title.Format(_T("状态:编辑  分辨率:%d*%d"),
				m_Factor>=0 ? (int)((double)m_BitmapEx.GetWidth()*(1-m_Factor)) : (int)((double)m_BitmapEx.GetWidth()/(1+m_Factor)),
				m_Factor>=0 ? (int)((double)m_BitmapEx.GetHeight()*(1-m_Factor))  : (int)((double)m_BitmapEx.GetHeight()/(1+m_Factor)));
			
		}
		else
		{
			memDC1.SetStretchBltMode(HALFTONE);

			memDC1.StretchBlt(0,0,m_ImageRect.Width(), m_ImageRect.Height(),
					&memDC, 
					0,0,m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight(),
					SRCCOPY);

			title.Format(_T("状态:显示  分辨率:%d*%d"),m_BitmapEx.GetWidth(),m_BitmapEx.GetHeight());
		}
		*/

		title.Format(_T("缩放:%d:100"),m_nScale);
		
		wFont.CreateFont(12, 0, 0, 0, 0,
			0, 0, 0,
			0, 0, 0, 0,
			VARIABLE_PITCH | FF_SWISS, _T("MS Sans Serif"));
		pOldFont = memDC1.SelectObject(&wFont);
		memDC1.SetTextColor(RGB(255,0,0));
		memDC1.SetBkMode(TRANSPARENT);
		memDC1.TextOut(2,m_ImageRect.bottom-14, title);
		memDC1.SelectObject(pOldFont);

		pDC->BitBlt(0,0,m_ImageRect.Width(), m_ImageRect.Height(),&memDC1,0,0,SRCCOPY);

		memDC.DeleteDC();
		memDC1.DeleteDC();

		ReleaseDC(pDC);

		tX = (m_BitmapEx.GetWidth() - m_CutRect.Width())/2;
		tY = (m_BitmapEx.GetHeight() - m_CutRect.Height())/2;

		m_PhotoBitmapEx.Create(m_CutRect.Width(),m_CutRect.Height());
		m_PhotoBitmapEx.Draw(0,0,m_CutRect.Width(),m_CutRect.Height(),m_BitmapEx,tX + m_pLeft,tY + m_pTop);

		DrawPhoto();

	}else
	{
		CDC *pDC = m_ctl_image.GetDC();
		CBrush bBlack(GetSysColor(COLOR_3DFACE));
		pDC->FillRect(m_ImageRect,&bBlack);

		//m_PhotoBitmapEx.Create(0,0);
		
		//DrawPhoto();
	}
}
コード例 #22
0
static WIN_DialogData *CreateDialogData(int w, int h, const char *caption)
{
    WIN_DialogData *dialog;
    DLGTEMPLATEEX dialogTemplate;
    WORD WordToPass;

    SDL_zero(dialogTemplate);
    dialogTemplate.dlgVer = 1;
    dialogTemplate.signature = 0xffff;
    dialogTemplate.style = (WS_CAPTION | DS_CENTER | DS_SHELLFONT);
    dialogTemplate.x = 0;
    dialogTemplate.y = 0;
    dialogTemplate.cx = w;
    dialogTemplate.cy = h;
    Vec2ToDLU(&dialogTemplate.cx, &dialogTemplate.cy);

    dialog = (WIN_DialogData *)SDL_calloc(1, sizeof(*dialog));
    if (!dialog) {
        return NULL;
    }

    if (!AddDialogData(dialog, &dialogTemplate, sizeof(dialogTemplate))) {
        FreeDialogData(dialog);
        return NULL;
    }

    /* No menu */
    WordToPass = 0;
    if (!AddDialogData(dialog, &WordToPass, 2)) {
        FreeDialogData(dialog);
        return NULL;
    }

    /* No custom class */
    if (!AddDialogData(dialog, &WordToPass, 2)) {
        FreeDialogData(dialog);
        return NULL;
    }

    /* title */
    if (!AddDialogString(dialog, caption)) {
        FreeDialogData(dialog);
        return NULL;
    }

    /* Font stuff */
    {
        /*
         * We want to use the system messagebox font.
         */
        BYTE ToPass;

        NONCLIENTMETRICSA NCM;
        NCM.cbSize = sizeof(NCM);
        SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0);

        /* Font size - convert to logical font size for dialog parameter. */
        {
            HDC ScreenDC = GetDC(0);
            WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / GetDeviceCaps(ScreenDC, LOGPIXELSY));
            ReleaseDC(0, ScreenDC);
        }

        if (!AddDialogData(dialog, &WordToPass, 2)) {
            FreeDialogData(dialog);
            return NULL;
        }

        /* Font weight */
        WordToPass = (WORD)NCM.lfMessageFont.lfWeight;
        if (!AddDialogData(dialog, &WordToPass, 2)) {
            FreeDialogData(dialog);
            return NULL;
        }

        /* italic? */
        ToPass = NCM.lfMessageFont.lfItalic;
        if (!AddDialogData(dialog, &ToPass, 1)) {
            FreeDialogData(dialog);
            return NULL;
        }

        /* charset? */
        ToPass = NCM.lfMessageFont.lfCharSet;
        if (!AddDialogData(dialog, &ToPass, 1)) {
            FreeDialogData(dialog);
            return NULL;
        }

        /* font typeface. */
        if (!AddDialogString(dialog, NCM.lfMessageFont.lfFaceName)) {
            FreeDialogData(dialog);
            return NULL;
        }
    }

    return dialog;
}
コード例 #23
0
bool is_gui_aligned(GLFWwindow *win)
{
#ifdef _WIN32
    try
    {
        auto hwn = glfwGetWin32Window(win);
        if (hwn == nullptr)
            return true;

        auto flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
            ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar |
            ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus;

        ImGui::SetNextWindowPos({ 0, 0 });

        ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
        ImGui::Begin("is_gui_aligned", nullptr, flags);

        auto DrawList = ImGui::GetWindowDrawList();
        if (DrawList == nullptr)
            return true;

        DrawList->AddRectFilled({ 0,0 }, { 1,1 }, ImColor(MAGIC / 255.f, 0.f, 0.f, 1.f));

        ImGui::End();
        ImGui::PopStyleVar();

        ImGui::Render();

        glfwSwapBuffers(win);

        ImGui_ImplGlfw_NewFrame(1.f);

        SetFocus(hwn);

        int width = 1;
        int height = 1;

        HDC hdc = GetDC(hwn);
        if (hdc == nullptr)
            return true;

        std::shared_ptr<HDC> shared_hdc(&hdc, [&](HDC* hdc) {ReleaseDC(hwn, *hdc); DeleteDC(*hdc);});

        HDC hCaptureDC = CreateCompatibleDC(hdc);
        if (hCaptureDC == nullptr)
            return true;

        std::shared_ptr<HDC> shared_capture_hdc(&hCaptureDC, [&](HDC* hdc) {ReleaseDC(hwn, *hdc); DeleteDC(*hdc);});

        HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hdc, width, height);
        if (hCaptureBitmap == nullptr)
            return true;

        std::shared_ptr<HBITMAP> shared_bmp(&hCaptureBitmap, [&](HBITMAP* bmp) {DeleteObject(bmp);});

        auto original = SelectObject(hCaptureDC, hCaptureBitmap);
        if (original == nullptr)
            return true;

        if (!BitBlt(hCaptureDC, 0, 0, width, height, hdc, 0, 0, SRCCOPY | CAPTUREBLT))
            return true;

        BITMAPINFO bmi = { 0 };
        bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
        bmi.bmiHeader.biWidth = width;
        bmi.bmiHeader.biHeight = height;
        bmi.bmiHeader.biPlanes = 1;
        bmi.bmiHeader.biBitCount = 32;
        bmi.bmiHeader.biCompression = BI_RGB;

        std::vector<RGBQUAD> pPixels(width * height);

        auto res = GetDIBits(
            hCaptureDC,
            hCaptureBitmap,
            0,
            height,
            pPixels.data(),
            &bmi,
            DIB_RGB_COLORS
        );

        if (res <= 0 || res == ERROR_INVALID_PARAMETER)
            return true;

        auto ret = pPixels[0].rgbRed == MAGIC;
        return ret;
    }
    catch (...)
    {
        return true;
    }
#else
    return true;
#endif
}
コード例 #24
0
int generateModAVI(int min, char * modfile, char * basename,int xres,int yres,int nbavi)
{
    HBITMAP hbm;
    HAVI avi;
    AVICOMPRESSOPTIONS opts;

    int i,j,filenb,fileend,frame;
    int audiosize,totalimg;
    char filename[512];
    void *bits;
    float frame_rate;
    unsigned long frameperiod, audiooffset,mainaudiooffset;
    unsigned char *dbits,*module;
    int filesize;
    FILE * fmod;
    framegenerator * fg;
    unsigned long * framebuf;

    BITMAPINFO bi;
    WAVEFORMATEX wfx;

    HDC hdcscreen;
    HDC comphdc;
    tracker_buffer_state trackbuf_state;

    modcontext modctx;

    hdcscreen = GetDC(0),
    comphdc = CreateCompatibleDC(hdcscreen);
    ReleaseDC(0,hdcscreen);

    ZeroMemory(&bi,sizeof(bi));

    bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
    bi.bmiHeader.biWidth = xres;
    bi.bmiHeader.biHeight = yres;
    bi.bmiHeader.biPlanes = 1;
    bi.bmiHeader.biBitCount = 24;
    bi.bmiHeader.biCompression = BI_RGB;
    bi.bmiHeader.biSizeImage = ((bi.bmiHeader.biWidth*bi.bmiHeader.biBitCount/8)&0xFFFFFFFC)*bi.bmiHeader.biHeight;
    bi.bmiHeader.biXPelsPerMeter = 10000;
    bi.bmiHeader.biYPelsPerMeter = 10000;
    bi.bmiHeader.biClrUsed = 0;
    bi.bmiHeader.biClrImportant = 0;

    hbm = CreateDIBSection(comphdc,(BITMAPINFO*)&bi.bmiHeader,DIB_RGB_COLORS,&bits,NULL,0);

    frame_rate = (float)29.97;
    frameperiod = (unsigned long)((1/frame_rate) * (1000 * 1000 * 10));

    fileend = 0;
    filenb = 0;

    totalimg = 0;

    mainaudiooffset = 0;

    filesize = 0;
    fmod = fopen(modfile,"rb");
    if(fmod)
    {
        fseek(fmod,0,SEEK_END);
        filesize = ftell(fmod);
        fseek(fmod,0,SEEK_SET);

        module = malloc(filesize);
        if(module)
        {
            fread(module,filesize,1,fmod);
        }

        fclose(fmod);
    }
    else
    {
        return 0;
    }

    if(!module)
        return 0;

    hxcmod_init( &modctx );

    fg = init_fg(xres,yres);

    if(!hxcmod_load( &modctx, module, filesize ))
    {
        free(module);
        return 0;
    }

    audiosize = (int)((float)AUDIORATE * (float)((float)frameperiod/(float)(1000*1000*10)));

    memset(&trackbuf_state,0,sizeof(trackbuf_state));
    trackbuf_state.nb_max_of_state = 100;
    trackbuf_state.track_state_buf = malloc(sizeof(tracker_state) * trackbuf_state.nb_max_of_state);
    memset(trackbuf_state.track_state_buf,0,sizeof(tracker_state) * trackbuf_state.nb_max_of_state);
    trackbuf_state.sample_step = ( audiosize * 4 ) / trackbuf_state.nb_max_of_state;

    do
    {
        audiooffset = 0;

        if(basename)
            sprintf(filename,"%s_%d.avi",basename,filenb);
        else
            sprintf(filename,"outavi_%d.avi",filenb);

        wfx.wFormatTag = 1;
        wfx.nChannels = 2;
        wfx.nSamplesPerSec = AUDIORATE;
        wfx.nAvgBytesPerSec = AUDIORATE*2*2;
        wfx.nBlockAlign = 4;
        wfx.wBitsPerSample = 16;
        wfx.cbSize = 0;

        avi = CreateAvi(filename,frameperiod,&wfx);

        ZeroMemory(&opts,sizeof(opts));
        opts.fccHandler=mmioFOURCC('L','A','G','S');
        //opts.fccHandler=mmioFOURCC('d','i','v','x');
        SetAviVideoCompression(avi,hbm,&opts,0,NULL);

        for (frame=0; (frame<=(int)(frame_rate*(float)60*(float)min)) && !fileend; frame++)
        {
            printf("file %d :  %d - %.2f \\%\n",filenb,frame,((float)frame*100/(float)((int)(frame_rate*(float)60*(float)min))));
            dbits=(unsigned char*)bits;

            audiosize = (int)((float)AUDIORATE * (float)((float)frameperiod/(float)(1000*1000*10)));
            if( ((float)(frame*(((float)AUDIORATE)/frame_rate) ) - (float)audiooffset)>=1)
            {
                audiosize++;
            }

            framebuf = fg_generateFrame(fg,&trackbuf_state,audiosize/4);
            for(i=0; i<yres; i++)
            {
                for(j=0; j<xres; j++)
                {
                    dbits[(((((yres-1)-i)*xres)+j)*3)+0] = (unsigned char)GETBLUE(framebuf[(((i*xres)+j))]);
                    dbits[(((((yres-1)-i)*xres)+j)*3)+1] = (unsigned char)GETGREEN(framebuf[(((i*xres)+j))]);
                    dbits[(((((yres-1)-i)*xres)+j)*3)+2] = (unsigned char)GETRED(framebuf[(((i*xres)+j))]);
                }
            }

            trackbuf_state.nb_of_state = 0;
            hxcmod_fillbuffer(&modctx, sound_buffer, audiosize, &trackbuf_state );
            AddAviAudio(avi, &sound_buffer, audiosize*4);

            AddAviFrame(avi,hbm);

            audiooffset += audiosize;

            totalimg++;
        }

        mainaudiooffset += audiooffset;
        audiooffset = 0;

        CloseAvi(avi);

        filenb++;
    } while(!fileend && filenb < nbavi );


    DeleteDC(comphdc);
    DeleteObject(hbm);

    return 0;
}
コード例 #25
0
ファイル: dibutil.c プロジェクト: russlank/WinBGI
HDIB BitmapToDIB(HBITMAP hBitmap, HPALETTE hPal)
{
    BITMAP              bm;         // bitmap structure
    BITMAPINFOHEADER    bi;         // bitmap header
    LPBITMAPINFOHEADER  lpbi;       // pointer to BITMAPINFOHEADER
    DWORD               dwLen;      // size of memory block
    HANDLE              hDIB, h;    // handle to DIB, temp handle
    HDC                 hDC;        // handle to DC
    WORD                biBits;     // bits per pixel

    // check if bitmap handle is valid

    if (!hBitmap)
        return NULL;

    // fill in BITMAP structure, return NULL if it didn't work

    if (!GetObject(hBitmap, sizeof(bm), (LPSTR)&bm))
        return NULL;

    // if no palette is specified, use default palette

    if (hPal == NULL)
        hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);

    // calculate bits per pixel

    biBits = bm.bmPlanes * bm.bmBitsPixel;

    // make sure bits per pixel is valid

    if (biBits <= 1)
        biBits = 1;
    else if (biBits <= 4)
        biBits = 4;
    else if (biBits <= 8)
        biBits = 8;
    else // if greater than 8-bit, force to 24-bit
        biBits = 24;

    // initialize BITMAPINFOHEADER

    bi.biSize = sizeof(BITMAPINFOHEADER);
    bi.biWidth = bm.bmWidth;
    bi.biHeight = bm.bmHeight;
    bi.biPlanes = 1;
    bi.biBitCount = biBits;
    bi.biCompression = BI_RGB;
    bi.biSizeImage = 0;
    bi.biXPelsPerMeter = 0;
    bi.biYPelsPerMeter = 0;
    bi.biClrUsed = 0;
    bi.biClrImportant = 0;

    // calculate size of memory block required to store BITMAPINFO

    dwLen = bi.biSize + PaletteSize((LPSTR)&bi);

    // get a DC

    hDC = GetDC(NULL);

    // select and realize our palette

    hPal = SelectPalette(hDC, hPal, FALSE);
    RealizePalette(hDC);

    // alloc memory block to store our bitmap

    hDIB = GlobalAlloc(GHND, dwLen);

    // if we couldn't get memory block

    if (!hDIB)
    {
      // clean up and return NULL

      SelectPalette(hDC, hPal, TRUE);
      RealizePalette(hDC);
      ReleaseDC(NULL, hDC);
      return NULL;
    }

    // lock memory and get pointer to it

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);

    /// use our bitmap info. to fill BITMAPINFOHEADER

    *lpbi = bi;

    // call GetDIBits with a NULL lpBits param, so it will calculate the
    // biSizeImage field for us    

    GetDIBits(hDC, hBitmap, 0, (UINT)bi.biHeight, NULL, (LPBITMAPINFO)lpbi,
        DIB_RGB_COLORS);

    // get the info. returned by GetDIBits and unlock memory block

    bi = *lpbi;
    GlobalUnlock(hDIB);

    // if the driver did not fill in the biSizeImage field, make one up 
    if (bi.biSizeImage == 0)
        bi.biSizeImage = WIDTHBYTES((DWORD)bm.bmWidth * biBits) * bm.bmHeight;

    // realloc the buffer big enough to hold all the bits

    dwLen = bi.biSize + PaletteSize((LPSTR)&bi) + bi.biSizeImage;

    if (h = GlobalReAlloc(hDIB, dwLen, 0))
        hDIB = h;
    else
    {
        // clean up and return NULL

        GlobalFree(hDIB);
        hDIB = NULL;
        SelectPalette(hDC, hPal, TRUE);
        RealizePalette(hDC);
        ReleaseDC(NULL, hDC);
        return NULL;
    }

    // lock memory block and get pointer to it */

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);

    // call GetDIBits with a NON-NULL lpBits param, and actualy get the
    // bits this time

    if (GetDIBits(hDC, hBitmap, 0, (UINT)bi.biHeight, (LPSTR)lpbi +
            (WORD)lpbi->biSize + PaletteSize((LPSTR)lpbi), (LPBITMAPINFO)lpbi,
            DIB_RGB_COLORS) == 0)
    {
        // clean up and return NULL

        GlobalUnlock(hDIB);
        hDIB = NULL;
        SelectPalette(hDC, hPal, TRUE);
        RealizePalette(hDC);
        ReleaseDC(NULL, hDC);
        return NULL;
    }

    bi = *lpbi;

    // clean up 
    GlobalUnlock(hDIB);
    SelectPalette(hDC, hPal, TRUE);
    RealizePalette(hDC);
    ReleaseDC(NULL, hDC);

    // return handle to the DIB
    return hDIB;
}
コード例 #26
0
ファイル: frame.cpp プロジェクト: Seldom/miranda-ng
static LRESULT CALLBACK FrameWndProc(HWND hwndFrame, UINT msg, WPARAM wParam, LPARAM lParam)
{
	CountdownFrameWndData *dat = (CountdownFrameWndData*)GetWindowLongPtr(hwndFrame, GWLP_USERDATA);

	switch (msg) {
	case WM_NCCREATE:  /* init window data */
		dat = (struct CountdownFrameWndData*)mir_calloc(sizeof(*dat));
		SetWindowLongPtr(hwndFrame, GWLP_USERDATA, (LONG_PTR)dat);
		if (dat == NULL) return FALSE; /* creation failed */
		dat->fTimeFlags = *(WORD*)((CREATESTRUCT*)lParam)->lpCreateParams;
		dat->flags = FWPDF_COUNTDOWNINVALID;
		break;

	case WM_CREATE:  /*  create childs */
		{
			CREATESTRUCT *params = (CREATESTRUCT*)lParam;
			dat->hwndIcon = CreateWindowEx(WS_EX_NOPARENTNOTIFY, _T("Static"), NULL, WS_CHILD | WS_VISIBLE | SS_ICON | SS_CENTERIMAGE | SS_NOTIFY,
				3, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), hwndFrame, NULL, params->hInstance, NULL);
			dat->hwndProgress = CreateWindowEx(WS_EX_NOPARENTNOTIFY, PROGRESS_CLASS, (dat->fTimeFlags&SDWTF_ST_TIME) ? TranslateT("Shutdown at:") : TranslateT("Time left:"),
				WS_CHILD | WS_VISIBLE | PBS_SMOOTH, GetSystemMetrics(SM_CXICON) + 5, 5, 90, (GetSystemMetrics(SM_CXICON) / 2) - 5, hwndFrame, NULL, params->hInstance, NULL);
			if (dat->hwndProgress == NULL) return -1; /* creation failed, calls WM_DESTROY */
			SendMessage(dat->hwndProgress, PBM_SETSTEP, 1, 0);
			mir_subclassWindow(dat->hwndProgress, ProgressBarSubclassProc);
			dat->hwndDesc = CreateWindowEx(WS_EX_NOPARENTNOTIFY, _T("Static"), (dat->fTimeFlags&SDWTF_ST_TIME) ? TranslateT("Shutdown at:") : TranslateT("Time left:"),
				WS_CHILD | WS_VISIBLE | SS_LEFTNOWORDWRAP | SS_NOTIFY, GetSystemMetrics(SM_CXICON) + 5, (GetSystemMetrics(SM_CXICON) / 2), 75,
				(GetSystemMetrics(SM_CXICON) / 2), hwndFrame, NULL, params->hInstance, NULL);
			dat->hwndTime = CreateWindowEx(WS_EX_NOPARENTNOTIFY, _T("Static"), NULL, WS_CHILD | WS_VISIBLE | SS_RIGHT | SS_NOTIFY | SS_ENDELLIPSIS,
				(GetSystemMetrics(SM_CXICON) + 80), (GetSystemMetrics(SM_CXICON) / 2), 35, (GetSystemMetrics(SM_CXICON) / 2), hwndFrame, NULL, params->hInstance, NULL);
			if (dat->hwndTime == NULL)
				return -1; /* creation failed, calls WM_DESTROY */

			// create tooltips
			TTTOOLINFO ti;
			dat->hwndToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX,
				CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndFrame, NULL, params->hInstance, NULL);
			if (dat->hwndToolTip != NULL) {
				SetWindowPos(dat->hwndToolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
				memset(&ti, 0, sizeof(ti));
				ti.cbSize = sizeof(ti);
				ti.hwnd = hwndFrame;
				ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_TRANSPARENT;
				ti.lpszText = LPSTR_TEXTCALLBACK; /* commctl 4.70+ */
				ti.uId = (UINT_PTR)dat->hwndTime; /* in-place tooltip */
				SendMessage(dat->hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
				ti.uFlags &= ~TTF_TRANSPARENT;
				ti.uId = (UINT_PTR)dat->hwndProgress;
				SendMessage(dat->hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
				if (dat->hwndDesc != NULL) {
					ti.uId = (UINT_PTR)dat->hwndDesc;
					SendMessage(dat->hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
				}
				if (dat->hwndIcon != NULL) {
					ti.uId = (UINT_PTR)dat->hwndIcon;
					SendMessage(dat->hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
				}
			}
			/* init layout */
			dat->hHookColorsChanged = HookEventMessage(ME_COLOUR_RELOAD, hwndFrame, M_REFRESH_COLORS);
			dat->hHookFontsChanged = HookEventMessage(ME_FONT_RELOAD, hwndFrame, M_REFRESH_FONTS);
			dat->hHookIconsChanged = HookEventMessage(ME_SKIN2_ICONSCHANGED, hwndFrame, M_REFRESH_ICONS);
			SendMessage(hwndFrame, M_REFRESH_COLORS, 0, 0);
			SendMessage(hwndFrame, M_REFRESH_FONTS, 0, 0);
			SendMessage(hwndFrame, M_REFRESH_ICONS, 0, 0);
			SendMessage(hwndFrame, M_SET_COUNTDOWN, 0, 0);
			SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
			if (!SetTimer(hwndFrame, 1, 1000, NULL))
				return -1; /* creation failed, calls WM_DESTROY */
		}
		return 0;

	case WM_DESTROY:
		if (dat == NULL) return 0;

		UnhookEvent(dat->hHookColorsChanged);
		UnhookEvent(dat->hHookFontsChanged);
		UnhookEvent(dat->hHookIconsChanged);
		/* other childs are destroyed automatically */
		if (dat->hwndToolTip != NULL)
			DestroyWindow(dat->hwndToolTip);
		break;

	case WM_NCDESTROY:
		if (dat == NULL) return 0;
		if (dat->hFont != NULL) DeleteObject(dat->hFont);
		if (dat->hbrBackground != NULL) DeleteObject(dat->hbrBackground);
		mir_free(dat);
		SetWindowLongPtr(hwndFrame, GWLP_USERDATA, 0);
		break;

	case WM_SIZE:
		{
			RECT rc;
			UINT defflg = SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE;
			SetRect(&rc, 0, 0, LOWORD(lParam), HIWORD(lParam)); /* width,height */
			/* workaround: reduce flickering of frame in clist */
			InvalidateRect(hwndFrame, &rc, FALSE);
			HDWP hdwp = BeginDeferWindowPos(3);
			/* progress */
			LONG width = rc.right - GetSystemMetrics(SM_CXICON) - 10;
			LONG height = rc.bottom - (GetSystemMetrics(SM_CYICON) / 2) - 5;
			if (NULL != dat->hwndProgress) /* Wine fix. */
				hdwp = DeferWindowPos(hdwp, dat->hwndProgress, NULL, 0, 0, width, height, SWP_NOMOVE | defflg);
			/* desc */
			if (dat->hwndDesc != NULL) /* Wine fix. */
				hdwp = DeferWindowPos(hdwp, dat->hwndDesc, NULL, GetSystemMetrics(SM_CXICON) + 5, 5 + height, 0, 0, SWP_NOSIZE | defflg);
			/* time */
			if (NULL != dat->hwndTime) /* Wine fix. */
				hdwp = DeferWindowPos(hdwp, dat->hwndTime, NULL, GetSystemMetrics(SM_CXICON) + 85, 5 + height, width - 80, (GetSystemMetrics(SM_CXICON) / 2), defflg);
			EndDeferWindowPos(hdwp);
		}
		PostMessage(hwndFrame, M_CHECK_CLIPPED, 0, 0);
		return 0;

	case M_REFRESH_COLORS:
		COLORREF clrBar;
		if (FontService_GetColor(_T("Automatic Shutdown"), _T("Progress Bar"), &clrBar))
			clrBar = GetDefaultColor(FRAMEELEMENT_BAR);
		if (FontService_GetColor(_T("Automatic Shutdown"), _T("Background"), &dat->clrBackground))
			dat->clrBackground = GetDefaultColor(FRAMEELEMENT_BKGRND);
		if (dat->hbrBackground != NULL) DeleteObject(dat->hbrBackground);
		dat->hbrBackground = CreateSolidBrush(dat->clrBackground);
		SendMessage(dat->hwndProgress, PBM_SETBARCOLOR, 0, (LPARAM)clrBar);
		SendMessage(dat->hwndProgress, PBM_SETBKCOLOR, 0, (LPARAM)dat->clrBackground);
		InvalidateRect(hwndFrame, NULL, TRUE);
		return 0;

	case M_REFRESH_ICONS:
		return 0;

	case M_REFRESH_FONTS:
		{
			LOGFONT lf;
			if (!FontService_GetFont(_T("Automatic Shutdown"), _T("Countdown on Frame"), &dat->clrText, &lf)) {
				if (dat->hFont != NULL) DeleteObject(dat->hFont);
				dat->hFont = CreateFontIndirect(&lf);
			}
			else {
				dat->clrText = GetDefaultColor(FRAMEELEMENT_TEXT);
				if (GetDefaultFont(&lf) != NULL) {
					if (dat->hFont != NULL) DeleteObject(dat->hFont);
					dat->hFont = CreateFontIndirect(&lf);
				}
			}
		}
		if (dat->hwndDesc != NULL)
			SendMessage(dat->hwndDesc, WM_SETFONT, (WPARAM)dat->hFont, FALSE);
		SendMessage(dat->hwndTime, WM_SETFONT, (WPARAM)dat->hFont, FALSE);
		InvalidateRect(hwndFrame, NULL, FALSE);
		return 0;

	case WM_SYSCOLORCHANGE:
		SendMessage(hwndFrame, M_REFRESH_COLORS, 0, 0);
		break;

	case WM_SETTINGCHANGE: /* colors depend on windows settings */
		SendMessage(hwndFrame, M_REFRESH_COLORS, 0, 0);
		SendMessage(hwndFrame, M_REFRESH_FONTS, 0, 0);
		SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
		RedrawWindow(hwndFrame, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE);
		break;

	case WM_TIMECHANGE: /* windows system clock changed */
		SendMessage(hwndFrame, M_SET_COUNTDOWN, 0, 0);
		PostMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
		break;

	case WM_CTLCOLORDLG:
	case WM_CTLCOLORSTATIC:
		SetTextColor((HDC)wParam, dat->clrText);
		SetBkColor((HDC)wParam, dat->clrBackground);
		return (INT_PTR)dat->hbrBackground;

	case WM_ERASEBKGND:
		{
			RECT rc;
			if (dat->hbrBackground != NULL && GetClientRect(hwndFrame, &rc)) {
				FillRect((HDC)wParam, &rc, dat->hbrBackground);
				return TRUE;
			}
			return FALSE;
		}
	case M_SET_COUNTDOWN:
		if (dat->fTimeFlags&SDWTF_ST_TIME) {
			dat->settingLastTime = (time_t)db_get_dw(NULL, "AutoShutdown", "TimeStamp", SETTING_TIMESTAMP_DEFAULT);
			dat->countdown = time(NULL);
			if (dat->settingLastTime > dat->countdown) dat->countdown = dat->settingLastTime - dat->countdown;
			else dat->countdown = 0;
		}
		else if (dat->flags&FWPDF_COUNTDOWNINVALID) {
			dat->countdown = (time_t)db_get_dw(NULL, "AutoShutdown", "Countdown", SETTING_COUNTDOWN_DEFAULT);
			dat->countdown *= (time_t)db_get_dw(NULL, "AutoShutdown", "CountdownUnit", SETTING_COUNTDOWNUNIT_DEFAULT);
		}
		dat->flags &= ~FWPDF_COUNTDOWNINVALID;
		/* commctl 4.70+, Win95: 1-100 will work fine (wrap around) */
		SendMessage(dat->hwndProgress, PBM_SETRANGE32, 0, (LPARAM)dat->countdown);
		return 0;
	case WM_TIMER:
		if (dat == NULL) return 0;
		if (dat->countdown != 0 && !(dat->flags&FWPDF_COUNTDOWNINVALID) && !(dat->flags&FWPDF_PAUSED)) {
			dat->countdown--;
			PostMessage(dat->hwndProgress, PBM_STEPIT, 0, 0);
		}
		if (IsWindowVisible(hwndFrame)) PostMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
		if (dat->countdown == 0) {
			SendMessage(hwndFrame, M_CLOSE_COUNTDOWN, 0, 0);
			ServiceShutdown(0, TRUE);
			ServiceStopWatcher(0, 0);
		}
		return 0;
	case WM_SHOWWINDOW:
		/* the text is kept unchanged while hidden */
		if ((BOOL)wParam) SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
		break;
	case M_UPDATE_COUNTDOWN:
		if (dat->flags&FWPDF_PAUSED && !(dat->flags&FWPDF_PAUSEDSHOWN)) {
			SetWindowText(dat->hwndTime, TranslateT("Paused"));
			dat->flags |= FWPDF_PAUSEDSHOWN;
		}
		else {
			TCHAR szOutput[256];
			if (dat->fTimeFlags&SDWTF_ST_TIME)
				GetFormatedDateTime(szOutput, _countof(szOutput), dat->settingLastTime, TRUE);
			else GetFormatedCountdown(szOutput, _countof(szOutput), dat->countdown);
			SetWindowText(dat->hwndTime, szOutput);
			PostMessage(hwndFrame, M_CHECK_CLIPPED, 0, 0);
			/* update tooltip text (if shown) */
			if (dat->hwndToolTip != NULL && !(dat->flags&FWPDF_PAUSED)) {
				TTTOOLINFO ti;
				ti.cbSize = sizeof(ti);
				if (SendMessage(dat->hwndToolTip, TTM_GETCURRENTTOOL, 0, (LPARAM)&ti) && (HWND)ti.uId != dat->hwndIcon)
					SendMessage(dat->hwndToolTip, TTM_UPDATE, 0, 0);
			}
			else dat->flags &= ~FWPDF_PAUSEDSHOWN;
		}
		return 0;
	case M_CLOSE_COUNTDOWN:
		KillTimer(hwndFrame, 1);
		dat->countdown = 0;
		dat->flags &= ~FWPDF_PAUSED;
		SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
		dat->flags |= FWPDF_COUNTDOWNINVALID;
		/* step up to upper range */
		SendMessage(dat->hwndProgress, PBM_SETPOS, SendMessage(dat->hwndProgress, PBM_GETRANGE, FALSE, 0), 0);
		SetWindowLongPtr(dat->hwndProgress, GWL_STYLE, GetWindowLongPtr(dat->hwndProgress, GWL_STYLE) | PBM_SETMARQUEE);
		SendMessage(dat->hwndProgress, PBM_SETMARQUEE, TRUE, 10); /* marquee for rest of time */
		return 0;
	case M_PAUSE_COUNTDOWN:
		if (dat->flags&FWPDF_PAUSED) {
			/* unpause */
			dat->flags &= ~(FWPDF_PAUSED | FWPDF_PAUSEDSHOWN);
			SendMessage(hwndFrame, M_SET_COUNTDOWN, 0, 0);
			SendMessage(dat->hwndProgress, PBM_SETSTATE, PBST_NORMAL, 0); /* WinVista+ */
		}
		else {
			/* pause */
			dat->flags |= FWPDF_PAUSED;
			SendMessage(dat->hwndProgress, PBM_SETSTATE, PBST_PAUSED, 0); /* WinVista+ */
		}
		SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
		return 0;
	case WM_CONTEXTMENU:
		{
			if (dat->flags & FWPDF_COUNTDOWNINVALID)
				return 0;

			POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
			if (pt.x == -1 && pt.y == -1) { /* invoked by keyboard */
				RECT rc;
				/* position in middle above rect */
				if (!GetWindowRect(hwndFrame, &rc)) return 0;
				pt.x = rc.left + ((int)(rc.right - rc.left) / 2);
				pt.y = rc.top + ((int)(rc.bottom - rc.top) / 2);
			}
			HMENU hContextMenu = CreatePopupMenu();
			if (hContextMenu != NULL) {
				AppendMenu(hContextMenu, MF_STRING, MENUITEM_PAUSECOUNTDOWN, (dat->flags&FWPDF_PAUSED) ? TranslateT("&Unpause Countdown") : TranslateT("&Pause Countdown"));
				SetMenuDefaultItem(hContextMenu, MENUITEM_PAUSECOUNTDOWN, FALSE);
				AppendMenu(hContextMenu, MF_STRING, MENUITEM_STOPCOUNTDOWN, TranslateT("&Cancel Countdown"));
				TrackPopupMenuEx(hContextMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_HORPOSANIMATION | TPM_VERPOSANIMATION | TPM_RIGHTBUTTON, pt.x, pt.y, hwndFrame, NULL);
				DestroyMenu(hContextMenu);
			}
		}
		return 0;
	case WM_LBUTTONDBLCLK:
		if (!(dat->flags&FWPDF_COUNTDOWNINVALID))
			SendMessage(hwndFrame, M_PAUSE_COUNTDOWN, 0, 0);
		return 0;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case MENUITEM_STOPCOUNTDOWN:
			/* close only countdown window when other watcher types running */
			if (dat->fTimeFlags&~(SDWTF_SPECIFICTIME | SDWTF_ST_MASK))
				CloseCountdownFrame(); /* something else is running */
			else ServiceStopWatcher(0, 0); /* calls CloseCountdownFrame() */
			return 0;
		case MENUITEM_PAUSECOUNTDOWN:
			SendMessage(hwndFrame, M_PAUSE_COUNTDOWN, 0, 0);
			return 0;
		}
		break;
	case M_CHECK_CLIPPED: /* for in-place tooltip on dat->hwndTime */
		{
			RECT rc;
			HDC hdc;
			SIZE size;
			HFONT hFontPrev = NULL;
			TCHAR szOutput[256];
			dat->flags &= ~FWPDF_TIMEISCLIPPED;
			if (GetWindowText(dat->hwndTime, szOutput, _countof(szOutput)))
				if (GetClientRect(dat->hwndTime, &rc)) {
					hdc = GetDC(dat->hwndTime);
					if (hdc != NULL) {
						if (dat->hFont != NULL)
							hFontPrev = (HFONT)SelectObject(hdc, dat->hFont);
						if (GetTextExtentPoint32(hdc, szOutput, (int)mir_tstrlen(szOutput), &size))
							if (size.cx >= (rc.right - rc.left))
								dat->flags &= FWPDF_TIMEISCLIPPED;
						if (dat->hFont != NULL)
							SelectObject(hdc, hFontPrev);
						ReleaseDC(dat->hwndTime, hdc);
					}
				}
			return 0;
		}
	case WM_NOTIFY:
		if (((NMHDR*)lParam)->hwndFrom == dat->hwndToolTip)
			switch (((NMHDR*)lParam)->code) {
			case TTN_SHOW: /* 'in-place' tooltip on dat->hwndTime */
				if (dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam == dat->hwndTime) {
					RECT rc;
					if (GetWindowRect(dat->hwndTime, &rc)) {
						SetWindowLongPtr(dat->hwndToolTip, GWL_STYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_STYLE) | TTS_NOANIMATE);
						SetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE) | WS_EX_TRANSPARENT);
						SendMessage(dat->hwndToolTip, TTM_ADJUSTRECT, TRUE, (LPARAM)&rc);
						SetWindowPos(dat->hwndToolTip, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
						return TRUE; /* self-defined position */
					}
				}
				SetWindowLongPtr(dat->hwndToolTip, GWL_STYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_STYLE) & (~TTS_NOANIMATE));
				SetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE) & (~WS_EX_TRANSPARENT));
				return 0;
			case TTN_POP:
				/* workaround #5: frame does not get redrawn after
				 * in-place tooltip	hidden on dat->hwndTime */
				RedrawWindow(hwndCountdownFrame, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE);
				return 0;
			case TTN_NEEDTEXT:
				{
					NMTTDISPINFO *ttdi = (NMTTDISPINFO*)lParam;
					if (dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam == dat->hwndTime) {
						if (GetWindowText(dat->hwndTime, ttdi->szText, _countof(ttdi->szText)))
							ttdi->lpszText = ttdi->szText;
					}
					else if ((HWND)wParam == dat->hwndIcon)
						ttdi->lpszText = TranslateT("Automatic Shutdown");
					else {
						TCHAR szTime[_countof(ttdi->szText)];
						if (dat->fTimeFlags&SDWTF_ST_TIME)
							GetFormatedDateTime(szTime, _countof(szTime), dat->settingLastTime, FALSE);
						else GetFormatedCountdown(szTime, _countof(szTime), dat->countdown);
						mir_sntprintf(ttdi->szText, _T("%s %s"), (dat->fTimeFlags&SDWTF_ST_TIME) ? TranslateT("Shutdown at:") : TranslateT("Time left:"), szTime);
						ttdi->lpszText = ttdi->szText;
					}
					return 0;
				}
			}
		break;
	}
	return DefWindowProc(hwndFrame, msg, wParam, lParam);
}
コード例 #27
0
static int
SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool created)
{
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    SDL_WindowData *data;

    /* Allocate the window data */
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        return SDL_OutOfMemory();
    }
    data->window = window;
    data->hwnd = hwnd;
    data->parent = parent;
    data->hdc = GetDC(hwnd);
    data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
    data->created = created;
    data->mouse_button_flags = 0;
    data->videodata = videodata;
    data->initializing = SDL_TRUE;

    window->driverdata = data;

    /* Associate the data with the window */
    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
        ReleaseDC(hwnd, data->hdc);
        SDL_free(data);
        return WIN_SetError("SetProp() failed");
    }

    /* Set up the window proc function */
#ifdef GWLP_WNDPROC
    data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
    if (data->wndproc == WIN_WindowProc) {
        data->wndproc = NULL;
    } else {
        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
    }
#else
    data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
    if (data->wndproc == WIN_WindowProc) {
        data->wndproc = NULL;
    } else {
        SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc);
    }
#endif

    /* Fill in the SDL window with the window data */
    {
        RECT rect;
        if (GetClientRect(hwnd, &rect)) {
            int w = rect.right;
            int h = rect.bottom;
            if ((window->windowed.w && window->windowed.w != w) || (window->windowed.h && window->windowed.h != h)) {
                /* We tried to create a window larger than the desktop and Windows didn't allow it.  Override! */
                int x, y;
                /* Figure out what the window area will be */
                WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_FALSE);
                SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
            } else {
                window->w = w;
                window->h = h;
            }
        }
    }
    {
        POINT point;
        point.x = 0;
        point.y = 0;
        if (ClientToScreen(hwnd, &point)) {
            window->x = point.x;
            window->y = point.y;
        }
    }
    {
        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
        if (style & WS_VISIBLE) {
            window->flags |= SDL_WINDOW_SHOWN;
        } else {
            window->flags &= ~SDL_WINDOW_SHOWN;
        }
        if (style & WS_POPUP) {
            window->flags |= SDL_WINDOW_BORDERLESS;
        } else {
            window->flags &= ~SDL_WINDOW_BORDERLESS;
        }
        if (style & WS_THICKFRAME) {
            window->flags |= SDL_WINDOW_RESIZABLE;
        } else {
            window->flags &= ~SDL_WINDOW_RESIZABLE;
        }
#ifdef WS_MAXIMIZE
        if (style & WS_MAXIMIZE) {
            window->flags |= SDL_WINDOW_MAXIMIZED;
        } else
#endif
        {
            window->flags &= ~SDL_WINDOW_MAXIMIZED;
        }
#ifdef WS_MINIMIZE
        if (style & WS_MINIMIZE) {
            window->flags |= SDL_WINDOW_MINIMIZED;
        } else
#endif
        {
            window->flags &= ~SDL_WINDOW_MINIMIZED;
        }
    }
    if (GetFocus() == hwnd) {
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
        SDL_SetKeyboardFocus(data->window);

        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
            RECT rect;
            GetClientRect(hwnd, &rect);
            ClientToScreen(hwnd, (LPPOINT) & rect);
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
            ClipCursor(&rect);
        }
    }

    /* Enable multi-touch */
    if (videodata->RegisterTouchWindow) {
        videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
    }

    data->initializing = SDL_FALSE;

    /* All done! */
    return 0;
}
コード例 #28
0
LRESULT CALLBACK
window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  GstGLWindowWin32 *window_win32;
  LRESULT ret = 0;

  if (uMsg == WM_CREATE) {
    window_win32 =
        GST_GL_WINDOW_WIN32 (((LPCREATESTRUCT) lParam)->lpCreateParams);

    GST_TRACE ("WM_CREATE");

    window_win32->device = GetDC (hWnd);
    /* Do this, otherwise we hang on exit. We can still use it (due to the
     * CS_OWNDC flag in the WindowClass) after we have Released.
     */
    ReleaseDC (hWnd, window_win32->device);

    SetProp (hWnd, "gl_window", window_win32);
  } else if (GetProp (hWnd, "gl_window")) {
    GstGLWindow *window;
    GstGLContext *context;
    GstGLContextClass *context_class;

    window_win32 = GST_GL_WINDOW_WIN32 (GetProp (hWnd, "gl_window"));
    window = GST_GL_WINDOW (window_win32);
    context = gst_gl_window_get_context (window);
    context_class = GST_GL_CONTEXT_GET_CLASS (context);

    g_assert (window_win32->internal_win_id == hWnd);

    switch (uMsg) {
      case WM_SIZE:
      {
        if (window->resize) {
          window->resize (window->resize_data, LOWORD (lParam),
              HIWORD (lParam));
        }
        break;
      }
      case WM_PAINT:
      {
        if (window->draw) {
          PAINTSTRUCT ps;
          BeginPaint (hWnd, &ps);
          window->draw (window->draw_data);
          context_class->swap_buffers (context);
          EndPaint (hWnd, &ps);
        }
        break;
      }
      case WM_CLOSE:
      {
        ShowWindowAsync (window_win32->internal_win_id, SW_HIDE);

        GST_TRACE ("WM_CLOSE");

        if (window->close)
          window->close (window->close_data);
        break;
      }
      case WM_CAPTURECHANGED:
      {
        GST_DEBUG ("WM_CAPTURECHANGED");
        if (window->draw)
          window->draw (window->draw_data);
        break;
      }
      case WM_ERASEBKGND:
      {
        ret = TRUE;
        break;
      }
      default:
      {
        /* transmit messages to the parrent (ex: mouse/keyboard input) */
        HWND parent_id = window_win32->parent_win_id;
        if (parent_id)
          PostMessage (parent_id, uMsg, wParam, lParam);
        ret = DefWindowProc (hWnd, uMsg, wParam, lParam);
      }
    }

    gst_object_unref (context);
  } else {
    ret = DefWindowProc (hWnd, uMsg, wParam, lParam);
  }

  return ret;
}
コード例 #29
0
/* CENTRY */
int APIENTRY 
glutGet(GLenum param)
{
  Window win, root;
  int x, y, value;
  unsigned int width, height, border, depth;

  switch (param) {
  case GLUT_INIT_WINDOW_X:
    return __glutInitX;
  case GLUT_INIT_WINDOW_Y:
    return __glutInitY;
  case GLUT_INIT_WINDOW_WIDTH:
    return __glutInitWidth;
  case GLUT_INIT_WINDOW_HEIGHT:
    return __glutInitHeight;
  case GLUT_INIT_DISPLAY_MODE:
    return __glutDisplayMode;
  case GLUT_WINDOW_X:
    XTranslateCoordinates(__glutDisplay, __glutCurrentWindow->win,
      __glutRoot, 0, 0, &x, &y, &win);
    return x;
  case GLUT_WINDOW_Y:
    XTranslateCoordinates(__glutDisplay, __glutCurrentWindow->win,
      __glutRoot, 0, 0, &x, &y, &win);
    return y;
  case GLUT_WINDOW_WIDTH:
    if (!__glutCurrentWindow->reshape) {
      XGetGeometry(__glutDisplay, __glutCurrentWindow->win,
        &root, &x, &y,
        &width, &height, &border, &depth);
      return width;
    }
    return __glutCurrentWindow->width;
  case GLUT_WINDOW_HEIGHT:
    if (!__glutCurrentWindow->reshape) {
      XGetGeometry(__glutDisplay, __glutCurrentWindow->win,
        &root, &x, &y,
        &width, &height, &border, &depth);
      return height;
    }
    return __glutCurrentWindow->height;

#define GET_CONFIG(attrib) { \
  if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) { \
    glXGetConfig(__glutDisplay, __glutCurrentWindow->vis, \
      attrib, &value); \
  } else { \
    glXGetConfig(__glutDisplay, __glutCurrentWindow->overlay->vis, \
      attrib, &value); \
  } \
}

  case GLUT_WINDOW_BUFFER_SIZE:
    GET_CONFIG(GLX_BUFFER_SIZE);
    return value;
  case GLUT_WINDOW_STENCIL_SIZE:
    GET_CONFIG(GLX_STENCIL_SIZE);
    return value;
  case GLUT_WINDOW_DEPTH_SIZE:
    GET_CONFIG(GLX_DEPTH_SIZE);
    return value;
  case GLUT_WINDOW_RED_SIZE:
    GET_CONFIG(GLX_RED_SIZE);
    return value;
  case GLUT_WINDOW_GREEN_SIZE:
    GET_CONFIG(GLX_GREEN_SIZE);
    return value;
  case GLUT_WINDOW_BLUE_SIZE:
    GET_CONFIG(GLX_BLUE_SIZE);
    return value;
  case GLUT_WINDOW_ALPHA_SIZE:
    GET_CONFIG(GLX_ALPHA_SIZE);
    return value;
  case GLUT_WINDOW_ACCUM_RED_SIZE:
    GET_CONFIG(GLX_ACCUM_RED_SIZE);
    return value;
  case GLUT_WINDOW_ACCUM_GREEN_SIZE:
    GET_CONFIG(GLX_ACCUM_GREEN_SIZE);
    return value;
  case GLUT_WINDOW_ACCUM_BLUE_SIZE:
    GET_CONFIG(GLX_ACCUM_BLUE_SIZE);
    return value;
  case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
    GET_CONFIG(GLX_ACCUM_ALPHA_SIZE);
    return value;
  case GLUT_WINDOW_DOUBLEBUFFER:
    GET_CONFIG(GLX_DOUBLEBUFFER);
    return value;
  case GLUT_WINDOW_RGBA:
    GET_CONFIG(GLX_RGBA);
    return value;
  case GLUT_WINDOW_COLORMAP_SIZE:
    GET_CONFIG(GLX_RGBA);
    if (value) {
      return 0;
    } else {
#if defined(WIN32)
      /* KLUDGE: we always assume 256 colors in CI mode on
         Win32 */
      return 256;
#else /* !WIN32 */
      return __glutCurrentWindow->vis->visual->map_entries;
#endif /* WIN32 */
    }
  case GLUT_WINDOW_PARENT:
    return __glutCurrentWindow->parent ?
      __glutCurrentWindow->parent->num + 1 : 0;
  case GLUT_WINDOW_NUM_CHILDREN:
    {
      int num = 0;
      GLUTwindow *children = __glutCurrentWindow->children;

      while (children) {
        num++;
        children = children->siblings;
      }
      return num;
    }
  case GLUT_WINDOW_NUM_SAMPLES:
#if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
    if (__glutIsSupportedByGLX("GLX_SGIS_multisample")) {
      GET_CONFIG(GLX_SAMPLES_SGIS);
      return value;
    } else {
      return 0;
    }
#else
    /* Independent of GLX server support, multisampling not
       supported by GLX client-side. */
    return 0;
#endif
  case GLUT_WINDOW_STEREO:
    GET_CONFIG(GLX_STEREO);
    return value;
  case GLUT_WINDOW_CURSOR:
    return __glutCurrentWindow->cursor;
  case GLUT_SCREEN_WIDTH:
    return DisplayWidth(__glutDisplay, __glutScreen);
  case GLUT_SCREEN_HEIGHT:
    return DisplayHeight(__glutDisplay, __glutScreen);
  case GLUT_SCREEN_WIDTH_MM:
    return DisplayWidthMM(__glutDisplay, __glutScreen);
  case GLUT_SCREEN_HEIGHT_MM:
    return DisplayHeightMM(__glutDisplay, __glutScreen);
  case GLUT_MENU_NUM_ITEMS:
    return __glutCurrentMenu->num;
  case GLUT_DISPLAY_MODE_POSSIBLE:
    {
      XVisualInfo *vi;
      Bool dummy, visAlloced;
#if defined(WIN32)      
      /* our fake glXChooseVisual (which is called by
         __glutDetermineVisual) needs an HDC to work with, so grab one
         from the "root" window. */
      XHDC = GetDC(GetDesktopWindow());
#endif
      vi = __glutDetermineWindowVisual(&dummy, &visAlloced);
#if defined(WIN32)      
      ReleaseDC(GetDesktopWindow(), XHDC);
#endif
      if (vi) {
        if (visAlloced)
          XFree(vi);
        return 1;
      }
      return 0;
    }
  case GLUT_ELAPSED_TIME:
    {
      struct timeval elapsed, beginning, now;

      __glutInitTime(&beginning);
      GETTIMEOFDAY(&now);
      TIMEDELTA(elapsed, now, beginning);
      /* Return elapsed milliseconds. */
#if defined(__vms)
      return (int) (elapsed.val / TICKS_PER_MILLISECOND);
#else
      return (int) ((elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000));
#endif
    }
  default:
    __glutWarning("invalid glutGet parameter: %d", param);
    return -1;
  }
}
コード例 #30
0
ファイル: de_win.c プロジェクト: 8l/lllm
LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
                          WPARAM wParam, LPARAM lParam)
{
   static HANDLE  hInstance;
   HDC dc;
   PAINTSTRUCT ps;
   RECT client_area;
   RECT this_line;
   RECT dummy;
   TEXTMETRIC tm;
   register int i;
   int id;

   switch (message)
   {
      case WM_CREATE:
           hInstance = ( (LPCREATESTRUCT) lParam)->hInstance;
           dc = GetDC(hwnd);
           SelectObject(dc, GetStockObject(SYSTEM_FIXED_FONT));
           GetTextMetrics(dc, &tm);
           ReleaseDC(hwnd, dc);
           char_width = tm.tmAveCharWidth;
           char_height = tm.tmHeight + tm.tmExternalLeading;
           GetClientRect(hwnd, &client_area);
           COLS = (client_area.right - client_area.left)/char_width;
           LINES = (client_area.bottom - client_area.top)/char_height;
           generic_init();
           return(0);

      case WM_CHAR:
           if (wParam == QUIT) {
               SendMessage( hwnd, WM_CLOSE, 0, 0L );
           } else {
               do_command((int)wParam);
           }
           return(0);

      case WM_SETFOCUS:
           CreateCaret(hwnd, NULL, char_width, char_height);
           ShowCaret(hwnd);
           caret_visible = 1;
           update_cursor();
           return(0);

      case WM_KILLFOCUS:
           HideCaret(hwnd);
           DestroyCaret();
           caret_visible = 0;
           return(0);

      case WM_LBUTTONUP:
           {
               unsigned xpos = LOWORD(lParam);  /* From left    */
               unsigned ypos = HIWORD(lParam);  /* from top */

               set_position(xpos / (unsigned)char_width,
                            ypos / (unsigned)char_height);
               return(0);
           }

      case WM_COMMAND:
           id = LOWORD(wParam);
           if (id & EDIT_CMD_FLAG) {
               if (id & REPEAT_FLAG) do_command(REPEAT);
               do_command(CHAR_CMD(id));
               return( 0 );
           } else {
             switch(id) {
               case IDM_FILEEXIT:
                  SendMessage( hwnd, WM_CLOSE, 0, 0L );
                  return( 0 );

               case IDM_HELPABOUT:
                  if( DialogBox( hInstance, TEXT("ABOUTBOX"),
                                 hwnd, AboutBoxCallback ) )
                     InvalidateRect( hwnd, NULL, TRUE );
                  return( 0 );
               case IDM_HELPCONTENTS:
                  de_error(
                       "Cursor keys: ^B(left) ^F(right) ^P(up) ^N(down)\n"
                       "Undo: ^U    Write: ^W   Quit:^D  Repeat count: ^R[n]\n"
                       "Top: ^T   Locate (search, find): ^L text ^L\n");
                  return( 0 );
             }
           }
           break;

      case WM_CLOSE:
           DestroyWindow( hwnd );
           return 0;

      case WM_DESTROY:
           PostQuitMessage (0);
           GC_win32_free_heap();
           return 0;

      case WM_PAINT:
           dc = BeginPaint(hwnd, &ps);
           GetClientRect(hwnd, &client_area);
           COLS = (client_area.right - client_area.left)/char_width;
           LINES = (client_area.bottom - client_area.top)/char_height;
           SelectObject(dc, GetStockObject(SYSTEM_FIXED_FONT));
           for (i = 0; i < LINES; i++) {
               get_line_rect(i, client_area.right, &this_line);
               if (IntersectRect(&dummy, &this_line, &ps.rcPaint)) {
                   CORD raw_line = retrieve_screen_line(i);
                   size_t len = CORD_len(raw_line);
                   char * text = CORD_to_char_star(raw_line);
                                /* May contain embedded NULLs   */
                   char * plain = plain_chars(text, len);
                   char * blanks = CORD_to_char_star(CORD_chars(' ',
                                                                COLS - len));
                   char * control = control_chars(text, len);
#                  define RED RGB(255,0,0)

                   SetBkMode(dc, OPAQUE);
                   SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));

                   TextOutA(dc, this_line.left, this_line.top,
                            plain, (int)len);
                   TextOutA(dc, this_line.left + (int)len * char_width,
                            this_line.top,
                            blanks, (int)(COLS - len));
                   SetBkMode(dc, TRANSPARENT);
                   SetTextColor(dc, RED);
                   TextOutA(dc, this_line.left, this_line.top,
                            control, (int)strlen(control));
               }
           }
           EndPaint(hwnd, &ps);
           screen_was_painted = 1;
           return 0;
   }
   return DefWindowProc (hwnd, message, wParam, lParam);
}