游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1611|回复: 3

找不出问题,但没有显示

[复制链接]

6

主题

17

帖子

50

积分

注册会员

Rank: 2

积分
50
发表于 2007-5-6 10:38:00 | 显示全部楼层 |阅读模式
// youyici.cpp : Defines the entry point for the application.
//

#include "stdafx.h"


HINSTANCE hInst;
LRESULT CALLBACK MainWndProc(HWND ,UINT ,WPARAM ,LPARAM );
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
        // TODO: Place code here.
        char szClassName[] = "MainWclass";
        WNDCLASSEX wc;
       
        wc.cbSize =sizeof(WNDCLASSEX);
        wc.style =CS_HREDRAW|CS_VREDRAW;
        wc.lpfnWndProc =(WNDPROC)MainWndProc;  
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = :oadIcon(NULL,IDI_APPLICATION);
        wc.hCursor =::LoadCursor(NULL,IDC_ARROW);
        wc.hbrBackground =(HBRUSH)::GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName =NULL;
        wc.lpszClassName =szClassName;
        wc.hIconSm =NULL;


        if(::RegisterClassEx(&wc) == NULL)
        {
                ::MessageBox(NULL,"","error1",MB_OK);
                return -1;
        }
        hInst = hInstance;
        HWND hwnd = ::CreateWindowEx(
                                0,
                                szClassName,
                                "My First Window!",
                                WS_OVERLAPPEDWINDOW,
                                CW_USEDEFAULT,
                                CW_USEDEFAULT,
                                CW_USEDEFAULT,
                                CW_USEDEFAULT,
                                NULL,
                                NULL,
                                hInstance,
                                NULL);
        if(hwnd = NULL)
        {
                ::MessageBox(NULL,"","error2",MB_OK);
                return -1;
        }

        ::ShowWindow(hwnd,nCmdShow);
        ::UpdateWindow(hwnd);

        MSG msg;

        while(::GetMessage(&msg,NULL,0,0))
        {
                ::TranslateMessage(&msg);
                :ispatchMessage(&msg);

       
        }

        return msg.wParam;
}

LRESULT CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{

        switch( message )
        {


                case WM_PAINT:                //在后台窗口模式时
                        {       
                                PAINTSTRUCT                ps;
                                HDC                                hdc;
                                hdc=::BeginPaint(hwnd,&ps);
                                ::TextOut(hdc,10,10,"mother",strlen("mother"));
                                ::EndPaint(hwnd,&ps);
                                return 0;
                        }
                       
                case WM_DESTROY:
                        PostQuitMessage(0);
                        return 0;
                default:
                        return DefWindowProc(hwnd, message, wParam, lParam);
               
        }
                return 0;
}

6

主题

17

帖子

50

积分

注册会员

Rank: 2

积分
50
 楼主| 发表于 2007-5-6 11:27:00 | 显示全部楼层

Re:找不出问题,但没有显示

if(hwnd = NULL)
{
::MessageBox(NULL,"","error2",MB_OK);
return -1;
}
晕 错在不是赋值 应该是==判断!真是打错一个字母害死人!

21

主题

100

帖子

100

积分

注册会员

Rank: 2

积分
100
QQ
发表于 2007-5-6 16:56:00 | 显示全部楼层

Re:找不出问题,但没有显示

- -! 也许if( NULL == hwnd )这样写会好点吧

16

主题

280

帖子

280

积分

中级会员

Rank: 3Rank: 3

积分
280
QQ
发表于 2007-5-8 20:45:00 | 显示全部楼层

Re: 找不出问题,但没有显示

[em15]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-4-12 05:19

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表