下面的代码通过编译,但为什么不能正常运行?请高手指教.

hangjier 2003-03-30 04:23:48
下面的代码通过编译,但为什么不能把“richedit"显示出来的?请高手指教.
还有就是如何才能支持unicode?要用sdk的。
#include <windows.h>
#include <richedit.h>
#include <commctrl.h>

HANDLE hRTFLib;
HINSTANCE hInst;
HWND hWndRichEdit;

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

char szClassName[ ] = "WindowsApp";
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;

InitCommonControls();

wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;

wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);


if(!RegisterClassEx(&wincl)) return 0;

hwnd = CreateWindowEx(
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
hInst = hThisInstance;

ShowWindow(hwnd, nFunsterStil);

hRTFLib = LoadLibrary("riched20.dll");

while(GetMessage(&messages, NULL, 0, 0))
{

TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}


LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:

hWndRichEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
"RichEdit",
"HELLO!",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_SAVESEL | WS_HSCROLL | WS_VSCROLL,
0,
0,
200,
200,
hwnd,
NULL,
hInst,
NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
...全文
30 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
In355Hz 2003-03-30
  • 打赏
  • 举报
回复
#include "stdafx.h"

#include <windows.h>
#include <richedit.h>
#include <tchar.h>

HANDLE hRichEditLib = NULL;

HINSTANCE hAppInstance = NULL;

HWND hWndRichEdit = NULL;

TCHAR tszClassName[] = _T("RichEditApp");

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

extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND hWnd;

WNDCLASSEX wndclass;

memset(&wndclass, 0, sizeof(WNDCLASSEX));
wndclass.cbSize = sizeof(WNDCLASSEX);

wndclass.style = CS_DBLCLKS;
wndclass.lpfnWndProc = WindowProc;

wndclass.hInstance = hInstance;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);

wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = tszClassName;

if (!RegisterClassEx(&wndclass))
{
OutputDebugString(_T("RegisterClassEx(&wndclass) failed!\n"));
return -1;
}

hAppInstance = hInstance;

hRichEditLib = LoadLibrary(_T("RICHED32.DLL"));
if (hRichEditLib == NULL)
{
OutputDebugString(_T("LoadLibrary(_T(\"RICHED32.DLL\")) failed!\n"));
return -1;
}

hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, tszClassName,
_T("RichEdit App"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);
if (hWnd == NULL)
{
OutputDebugString(_T("CreateWindowEx(_T(\"RichEditApp\"), ...) failed!\n"));
return -1;
}

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

while ( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

return Msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rectClient;

switch (message)
{
case WM_CREATE:

GetClientRect(hwnd, &rectClient);

hWndRichEdit = CreateWindowEx( 0, _T("RICHEDIT"),
_T("RICHEDIT32"),
WS_CHILD | ES_MULTILINE | ES_SAVESEL | WS_HSCROLL | WS_VSCROLL,
rectClient.left, rectClient.top, rectClient.right, rectClient.bottom,
hwnd, NULL, hAppInstance, NULL);
if (hWndRichEdit == NULL)
{
OutputDebugString(_T("CreateWindowEx(_T(\"RICHEDIT\"), ...) failed!\n"));
return -1;
}

ShowWindow(hWndRichEdit, SW_SHOW);
UpdateWindow(hWndRichEdit);

break;

case WM_DESTROY:

if (hWndRichEdit)
DestroyWindow(hWndRichEdit);

hWndRichEdit = NULL;

PostQuitMessage(0);

break;

default:

return DefWindowProc(hwnd, message, wParam, lParam);
}

return 0;
}
timepalette 2003-03-30
  • 打赏
  • 举报
回复

在InitCommonControls()后面加
AfxInitRichEdit()

我没试过在OnCreat里加
hangjier 2003-03-30
  • 打赏
  • 举报
回复
多谢各位的回复,我想用SDK来写。不想用MFC。
ColderRain 2003-03-30
  • 打赏
  • 举报
回复
case WM_CREATE:
::AfxInitRichEdit();
hWndRichEdit = CreateWindowEx(...)
KcSoft 2003-03-30
  • 打赏
  • 举报
回复
在MFC中RichEdit要初始化,在这里可能也要初始化。
9731boy 2003-03-30
  • 打赏
  • 举报
回复
UP

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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