Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <Windows.h>
- #define Free(addr) if(addr != 0) free(addr); else MessageBox(0, "Invalid pointer!", 0, 0);
- #define IDC_BUTTON1 101
- #define IDC_BUTTON2 102
- void function1()
- {
- MessageBox(0, "Wykonalem function1", 0, 0);
- }
- void function2(int number)
- {
- char * szBuffer = new char[100];
- sprintf(szBuffer, "Wykonalem function2, number = %i", number);
- MessageBox(0, szBuffer, 0, 0);
- Free(szBuffer);
- }
- LRESULT __stdcall WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
- int __stdcall WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
- {
- WNDCLASSEX wc;
- wc.cbSize = sizeof( WNDCLASSEX );
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "win32_sample_game_hooking";
- wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
- if( !RegisterClassEx( & wc ) )
- return 1;
- HWND hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, "win32_sample_game_hooking", "Gra", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL );
- if( hwnd == NULL )
- {
- return 1;
- }
- CreateWindowEx(0, "BUTTON", "przycisk1", WS_VISIBLE | WS_CHILD, 5, 5, 100, 50, hwnd, (HMENU)IDC_BUTTON1, hInstance, 0);
- CreateWindowEx(0, "BUTTON", "przycisk2", WS_VISIBLE | WS_CHILD, 105, 5, 100, 50, hwnd, (HMENU)IDC_BUTTON2, hInstance, 0);
- ShowWindow( hwnd, nCmdShow );
- UpdateWindow( hwnd );
- MSG Msg;
- while( GetMessage( & Msg, NULL, 0, 0 ) )
- {
- TranslateMessage( & Msg );
- DispatchMessage( & Msg );
- }
- return Msg.wParam;
- }
- LRESULT __stdcall WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
- {
- switch( msg )
- {
- case WM_COMMAND:
- {
- if(LOWORD(wParam) == IDC_BUTTON1)
- {
- function1();
- }
- else if(LOWORD(wParam) == IDC_BUTTON2)
- {
- function2((rand()%10));
- }
- }
- break;
- case WM_CLOSE:
- DestroyWindow( hwnd );
- break;
- case WM_DESTROY:
- PostQuitMessage( 0 );
- break;
- default:
- return DefWindowProc( hwnd, msg, wParam, lParam );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement