윈도우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);
}서버에서는 버튼이 나오는데
왜 클라이언트는 버튼이 안나올까요ㅜㅜㅜ
두개 다른 프로젝트로 만들엇는데 서버는 나오는데 클라이언트는 안나와요ㅜㅜ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700695 | 간단한 메모장 구현을 할려고 하는데요 (9) | 늘솜 | 2025-07-07 |
2700668 | c언어 질문입니다. 도와주세요~ (3) | 가자 | 2025-07-07 |
2700639 | 한글입력받아서 ㄱㄴㄷ순서대로출력하는법좀 | 두빛나래 | 2025-07-06 |
2700610 | 정말 기초적인 더하기,여백 문제 help | 무슬 | 2025-07-06 |
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |