亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? backprnt.c

?? 《Win32多線程程序設計》配套代碼.集成了一般簡單的線程設計及優化的原理。
?? C
字號:
/*
 * BackPrnt.c
 *
 * Sample code for "Multithreading Applications in Win32"
 * This is from Chapter 2, Listing 2-3
 *
 * Demonstrates background printing
 */

#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <windowsx.h>
#include <commdlg.h>
#include "resource.h"
#include "MtVerify.h"

//
// Macro definitions
//
#define WM_SHOWBITMAP   WM_APP

#define MAX_PRINT_JOBS  64


//
// Structures
//
typedef struct
{   // Information passed to background thread for printing
    HWND hDlg;
    HWND hWndParent;
    HDC hDc;
    BOOL bPrint;    // TRUE if printing;
    char szText[256];
} ThreadPrintInfo;

//
// Global variables
//
HANDLE hInst;
HBITMAP gbmpDisplay;
RECT gDisplayRect;

int gNumPrinting = 0;

// Handle to each created thread
HANDLE gPrintJobs[64];

// Height of bitmap returned by DrawText
int iHeight;

// HWND of the dialog so other threads can find it.
HWND hDlgMain;


//
// Function declarations
//
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK MainWndProc(HWND hWnd, unsigned msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK PrintDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL PrintDlg_OnInitDialog(HWND hwndDlg, HWND hwndFocus, LPARAM lParam);
void PrintDlg_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify);
void PrintDlg_OnPaint(HWND hwnd);
void PrintText(HWND hwndParent, char *pszText);
void PrintToDisplay(HWND hwndParent, char *pszText);
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
DWORD WINAPI BackgroundPrintThread(LPVOID pVoid);


///////////////////////////////////////////////////////////
//
//      WinMain
//
// Main entry point of application. This will be a
// dialog based app, not a normal window, so this
// routine acts a little differently than "normal".
//
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG     msg;
    HWND    hWnd;
    WNDCLASS wc;
	int index;

    hInst = hInstance;
    if (!hPrevInstance)
    {
        memset(&wc, 0, sizeof(wc));
        wc.lpfnWndProc  = MainWndProc;
        wc.hInstance    = hInstance;
        wc.hIcon        = LoadIcon (hInstance, "GenIco");
        wc.hCursor      = LoadCursor(NULL,IDC_ARROW);
        wc.hbrBackground= GetSysColorBrush(COLOR_BACKGROUND);
        wc.lpszMenuName = "PRINTING_MENU";
        wc.lpszClassName= "PrintDlgClass";
        if (!RegisterClass(&wc))
            return FALSE;
    }


    hWnd = CreateWindow(
        "PrintDlgClass",
        "Background Printing",
        WS_OVERLAPPED|WS_CAPTION|WS_MINIMIZEBOX|WS_SYSMENU,
        CW_USEDEFAULT, // At this point we do not want to
        0,             //  show the window until we know
        0,             //  how big the Dialog Box is so
        0,             //  that we can fit the main window
        NULL,          //  around it.
        NULL,
        hInstance,
        NULL);

    hDlgMain = CreateDialog(hInst,
                    MAKEINTRESOURCE(IDD_PRINT),
                    hWnd, PrintDlgProc);

    ShowWindow(hWnd, nCmdShow);
    ShowWindow(hDlgMain, SW_SHOW);

	while (GetMessage(&msg, NULL, 0, 0))
	{	// Get Next message in queue
		if(hDlgMain == NULL || !IsDialogMessage(hDlgMain,&msg))
		{
			TranslateMessage(&msg); /* Translate virtual key codes */
			DispatchMessage(&msg);	/* Dispatches message to window */
		}
	} // end while

	// Wait for all threads to terminate. The Window will
    // have already disappeared by this point.
	for (index = 0; index < gNumPrinting; index++)
	{
		DWORD status;
		do 
		{	// Wait for thread to terminate
			GetExitCodeThread(gPrintJobs[index], &status);
			Sleep(10);
		} while (status == STILL_ACTIVE);

	} // end for

	return (msg.wParam);  /* Returns the value from PostQuitMessage */
}


