/* プリンタへの出力   2000/ 5/25 宍戸 輝光 */ #include LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); HWND hwMain; void draw(HDC hdc) { SetMapMode(hdc,MM_LOMETRIC); SelectObject(hdc,GetStockObject(BLACK_PEN)); Rectangle(hdc,0,0,500,-500); MoveToEx(hdc,0,0,NULL); LineTo(hdc,250,-500); LineTo(hdc,500,0); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; WNDCLASSEX wndclass ; HMENU hMenu,hMenuA; wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = NULL; wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = "CWindow"; wndclass.hIconSm = NULL; RegisterClassEx (&wndclass); hwMain=CreateWindow ("CWindow",NULL,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,500,568,NULL,NULL,hInstance,NULL); /* メニュー作成 */ hMenu=CreateMenu(); hMenuA=CreateMenu(); AppendMenu(hMenuA,MF_STRING,1,"Print"); AppendMenu(hMenu,MF_POPUP,(UINT)hMenuA,"File"); SetMenu(hwMain,hMenu); ShowWindow (hwMain,iCmdShow); /* ウインドウを表示 */ UpdateWindow (hwMain); while (GetMessage (&msg,NULL,0,0)) { /* メッセージループ */ TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; static PRINTDLG pd; static DOCINFO dci; static LPTSTR lpszDocName="Print Test"; switch (iMsg) { case WM_CREATE: pd.lStructSize=sizeof(pd); pd.hwndOwner=hwnd; pd.hDevMode=NULL; pd.hDevNames=NULL; pd.Flags=PD_RETURNDC|PD_HIDEPRINTTOFILE; pd.nFromPage=1; pd.nToPage=1; pd.nMinPage=1; pd.nMaxPage=1; pd.nCopies=1; dci.cbSize=sizeof(dci); dci.lpszDocName=lpszDocName; dci.lpszOutput=NULL; dci.lpszDatatype=NULL; dci.fwType=0; return 0; case WM_COMMAND: /* マッピングモード変更メニュー */ switch (LOWORD(wParam)) { case 1: /* printメニュー */ if (!PrintDlg(&pd)) return 0; hdc=pd.hDC; StartDoc(hdc,&dci); StartPage(hdc); draw(hdc); EndPage(hdc); EndDoc(hdc); break; } return 0; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); draw(hdc); EndPaint(hwnd,&ps); return 0; case WM_DESTROY : /* 終了処理 */ PostQuitMessage(0); return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }