📄 glw_w32.c
字号:
break; } case WM_LBUTTONDOWN: { if(win!=NULL) { pnts=MAKEPOINTS(SecondParameter); win->conn->mx=win->conn->curr_event.mousex=pnts.x; win->conn->my=win->conn->curr_event.mousey=pnts.y; win->conn->curr_event.event=GLWEV_MOUSEBUTTONS; win->conn->curr_event.data=GLWEVD_LEFTDOWN; } ret=0; break; } case WM_LBUTTONUP: { if(win!=NULL) { pnts=MAKEPOINTS(SecondParameter); win->conn->mx=win->conn->curr_event.mousex=pnts.x; win->conn->my=win->conn->curr_event.mousey=pnts.y; win->conn->curr_event.event=GLWEV_MOUSEBUTTONS; win->conn->curr_event.data=GLWEVD_LEFTUP; } ret=0; break; } case WM_RBUTTONUP: { if(win!=NULL) { pnts=MAKEPOINTS(SecondParameter); win->conn->mx=win->conn->curr_event.mousex=pnts.x; win->conn->my=win->conn->curr_event.mousey=pnts.y; win->conn->curr_event.event=GLWEV_MOUSEBUTTONS; win->conn->curr_event.data=GLWEVD_RIGHTUP; } ret=0; break; } case WM_RBUTTONDOWN: { if(win!=NULL) { pnts=MAKEPOINTS(SecondParameter); win->conn->mx=win->conn->curr_event.mousex=pnts.x; win->conn->my=win->conn->curr_event.mousey=pnts.y; win->conn->curr_event.event=GLWEV_MOUSEBUTTONS; win->conn->curr_event.data=GLWEVD_RIGHTDOWN; } ret=0; break; } case WM_MBUTTONUP: { if(win!=NULL) { pnts=MAKEPOINTS(SecondParameter); win->conn->mx=win->conn->curr_event.mousex=pnts.x; win->conn->my=win->conn->curr_event.mousey=pnts.y; win->conn->curr_event.event=GLWEV_MOUSEBUTTONS; win->conn->curr_event.data=GLWEVD_MIDDLEUP; } ret=0; break; } case WM_MBUTTONDOWN: { if(win!=NULL) { pnts=MAKEPOINTS(SecondParameter); win->conn->mx=win->conn->curr_event.mousex=pnts.x; win->conn->my=win->conn->curr_event.mousey=pnts.y; win->conn->curr_event.event=GLWEV_MOUSEBUTTONS; win->conn->curr_event.data=GLWEVD_MIDDLEDOWN; } ret=0; break; } case WM_KEYDOWN: { if(win!=NULL) { win->conn->curr_event.event=GLWEV_KEYDOWN; win->conn->curr_event.data=FirstParameter; } ret=0; break; } case WM_KEYUP: { if(win!=NULL) { win->conn->curr_event.event=GLWEV_KEYUP; win->conn->curr_event.data=FirstParameter; } ret=0; break; } case WM_DISPLAYCHANGE: { HDC hDC; HWND dw; RECT rct; int oldX,oldY; if(win!=NULL) { oldX=buffsizeX; oldY=buffsizeY; dw=GetDesktopWindow(); GetClientRect(dw,&rct); buffsizeX=rct.right; buffsizeY=rct.bottom; hDC=GetDC(dw); glw_DeleteBuffer(win); glw_CreateBuffer(win,hDC,buffsizeX,buffsizeY); ReleaseDC(dw,hDC); if((win->wrect.right-win->wrect.left)>buffsizeX||(win->wrect.bottom-win->wrect.top)>buffsizeY) { int w=min((win->wrect.right-win->wrect.left),buffsizeX); int h=min((win->wrect.bottom-win->wrect.top),buffsizeY); MoveWindow(Window,win->wrect.left,win->wrect.top,w,h,FALSE); win->wrect.right=win->wrect.left+w; win->wrect.bottom=win->wrect.top+h; } win->conn->curr_event.event=GLWEV_WINDOW; win->conn->curr_event.data=GLWEVD_REPAINT; } ret=0; break; } case WM_GETMINMAXINFO: { MINMAXINFO *sp=(MINMAXINFO *)SecondParameter; struct glw_Window *win; win=(struct glw_Window *)list_GetNodeData(glw_GetNode(Window)); if(win!=NULL) { sp->ptMaxSize.x=buffsizeX; sp->ptMaxSize.y=buffsizeY; sp->ptMaxTrackSize.x=buffsizeX; sp->ptMaxTrackSize.y=buffsizeY; sp->ptMinTrackSize.x=win->minwidth; sp->ptMinTrackSize.y=win->minheight; } ret=0; break; } case WM_SIZING: { ret=0; break; } case WM_NCCALCSIZE: { if(win!=NULL) { memcpy(&win->wrect,(RECT *)SecondParameter,sizeof(RECT)); if(win->state==1) { // first WM_SIZING message win->state=2; win->conn->curr_event.event=GLWEV_WINDOW; win->conn->curr_event.data=GLWEVD_SIZEBEGIN; win->done|=gui_Event((u32)win->conn,&win->conn->curr_event); } win->conn->curr_event.event=GLWEV_WINDOW; win->conn->curr_event.data=GLWEVD_SIZING; win->done|=gui_Event((u32)win->conn,&win->conn->curr_event); } ret=0; break; } case WM_MOVING: { if(win!=NULL) { memcpy(&win->wrect,(RECT *)SecondParameter,sizeof(RECT)); if(win->state==1) { // first WM_MOVING message win->state=3; win->conn->curr_event.event=GLWEV_WINDOW; win->conn->curr_event.data=GLWEVD_MOVEBEGIN; win->done|=gui_Event((u32)win->conn,&win->conn->curr_event); } win->conn->curr_event.event=GLWEV_WINDOW; win->conn->curr_event.data=GLWEVD_MOVING; win->done|=gui_Event((u32)win->conn,&win->conn->curr_event); } ret=0; break; } case WM_TIMER: { if(win!=NULL) { win->conn->curr_event.event=GLWEV_TIMER; win->conn->curr_event.data=FirstParameter; } ret=0; break; } case WM_PAINT: { if(win!=NULL) { BeginPaint(Window,&ps); if(win->paint>0) { glw_CopyBckIndirect(Window,&ps.rcPaint); } else win->paint=1; EndPaint(Window,&ps); } ret=0; break; } case WM_NCPAINT: { ret=0; break; } case WM_SYSCOMMAND: { DefWindowProc(Window, MessageType, FirstParameter, SecondParameter); ret=0; break; } case WM_APP: { if(conn!=NULL) glw_ReadMessage(conn); ret=0; break; } } debug_End(); return(ret);}/*---*//** * \param TAG_GLW_VALUE u32 */u32 glw_htonl2(u32 firsttag, ...){ return(glw_htonl2TL((tag *)&firsttag));}u32 glw_htonl2TL(tag *taglist){ u32 value; u32 ret; debug_Begin(); value=(u32 )tag_GetTagData(taglist,TAG_GLW_VALUE,0L); ret=htonl(value); debug_End(); return((u32)ret);}/** * \param TAG_GLW_VALUE u32 */u32 glw_ntohl2(u32 firsttag, ...){ return(glw_ntohl2TL((tag *)&firsttag));}u32 glw_ntohl2TL(tag *taglist){ u32 value; u32 ret; debug_Begin(); value=(u32 )tag_GetTagData(taglist,TAG_GLW_VALUE,0L); ret=ntohl(value); debug_End(); return((u32)ret);}u32 glw_htonl(u32 value){ return(htonl(value));}u32 glw_ntohl(u32 value){ return(ntohl(value));}int glw_Recv(u32 connection, u8 *buff, int bufflen){ struct glw_Connection *conn=(struct glw_Connection *)connection; int ret=0; debug_Begin(); if(conn!=NULL&&buff!=NULL&&bufflen>0) { ret=recv(conn->sd,buff,bufflen,0); } debug_End(); return(ret);}int glw_Send(u32 connection, u8 *buff, int bufflen){ struct glw_Connection *conn=(struct glw_Connection *)connection; int ret=0; debug_Begin(); if(conn!=NULL&&buff!=NULL&&bufflen>0) { ret=send(conn->sd,buff,bufflen,0); } debug_End(); return(ret);}int glw_SendMsg(u32 connection, u8 type, u32 id, u8 *buff, int bufflen){ struct glw_Connection *conn=(struct glw_Connection *)connection; u8 header[GLW_HEADER_LENGTH]; int mlen; debug_Begin(); mlen=bufflen+GLW_HEADER_LENGTH; header[0]='?'; header[1]=type; *((u32 *)&header[2])=htonl(mlen); *((u32 *)&header[6])=htonl(id); if(mlen<NET_WRITE_BUFFER_SIZE) { memcpy(conn->write_buffer,header,GLW_HEADER_LENGTH); if(bufflen>0) memcpy(conn->write_buffer+GLW_HEADER_LENGTH,buff,bufflen); send(conn->sd,conn->write_buffer,mlen,0); } else { send(conn->sd,header,GLW_HEADER_LENGTH,0); if(bufflen>0&&buff!=NULL) send(conn->sd,buff,bufflen,0); } debug_End(); return(0);}#define SOCK_CLOSE_BUFSIZE 256static DWORD WINAPI glw_Thread(void *sock){ struct glw_Connection *conn; int NewBytes; char ReadBuffer[SOCK_CLOSE_BUFSIZE]; Node_t *node; printf("server start (socket=%d)\n",(int)sock); mem_trace_checkpoint(); if(NULL!=(conn=mem_calloc(1,sizeof(struct glw_Connection)))) { if(NULL!=(conn->windowlist=list_CreateList())) { conn->sd=(SOCKET)sock; conn->cuser.quit=0; conn->win=NULL; conn->window_count=0; if(NULL!=(conn->write_buffer=mem_malloc(NET_WRITE_BUFFER_SIZE))) { if(NULL!=(conn->cuser.appname=net_CheckClient((u32)conn))) { net_Server((u32)conn); } if(shutdown(conn->sd,SD_SEND)!=SOCKET_ERROR) { while(1) { NewBytes=recv(conn->sd,ReadBuffer,SOCK_CLOSE_BUFSIZE,0); if(NewBytes==0||NewBytes==SOCKET_ERROR) break; } closesocket(conn->sd); } } while(NULL!=(node=list_GetNodeHead(conn->windowlist))) glw_CloseWindow((u32)list_GetNodeData(node)); list_DeleteList(conn->windowlist); if(conn->cuser.appname!=NULL) mem_free(conn->cuser.appname); mem_free(conn->write_buffer); mem_free(conn); } } mem_trace_report(); printf("server end\n"); return(0);}static void glw_Server(int port){ char address[]="0.0.0.0"; WSADATA wsaData; u_long InterfaceAddr; SOCKET ret=INVALID_SOCKET,sd,clisd; struct sockaddr_in Interface,Remote; int AddrSize=sizeof(Remote); debug_Begin(); InterfaceAddr=inet_addr(address); if(WSAStartup(MAKEWORD(1,1),&wsaData)==0) { printf("Establishing the listener...\n"); if(InterfaceAddr!=INADDR_NONE) { sd=socket(AF_INET,SOCK_STREAM,0); if(sd!=INVALID_SOCKET) { Interface.sin_family=AF_INET; Interface.sin_addr.s_addr=InterfaceAddr; Interface.sin_port=htons(port); if(bind(sd,(struct sockaddr *)&Interface,sizeof(struct sockaddr_in))!=SOCKET_ERROR) { listen(sd,SOMAXCONN); ret=sd; } } } if(ret!=INVALID_SOCKET) { sd=ret; printf("Waiting for connections...\n"); while(1) { clisd=accept(sd,(struct sockaddr *)&Remote,&AddrSize); if(clisd!=INVALID_SOCKET) { printf("Accepted (on socket %d) %lx connection from %s:%d .\n",clisd,Remote.sin_addr.s_addr,inet_ntoa(Remote.sin_addr),ntohs(Remote.sin_port)); CreateThread(0,0,glw_Thread,(void *)clisd,0,NULL); } } } WSACleanup(); } debug_End();}// Main Functionint WINAPI WinMain(HINSTANCE Instance, HINSTANCE PreviousInstance, LPSTR CommandLine, int CommandShow){ RECT rct3vv; Node_t *node; OSVERSIONINFO ovi; debug_Begin();/* { int i; for(i=0;i<sizeof(call_vector);i++) call_vector[i]=(u32 (*)(tag *))bases_Unimplemented; }*///Initialize call vector BEGIN - put this into the init function of this module call_vector[GLW_STARTMOUSETRACKING-GLW_FUNCBASE]=glw_StartMouseTrackingTL; call_vector[GLW_STOPMOUSETRACKING-GLW_FUNCBASE]=glw_StopMouseTrackingTL; call_vector[GLW_DRAGWINDOW-GLW_FUNCBASE]=glw_DragWindowTL; call_vector[GLW_RESIZEWINDOW-GLW_FUNCBASE]=glw_ResizeWindowTL; call_vector[GLW_SETCOLOR-GLW_FUNCBASE]=glw_SetColorTL; call_vector[GLW_SETBACKGROUND-GLW_FUNCBASE]=glw_SetBackgroundTL; call_vector[GLW_DRAWLINE-GLW_FUNCBASE]=glw_DrawLineTL; call_vector[GLW_DRAWRECT-GLW_FUNCBASE]=glw_DrawRectTL; call_vector[GLW_DRAWFILLEDRECT-GLW_FUNCBASE]=glw_DrawFilledRectTL; call_vector[GLW_DRAWPIXEL-GLW_FUNCBASE]=glw_DrawPixelTL; call_vector[GLW_OPENFONT-GLW_FUNCBASE]=glw_OpenFontTL; call_vector[GLW_CLOSEFONT-GLW_FUNCBASE]=glw_CloseFontTL; call_vector[GLW_DRAWTEXT-GLW_FUNCBASE]=glw_DrawTextTL; call_vector[GLW_GETFONTSIZE-GLW_FUNCBASE]=glw_GetFontSizeTL; call_vector[GLW_GETTEXTLENGTH-GLW_FUNCBASE]=glw_GetTextLengthTL; call_vector[GLW_PUTIMAGE-GLW_FUNCBASE]=glw_PutImageTL; call_vector[GLW_GETSCREENDIMENSIONS-GLW_FUNCBASE]=glw_GetScreenDimensionsTL; call_vector[GLW_TIMERSTART-GLW_FUNCBASE]=glw_TimerStartTL; call_vector[GLW_TIMERCANCEL-GLW_FUNCBASE]=glw_TimerCancelTL; call_vector[GLW_GETTIME-GLW_FUNCBASE]=glw_GetTimeTL; call_vector[GLW_HTONL2-GLW_FUNCBASE]=glw_htonl2TL; call_vector[GLW_NTOHL2-GLW_FUNCBASE]=glw_ntohl2TL; bases_modules.glw_Call=glw_Call; bases_modules.glw_CallTL=glw_CallTL;//Initialize call vector END // detect windows version ovi.dwOSVersionInfoSize=sizeof(ovi); GetVersionEx(&ovi); // wv=0 3.1 // wv=1 95 // wv=2 98 // wv=3 NT4 // wv=4 2k // wv=5 xp if(ovi.dwPlatformId==VER_PLATFORM_WIN32_NT&&ovi.dwMajorVersion>=5) wv=4; // 2k or xp else if(ovi.dwPlatformId==VER_PLATFORM_WIN32_NT&&ovi.dwMajorVersion>=4) wv=3; // NT4 else if(ovi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS&&ovi.dwMajorVersion>=4) wv=2; // 98 else if(ovi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS&&ovi.dwMajorVersion>=3) wv=1; // 95 else wv=0; sInstance=Instance; sCommandShow=CommandShow; if(NULL!=(windowlist=list_CreateList())) { if(NULL!=(fontfacelist=list_CreateList())) { if(0==(glw_LoadFontFaces(fontfacelist))) { if(NULL!=(fontlist=list_CreateList())) { WindowClass.cbSize = sizeof(WNDCLASSEX); WindowClass.style = 0; WindowClass.lpfnWndProc = glw_StdWindowProc; WindowClass.cbClsExtra = 0; WindowClass.cbWndExtra = 0; WindowClass.hInstance = sInstance; WindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); WindowClass.hbrBackground = GetStockObject(WHITE_BRUSH); WindowClass.lpszMenuName = NULL; WindowClass.lpszClassName = "glw_StdWindowClass"; WindowClass.hIconSm = NULL; if(RegisterClassEx(&WindowClass)!=0) { GetClientRect(GetDesktopWindow(),&rct3vv); buffsizeX=rct3vv.right; buffsizeY=rct3vv.bottom; workDC=CreateCompatibleDC(NULL); gui_Init(); glw_Server(net_GetPort()); gui_CleanUp(); while(NULL!=(node=list_GetNodeHead(windowlist))) glw_CloseWindow((u32)list_GetNodeData(node)); } while(NULL!=(node=list_GetNodeHead(fontlist))) glw_CloseFont(TAG_GLW_FONT,(u32)list_GetNodeData(node),TAG_DONE); list_DeleteList(fontlist); if(NULL!=workDC) DeleteDC(workDC); } glw_UnloadFontFaces(fontfacelist); fontfacelist=NULL; } } list_DeleteList(windowlist); } mem_trace_report(); debug_End(); return(0L);}/*----*/u32 glw_OpenWindow(u32 connection, Rect_t *dim, u32 flags, u32 userdata){ struct glw_Connection *conn=(struct glw_Connection *)connection; HWND dw; HDC hDC; struct glw_Window *win=NULL; Node_t *node,*node2; debug_Begin(); if(NULL!=(node=list_CreateNode())) { if(NULL!=(node2=list_CreateNode())) { if(NULL!=(win=mem_malloc(sizeof(struct glw_Window)))) { win->user_state=GLWWS_OPENING; win->conn=conn; win->flags=flags; win->userdata=userdata; list_SetNodeData(node,win); list_SetNodeData(node2,win); list_InsertNodeTail(windowlist,node); list_InsertNodeTail(conn->windowlist,node2); if((dw=CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, "glw_StdWindowClass", NULL, WS_OVERLAPPED, dim->left, dim->top, dim->width, dim->height, NULL, NULL, sInstance, NULL))!=NULL) { if(conn->window_count==0) { WSAAsyncSelect(conn->sd,dw,WM_APP,FD_READ); conn->win=win; } win->window=dw; ShowWindow(win->window,sCommandShow); dw=GetDesktopWindow(); hDC=GetDC(dw); glw_CreateBuffer(win,hDC,buffsizeX,buffsizeY); ReleaseDC(dw,hDC); GetWindowRect(win->window,&win->wrect); glw_ClearWindow((u32)win); SetCursor(LoadCursor(NULL,IDC_ARROW)); conn->window_count++; win->minwidth=0; win->minheight=0; win->done=0; } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -