我正在使用c ++中的windows api创建一个在多行编辑中绘制文本的程序。它由WM_PAINT
消息组成,用于绘制客户区域中的文本,但插入符号显示编辑中的意外行为。它有时不会打印字符,有时会打印字符隐藏。
代码是
#define UNICODE
/*
**
**ALL HEADER FILES
**
*/
#include<wchar.h>
#include<windows.h>
#include <errno.h>
#include<conio.h>
#include<iostream>
#include<stdio.h>
#include<resource.h>
/*
**
**ALL DEFINES CONSTANT
**
*/
#define WINVER 0x0A00
#define _WIN32_WINNT 0x0A00
LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);
using namespace std;
HWND hwnd_handle;
HWND hw;
HINSTANCE his;
int WINAPI WinMain(HINSTANCE hvalue,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
his=hvalue;
/////com=nCmdShow;
LPWSTR myname=L"MY WINDOWS CLASS";
MSG msg={0};
WNDCLASSW wc;
wc.hbrBackground=(HBRUSH)COLOR_BTNFACE;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.lpszMenuName=NULL;
wc.lpszClassName=myname;
wc.hCursor=NULL;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.style=0;
wc.hInstance=hvalue;
wc.lpfnWndProc=WindowProcedure;
if(!RegisterClassW(&wc))
{
return 0;
}
///////main window
hwnd_handle=CreateWindowW(myname,L"CODE EDITOR",WS_OVERLAPPEDWINDOW,240,80,600,600,NULL, NULL,hvalue, NULL);
ShowWindow(hwnd_handle,nCmdShow);
UpdateWindow(hwnd_handle);
////////HWND hwnd=CreateWindowW(L"STATIC",L"CODE EDITOR",WS_OVERLAPPEDWINDOW,24,8,60,6,hwnd_handle, NULL,hInstance, NULL);
while(GetMessageW(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
/////main_structure(hwnd);
hw=CreateWindowW(TEXT("edit"),TEXT(""), WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL ,3,0,600,600,hwnd,NULL,his,NULL);
}
break;
case WM_COMMAND:
{
/////menu_function(hwnd,wParam);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
RECT info;
HBRUSH hbrush;
HDC hdc = BeginPaint(hw,&ps);
wcout<<"vishal";
TextOut(hdc,20,20,L"vishak",6);
EndPaint(hw,&ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
break;
}
}
///////all men
答案 0 :(得分:0)
由于您使用的是编辑控件,因为窗口的客户区域不会自行处理WM_PAINT;而是将文本添加到编辑控件(使用带有EM_SETTEXT的SendMessage或可能是EM_REPLACESEL)并让它进行绘图。
此外,您应该处理WM_SIZE并将编辑控件设置为实际的客户区大小。