윈도우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);
}서버에서는 버튼이 나오는데
왜 클라이언트는 버튼이 안나올까요ㅜㅜㅜ
두개 다른 프로젝트로 만들엇는데 서버는 나오는데 클라이언트는 안나와요ㅜㅜ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2655440 | test파일이 안 되요. (2) | 리라 | 2024-05-19 |
2655416 | 고수님들 도움이 절실합니다. (2) | 세리 | 2024-05-19 |
2655361 | 엔터 입력받을때까지 기다리는 getchar (1) | 큰모음 | 2024-05-19 |
2655328 | 함수에서 포인터 (3) | 모아 | 2024-05-18 |
2655299 | 아이콘바꾸는법..? | 소 | 2024-05-18 |
2655271 | scanf 입력받으면 쭉 실행되는.. (5) | ComeOn | 2024-05-18 |
2655184 | 이 세개 프로그램좀 해결해주실.... 고수님들???? (3) | 말달리자 | 2024-05-17 |
2655129 | 다차원 배열 원소들 주소계산하는거 질문이요~ | 터전 | 2024-05-17 |
2655103 | AVRstudio MoveAxis. MoveLine 함수질문 | 앨버트 | 2024-05-16 |
2655072 | 콘솔창의 위치와 크기를 정하고 싶습니다. | 딥레드 | 2024-05-16 |
2655044 | 자료구조랑 online judge site에 대해서 질문있습니다... (1) | 뽀송뽀송 | 2024-05-16 |
2655016 | 별찍기 문제 중 이해안되는 부분이 있어요... | 도전중 | 2024-05-16 |
2654986 | 입력받은 성적을 배열에 저장하기 (3) | 안녕나야 | 2024-05-15 |
2654959 | ===========-이런거 미리 지정하는법 (1) | 김자영 | 2024-05-15 |
2654930 | 도와주십시요 ㅜㅜ 자료구조 ㅜㅜ | 도널드 | 2024-05-15 |
2654881 | PID 모듈 검색 부분 질문합니다 . | 이름없음 | 2024-05-14 |
2654850 | 조건에 만족하는 다음 수를 찾고 싶습니다. | 초엘 | 2024-05-14 |
2654790 | 두파일간 byte단위 txt파일 복사 中 | 슬찬 | 2024-05-14 |
2654768 | 사전만들기 입니다. | 여우By | 2024-05-13 |
2654716 | c언어 고수님들 답좀적어주세요 급합니다 ㅠㅠ | 한말글 | 2024-05-13 |