WM_ACTIVATEAPP

This is a test code, but why is it that when I minimize the window for the second time, the wParam is TRUE(in WindowProc). Why is it TRUE instead of FALSE. Please help!

Code:

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#define UNICODE
#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam, LPARAM lParam);
const wchar_t* CName=L"class_name";
int x=1;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASS wc;

    //filling the struct
    wc.lpfnWndProc=WindowProc;
    wc.hInstance=hInstance;
    wc.lpszClassName=CName;
    wc.cbClsExtra=0;
    wc.cbWndExtra=0;
    wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
    wc.hCursor=LoadCursor(NULL, IDC_ARROW);
    wc.hIcon=LoadIcon(NULL, IDI_APPLICATION);
    wc.style=0;


    if(!RegisterClass(&wc))
    {
        MessageBox(NULL,L"Class registration Failed !!!",L"Error",MB_ICONERROR);
        return 0;
    }

    HWND hwnd=CreateWindowEx(0,CName,L"My First Application Window",
                            WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,CW_USEDEFAULT,360,390,
                            NULL,NULL,hInstance,NULL);
    if(hwnd==NULL)
    {
        MessageBox(NULL,L"Windows Creation Failed!",L"Error",MB_ICONERROR|MB_OK);
        return 0;
    }
    ShowWindow(hwnd,nCmdShow);
    MSG msg;
    while(GetMessageW(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}


LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_ACTIVATEAPP:
            if(wParam==FALSE) break;
            if(wParam==TRUE && x!=1)
            {
                MessageBox(NULL,L"Thanks for coming back!",L"Info...",MB_OK);
                return 0;
            }
            break;
        case WM_QUIT:
            DestroyWindow(hwnd);
            break;
        case WM_DESTROY:
			PostQuitMessage(0);
            break;
		case WM_PAINT:
            if(x==1)
            {
                HDC hdc;
                PAINTSTRUCT ps;
                BeginPaint(hwnd,&ps);
                MessageBox(NULL,L"\tI am being painted for the first run!\
                           \n    I got to know through the WM_PAINT message",L"Info...",MB_OK);
                FillRect(hdc,&ps.rcPaint,(HBRUSH)(COLOR_WINDOW)+1);
                EndPaint(hwnd,&ps);
                break;
            }
            else
            {
                HDC hdc;
                PAINTSTRUCT ps;
                BeginPaint(hwnd,&ps);
                FillRect(hdc,&ps.rcPaint,(HBRUSH)(COLOR_WINDOW)+1);
                EndPaint(hwnd,&ps);
                break;
            }
            break;
        default:
            return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    x++;
    return 0;
}
If you move the x++ into the WM_PAINT loop where x==1 and place it at the bottom everything seems to work okay. Otherwise x is larger than 1 by the time WM_PAINT is called and the first run message does not appear. When I compiled and ran the wParam is always TRUE when activating the minimized window.
Thanks! but that still didn't solve the problem.
Try minimizing with the taskbar and see
Last edited on
I dont' know if this is what behavior you want but instead of WM_ACTIVATEAPP why not WM_SYSCOMMAND ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
case WM_SYSCOMMAND:
{
  switch(wParam)
  {
    case SC_MINIMIZE:
    {
      MessageBox(hwnd,L"Window going inactive",L"Info...",MB_OK);
    } break;
    case SC_RESTORE:
    {
      MessageBox(hwnd,L"Window going active",L"Info...",MB_OK);
    } break;
  }
  return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
Thanks Texan40, this will be able to solve my problem. THANKS YOU!!!
Topic archived. No new replies allowed.