LRESULT CALLBACK MainWndProc(HWND hWnd, unsigned msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_CREATE:
        break;

    case WM_COMMAND:

        switch (wParam)
        {
        case IDM_ABOUT:
            DialogBox(hInst, "AboutBox", hWnd, (DLGPROC)About);
            break;
        case IDM_EXIT:
            PostQuitMessage(0);
            break;
        default:
            return (DefWindowProc(hWnd, msg, wParam, lParam));
        }

    case WM_SETFOCUS:
        // ensure that the Dialog Box has the focus
        SetFocus(hDlgMain);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);

    }
    return 0;
}


LRESULT CALLBACK PrintDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_CLOSE:
        DestroyWindow(hDlg);
        hDlgMain = NULL;
        break;
        
    case WM_DESTROY:
        return TRUE;
        break;

    case WM_SHOWBITMAP:
        if (gbmpDisplay)
            DeleteObject(gbmpDisplay);

        gDisplayRect = *(RECT*)wParam;
        gbmpDisplay = (HBITMAP) lParam;
        InvalidateRect(hDlgMain, NULL, TRUE);
        break;

    HANDLE_MSG(hDlg, WM_INITDIALOG, PrintDlg_OnInitDialog);
    HANDLE_MSG(hDlg, WM_COMMAND, PrintDlg_OnCommand);
    HANDLE_MSG(hDlg, WM_PAINT, PrintDlg_OnPaint);

    default:
        return (FALSE);
    }

    return 0;
}

BOOL PrintDlg_OnInitDialog(HWND hwndDlg, HWND hwndFocus, LPARAM lParam)
{
    RECT rect;

    // Size parent to fit this dialog
    GetWindowRect(hwndDlg, &rect); 
    SetWindowPos(GetParent(hwndDlg),NULL,
        0,0,
        rect.right-rect.left,
        rect.bottom-rect.top+GetSystemMetrics(SM_CYMENU)
            +GetSystemMetrics(SM_CYCAPTION),
        SWP_NOMOVE | SWP_NOZORDER);

    return TRUE;
}

void PrintDlg_OnCommand(HWND hDlg, int id,HWND hwndCtl, UINT codeNotify)
{
    char szText[256];

    switch (id)
    {
    case IDC_PRINT:
        GetDlgItemText(hDlg, IDC_EDIT_TEXT, szText, 256);
        PrintText(hDlg, szText);
        break;

    case IDC_DISPLAY:
        GetDlgItemText(hDlg, IDC_EDIT_TEXT, szText, 256);
        PrintToDisplay(hDlg, szText);
        break;

    case IDCANCEL:
    case IDM_EXIT:
        PostMessage(GetParent(hDlg),WM_DESTROY,
                        (WPARAM)0, (LPARAM)0);
        DestroyWindow(hDlgMain);
        hDlgMain = NULL;
        break;
        
    default:
        break;
    }
}

void PrintDlg_OnPaint( HWND hwnd )
{
    PAINTSTRUCT paint;
    HWND hwndCtrl;
	HDC hdc;
    HDC hDcMem;
    HBITMAP bmpOld;
    RECT rect;
    POINT point;

	if (!gbmpDisplay)
		return;

    hwndCtrl = GetDlgItem(hwnd, IDC_OUTPUT);

    hdc = BeginPaint(hwnd, &paint);

    GetWindowRect(hwndCtrl, &rect);
    point = *((POINT *)&rect);
    ScreenToClient(hwnd, &point);

    hDcMem = CreateCompatibleDC(NULL);
    bmpOld = SelectObject(hDcMem, gbmpDisplay);

    // Copy bitmap to screen
    MTVERIFY( BitBlt(hdc, point.x+10, point.y+40,
        gDisplayRect.right-gDisplayRect.left, gDisplayRect.bottom-gDisplayRect.top,
        hDcMem, iHeight, 0, SRCCOPY) );

    SelectObject(hDcMem, bmpOld);
    DeleteDC(hDcMem);

    EndPaint(hwnd, &paint);
}

