PostQuitMessage() Undefined?

Hello, I have been working through a basic windows programming tutorial, and got stuck when using PostQuitMessage(0); the compiler claims that it is undefined. I believe that the problem is that I am missing a 'using namespace', but cannot figure it out. Also highly note that PostQuitMessage() is not the only undefined function, others include: DefWindowProc(), WNDCLASSEX, and GetClientRect(). I am using Windows.h with Visual Studio 2015. Any help is very much appreciated. The below is my code:

#include <Windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_DESTROY)
{
PostQuitMessage(0);
return 0;
}

DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE prevInst, LPWSTR cmd, int nCmdShow)
{
WNDCLASSEX windowClass;

return 0;
}


(Yes I understand that the code is not nearly finished, I just wanted to solve these errors before I continue.)
Last edited on
Two things:

The main function is called WinMain not wWinMain.


DefWindowProc(hwnd, uMsg, wParam, lParam);
must be:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
closed account (z05DSL3A)
Thomas1965 wrote:
The main function is called WinMain not wWinMain.

https://msdn.microsoft.com/en-us/library/windows/desktop/ff381406(v=vs.85).aspx
@Grey Wolf,

thanks, didn't know this.
What? There's still folks learning to code native, unmanaged code? Still not working in the cloud?

Me neither!

Welcome to Win32 Cynix! Its good!

Just to give you an idea of the barest of bare essentials, here's a Win32 (I used x64, wide character) app at the bare minimum...

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
// cl Form1.cpp /O1 /Os /GS- /link TCLib.lib kernel32.lib user32.lib 
// 3,072 Bytes x64 UNICODE
#define UNICODE   // /entry:wWinMainCRTStartup
#define _UNICODE
#include <windows.h>
#include <tchar.h>

LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
 if(msg==WM_DESTROY)
 {
    PostQuitMessage(0);
    return 0;
 }

 return (DefWindowProc(hwnd, msg, wParam, lParam));
}

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevIns, LPTSTR lpszArgument, int iShow)
{
 WNDCLASSEX wc={};
 MSG messages;
 HWND hWnd;

 wc.lpszClassName = _T("Form1");
 wc.lpfnWndProc   = fnWndProc;
 wc.cbSize        = sizeof(WNDCLASSEX);
 wc.hInstance     = hInstance;
 wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,_T("Form1"),_T("Form1"),WS_OVERLAPPEDWINDOW|WS_VISIBLE,200,100,325,300,HWND_DESKTOP,0,hInstance,0);
 while(GetMessage(&messages,NULL,0,0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }

 return messages.wParam;
}


There's actually one thing you could pare from that yet, and that would be the WNDCLASSEX::hbrBackground. The only absolutely critical members of WNDCLASSEX are the pointer to the Window Procedure and the szClassName (which, by the way, the official MSDN documentation has wrong. It lists it as an optional parameter and its not.) The .cbSize is necessary, but you could use WNDCLASS and CreateWindow() instead of WNDCLASSEX and CreateWindowEx().
Topic archived. No new replies allowed.