VC6.0 用api新建一个窗口却显示不出来

按照书上讲的编了一个Windos窗口,编译后显示没有错误却无法显示出窗口代码如下:#include"windows.h"#include"resource.h"LRESU... 按照书上讲的编了一个Windos窗口,编译后显示没有错误却无法显示出窗口
代码如下:
#include"windows.h"
#include"resource.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdline,
int nCmdShow)
{
WNDCLASS wcApp;
MSG msg;
HWND ghWnd=NULL;
char*szAppName="Windows API Application";
char*szAppTitle="Windows API 窗口程序";
wcApp.style=CS_HREDRAW;
wcApp.lpfnWndProc=WndProc;
wcApp.cbWndExtra=0;
wcApp.cbClsExtra=0;
wcApp.hInstance=hInstance;
wcApp.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wcApp.hbrBackground=(HBRUSH)COLOR_WINDOW;
wcApp.lpszMenuName=NULL;
wcApp.lpszClassName=szAppName;
RegisterClass(&wcApp);
ghWnd=CreateWindow(szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
100,
100,
350,
300,
NULL,
NULL,
hInstance,
NULL);
if(NULL==ghWnd)
return 0;
ShowWindow(ghWnd,SW_SHOWNORMAL);
UpdateWindow(ghWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
LPCSTR lpszCreate="收到WM_CREATE消息,建立窗口";
LPCSTR lpszDestroy="收到WM_DESTROY消息,窗口关闭";
LPCSTR lpszCaption="收到消息";
LPCSTR lpszLBTN="鼠标左键按下,收到WM_LBUTIONDOWN消息";
LPCSTR lpszExit="你确定要退出么?";
switch(message)
{
case WM_CREATE:
MessageBox(GetFocus(),lpszCreate,lpszCaption,MB_OK|MB_ICONEXCLAMATION);
break;

case WM_LBUTTONDOWN:
MessageBox(GetFocus(),lpszLBTN,lpszCaption,MB_OK|MB_ICONINFORMATION);
break;

case WM_KEYDOWN:
if(wParam==VK_ESCAPE)
SendMessage(hwnd,WM_CLOSE,NULL,NULL);
break;
case WM_CLOSE:
if(MessageBox(NULL,lpszExit,lpszCaption,MB_YESNO|MB_DEFBUTTON2|MB_ICONASTERISK)==IDYES)
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return FALSE;
}
望大神给予帮助
展开
 我来答
龚炜林
2014-04-21 · TA获得超过1560个赞
知道大有可为答主
回答量:1102
采纳率:66%
帮助的人:583万
展开全部
#include"windows.h"
#include"resource.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdline,
                   int nCmdShow)
{
    WNDCLASS wcApp;
    MSG msg;
    HWND ghWnd=NULL;
    char*szAppName="Windows API Application";
    char*szAppTitle="Windows API 窗口程序";
    wcApp.style=CS_HREDRAW|CS_VREDRAW;       // 此处修改
    wcApp.lpfnWndProc=WndProc;
    wcApp.cbWndExtra=0;
    wcApp.cbClsExtra=0;
    wcApp.hInstance=hInstance;
    wcApp.hCursor = LoadCursor (NULL, IDC_ARROW); // 此处修改
    wcApp.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
    wcApp.hbrBackground=(HBRUSH)COLOR_WINDOW;
    wcApp.lpszMenuName=NULL;
    wcApp.lpszClassName=szAppName;
    RegisterClass(&wcApp);
    ghWnd=CreateWindow(szAppName,
                       szAppTitle,
                       WS_OVERLAPPEDWINDOW,
                       100,
                       100,
                       350,
                       300,
                       NULL,
                       NULL,
                       hInstance,
                       NULL);
    if(NULL==ghWnd)
        return 0;
    ShowWindow(ghWnd,SW_SHOWNORMAL);
    UpdateWindow(ghWnd);
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}
//////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hwnd,
                         UINT message,
                         WPARAM wParam,
                         LPARAM lParam)
{
   LPCSTR lpszCreate="收到WM_CREATE消息,建立窗口";                    
    LPCSTR lpszDestroy="收到WM_DESTROY消息,窗口关闭";
    LPCSTR lpszCaption="收到消息";
    LPCSTR lpszLBTN="鼠标左键按下,收到WM_LBUTIONDOWN消息";
    LPCSTR lpszExit="你确定要退出么?";
    switch(message)
    {
    case WM_CREATE:
         MessageBox(GetFocus(),lpszCreate,lpszCaption,MB_OK|MB_ICONEXCLAMATION);
         break;

    case WM_LBUTTONDOWN:
         MessageBox(GetFocus(),lpszLBTN,lpszCaption,MB_OK|MB_ICONINFORMATION);
         break;
    
    case WM_KEYDOWN:
         if(wParam==VK_ESCAPE)
             SendMessage(hwnd,WM_CLOSE,NULL,NULL);
         break;
    case WM_CLOSE:
        if(MessageBox(NULL,lpszExit,lpszCaption,MB_YESNO|MB_DEFBUTTON2|MB_ICONASTERISK)==IDYES)
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
         PostQuitMessage(0);
         break;
    default:
        break; // 此处修改
    }
    return DefWindowProc(hwnd,message,wParam,lParam); // 此处修改
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式