Advertisement
Guest User

Untitled

a guest
Jan 17th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <Windows.h>
  3.  
  4. #define Free(addr) if(addr != 0) free(addr); else MessageBox(0, "Invalid pointer!", 0, 0);
  5.  
  6. #define IDC_BUTTON1 101
  7. #define IDC_BUTTON2 102
  8.  
  9. void function1()
  10. {
  11.     MessageBox(0, "Wykonalem function1", 0, 0);
  12. }
  13.  
  14. void function2(int number)
  15. {
  16.     char * szBuffer = new char[100];
  17.     sprintf(szBuffer, "Wykonalem function2, number = %i", number);
  18.     MessageBox(0, szBuffer, 0, 0);
  19.     Free(szBuffer);
  20. }
  21.  
  22. LRESULT __stdcall WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
  23.  
  24. int __stdcall WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  25. {
  26.     WNDCLASSEX wc;
  27.    
  28.     wc.cbSize = sizeof( WNDCLASSEX );
  29.     wc.style = 0;
  30.     wc.lpfnWndProc = WndProc;
  31.     wc.cbClsExtra = 0;
  32.     wc.cbWndExtra = 0;
  33.     wc.hInstance = hInstance;
  34.     wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
  35.     wc.hCursor = LoadCursor( NULL, IDC_ARROW );
  36.     wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
  37.     wc.lpszMenuName = NULL;
  38.     wc.lpszClassName = "win32_sample_game_hooking";
  39.     wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
  40.    
  41.     if( !RegisterClassEx( & wc ) )
  42.         return 1;      
  43.     HWND hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, "win32_sample_game_hooking", "Gra", WS_OVERLAPPEDWINDOW,
  44.     CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL );
  45.    
  46.     if( hwnd == NULL )
  47.     {
  48.         return 1;
  49.     }
  50.     CreateWindowEx(0, "BUTTON", "przycisk1", WS_VISIBLE | WS_CHILD, 5, 5, 100, 50, hwnd, (HMENU)IDC_BUTTON1, hInstance, 0);
  51.     CreateWindowEx(0, "BUTTON", "przycisk2", WS_VISIBLE | WS_CHILD, 105, 5, 100, 50, hwnd, (HMENU)IDC_BUTTON2, hInstance, 0);
  52.  
  53.     ShowWindow( hwnd, nCmdShow );
  54.     UpdateWindow( hwnd );
  55.     MSG Msg;
  56.     while( GetMessage( & Msg, NULL, 0, 0 ) )
  57.     {
  58.         TranslateMessage( & Msg );
  59.         DispatchMessage( & Msg );
  60.     }
  61.     return Msg.wParam;
  62. }
  63.  
  64. LRESULT __stdcall WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
  65. {
  66.     switch( msg )
  67.     {
  68.     case WM_COMMAND:
  69.         {
  70.             if(LOWORD(wParam) == IDC_BUTTON1)
  71.             {
  72.                 function1();
  73.             }
  74.             else if(LOWORD(wParam) == IDC_BUTTON2)
  75.             {
  76.                 function2((rand()%10));
  77.             }
  78.         }
  79.         break;
  80.     case WM_CLOSE:
  81.         DestroyWindow( hwnd );
  82.         break;
  83.        
  84.     case WM_DESTROY:
  85.         PostQuitMessage( 0 );
  86.         break;
  87.        
  88.         default:
  89.         return DefWindowProc( hwnd, msg, wParam, lParam );
  90.     }
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement