|
-
Apr 29th, 2001, 03:18 PM
#1
Thread Starter
Fanatic Member
Starting Win32
hello
I had a question about win32 apps. How do i make one in C++. I've been working with console appications for a while, and now im hoping to move into the win32 applications. I know theres an option that you can start with, but how do I structure it. Can anyone give me a starting point. The Hello World program is a bit complicated if you don't have a clue where to start.
Any tips or hints are greatly appriciated!
Thanks!
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Apr 29th, 2001, 03:32 PM
#2
Monday Morning Lunatic
Well, how about the thread RIGHT NEXT to this one? 
http://forums.vb-world.net/showthrea...threadid=71834
Here's a skeleton of your basic Win32 entry point:
Code:
#include <windows.h>
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MessageBox(NULL, "Hello!", "Windows App!", MB_OK);
return 0;
}
What those parameters mean:
hInstance -- handle to the current instance of your program
hPrevInstance -- unused in Win32, it's a relic from old versions
lpCmdLine -- the whole command line supplied w/o the program filename
nCmdShow -- you know in shortcuts where you can set it to open a window maximised/minimised/etc? this is where windows passes that to the program
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 29th, 2001, 03:35 PM
#3
Frenzied Member
Try the
http://www.winprog.org/tutorial
the tutorial there is very thorough and explains basic windows programming in details.
-
Apr 29th, 2001, 03:37 PM
#4
Frenzied Member
Here is the most common example:
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 29th, 2001, 03:40 PM
#5
Yet another example of why we need an FAQ.
-
Apr 29th, 2001, 03:41 PM
#6
Monday Morning Lunatic
Code:
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Actually, that's wrong, I'm afraid Since GetMessage can also return -1 you need to check for that as well, otherwise your program can get stuck looping around doing nothing 
Code:
int i;
while(i = GetMessage(&msg, NULL, 0, 0)) {
if(i == -1) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
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 29th, 2001, 03:45 PM
#7
Monday Morning Lunatic
Originally posted by ChimpFace9000
Yet another example of why we need an FAQ.
True
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 29th, 2001, 07:54 PM
#8
Thread Starter
Fanatic Member
Hey thanks for all the replies!
I'm gonna go check out the links right now... I was in a rush and I din't pay attention to the other threads, next time i'll be more observant.
I agree that we need a FAQ , so ppl. like me can directly go there.
Anyways, thanks for links
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
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
|