윈도우api 버튼 문제
Soeun
#include windows.h
#include stdio.h
#define WM_ASYNC WM_USER+2
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra= 0;
WndClass.cbWndExtra= 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = Window Class Name;
RegisterClass(&WndClass);
hwnd = CreateWindow(
Window Class Name,
Client Window,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
#define SIZE 80
#define XSIZE 8
#define YSIZE 4
#define IDC_BUTTON 100
typedef struct//클릭한 사각형의 행, 열, count가 저장되는 구조체
{
int row;
int col;
}element;
element emt[1000];
int count = 0;//총 원의 개수
BOOL InRect(int x, int y)//어느 사각형에 들어가는지 알 수 있는 함수
{
int i, j;
for(i = 0; i XSIZE; i++)
for(j = 0; j YSIZE; j++)
if(i*SIZE x && x (i+1)*SIZE && j*SIZE y && y (j+1)*SIZE) //사각형 안에 위치하게되면
{
emt[count].row = i;//해당 사각형의 행, 열 번호 저장
emt[count].col = j;
//count++;
return TRUE;
}
return FALSE;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static WSADATA wsadata;
static SOCKET s;
static SOCKADDR_IN addr = { 0 };
int size;
int i, j , index;
static int x, y;
static BOOL selection;
static BOOL sending;
HPEN hPen, oldPen;
int tmp;
HWND hButton;
switch (iMsg)
{
case WM_CREATE:
WSAStartup(MAKEWORD(2, 2), &wsadata);
s = socket(AF_INET, SOCK_STREAM, 0);
addr.sin_family = AF_INET;
addr.sin_port = 20;
addr.sin_addr.s_addr = inet_addr(127.0.0.1);
WSAAsyncSelect(s, hwnd, WM_ASYNC, FD_READ);
if (connect(s, (LPSOCKADDR)&addr, sizeof(addr)) == -1)
return 0;
x = 0; y = 0;
selection = FALSE;
sending = FALSE;
hButton = CreateWindow(//전송 버튼
button,
전송,
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
650,
150,
80,
25,
hwnd,
(HMENU)IDC_BUTTON,
hInst,
NULL
);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON://전송 시
//tmp = emt[count].row;
send(s, (char *)&emt[count].row, 4, 0);
//tmp = emt[count].col;
send(s, (char *)&emt[count].col, 4, 0);
count++;//전송 후 원 개수 증가
sending = TRUE;
break;
}
break;
case WM_ASYNC:
switch(lParam)
{
case FD_READ:
recv(s, (char *)&emt[count].row, 4, 0);
//emt[count].row = tmp;
recv(s, (char *)&emt[count].col, 4, 0);
//emt[count].col = tmp;
count++;//원 받으면 원 개수 증가
sending = FALSE;
InvalidateRgn(hwnd, NULL, TRUE);
break;
default:
break;
}
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
for(i = 0; i XSIZE; i++)
for(j = 0; j YSIZE; j++)
Rectangle(hdc, i*SIZE, j*SIZE, (i+1)*SIZE, (j+1)*SIZE);//기본 사각형
if(selection == TRUE)
for(index = 0 ; index count + 1 ; index++)//emt.row, emt.col에 해당 i,j값이 들어있으므로 동그라미 그릴려고 돌리는 것
{
hPen = CreatePen(PS_SOLID, 2, RGB(0,0,255));
oldPen = (HPEN)SelectObject(hdc, hPen);
Ellipse(hdc, emt[index].row*SIZE, emt[index].col*SIZE, (emt[index].row+1)*SIZE, (emt[index].col+1)*SIZE);
SelectObject(hdc, oldPen);
DeleteObject(hPen);
}
EndPaint(hwnd, &ps);
break;
case WM_LBUTTONDOWN :
if(sending == FALSE)
{
x = LOWORD(lParam);
y = HIWORD(lParam);
if(InRect(x, y) == TRUE)selection = TRUE;
InvalidateRgn(hwnd, NULL, TRUE);
}
break;
case WM_DESTROY:
closesocket(s);
WSACleanup();
PostQuitMessage(0);
break;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}서버에서는 버튼이 나오는데
왜 클라이언트는 버튼이 안나올까요ㅜㅜㅜ
두개 다른 프로젝트로 만들엇는데 서버는 나오는데 클라이언트는 안나와요ㅜㅜ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |
2694229 | 단순한 질문이요 (8) | 여름 | 2025-05-09 |
2694202 | 용돈을 가지고 할 수 있는 일을 여러가지로 출력하는 방법 좀 알려주세요! (2) | 미나 | 2025-05-09 |
2694145 | 화면깜빡임을 없애고 싶은데요... (1) | 어서와 | 2025-05-08 |
2694069 | unsigned 질문입니다. | 힘차 | 2025-05-07 |
2694012 | 전공 비전공자 개발자 (10) | 말글 | 2025-05-07 |
2693984 | 오버로딩이 무엇인가요? (2) | 헛매질 | 2025-05-07 |
2693956 | PlaySound재생이 안됩니다!(C에 음악넣기) | 지존 | 2025-05-06 |
2693928 | &와 *의 사용에 관한 명확한 이해 | 제나 | 2025-05-06 |
2693903 | 반복문 설명좀요 ㅠㅠ (2) | 란새 | 2025-05-06 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |
2693788 | 이런 함수는 없나요? (3) | 앤드류 | 2025-05-05 |
2693758 | txt파일 불러와서 행렬로 저장 | 큰애 | 2025-05-05 |
2693727 | scanf 오류 문제!! (2) | 큰나래 | 2025-05-04 |
2693704 | 구조체 주소록 문제인데 도와주세요 (2) | 도1도캣 | 2025-05-04 |
2693676 | 열혈강의 c언어 질문입니다 | 하양이 | 2025-05-04 |
2693647 | 12.620000 을요 12.620 으로 어떻게 표현해요? (2) | 파도 | 2025-05-04 |
2693619 | 타이틀 코드.. | 단순드립 | 2025-05-03 |