//
// Asks user which printer to use, then creates
// background printing thread.
//
void PrintText(HWND hwndParent, char *pszText)
{
    ThreadPrintInfo *pInfo;
    HANDLE hThread;
    DWORD dwThreadId;
    int result;
    DOCINFO docInfo;

    PRINTDLG dlgPrint;

    // Put up Common Dialog for Printing and get hDC.
    memset(&dlgPrint, 0, sizeof(PRINTDLG));
    dlgPrint.lStructSize = sizeof(PRINTDLG);
    dlgPrint.hwndOwner = hwndParent;
    dlgPrint.Flags = PD_ALLPAGES | PD_USEDEVMODECOPIES
           | PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC;
    dlgPrint.hInstance = hInst;
    if (!PrintDlg(&dlgPrint))
        return;

    // Initialize Printer device
    docInfo.cbSize = sizeof(DOCINFO);
    docInfo.lpszDocName = "Background Printing Example";
    docInfo.lpszOutput = NULL;
    docInfo.lpszDatatype = NULL;
    docInfo.fwType = 0;
    result = StartDoc(dlgPrint.hDC, &docInfo);
    result = StartPage(dlgPrint.hDC);

    pInfo = HeapAlloc(GetProcessHeap(),
                      HEAP_ZERO_MEMORY,
                      sizeof(ThreadPrintInfo));
    pInfo->hDlg = hwndParent;
    pInfo->hWndParent = hwndParent;
    pInfo->hDc = dlgPrint.hDC;
    pInfo->bPrint = TRUE;
    strcpy(pInfo->szText, pszText);

    MTVERIFY( hThread = CreateThread(NULL, 0,
        BackgroundPrintThread, (LPVOID)pInfo,
        0, &dwThreadId ));

	// keep track of all background printing threads
    gPrintJobs[gNumPrinting++] = hThread;
}

//
// Shows output on the dialog box.
//
void PrintToDisplay(HWND hwndParent, char *pszText)
{
    ThreadPrintInfo *pInfo;
    DWORD dwThreadId;
    HANDLE hThread;

    pInfo = HeapAlloc(GetProcessHeap(),
                      HEAP_ZERO_MEMORY,
                      sizeof(ThreadPrintInfo));
    pInfo->hDlg = hwndParent;
    pInfo->hWndParent = GetDlgItem(hwndParent, IDC_OUTPUT);
	pInfo->hDc = GetDC(pInfo->hWndParent);
    pInfo->bPrint = FALSE;
    strcpy(pInfo->szText, pszText);

    MTVERIFY( hThread = CreateThread(NULL, 0,
                                     BackgroundPrintThread,
                                     (LPVOID)pInfo,
                                     0, &dwThreadId ));

	// keep track of all background printing threads
    gPrintJobs[gNumPrinting++] = hThread;
}



//---------------------------------------------------------
// About Box Handling
//---------------------------------------------------------

LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK
                || LOWORD(wParam) == IDCANCEL)
            {
                EndDialog(hDlg, TRUE);
                return (TRUE);
            }
            break;

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

    return FALSE;
}


//---------------------------------------------------------
// Background Printing Code
//---------------------------------------------------------

