Click to See Complete Forum and Search --> : Beginner can't create window!?
Jhd.Honza
Apr 20th, 2001, 10:00 AM
Hi,
I am new to C++, and I would like to use CreateWindow/Ex to display a normal window. Can somebody show me how to do it, please?
Technocrat
Apr 20th, 2001, 10:27 AM
BOOL InitInstance(HANDLE hInstance, int nCmdShow)
{
HWND hWnd;
DWORD dwFlags = WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
hWnd = CreateWindow(szClass, "Tutorial", dwFlags,
200, 300, 300, 100, NULL, NULL, (HINSTANCE)hInstance, NULL);
if(!hWnd)
return FALSE;
return TRUE;
}
parksie
Apr 20th, 2001, 12:09 PM
Technocrat -- it's now HINSTANCE rather than HANDLE for the instance handle :)
And Jhd -- are you new to C++ or Windows programming with C++?
http://www.parksie.net/Raw.zip (change LONG_PTR to LRESULT if you have any problems)
Technocrat
Apr 20th, 2001, 12:12 PM
You know I dont know why it is that way in that program I took that snipit from. Thats strange :confused:
Vlatko
Apr 20th, 2001, 12:14 PM
1. open visual c++
2. File > New
3. Click Projects tab
4. click Win32 Application and give it a name
5. click finish
6. click the File View Tab on TreeView
7. go to File > New
8. in the first tab Click C++ Source File and name it
9. Copy and paste the code in the new file
10. right click the Header folder and add Windows.h
11. click execute
#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);
while(GetMessage(&msg, NULL, 0, 0))
{
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;
}
parksie
Apr 20th, 2001, 12:15 PM
Don't add windows.h to your project...that'll confuse the compiler :eek:
Technocrat -- it used to be HANDLE for everything, until they started differentiating the handle types.
Technocrat
Apr 20th, 2001, 12:18 PM
I pulled it out of a Novell SDK pack I am working with. They had backwards comp on everything they could, thats prob why it was like that.
Once again it would be nice to have a FAQ so poor Vlatko doesnt have to paste that code in every week when some on asks the same question. :rolleyes:
parksie
Apr 20th, 2001, 12:38 PM
Yeah...and that list of C++ tutorial sites :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.