fork(1) download
  1. #include<windows.h>
  2. #include<gdiplus.h>
  3. #include <stdio.h>
  4. using namespace Gdiplus;
  5. #pragma comment(lib,"gdiplus.lib")
  6.  
  7.  
  8.  
  9.  
  10. void draw(HDC hdc,int x,int y)
  11. {
  12. GdiplusStartupInput gdiplusStartupInput;
  13. ULONG_PTR gdiplusToken; // ULONG PTR 為無符號長整型指針
  14. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  15. static int cy[]={0,600,1200,1800,2400},i=0;
  16. Rect rect(x,y,250,550); //(x,y,cx,cy) x,y為開始貼圖的位置;cx,cy為貼出來的大小
  17. Unit srcunit = UnitPixel; //像素大小
  18. Image* image = new Image(L"peo.png");
  19. Bitmap CacheImage( 1024, 768 );
  20. Graphics CacheGraphics( &CacheImage );
  21. CacheGraphics.DrawImage(image, rect,0,cy[i++],500,590,UnitPixel);
  22.  
  23. Graphics graphics(hdc);
  24. graphics.DrawImage(&CacheImage, 0,0); //(image,rect,x,y,cx,cy,Unit)
  25. //x,y為要貼的圖的左上角位置;cx,cy為要貼的圖的右下角位置
  26. ;
  27. if(i==5)i=0;
  28. delete image;
  29. GdiplusShutdown(gdiplusToken);
  30. return;
  31. }
  32.  
  33.  
  34. LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  35. {
  36. HDC hdc ;
  37. PAINTSTRUCT ps ;
  38. RECT rect ;
  39. static int x=20,y=20;
  40. switch(uMsg){
  41. case WM_PAINT:
  42. hdc = BeginPaint (hwnd, &ps);
  43. draw(hdc,x,y);
  44. EndPaint (hwnd, &ps);
  45. case WM_CREATE:break;
  46. case WM_KEYDOWN:
  47. switch (wParam){
  48. case VK_UP: y--;break;
  49. case VK_DOWN:y++;break;
  50. case VK_LEFT:x--;break;
  51. case VK_RIGHT:x++;break;
  52. default: break;
  53. }
  54. InvalidateRect(hwnd,NULL,true) ;
  55. UpdateWindow(hwnd);
  56. break;
  57. case WM_CLOSE: DestroyWindow(hwnd);break;
  58. case WM_DESTROY: PostQuitMessage(0); break;
  59. case WM_COMMAND:break;
  60.  
  61. default: return DefWindowProc(hwnd,uMsg,wParam,lParam);
  62. }
  63.  
  64.  
  65.  
  66. }
  67.  
  68. int WINAPI WinMain(HINSTANCE hInstance,
  69. HINSTANCE hPrevInstance,
  70. LPSTR lpCmdLine,
  71. int nCmdShow){
  72. WNDCLASSEX wcx;
  73. MSG Msg; //訊息
  74. HWND hwnd; //代號
  75. //註冊窗口
  76. wcx.cbSize =sizeof(wcx);
  77. wcx.style =CS_HREDRAW | CS_VREDRAW; //指定視窗樣式為:改變視窗大小就重繪
  78. wcx.lpfnWndProc =WndProc; //指定處理函式為WndProc
  79. wcx.cbClsExtra =0;
  80. wcx.cbWndExtra =0;
  81. wcx.hInstance =hInstance;
  82. wcx.hIcon =LoadIcon(NULL, IDI_APPLICATION); //LoadIcon 載入圖示供程式使用。
  83. wcx.hCursor =LoadCursor(NULL, IDC_ARROW); //LoadCursor 載入滑鼠游標供程式使用。
  84. wcx.hbrBackground= (HBRUSH) GetStockObject (GRAY_BRUSH) ; //GetStockObject取得一個圖形物件
  85. wcx.lpszMenuName = NULL;
  86. wcx.lpszClassName="MainClass";
  87. wcx.hIconSm =LoadIcon(NULL, IDI_APPLICATION);
  88. if(!RegisterClassEx(&wcx)){ //為程式視窗註冊視窗類別。
  89. MessageBox(NULL,"RegisterClass Error","ERROR",MB_OK);
  90. return 0;
  91. }
  92. //創建窗口
  93. hwnd=CreateWindow( //根據視窗類別建立一個視窗,回傳視窗代號到hwnd。
  94. "MainClass",
  95. "Test Create Window",
  96. WS_OVERLAPPEDWINDOW,
  97. CW_USEDEFAULT,
  98. CW_USEDEFAULT,
  99. 1024,768,
  100. (HWND)NULL,
  101. (HMENU)NULL,
  102. hInstance,
  103. NULL
  104. );
  105. if(hwnd==NULL){
  106. MessageBox(NULL,"CreateWindow Error","ERROR",MB_OK);
  107. return 0;
  108. }
  109. ShowWindow(hwnd,nCmdShow); //在螢幕上顯示視窗。
  110. UpdateWindow(hwnd); //指示視窗自我更新
  111. while(GetMessage(&Msg,NULL,0,0)>0){ //從訊息佇列中取得訊息
  112. TranslateMessage(&Msg); // 轉譯某些鍵盤訊息。
  113. DispatchMessage(&Msg); //將訊息發送給視窗訊息處理程式。
  114. }
  115. return Msg.wParam;
  116.  
  117. }
  118.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:20: error: windows.h: No such file or directory
prog.cpp:2:20: error: gdiplus.h: No such file or directory
prog.cpp:5: warning: ignoring #pragma comment 
prog.cpp:4: error: ‘Gdiplus’ is not a namespace-name
prog.cpp:4: error: expected namespace-name before ‘;’ token
prog.cpp:10: error: variable or field ‘draw’ declared void
prog.cpp:10: error: ‘HDC’ was not declared in this scope
prog.cpp:10: error: expected primary-expression before ‘int’
prog.cpp:10: error: expected primary-expression before ‘int’
stdout
Standard output is empty