DWORD WINAPI BackgroundPrintThread(LPVOID pVoid)
{
    ThreadPrintInfo *pInfo = (ThreadPrintInfo*) pVoid; 
    RECT rect;
    RECT rectMem;
    HDC hDcMem;
    HBITMAP bmpMem;
    HBITMAP bmpOld;
    int x, y;
    int counter = 0;
    int nHeight;
    HFONT hFont;
    HFONT hFontOld;

    // Get dimensions of paper into rect
    rect.left = 0;
    rect.top = 0;
    rect.right =  GetDeviceCaps(pInfo->hDc, HORZRES);
    rect.bottom = GetDeviceCaps(pInfo->hDc, VERTRES);

    nHeight = -MulDiv(36, GetDeviceCaps(pInfo->hDc, LOGPIXELSY), 72);

    // Create Font
    hFont = CreateFont(nHeight, 0, 
        0, 0, FW_DONTCARE, 
        FALSE, FALSE, FALSE, 
        ANSI_CHARSET, 
        OUT_TT_PRECIS, 
        CLIP_DEFAULT_PRECIS,
        PROOF_QUALITY, 
        VARIABLE_PITCH,
        NULL);
    MTASSERT( hFont != 0);

    // Draw into memory device context
    hDcMem = CreateCompatibleDC(pInfo->hDc);
    hFontOld = SelectObject(hDcMem, hFont);
    iHeight = DrawText(hDcMem, pInfo->szText, -1,  &rect, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT);
    rectMem = rect;
    rectMem.left = rect.left + iHeight;
    rectMem.right = rect.right + (iHeight*2);
    bmpMem = CreateCompatibleBitmap(hDcMem,
                                    rectMem.right, rect.bottom);
    bmpOld = SelectObject(hDcMem, bmpMem);
    OffsetRect(&rect, iHeight, 0); 
    DrawText(hDcMem, pInfo->szText, -1,  &rect,
             DT_LEFT | DT_NOPREFIX | DT_WORDBREAK);

    // Italicize bitmap. We use GetPixel and
    // SetPixel because they are horribly inefficient,
    // thereby causing the thread to run for awhile.
    for (y = 0; y < iHeight; y++)
    {   // Italicize line y
        for (x = rectMem.right; x > iHeight; x--)
        {   // Move specified pixel to the right.
            COLORREF color;
            int offset;
            offset = y - iHeight;
            color = GetPixel(hDcMem, x + offset, y);
            if (color != 0)
                counter++;
            SetPixel(hDcMem, x, y, color);
        } // end for x
    } // end for y
    MTASSERT( counter > 0);

    // Copy bitmap of italicized text from memory to device
    if (pInfo->bPrint)
    {
        BitBlt(pInfo->hDc, 50, 50, rectMem.right-rect.left, rectMem.bottom-rect.top,
            hDcMem, iHeight, 0, SRCCOPY);
    }

    SelectObject(hDcMem, hFontOld);
    SelectObject(hDcMem, bmpOld);
    DeleteDC(hDcMem);

    if (!pInfo->bPrint)
    {
        // We can't just write to the global variable where the
        // bitmap is kept or we might overwrite the work of
        // another thread, thereby "losing" a bitmap

        // Also, if we used PostMessage instead of SendMessage, then
        // the rectangle could have been deleted (it's on the stack)
        // by the time the main message loop is reached.
        SendMessage(pInfo->hDlg, WM_SHOWBITMAP, (WPARAM)&rectMem, (LPARAM) bmpMem);
    }

    if (pInfo->bPrint)
    {   // Finish printing
        int result;

        result = EndPage(pInfo->hDc);
        MTASSERT (result != SP_ERROR);
        result = EndDoc(pInfo->hDc);
        MTASSERT (result != SP_ERROR);
        DeleteDC(pInfo->hDc);
        // If we are printing, we are done with the bitmap.
        DeleteObject(bmpMem);
    } 
    else
    {
        ReleaseDC(pInfo->hWndParent, pInfo->hDc);
    }

    // free data structure passed in.
    HeapFree(GetProcessHeap(), 0, pInfo);

    return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜在线成人av| 日韩二区三区在线观看| 国产欧美一区二区精品仙草咪| 欧美三级中文字| 欧洲激情一区二区| 欧美写真视频网站| 欧美日韩精品一二三区| 678五月天丁香亚洲综合网| 欧美精品乱码久久久久久按摩| 欧美日韩亚洲综合在线 | 国产乱理伦片在线观看夜一区| 男女视频一区二区| 麻豆国产精品视频| 成人一级片网址| 91在线视频播放| 欧美偷拍一区二区| 欧美一级欧美一级在线播放| 久久女同互慰一区二区三区| 国产精品久久久久影院老司| 亚洲欧美国产毛片在线| 午夜av区久久| 国产精品香蕉一区二区三区| 日韩视频免费直播| 日韩免费视频一区| 亚洲欧美一区二区视频| 天天综合网 天天综合色| 国产精品99久久久久久久vr | 亚洲免费大片在线观看| 日韩高清中文字幕一区| 国产成人在线电影| 欧美午夜理伦三级在线观看| 日韩欧美精品三级| 亚洲天堂免费看| 蜜桃视频免费观看一区| 色综合欧美在线视频区| 精品久久人人做人人爽| 亚洲欧美区自拍先锋| 男男成人高潮片免费网站| 成人激情图片网| 日韩欧美一区二区在线视频| 中文乱码免费一区二区| 青青草原综合久久大伊人精品 | av中文字幕在线不卡| 欧美放荡的少妇| 自拍偷拍国产精品| 精品一区二区成人精品| 欧美日韩专区在线| 亚洲欧洲性图库| 国产成人综合精品三级| 7799精品视频| 亚洲精品大片www| 不卡一区在线观看| 久久久精品国产免大香伊| 亚洲成人激情av| hitomi一区二区三区精品| 欧美mv日韩mv国产网站| 天天爽夜夜爽夜夜爽精品视频| 大胆欧美人体老妇| 久久久久国产精品厨房| 全部av―极品视觉盛宴亚洲| 日本韩国欧美三级| 亚洲欧美在线高清| 99久久久免费精品国产一区二区| 欧美tickling挠脚心丨vk| 日韩精品一区第一页| 欧美日韩国产综合视频在线观看| 中文字幕欧美国产| 国产精品一二三在| 国产欧美精品区一区二区三区| 日本欧美一区二区在线观看| 欧美天堂一区二区三区| 亚洲一区在线观看免费观看电影高清| aa级大片欧美| 亚洲色图欧美激情| 色视频欧美一区二区三区| 中文字幕中文在线不卡住| 成人性色生活片| 国产精品福利电影一区二区三区四区| 成人自拍视频在线| 国产精品乱人伦一区二区| 国产二区国产一区在线观看| 国产午夜精品一区二区 | 色综合久久久久网| 亚洲三级电影网站| 欧美在线影院一区二区| 亚洲成年人影院| 91精品国产综合久久久久久 | 国产精品一区二区果冻传媒| 精品剧情v国产在线观看在线| 久久99九九99精品| 国产欧美日韩视频在线观看| 国产999精品久久久久久绿帽| 国产亚洲1区2区3区| 成人小视频在线| 亚洲高清在线精品| 久久综合精品国产一区二区三区 | 久久网站热最新地址| 成人伦理片在线| 一区二区三区在线视频播放| 欧美精品在欧美一区二区少妇| 日本欧美大码aⅴ在线播放| 久久综合精品国产一区二区三区| 国产99久久久精品| 亚洲自拍偷拍网站| 欧美第一区第二区| 97久久超碰国产精品| 日韩国产欧美一区二区三区| 日韩欧美亚洲一区二区| 99久久精品情趣| 日韩**一区毛片| 国产精品久久午夜| 91精品欧美福利在线观看| 国产在线播放一区二区三区| 国产精品久久久久久久裸模| 欧美日韩在线直播| 成人一级视频在线观看| 天天色天天爱天天射综合| 中文字幕第一页久久| 欧美日本免费一区二区三区| 国产成人精品免费看| 日韩电影一区二区三区| 一区在线中文字幕| xnxx国产精品| 欧美精品在线观看一区二区| 成人永久免费视频| 久久99精品网久久| 日韩高清在线一区| 亚洲成人av中文| 中文字幕在线一区| 精品99一区二区| 欧美一二三四在线| 欧美午夜精品一区二区三区| 成人a免费在线看| 国产高清成人在线| 精品午夜久久福利影院| 亚洲国产精品久久艾草纯爱| 亚洲丝袜精品丝袜在线| 国产午夜精品一区二区| 久久影院午夜片一区| 欧美成人欧美edvon| 欧美二区三区的天堂| 91精品办公室少妇高潮对白| 不卡欧美aaaaa| www.日韩精品| 成人av在线资源网| 成人一道本在线| av一本久道久久综合久久鬼色| 激情综合色播五月| 麻豆免费看一区二区三区| 毛片一区二区三区| 久久99热这里只有精品| 国产一区啦啦啦在线观看| 九色|91porny| 国产在线精品一区二区夜色| 看片的网站亚洲| 国产馆精品极品| av网站一区二区三区| 成人h动漫精品一区二| 99精品国产99久久久久久白柏| 高清不卡在线观看| 91在线视频官网| 欧美女孩性生活视频| 欧美一级黄色大片| 欧美精品一区二区三区一线天视频| 欧美一级一区二区| 久久久蜜臀国产一区二区| 国产欧美一区二区三区在线老狼| 欧美国产日本韩| 一区二区三区产品免费精品久久75| 亚洲天堂久久久久久久| 视频在线在亚洲| 国产真实乱对白精彩久久| 国产成人免费9x9x人网站视频| 成人激情免费电影网址| 在线视频国产一区| 欧美电视剧在线观看完整版| 欧美—级在线免费片| 亚洲精品成人在线| 久久av中文字幕片| 一本色道久久加勒比精品| 欧美精选午夜久久久乱码6080| 亚洲精品在线三区| 亚洲人成精品久久久久| 日韩电影在线观看网站| 国产不卡视频一区| 欧美乱妇15p| 国产精品女同互慰在线看| 亚洲国产视频一区二区| 国产成a人亚洲精| 在线综合视频播放| 成人欧美一区二区三区在线播放| 丝袜诱惑亚洲看片| 粉嫩绯色av一区二区在线观看| 欧美在线999| 国产精品素人视频| 蜜桃精品视频在线| 欧美无乱码久久久免费午夜一区| 久久久午夜精品| 日本欧美一区二区| 欧美三级在线播放|