我们是学习计算机的,我的一个实习是用API做一个Windows的窗口
我不会用API做Windows的窗口,请问什么做啊 
WinMain 和WndProc 函数该怎么用啊??

解决方案 »

  1.   

    程序清单
    simpwin.c程序如下#include <windows.h>
    #include <string.h>
    #include "simpwin.h"HINSTANCE hInst;
    HWND hWndMain;int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
    MSG msg;
    if(!InitApplication(hInstance))
    return(FALSE); if(!InitInstance(hInstance,nCmdShow))
    return(FALSE); while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    } return (msg.wParam);
    }BOOL InitApplication(HINSTANCE hInstance)
    {
    WNDCLASS wcSimpwin;
    wcSimpwin.style = 0;
    wcSimpwin.lpfnWndProc = (WNDPROC)MainWndProc;
    wcSimpwin.cbClsExtra = 0;
    wcSimpwin.cbWndExtra = 0;
    wcSimpwin.hInstance = hInstance;
    wcSimpwin.hIcon = NULL;
    wcSimpwin.hCursor = NULL;
    wcSimpwin.hbrBackground = GetStockObject(WHITE_BRUSH);
    wcSimpwin.lpszMenuName = NULL;
    wcSimpwin.lpszClassName = "SimpwinWClass"; return (RegisterClass(&wcSimpwin));
    }
    BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
    {
    hInst = hInstance;
    hWndMain = CreateWindow("SimpwinWClass","我的第一个窗口",WS_OVERLAPPEDWINDOW,0,0,400,400,NULL,NULL,hInstance,NULL);

    if(!hWndMain)
    {
    return(FALSE);
    } ShowWindow(hWndMain,nCmdShow);
    UpdateWindow(hWndMain);
    return(TRUE);
    }LRESULT CALLBACK MainWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    HDC hdc;
    PAINTSTRUCT ps; switch(message)
    {
    case WM_PAINT:
    hdc = BeginPaint(hWnd,&ps);
    TextOut(hdc,20,10,hello,lstrlen(hello));
    EndPaint(hWnd,&ps);
    break; case WM_DESTROY:
    PostQuitMessage(0);
    break; default:
    return(DefWindowProc(hWnd,message,wParam,lParam));
    } return(0);
    }
    simpwin.h程序如下LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);
    BOOL InitApplication(HINSTANCE);
    BOOL InitInstance(HINSTANCE,int);char *hello = "窗口外的世界很精彩,窗口内的天地也很奇妙";
      

  2.   

    VS 2003 的向导会自动生成的, 你新建项目时选  win2项目就行了