Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. #define MINE_ORE 1
  4. #define START 2
  5.  
  6. int vars() // Diese soll irgendwo eingefügt werden sodass sie nur einmal geladen wird aber die klasse "LRESULT CALLBACK WndProc" auf die variablen zugriff hat.
  7. {
  8. int minerals;
  9. minerals = 0;
  10.  
  11. bool sound;
  12. sound = false;
  13.  
  14. int ms;
  15. ms = 0;
  16.  
  17. int beep;
  18. beep = 0;
  19. }
  20.  
  21. /* This is where all the input to the window goes to */
  22. LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam, int ms) {
  23. switch(Message) {
  24. case WM_CREATE:
  25. {
  26.  
  27. CreateWindow(TEXT("BUTTON"), TEXT("Erz abbauen"),
  28. WS_CHILD | WS_VISIBLE | WS_BORDER,
  29. 200, 400, 100, 50,
  30. hwnd, (HMENU) MINE_ORE, NULL, NULL
  31. );
  32.  
  33. CreateWindow(TEXT("BUTTON"), TEXT("Start"),
  34. WS_CHILD | WS_VISIBLE | WS_BORDER,
  35. 300, 400, 100, 50,
  36. hwnd, (HMENU) START, NULL, NULL
  37. );
  38.  
  39. CreateWindow(TEXT("STATIC"), TEXT("[Minenbasis]"),
  40. WS_CHILD | WS_VISIBLE,
  41. 200, 10, 100, 20,
  42. hwnd, (HMENU) NULL, NULL, NULL
  43. );
  44.  
  45. break;
  46. }
  47.  
  48. case WM_COMMAND:
  49. {
  50.  
  51.  
  52. if (LOWORD(wParam) == MINE_ORE)
  53. {
  54. if(ms == 3) //Hier kommen noch Errors weil es die Variable nicht findet. Das ist ja das Problem.
  55. {
  56. Beep(3000, 500);
  57. ms = 0;
  58. }
  59. else
  60. {
  61. ms = ms + 1;
  62. SetCursorPos(0,0);
  63. }
  64. }
  65.  
  66.  
  67. break;
  68. }
  69. /* Upon destruction, tell the main thread to stop */
  70. case WM_DESTROY: {
  71. PostQuitMessage(0);
  72. break;
  73. }
  74.  
  75. /* All other messages (a lot of them) are processed using default procedures */
  76. default:
  77. return DefWindowProc(hwnd, Message, wParam, lParam);
  78. }
  79. return 0;
  80. }
  81.  
  82. /* The 'main' function of Win32 GUI programs: this is where execution starts */
  83. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  84.  
  85.  
  86.  
  87. WNDCLASSEX wc; /* A properties struct of our window */
  88. HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
  89. MSG Msg; /* A temporary location for all messages */
  90.  
  91. /* zero out the struct and set the stuff we want to modify */
  92. memset(&wc,0,sizeof(wc));
  93. wc.cbSize = sizeof(WNDCLASSEX);
  94. wc.lpfnWndProc = WndProc; /* This is where we will send messages to */
  95. wc.hInstance = hInstance;
  96. wc.hCursor = LoadCursor(NULL, IDC_CROSS);
  97.  
  98. /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
  99. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  100. wc.lpszClassName = "WindowClass";
  101. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
  102. wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */
  103.  
  104. if(!RegisterClassEx(&wc)) {
  105. MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  106. return 0;
  107. }
  108.  
  109. hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Mining Game",WS_VISIBLE|WS_SYSMENU,
  110. 710, /* x */
  111. 290, /* y */
  112. 500, /* width */
  113. 500, /* height */
  114. NULL,NULL,hInstance,NULL);
  115.  
  116. if(hwnd == NULL) {
  117. MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  118. return 0;
  119. }
  120.  
  121. /*
  122. This is the heart of our program where all input is processed and
  123. sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
  124. this loop will not produce unreasonably high CPU usage
  125. */
  126. while(GetMessage(&Msg, NULL, 0, 0) > 0) { /* If no error is received... */
  127. TranslateMessage(&Msg); /* Translate key codes to chars if present */
  128. DispatchMessage(&Msg); /* Send it to WndProc */
  129. }
  130. return Msg.wParam;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement