Ansi-c win32API - kan ikke oprette Richedit4.1 kontrol
Hejsa,Jeg prøver at oprette en Richedit textbox baseret på msftrich.dll
Når jeg skriver CreateWindowEx(...,MSFTEDIT_CLASS,...) får jeg fejlmeddelelse 1407.Cannot find window class.
JEg har prøvet alt, og undersøgt utallige sider på Internet, uden at finde svar. håber nogen kan fortælle hvad jeg gør forkert.
jeg har windows 7 på 32 bit. compiler er cl.exe via commandline
cl /TC sourcefile.c
Her er mit program:
#define NTDDI_WIN7 0x06010000
#define _WIN32_WINNT_WIN7 0x0601
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <commctrl.h>
#include <Richedit.h>
#include <strsafe.h> // For error checking
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"comctl32.lib")
#define IDC_MAIN_EDIT 101
#define WM_SETTEXT 0x000C
//Definitions for the controls
#define BTN1 4000
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void ErrorExit(LPTSTR lpszFunction)
{
// Retrieve the system error message for the last-error code
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
MSG msg ;
HWND hwnd;
WNDCLASS wc;
// InitCommonControls();
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
//icex.dwICC = ICC_USEREX_CLASSES;
InitCommonControlsEx(&icex);
LoadLibrary("msftedit.dll");
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpszClassName = TEXT( "Window" );
wc.hInstance = hInstance ;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpszMenuName = NULL;
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
RegisterClass(&wc);
hwnd = CreateWindow( wc.lpszClassName, TEXT("Window"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100, 1050, 1050, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while( GetMessage(&msg, NULL, 0, 0)) {
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_CREATE:
{
HWND hEdit;
HWND hButton1;
hEdit= CreateWindowExA(ES_SUNKEN,"MSFTEDIT_CLASS","Type here", ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_WANTRETURN, 2, 2, 200, 220, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
if (!hEdit)
{
ErrorExit(TEXT("MSFTEDIT"));
}
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}