Есть тестовый проектик -- окно и 5 кнопок:
| Код | #include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstans,HINSTANCE hPrev,LPSTR lpCmdLine,int nCmdShow) { HWND hMainWnd; char szClassName[]="MyClass"; MSG msg; WNDCLASSEX wc; wc.cbSize =sizeof(wc); wc.style =CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc =WndProc; wc.cbClsExtra =0; wc.cbWndExtra =0; wc.hInstance =hInstans; wc.hIcon =LoadIcon(NULL,IDI_APPLICATION); wc.hCursor =LoadCursor(NULL,IDC_ARROW); wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName =NULL; wc.lpszClassName =szClassName; wc.hIconSm =LoadIcon(NULL,IDI_APPLICATION); if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Error", "Error",MB_OK); return 0; } hMainWnd = CreateWindow(szClassName,"My window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HWND)NULL,(HMENU)NULL,(HINSTANCE)hInstans,NULL); HWND bt1=CreateWindowEx(0, "BUTTON", "Button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 10, 100, 82, 30,hMainWnd,NULL,hInstans,NULL); HWND bt2=CreateWindowEx(0, "BUTTON", "Button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 10, 140, 82, 30,hMainWnd,NULL,hInstans,NULL); HWND bt3=CreateWindowEx(0, "BUTTON", "Button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 10, 180, 82, 30,hMainWnd,NULL,hInstans,NULL); HWND bt4=CreateWindowEx(0, "BUTTON", "Button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 10, 220, 82, 30,hMainWnd,NULL,hInstans,NULL); HWND bt5=CreateWindowEx(0, "BUTTON", "Button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 10, 260, 82, 30,hMainWnd,NULL,hInstans,NULL); ShowWindow(hMainWnd,nCmdShow); while(GetMessage(&msg,NULL,0,0)) { if (!IsDialogMessage(hMainWnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { HDC hDC; PAINTSTRUCT ps; RECT rect; switch(uMsg) { case WM_PAINT: hDC=BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rect); DrawText(hDC, "исключительно для тестов",-1, &rect, DT_SINGLELINE | DT_CENTER |DT_VCENTER); EndPaint(hWnd,&ps); break; case WM_CLOSE: DestroyWindow(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd,uMsg,wParam,lParam); } return 0; }
|
|