Windows.h header file details

Oct 4, 2013 at 12:54pm
it would be a great help if somebody could breifly explain the uses of windows.h . Also tell about the features it offer.
Oct 4, 2013 at 3:03pm
Windows.h is the main header file for WinAPI.

WinAPI is anything and everything related to programming on Windows. Anything that involves window creation/management or communication with the OS or filesystem.

Things like:
- Creating Windows
- Basic graphical capabilities (WinGDI)
- Enumerating files in a directory
- Popping up common dialog boxes ("Save As" dialog, "Pick a color" dialog, etc)
- Querying information about the system (like running processes, etc)
- etc
- etc

The list goes on and on. WinAPI is huge.
Oct 4, 2013 at 3:53pm
can it be used to get a mouse click. If yes will you help me with the code. Plz include explanations. Thanks!
Oct 4, 2013 at 4:19pm
Yes. Though I only know how to handle mouse input through normal windows... not through the console. So if you're not already using WinAPI to create your own window, then I can't help you with that immediate problem without writing a big tutorial on WinAPI basics, which is more than I'm willing to do right now =x Sorry.

You should be able to find some 'getting started with WinAPI' tutorials on google. Or maybe someone else on here can field your question.
Oct 4, 2013 at 4:31pm
closed account (jwkNwA7f)
Yes, it is possible.
You should be able to find some thing here, for the console:
http://www.cplusplus.com/forum/lounge/17053/

I don't have much time, but I'll throw something together real quick:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <Windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR commandLine, INT commandShow)
{
    HWND hwnd = NULL;
    MSG msg = { };
    WNDCLASS wc = { };
    wc.hInstance = hInstance;
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = "Window Class";
    wc.style = CS_HREDRAW | CS_VREDRAW;
    if (!RegisterClass(&wc))
        return 1;
    hwnd = CreateWindow("Window Class", "App Title", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
            CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL);
    if (!hwnd)
        return 1;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
     case WM_LBUTTONDOWN:
         MessageBox(hwnd, "Left Button Clicked", "An Event Happened", MB_OK | MB_ICONINFORMATION);
         return 0;
     case WM_CLOSE:
         PostQuitMessage(0);
         return 0;
     default:
         return DefWindowProc(hwnd, msg, wParam, lParam);
    }
}


Well, I could have just gotten something from the internet, instead of typing all of that out here, but oh well, too late now.

Hope this helped!
Oct 4, 2013 at 4:37pm
Of course, you're using the wrong character type there.
ref: http://www.cplusplus.com/forum/windows/106683/

The correct structs/functions to use in that code would be:

WNDCLASSA (not WNDCLASS)
CreateWindowA (not CreateWindow)
MessageBoxA (not MessageBox)


</stickler>

;P
Oct 4, 2013 at 4:42pm
Thanks guys!
Oct 4, 2013 at 5:16pm
Umm if you're just after a fast and easy way to retrieve if the mouse button has been pressed, just look up GetAsyncKeyState(VK_LBUTTON), although that doesn't work with the mouse key switching voodoo...
Topic archived. No new replies allowed.