win32 Test

 
引用
#define UNICODE #include<windows.h> #include <stdlib.h> #include<stdio.h> #undef _WINDOWS_ #include<afx.h> #define SHOWMSG \ int x=HIWORD(lParam);\ int y=LOWORD(lParam);\ CString str;\ str.Format(TEXT("宽度x=%d 高度y=%d"),x,y);\ SetWindowText(hwnd,str); #define ID_SMALLER 120 LRESULT CALLBACK winproc(HWND hwnd ,UINT msg,WPARAM wParam,LPARAM lParam); LRESULT CALLBACK btproc(HWND hwnd ,UINT msg,WPARAM wParam,LPARAM lParam); TCHAR *szAppName=TEXT("window"); VOID CALLBACK myTimerShow(HWND hwnd, UINT uMsg,UINT_PTR idEvent, DWORD dwTime ); HWND initBt(HWND hwnd,HINSTANCE instance); HWND winHwnd; SYSTEMTIME systime; WNDCLASS regWinClass(HINSTANCE hInstance ) { WNDCLASS wnd; wnd.cbClsExtra=0; wnd.cbWndExtra=0; wnd.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH) ; wnd.lpfnWndProc=winproc; wnd.hInstance=hInstance; wnd.hIcon=LoadIcon(NULL,IDI_ASTERISK); wnd.lpszMenuName=NULL; wnd.style= CS_HREDRAW | CS_VREDRAW ; wnd.lpszClassName=szAppName; wnd.hCursor=LoadCursor(NULL,IDC_ARROW); return wnd; } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstancd,LPSTR szCmdLine,int iCmdShow) { HWND hwnd ; MSG msg ; WNDCLASS _winClass=regWinClass(hInstance); if (!RegisterClass(&_winClass)) { MessageBox (NULL,TEXT("This program requires Windows NT!"),szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow( szAppName, // window class name TEXT ("The Hello Program"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT,// initial x position CW_USEDEFAULT,// initial y position CW_USEDEFAULT,// initial x size CW_USEDEFAULT,// initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ; // creation parameter ShowWindow (hwnd, iCmdShow) ; SetTimer(hwnd,1,1000,myTimerShow); winHwnd=hwnd; HWND btWnd= initBt(hwnd,hInstance); UpdateWindow (hwnd) ; // btproc=SetWindowLong(btWnd,GWL_WNDPROC,(long)winproc); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK winproc(HWND hwnd ,UINT message,WPARAM wParam,LPARAM lParam) { PAINTSTRUCT ps ; switch (message) { case WM_CREATE: { TCHAR *test=L"test"; SendMessage(hwnd,12345,(WPARAM)test,120); return 0; } case 12345: { //SHOWMSG TCHAR *t=(TCHAR*)wParam; CString str; str.Format(L"%s",t); // MessageBox(hwnd,t,L"",MB_OK); return 0; } case WM_COMMAND: { switch (wParam) { case ID_SMALLER: MessageBox(hwnd,L"j",L"j",MB_OK); break; } return 0; } case WM_TIMER: { return 0; } case WM_PAINT: { TCHAR *userName=TEXT("java home"); HDC hdc= BeginPaint(hwnd,&ps); TextOut(hdc,10,10,userName,wcslen(userName)); Arc(hdc,10,10,200,300,50,60,200,250); EndPaint(hwnd,&ps); delete userName; return 0; } case WM_DESTROY: { KillTimer(hwnd,1); PostQuitMessage(0) ; return 0 ; } case WM_SIZE: { return 0; } } return DefWindowProc(hwnd, message, wParam, lParam) ; } VOID CALLBACK myTimerShow(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime ) { GetSystemTime(&systime); CString str; str.Format(L"%d-%d-%d:%d:%d:%d",systime.wYear ,systime.wMonth ,systime.wDay, systime.wHour, systime.wMinute ,systime.wSecond ); SetWindowText(winHwnd,str); } /* HWND CreateWindow( LPCTSTR lpClassName, // registered class name LPCTSTR lpWindowName, // window name DWORD dwStyle, // window style int x, // horizontal position of window int y, // vertical position of window int nWidth, // window width int nHeight, // window height HWND hWndParent, // handle to parent or owner window HMENU hMenu, // menu handle or child identifier HINSTANCE hInstance, // handle to application instance LPVOID lpParam // window-creation data ); */ HWND initBt(HWND hwnd,HINSTANCE instance) { HWND btHandle=CreateWindow(L"button",L"确定",WS_CHILD|WS_VISIBLE, 10,30,160,25,hwnd,(HMENU)ID_SMALLER,instance,NULL); return btHandle; } LRESULT CALLBACK btproc(HWND hwnd ,UINT message,WPARAM wParam,LPARAM lParam) { return DefWindowProc(hwnd, message, wParam, lParam) ; }

你可能感兴趣的:(windows,J#)