我在VS6.0下用win32 application创建了一个工程,文件内容如下#include <windows.h>
#include <stdio.h>long CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);int WINAPI WinMain(
HINSTANCE hInstance, 
HINSTANCE hPrevInstance, 
LPSTR lpCmdLine, 
int nShowCmd)
{
WNDCLASSEX stMyclass;
MSG stMsg; HWND hWindow; 
//char* ClassName = "MyClass";
//char* CaptionName = "时钟";// 注册窗口类
RtlZeroMemory(&stMyclass, sizeof(stMyclass));
stMyclass.cbSize = sizeof(stMyclass);
stMyclass.hInstance = hInstance;
stMyclass.hIcon = LoadIcon(0, IDI_APPLICATION);
stMyclass.hIconSm = LoadIcon(0, IDI_APPLICATION);
stMyclass.hCursor = LoadCursor(0, IDC_ARROW);
stMyclass.lpszClassName = "MyClass";
stMyclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
stMyclass.style = CS_HREDRAW | CS_VREDRAW;
stMyclass.lpfnWndProc = WinProc;
RegisterClassEx(&stMyclass);
// 创建窗口
hWindow = CreateWindowEx(WS_EX_CLIENTEDGE, "MyClass", "Clock", 
WS_OVERLAPPEDWINDOW, 200, 200, 200, 200, NULL, NULL, hInstance, NULL);
ShowWindow(hWindow, SW_SHOWNORMAL);
UpdateWindow(hWindow);
// 消息循环
while (GetMessage(&stMsg, NULL, 0, 0))
{
TranslateMessage(&stMsg);
DispatchMessage(&stMsg);
}
return 0;
}long CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_CREATE)
{
MessageBox(hWnd, "创建窗口", "aaa", MB_OK);
}
else if (uMsg == WM_CLOSE)
{
PostQuitMessage(0);
DestroyWindow(hWnd);
}
else
DefWindowProc(hWnd, uMsg, wParam, lParam);return 0;
}
编译一点问题没有,为啥运行后窗口就是不出来呢

解决方案 »

  1.   

    CreateWindowEx返回的hWindow是0,有木有人说说呀
      

  2.   

    WM_CREATE返回0;你说,它还能出来吗?
    WinProc设计有问题
      

  3.   

    long CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

    if (uMsg == WM_CREATE) 

    MessageBox(hWnd, "创建窗口", "aaa", MB_OK); 

    else if (uMsg == WM_CLOSE) 

    PostQuitMessage(0); 
    DestroyWindow(hWnd); 

    return DefWindowProc(hWnd, uMsg, wParam, lParam);;
    }
      

  4.   


    我问的就是为什么返回0,我用win32汇编写运行都是正常的
      

  5.   


    谢谢哈,明白了,改成这样子也可以,是吧O(∩_∩)O~long CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    if (uMsg == WM_CREATE)
    {
    MessageBox(hWnd, "创建窗口", "aaa", MB_OK);
    }
    else if (uMsg == WM_CLOSE)
    {
    PostQuitMessage(0);
    DestroyWindow(hWnd);
    }
    else
    {
    DefWindowProc(hWnd, uMsg, wParam, lParam);
    return 1;
    } return 0;
    }
      

  6.   

    long CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    if (uMsg == WM_CREATE)
    {
    MessageBox(hWnd, "创建窗口", "aaa", MB_OK);
    }
    else if (uMsg == WM_CLOSE)
    {
    PostQuitMessage(0);
    DestroyWindow(hWnd);
    }
    else
    return DefWindowProc(hWnd, uMsg, wParam, lParam); //改这一句增加 return 

    return 0;
    }
    调用 DefWindowProc 后不要再 reuturn 0,否则系统认为“无事可干”了。
      

  7.   

    把你的窗口过程函数的最后一个语句return 0;改成return DefWindowProc(hWnd, uMsg, wParam, lParam);long CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

    if (uMsg == WM_CREATE) 

    MessageBox(hWnd, "创建窗口", "aaa", MB_OK); 

    else if (uMsg == WM_CLOSE) 

    PostQuitMessage(0); 
    DestroyWindow(hWnd); 

    else 
    DefWindowProc(hWnd, uMsg, wParam, lParam);return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    改完后的全部代码为:#include <windows.h>
    #include <stdio.h>long CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);int WINAPI WinMain(
    HINSTANCE hInstance,  
    HINSTANCE hPrevInstance,  
    LPSTR lpCmdLine,  
    int nShowCmd)

    WNDCLASSEX stMyclass; 
    MSG stMsg; HWND hWindow;  
    //char* ClassName = "MyClass"; 
    //char* CaptionName = "时钟";// 注册窗口类 
    RtlZeroMemory(&stMyclass, sizeof(stMyclass)); 
    stMyclass.cbSize = sizeof(stMyclass); 
    stMyclass.hInstance = hInstance; 
    stMyclass.hIcon = LoadIcon(0, IDI_APPLICATION); 
    stMyclass.hIconSm = LoadIcon(0, IDI_APPLICATION); 
    stMyclass.hCursor = LoadCursor(0, IDC_ARROW); 
    stMyclass.lpszClassName = "MyClass"; 
    stMyclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 
    stMyclass.style = CS_HREDRAW | CS_VREDRAW; 
    stMyclass.lpfnWndProc = WinProc; 
    RegisterClassEx(&stMyclass); 
    // 创建窗口 
    hWindow = CreateWindowEx(WS_EX_CLIENTEDGE, "MyClass", "Clock",  
    WS_OVERLAPPEDWINDOW, 200, 200, 200, 200, NULL, NULL, hInstance, NULL); 
    ShowWindow(hWindow, SW_SHOWNORMAL); 
    UpdateWindow(hWindow);
    // 消息循环 
    while (GetMessage(&stMsg, NULL, 0, 0)) 

    TranslateMessage(&stMsg); 
    DispatchMessage(&stMsg); 
    }
    return 0;
    }long CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

    if (uMsg == WM_CREATE) 

    MessageBox(hWnd, "创建窗口", "aaa", MB_OK); 

    else if (uMsg == WM_CLOSE) 

    PostQuitMessage(0); 
    DestroyWindow(hWnd); 

    else 
    DefWindowProc(hWnd, uMsg, wParam, lParam);return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }记得把分给我。
      

  8.   


    谢谢你的回答,但分已经给3L的兄弟了,不好意思O(∩_∩)O~