没有注册WNDCLASS创建窗口? [英] Create Window without Registering a WNDCLASS?
问题描述
时是绝对必要的始终,并建立您的应用程序注册一个新的WNDCLASS(EX)?然后用lpszClassName主窗口?
Is it absolutely necessary to always build and register a new WNDCLASS(EX) for your application? And then use the lpszClassName for the main window?
是不是有我们可以使用一个主窗口,一些prebuilt类名像有按钮和编辑按钮和文本框等。
Isn't there some prebuilt class name we can use for a main window, like there is "Button" and "Edit" for buttons and text-boxes etc.?
推荐答案
您可以从一个对话框资源创建一个小的应用程序,你可以使用CreateDialog()而不是CreateWindow的()。样板code可能看起来像这样,减去所需的错误检查:
You can create a mini app out of a dialog resource, you use CreateDialog() instead of CreateWindow(). Boilerplate code could look like this, minus the required error checking:
#include "stdafx.h"
#include "resource.h"
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
DestroyWindow(hDlg);
PostQuitMessage(LOWORD(wParam)-1);
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
HWND hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
if (hWnd == NULL) DebugBreak();
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
它假定您使用的ID IDD_DIALOG1创建一个对话框与资源编辑器。
Which assumes you created a dialog with the resource editor using id IDD_DIALOG1.
这篇关于没有注册WNDCLASS创建窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!