|
-
Apr 20th, 2001, 10:00 AM
#1
Thread Starter
Hyperactive Member
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?
-
Apr 20th, 2001, 10:27 AM
#2
Frenzied Member
PHP Code:
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;
}
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Apr 20th, 2001, 12:09 PM
#3
Monday Morning Lunatic
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)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 20th, 2001, 12:12 PM
#4
Frenzied Member
You know I dont know why it is that way in that program I took that snipit from. Thats strange
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Apr 20th, 2001, 12:14 PM
#5
Frenzied Member
Code:
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;
}
-
Apr 20th, 2001, 12:15 PM
#6
Monday Morning Lunatic
Don't add windows.h to your project...that'll confuse the compiler 
Technocrat -- it used to be HANDLE for everything, until they started differentiating the handle types.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 20th, 2001, 12:18 PM
#7
Frenzied Member
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.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Apr 20th, 2001, 12:38 PM
#8
Monday Morning Lunatic
Yeah...and that list of C++ tutorial sites
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|