请问如果用WindowsAPI创建文本框之类的控件,并把它放到WindowsAPI创建的窗口上?

taojy 2006-09-13 08:35:07
rt
谢谢大家了
...全文
320 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
handsomerun 2006-09-14
  • 打赏
  • 举报
回复
看以下windows程序设计这本书上的例子
hhyytt 2006-09-14
  • 打赏
  • 举报
回复
ls回答正解.
lockydeng 2006-09-13
  • 打赏
  • 举报
回复
CreateWindow("EDIT", "这个是编辑框", WS_CHILD | WS_VISIBLE, 10, 10, 100, 100, hWnd, NULL, NULL, NULL);//这句话创建编辑框

新建一个空Win32工程,把以下代码拷贝到一个cpp文件,并加入到工程中就可以了。
////////////////////以下是演示/////////////////////////
#include "stdafx.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING] = "Edit演示"; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING] = "EditShow"; // The title bar text

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;

MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}

ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;//LoadIcon(hInstance, (LPCTSTR)IDI_EDIT);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)BLACK_BRUSH;//(HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = NULL;//LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_CREATE:
CreateWindow("EDIT", "这个是编辑框", WS_CHILD | WS_VISIBLE, 10, 10, 100, 100, hWnd, NULL, NULL, NULL);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}




「已注销」 2006-09-13
  • 打赏
  • 举报
回复
BOOL CreateEx (
DWORD dwExStyle,
LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hwndParent, _
HMENU nIDorHMenu,
LPVOID lpParam = NULL );

CreateEx(WS_EX_CLIENTEDGE, // Make a client edge label.
_T("STATIC"), "Hi",
WS_CHILD | WS_TABSTOP | WS_VISIBLE,
5, 5, 30, 30, m_hWnd, (HMENU)1234);


MSDN上的例子



zjh824 2006-09-13
  • 打赏
  • 举报
回复
createWindow("EDIT",...),父窗口为你创建的窗口就行了,
taojy 2006-09-13
  • 打赏
  • 举报
回复
能否给个简单的例子
DentistryDoctor 2006-09-13
  • 打赏
  • 举报
回复
就用CreateEx

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