|

楼主 |
发表于 2013-1-22 22:14:03
|
显示全部楼层
hy19970612 发表于 2013-1-22 22:05
窗口 过程函数 也上来 - #include "Windows.h"
- #include "tchar.h"
- HWND hWinMain;
- TCHAR szClassName[] = _T("MyClass");
- TCHAR szCaptionMain[] = _T("My First Window!");
- TCHAR FontName[] = _T("宋体");
- WNDCLASSEX stdWndClass;
- WPARAM keyChar = 0x20; //0x20 是空格的ascii 码,保证没有按键的时候程序正常显示。
- BOOL MouseClick = FALSE;
- POINT hitPoint;
- LRESULT CALLBACK ProcWinMain( HWND hWnd,
- UINT Msg,
- WPARAM wParam,
- LPARAM lParam
- )
- {
- PAINTSTRUCT stPs;
- HDC hDC;
- HFONT hFont,hOldFont;
- switch(Msg)
- {
- case WM_PAINT:
- {
- hDC = BeginPaint(hWnd,&stPs);
- hFont = CreateFont(24,16,0,0,400,0,0,0,OEM_CHARSET,OUT_DEFAULT_PRECIS,
- CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,FontName);
- hOldFont = (HFONT)SelectObject(hDC,hFont);
- SetTextColor(hDC,RGB(200,200,50));
- SetBkColor(hDC,RGB(0,0,255));
- TextOut(hDC,0,0,(char *)&keyChar,1);
- if(MouseClick)
- {
- TextOut(hDC,hitPoint.x,hitPoint.y,szCaptionMain,lstrlen(szCaptionMain));
- }
- SelectObject(hDC,hOldFont);
- EndPaint(hWnd,&stPs);
- }
- break;
- case WM_LBUTTONDOWN:
- {
- hitPoint.x = LOWORD(lParam);
- hitPoint.y = HIWORD(lParam);
- MouseClick = TRUE;
- InvalidateRect(hWnd,NULL,FALSE);
- }
- break;
- case WM_RBUTTONDOWN:
- {
- hitPoint.x=LOWORD(lParam);
- hitPoint.y = HIWORD(lParam);
- MouseClick = TRUE;
- InvalidateRect(hWnd,NULL,FALSE);
- }
- break;
- case WM_CHAR:
- {
- keyChar = wParam;
- InvalidateRect(hWnd,NULL,TRUE);
- }
- break;
- case WM_DESTROY:
- {
- PostQuitMessage(NULL);
- }
- break;
- default:
- return DefWindowProc(hWnd, Msg, wParam, lParam );
- }
- return 0;
- }
- int WINAPI WinMain( HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow
- )
- {
- MSG stMsg;
- WNDCLASSEX stdWndClass;
- RtlZeroMemory(&stdWndClass, sizeof(stdWndClass));
- stdWndClass.hCursor = LoadCursor(0,IDC_ARROW);
- stdWndClass.cbSize = sizeof(stdWndClass);
- stdWndClass.style = CS_HREDRAW|CS_VREDRAW;
- stdWndClass.lpfnWndProc = ProcWinMain;
- stdWndClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
- stdWndClass.lpszClassName = szClassName;
- stdWndClass.hInstance = hInstance;
- RegisterClassEx(&stdWndClass);
- hWinMain = CreateWindowEx(WS_EX_CLIENTEDGE,szClassName,szCaptionMain,\
- WS_OVERLAPPEDWINDOW,100,100,600,400,NULL,NULL,hInstance,NULL);
- if(!hWinMain)
- return 0;
- ShowWindow(hWinMain,SW_SHOWNORMAL);
- UpdateWindow(hWinMain);
- while(TRUE)
- {
- if (GetMessage(&stMsg,NULL,0,0))
- {
- TranslateMessage(&stMsg);
- DispatchMessage(&stMsg);
- }
- }
- return stMsg.wParam;
- }
复制代码 |
|