Which is bettor to start with? MFC or everything with API?
VisualPenguin
Printable View
Which is bettor to start with? MFC or everything with API?
VisualPenguin
I would say API.
Definitely API, and everyone here will agree (well, almost everyone). You can later learn MFC too, if you really understand what's going on. You can make apps far quicker, but if you don't know it well you might get really lost. MFC is an advantage at a prize. (z or c?)
I got flamed once on a non-programming forum for suggesting to someone who wanted to learn Windows programming that the API is better than MFC...
CB - price :)
Josh - ack, everyone knows API is better *smirk* Silly fools :p
API is functional and quite lowlevel, me and parksie decided to make an object oriented layer to it, but I'm too busy writing my own language right now :p the classes for the layer will then be compiled in BORK to a set of generic C++ classes that will be upwards compatible with BORK modules. By then you can choose to write your win32 application in C++ or BORK using the generated layer, and it will highly efficient compared to MFC ;)
API = speed, control, runtimeless, you ONLY use what u want to, say you are using API functions
EnumWindows
CreateFont
CreateWindow
ReturnDlgProc
...or whatever
you WILL be realy using ONLY those API's, nothing more :)
MFC = easiness OR a bit of confustion, mess, +size, -control, runtimes :( DLL files
can anybody then give me a realy simple program? with just the basic needs like one dialog, so I can find out how to make it myself?
VisualPenguin
Visual C++
Code:#include <windows.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
char szWinNamw[] = "MyWin";
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR kposzArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = "My Window";
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wcl)) return 0;
hwnd = CreateWindow( "My Window",
"Skeleton Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL );
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
int i;
while(i = GetMessage(&msg, NULL, 0, 0))
{ if (i == -1) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam; }
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
Why did you double space that? It makes it look twice as long =).
You should also be handling WM_PAINT:
Otherwise, the window will continue to get WM_PAINT messages.Code:LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
ValidateRect(hwnd, NULL);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
Z.
I thought DefWindowProc would handle that.
Glad to see that it's got the check for -1 in there ;)
You dont have to ValidateRect, but you do have to return 0. GetMessage will leave WM_PAINT in the queue until there arent any more messages (i think that's what the docs said). I found this info under the GetMessage() docs, the WM_PAINT message docs and the "Designing a Window Procedure" topic, in the MSDN.
Z.