Hm, eksempel nr 2 minder vist lidt om min metode, dvs. den gør brug af MoveWindow, men så er vi jo tilbage ved starten. Måske hjælper det hvis du har noget kode at gå ud fra?
/* Includes */
#include <windows.h>
#include <richedit.h>
/* Definitions */
#define IDI_CPP_ICON 001
#define IDM_MENU 002
#define IDM_AABEN 003
#define IDM_LEFT 004
#define IDM_CENTER 005
#define IDM_RIGHT 006
#define IDM_BOLD 007
/* Declare procedures */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void DoSelectDefaultFont (HWND windowhandle, LPSTR fontname);
/* Make the class name into a global variable */
char szClassName[] = "Main-Window";
HWND edit, hwnd;
RECT r;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
HMODULE hmod = LoadLibrary("riched20.DLL");
/* The Window structure */
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);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_CPP_ICON));
wincl.hIconSm = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_CPP_ICON));
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = MAKEINTRESOURCE (IDM_MENU); /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
WS_EX_CLIENTEDGE, /* Extended possibilites for variation */
szClassName, /* Classname */
"Editor", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
CW_USEDEFAULT, /* The programs width */
CW_USEDEFAULT, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
/* Paragraph formatting structure */
PARAFORMAT pfm;
pfm.cbSize = sizeof (PARAFORMAT);
pfm.dwMask = PFM_ALIGNMENT;
pfm.wNumbering = 0;
/* Character formatting structure */
CHARFORMAT cfm;
cfm.cbSize = sizeof (CHARFORMAT);
cfm.dwMask = CFM_BOLD;
switch (message) /* handle the messages */
{
case WM_CREATE:
/* Create the edit control */
edit = CreateWindowEx (
0,
RICHEDIT_CLASS,
NULL,
WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL | ES_NOHIDESEL | WS_TABSTOP,
0, 0,
100, 100,
hwnd, NULL, NULL, NULL);
DoSelectDefaultFont (edit, "Times New Roman");
/* Focus the edit control */
SetFocus (edit);
break;
case WM_SIZE:
GetClientRect (hwnd, &r);
MoveWindow (edit, 0, 0, r.right, r.bottom, true);
break;
case WM_COMMAND:
switch (LOWORD (wParam)) {
case IDM_AABEN:
MessageBox (hwnd, "Hej", "Hej", MB_OK);
break;
case IDM_LEFT:
pfm.wAlignment = PFA_LEFT;
SendMessage (edit, EM_SETPARAFORMAT, 0, (LPARAM) &pfm);
break;
case IDM_CENTER:
pfm.wAlignment = PFA_CENTER;
SendMessage (edit, EM_SETPARAFORMAT, 0, (LPARAM) &pfm);
break;
case IDM_RIGHT:
pfm.wAlignment = PFA_RIGHT;
SendMessage (edit, EM_SETPARAFORMAT, 0, (LPARAM) &pfm);
break;
case IDM_BOLD:
SendMessage (edit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM) &cfm);
break;
};
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void DoSelectDefaultFont (HWND windowhandle, LPSTR fontname) {
HFONT Font = CreateFont (19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, fontname);
SendMessage (windowhandle, WM_SETFONT, (WPARAM) Font, true);
};
Jeg er faktisk lidt i tvivl om hvad MFC er
Men I alle MFC eksempler, jeg har set, er der gjort brug af klasser, og det gør jeg jo ikke, så jeg bruger sikkert ikke MF
Hvis du kan din Delphi kan jeg sige, det er "alClient" jeg leder efter