典型的Hello world!版,用windows的API,注册窗口类,创建窗口,显示窗口,
消息处理,我想要个模板,用来学习,以前有的,找不到了,来此求一个。
谁的代码比较全的,20分果断给,果断结贴。

解决方案 »

  1.   

    Windows SDK里的各种Sample应该可以满足你的需求。
      

  2.   

    #include<windows.h>
    #include<stdio.h>LRESULT CALLBACK WindowProc(
    HWND hwnd, // handle to window
    UINT uMsg, // message identifier
    WPARAM wParam, // first message parameter
    LPARAM lParam // second message parameter
    );HWND hwnd = 0;
    char _szAppName[100] = "AppName";
    char _szTitle[] = "tilte";int WINAPI WinMain(
       HINSTANCE hInstance, // handle to current instance
       HINSTANCE hPrevInstance, // handle to previous instance
       LPSTR lpCmdLine, // pointer to command line
       int nCmdShow // show state of window
       )
    {
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
    wndcls.hIcon=LoadIcon(NULL, IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc= WindowProc; 
    wndcls.lpszClassName= _szAppName; 
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW|CS_VREDRAW;

    BOOL bReg = RegisterClass(&wndcls);

    hwnd=CreateWindow(_szAppName,_szTitle,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
    ShowWindow(hwnd,SW_SHOW);
    UpdateWindow(hwnd);

    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return 0;
    }
    LRESULT CALLBACK WindowProc(
    HWND hwnd, // handle to window
    UINT uMsg, // message identifier
    WPARAM wParam, // first message parameter
    LPARAM lParam // second message parameter
    )
    {
    HDC hdc;
    PAINTSTRUCT ps;
    switch(uMsg)
    {
    case WM_CHAR:
    char szChar[20];
    sprintf(szChar,"char is %d",wParam);
    MessageBox(hwnd,szChar,"输入字符",MB_YESNO);
    break;
    case WM_LBUTTONDOWN:
    MessageBox(hwnd,"mouse click","左键按下",MB_OK);
    HDC hDC;
    hDC=GetDC(hwnd);
    TextOut(hDC,0,50,"我勒个去去",strlen("我勒个去去"));
    ReleaseDC(hwnd,hDC);
    break;
    case WM_PAINT:
    hdc=BeginPaint(hwnd,&ps);
    TextOut(hdc,0,0,"生活为了什么",strlen("生活为了什么"));
    EndPaint(hwnd,&ps);
    break;
    case WM_CLOSE:
    if(IDYES==MessageBox(hwnd,"是否要退出程序","明明",MB_YESNO))
    {
    DestroyWindow(hwnd);
    }
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return (DefWindowProc(hwnd,uMsg,wParam,lParam));
    }
    return 0;
    }