看一哈,哪有问题吖?我研究了好长时间#include<windows.h>
#include<stdio.h>LRESULT    CALLBACK   WinMuPro(
HWND   hwnd,
    UINT   uMsg,
WPARAM wParam,
LPARAM lParam  );int  WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND  hwnd;
MSG   msg;
WNDCLASS  wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WinMuPro;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0; wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL, IDC_UPARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wndclass.hInstance = hInstance; wndclass.lpszClassName = TEXT("Janear");
wndclass.lpszMenuName = NULL;//注册窗口
if(!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("Hello Win 7!"), NULL, MB_HELP);
return 0;
}//创建窗口
hwnd = CreateWindow(TEXT("WinMain"),
TEXT("Janear"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return  msg.wParam;
}
LRESULT    CALLBACK   WinMuPro(
HWND   hwnd,
    UINT   uMsg,
WPARAM wParam,
LPARAM lParam  ){
HDC   hdc;
PAINTSTRUCT  ps;
RECT  rc; switch(uMsg)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
DrawText(hdc, TEXT("HelloWIn!"), -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
MessageBox(hwnd, TEXT("北京维新科学技术培训中心"),TEXT("维新"),MB_OK);
EndPaint(hwnd, &ps);
break;
case WM_CHAR:
char  str[20];
sprintf(str,"char is %d", wParam);
MessageBox(hwnd, str, "维新", MB_OK);
break;
case WM_CLOSE:
if(IDYES == MessageBox(hwnd, TEXT("你真的是否退出程序?"), "Yeah", MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_LBUTTONDOWN:
 MessageBox(hwnd, TEXT("Mouse Click!"),"维新", 0);
 hdc = GetDC(hwnd);
 TextOut(hdc, 0, 100, "计算机培训中心", strlen( "计算机培训中心"));
 ReleaseDC(hwnd, hdc);
 break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);

}
return 0;
}

解决方案 »

  1.   

    窗口出不来。初步猜测是创建窗口那块有问题吖
    看一哈,哪有问题吖?我研究了好长时间#include<windows.h>
    #include<stdio.h>LRESULT CALLBACK WinMuPro(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam );int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    HWND hwnd;
    MSG msg;
    WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WinMuPro;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.hCursor = LoadCursor(NULL, IDC_UPARROW);
    wndclass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    wndclass.hInstance = hInstance;wndclass.lpszClassName = TEXT("Janear");
    wndclass.lpszMenuName = NULL;//注册窗口 
    if(!RegisterClass(&wndclass))
    {
    MessageBox(NULL, TEXT("Hello Win 7!"), NULL, MB_HELP);
    return 0;
    }//创建窗口
    hwnd = CreateWindow(TEXT("WinMain"),
    TEXT("Janear"),
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    NULL,
    NULL,
    hInstance,
    NULL
    );
    单步调试时,hwnd为空
      

  2.   


    窗口出不来。初步猜测是创建窗口那块有问题吖
    看一哈,哪有问题吖?我研究了好长时间单步调试,hwnd为空。。
      

  3.   

    CreateWindow(TEXT("Janear"),
    这样创立窗口即可,你创建的窗体类名很重要,它将你的wndproc与hwnd关联起来,所以createwindow要用你自己的类名来创建。
      

  4.   

    wndclass.lpszClassName = TEXT("Janear");hwnd = CreateWindow(TEXT("WinMain"),
    你注册的类名为Janear,而你创建窗口指定的类名为WinMain,两者不一致,所以出现不了窗口,改成一样即可。