Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a Win32 program,it simply demonstrates how to draw lines in a window
- // Basicaly,you draw a line by clicking somehwere on the window and while the button
- // is pressed,you simply move the mouse to a new position and then release the button
- // @author: Gonzales Cenelia
- // homepage: www.ai-search.4t.com
- #include <windows.h>
- #include <windows.h>
- LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
- int WINAPI WinMain( HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nShowCmd) {
- HWND hWnd;
- MSG msg;
- WNDCLASSEX wc;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- wc.hInstance = hInstance;
- wc.lpfnWndProc = WndProc;
- wc.lpszClassName = "DrawingApp1";
- wc.lpszMenuName = NULL;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- // registering the class
- if(!RegisterClassEx(&wc)) {
- MessageBox(NULL, "Error while registering window", "OPenGL Tutorial", MB_OK );
- return 1;
- }
- // creating the window
- hWnd = CreateWindowEx(
- WS_EX_OVERLAPPEDWINDOW,
- "DrawingApp1",
- "Win32 DrawingApp",
- WS_OVERLAPPEDWINDOW,
- 150,
- 100,
- 640,
- 480,
- NULL,
- NULL,
- hInstance,
- NULL );
- if(!hWnd) {
- MessageBox(NULL, "Error while creating window", "OpenGL Tutorial", MB_OK );
- return 1;
- }
- ShowWindow(hWnd, SW_SHOW);
- UpdateWindow(hWnd);
- while( GetMessage( &msg, 0, 0, 0 ) > 0 ) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
- static BOOL bButtonClicked = 0;
- static int X = 0, Y = 0;
- HDC hDC = NULL;
- switch(Msg) {
- case WM_LBUTTONDOWN:
- bButtonClicked = 1;
- X = LOWORD(lParam);
- Y = HIWORD(lParam);
- break;
- case WM_LBUTTONUP:
- if(bButtonClicked) {
- hDC = GetDC(hWnd);
- MoveToEx( hDC, X, Y, NULL );
- X = LOWORD(lParam);
- Y = HIWORD(lParam);
- LineTo( hDC, X, Y );
- bButtonClicked = 0;
- ReleaseDC( hWnd, hDC );
- }
- break;
- case WM_MOUSEMOVE:
- break;
- case WM_CLOSE:
- DestroyWindow(hWnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- }
- return DefWindowProc(hWnd, Msg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement