《Windows程序设计》学习笔记(chap11 对话框)-->重写俄罗斯方块代码

来源:互联网 发布:url 加密数组php 编辑:程序博客网 时间:2024/05/06 04:46

自己学做个俄罗斯方块代码,真是困难重重,开始游戏是的游戏设置对话框对话框都做不出来,继续学习……

想用个dialogbox函数,却总也弹不出来,先把该函数的MSDN定义写一下:

DialogBox Function


The DialogBox macro creates a modal dialog box from a dialog box template resource. DialogBox does not return control until the specified callback function terminates the modal dialog box by calling the EndDialog function. The DialogBox macro uses the DialogBoxParam function.

Syntax

INT_PTR DialogBox(      

    HINSTANCE hInstance,     LPCTSTR lpTemplate,     HWND hWndParent,     DLGPROC lpDialogFunc);

Parameters

hInstance
[in] Handle to the module whose executable file contains the dialog box template.
lpTemplate
[in] Specifies the dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can use the MAKEINTRESOURCE macro to create this value.
hWndParent
[in] Handle to the window that owns the dialog box.
lpDialogFunc
[in] Pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc.

Return Value

If the function succeeds, the return value is the nResult parameter in the call to the EndDialog function used to terminate the dialog box.

If the function fails because the hWndParent parameter is invalid, the return value is zero. The function returns zero in this case for compatibility with previous versions of Microsoft Windows. If the function fails for any other reason, the return value is –1. To get extended error information, call GetLastError.

This function typically fails for one of the following reasons:

  • an invalid parameter value
  • the system class was registered by a different module
  • The WH_CBT hook is installed and returns a failure code
  • if one of the controls in the dialog template is not registered, or its window window procedure fails WM_CREATE or WM_NCCREATE

Remarks

The DialogBox macro uses the CreateWindowEx function to create the dialog box. DialogBox then sends a WM_INITDIALOG message (and a WM_SETFONT message if the template specifies the DS_SETFONT or DS_SHELLFONT style) to the dialog box procedure. The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box.

When the dialog box procedure calls the EndDialog function, DialogBox destroys the dialog box, ends the message loop, enables the owner window (if previously enabled), and returns the nResult parameter specified by the dialog box procedure when it called EndDialog.

Windows 95/98/Me:The system can support a maximum of 255 controls per dialog box template. To place more than 255 controls in a dialog box, create the controls in the WM_INITDIALOG message handler rather than placing them in the template.

Example

For an example, see Creating a Modal Dialog Box.

Function Information

Minimum DLL Version
user32.dll

Header
Declared in Winuser.h, include Windows.h

Import library
User32.lib

Minimum operating systems
Windows 95, Windows NT 3.1

Unicode
Implemented as ANSI and Unicode versions.

个人在这里调用,可惜和VS里面创建的的资源还是对不上号,继续寻找原因:

DialogBox ( hInstance, TEXT( "IDD_START"), hwnd, StartProc);//这里有的要改了

使用后调用getlasteror函数获得如下错误代码的提示:

ERROR_RESOURCE_NAME_NOT_FOUND
1814
The specified resource name cannot be found in the image file.

很显然是没找到加载的资源……

呃……别人看了说我的资源ID很多重复的,赶紧删了重新弄……

重建模板……拖代码……