WINCE6.0中的“hello world”,7月15日

来源:互联网 发布:ubuntu安装步骤 编辑:程序博客网 时间:2024/06/18 01:44

WINCE6.0中的“hello world”

#include <Windows.h>LRESULT CALLBACK  myWNDPROC(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);int WinMain( HINSTANCE hInstance, //句柄HINSTANCE hPrevInstance,  LPSTR lpCmdLine, //应用程序的启动参数 int nShowCmd) //显示方式{//创建一个窗体类对象WNDCLASS ws;HWND hwnd;MSG msgs;int nCmdShow;ws.cbClsExtra = 0;ws.cbWndExtra = 0;ws.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);ws.hCursor = NULL;ws.hIcon = NULL;ws.hInstance = hInstance;ws.lpfnWndProc = myWNDPROC;    ws.lpszClassName = TEXT("hello");ws.lpszMenuName = NULL;ws.style = CS_VREDRAW | CS_HREDRAW;//注册窗体类if(!RegisterClass(&ws)) return -1;//创建窗体hwnd = CreateWindow(TEXT("hello"),TEXT("my first windows"),WS_VISIBLE|WS_BORDER,10,10,400,300,NULL,NULL,hInstance,NULL);//更新窗体内容UpdateWindow(hwnd);ShowWindow(hwnd,nCmdShow);//获取windows消息并进行发送while(GetMessage(&msgs,NULL,0,0)){TranslateMessage(&msgs);DispatchMessage(&msgs);}return 1;}CALLBACK myWNDPROC(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){if(msg == WM_DESTROY){PostQuitMessage(1);}return DefWindowProc(hwnd,msg,wParam,lParam);}


在以上代码基础上在进行修改,实现文字显示。

#include <Windows.h>LRESULT CALLBACK  myWNDPROC(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);int WinMain( HINSTANCE hInstance, //句柄HINSTANCE hPrevInstance,  LPSTR lpCmdLine, //应用程序的启动参数 int nShowCmd) //显示方式{//创建一个窗体类对象WNDCLASS ws;HWND hwnd;MSG msgs;int nCmdShow;ws.cbClsExtra = 0;ws.cbWndExtra = 0;ws.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);ws.hCursor = NULL;ws.hIcon = NULL;ws.hInstance = hInstance;ws.lpfnWndProc = myWNDPROC;    ws.lpszClassName = TEXT("hello");ws.lpszMenuName = NULL;ws.style = CS_VREDRAW | CS_HREDRAW;//注册窗体类if(!RegisterClass(&ws)) return -1;//创建窗体hwnd = CreateWindow(TEXT("hello"),TEXT("my first windows"),WS_VISIBLE|WS_BORDER|WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_CAPTION,10,10,400,300,NULL,NULL,hInstance,NULL);//更新窗体内容UpdateWindow(hwnd);ShowWindow(hwnd,nCmdShow);//获取windows消息并进行发送while(GetMessage(&msgs,NULL,0,0)){TranslateMessage(&msgs);DispatchMessage(&msgs);}return 1;}CALLBACK myWNDPROC(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){PAINTSTRUCT ps;HDC hdc;//设备环境RECT rect;GetClientRect(hwnd,&rect);if(msg == WM_DESTROY){PostQuitMessage(1);}if(msg==WM_PAINT){hdc=BeginPaint(hwnd,&ps);DrawText(hdc,TEXT("hello world"),-1,&rect,DT_VCENTER|DT_CENTER);EndPaint(hwnd,&ps);}return DefWindowProc(hwnd,msg,wParam,lParam);}