游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1913|回复: 1

大家帮我看看这个基于SDK的对话框程序

[复制链接]

6

主题

65

帖子

67

积分

注册会员

Rank: 2

积分
67
发表于 2007-10-29 21:16:00 | 显示全部楼层 |阅读模式
这个程序几乎是从教程上照搬下来的,总是不能运行成功,说生成窗口失败。

大家帮我看看原因,谢谢了。
我上传了附件,很小,只有5k,可以下载在vc6下跑一下看。
---------------------------myDlg.cpp----------------------------------
#include <windows.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,                                       
                                        PSTR szCmdLine, int iCmdShow)                                       
{       
        static TCHAR szAppName[] = TEXT ("myDlg") ;       
        HWND                          hwnd ;       
        MSG                           msg ;       
        WNDCLASS                      wndclass ;
       
        wndclass.style                       = CS_HREDRAW | CS_VREDRAW;       
        wndclass.lpfnWndProc                 = WndProc ;       
        wndclass.cbClsExtra                  = 0 ;       
        wndclass.cbWndExtra                  = DLGWINDOWEXTRA ;                // Note!       
        wndclass.hInstance                   = hInstance ;       
        wndclass.hIcon                       = LoadIcon (hInstance, szAppName) ;       
        wndclass.hCursor                     = LoadCursor (NULL, IDC_ARROW) ;       
        wndclass.hbrBackground               = (HBRUSH) (COLOR_BTNFACE + 1) ;       
        wndclass.lpszMenuName                = NULL ;       
        wndclass.lpszClassName               = szAppName ;       
       
       
        if (!RegisterClass (&wndclass))        
          {        
                MessageBox (  NULL, TEXT ("This program requires Windows NT!"),                       
                        szAppName, MB_ICONERROR) ;        
                return 0 ;        
        }
       
        hwnd = CreateDialog (hInstance, szAppName, 0, NULL) ;
        if(!hwnd){
                MessageBox(NULL, "create dialog failure!", "error", MB_ICONERROR);
                return 1;
        }
       
        ShowWindow (hwnd, iCmdShow) ;
       
        while (GetMessage (&msg, NULL, 0, 0))        
        {        
                TranslateMessage (&msg) ;        
                DispatchMessage (&msg) ;        
           }
       
        return msg.wParam ;       
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)        
{        
        switch (message)        
        {
        case   WM_DESTROY:
                PostQuitMessage (0) ;
                return 0 ;
        }
       
        return DefWindowProc (hwnd, message, wParam, lParam) ;
}

----------------------------------------------------------------------------------
----------------------myDlg.rc------------------------------------------
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#include "afxres.h"


myDlg DIALOG DISCARDABLE  0, 0, 187, 66
STYLE WS_OVERLAPPED| WS_CAPTION | WS_SYSMENU
CLASS        "myDlg"
CAPTION "sdk对话框"
CLASS "myDlg"
FONT 10, "System"
BEGIN
END

myDlg                   ICON    DISCARDABLE     "icon1.ico"

------------------------------------------------------------------
----------------------resource.h---------------------------------
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by myDlg.rc
//
#define myDlg                           101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        103
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif
---------------------------------------------------------

sf_20071029211550.rar

4.31 KB, 下载次数:

6

主题

65

帖子

67

积分

注册会员

Rank: 2

积分
67
 楼主| 发表于 2007-10-29 21:35:00 | 显示全部楼层

Re:大家帮我看看这个基于SDK的对话框程序

好了,我搞定了。
程序里面使得对话框资源和图标资源的ID重复了,所以会出错。
现在搞定了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-6-19 11:49

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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