Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  sss
Language: C/C++
Code:
#include <windows.h>
#include <commctrl.h>
#include <mmsystem.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
                       WPARAM wParam, LPARAM lParam);

LPSTR const lpWndClassName = "WindowClass";
HWND hWnd;
HWND hOpenButton;
HWND hCloseButton;

#define IDC_OPEN_BUTTON 1
#define IDC_CLOSE_BUTTON 2

int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nShowCmd)
{
    WNDCLASSEX wxWndClass = {0};

    wxWndClass.hInstance = GetModuleHandle(NULL);
    wxWndClass.cbSize = sizeof(WNDCLASSEX);
    wxWndClass.lpfnWndProc = WndProc;
    wxWndClass.lpszClassName = lpWndClassName;

    wxWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wxWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wxWndClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wxWndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    wxWndClass.lpszMenuName = NULL;
    wxWndClass.style = CS_VREDRAW | CS_HREDRAW;
    wxWndClass.cbClsExtra = 0;
    wxWndClass.cbWndExtra = 0;

    RegisterClassEx(&wxWndClass);

    hWnd = CreateWindowEx(NULL, lpWndClassName, "CD-ROM", WS_SYSMENU,
                          100, 100, 150, 80, NULL, NULL,
                          GetModuleHandle(NULL), NULL);

    ShowWindow(hWnd, SW_NORMAL);
    UpdateWindow(hWnd);

        MSG msg = {0};
        while (GetMessage(&msg, NULL, 0, 0))
        {
            
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
    
    UnregisterClass(lpWndClassName, GetModuleHandle(NULL));
    
    return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
                       WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_CREATE:
            hOpenButton = CreateWindowEx(0, "BUTTON", "Wysuń",
                                     WS_CHILD|WS_VISIBLE, 0, 0,
                                     150, 25, hWnd, (HMENU)IDC_OPEN_BUTTON,
                                     GetModuleHandle(NULL), NULL);
            
            hCloseButton = CreateWindowEx(0, "BUTTON", "Zamknij",
                                     WS_CHILD|WS_VISIBLE, 0, 25,
                                     150, 25, hWnd, (HMENU)IDC_CLOSE_BUTTON,
                                     GetModuleHandle(NULL), NULL);

            break;

        case WM_COMMAND:
            if(wParam == IDC_OPEN_BUTTON)
            mciSendString("set cdaudio door open", 0, 0, 0);
            
            if(wParam == IDC_CLOSE_BUTTON)
            mciSendString("set cdaudio door close", 0, 0, 0);
            break;
        
        case WM_CLOSE:
            DestroyWindow(hOpenButton);
            DestroyWindow(hCloseButton);
            DestroyWindow(hWnd);
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }

    return 0;

}
          
Comments: