Multiple desktop

I just met with some problems. I tried to write a program, this program to the desktop window group. Programs use a forever hidden window as the main window, use hotkeys WIN + F1 - F10 switch group. When switching enumerated all of your Windows, use ShowWindow (HWND, SW_HIDE) hide the current packet window and ShowWindow (HWND, SW_SHOW) display to switch group. The problem is, when I use hotkeys WIN + add exit, the program has a reaction, other times no response. If (! RegisterHotKey (HWND, keyid [I] = GlobalAddAtom (" # 1234 ") - 0 xc000, MOD_WIN | MOD_SHIFT, VK_F1 + I).
/ / registered hotkey
MessageBox (0, "error", "error", 0); No report errors, in response to WIN + F1 - F10's MessageBox (0, "1", "1", 0); There will be no response. This is why? What's more ,you give I recommend network storage site from China landing is not stable.
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Include <windows.h>
BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
HWND * win [10];
int now = 0;
HWND mywin;
int size [10] = {0,0,0,0,0,0,0,0,0,0};
HGLOBAL allwin [10];
int keyid [12];
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName [] = TEXT ("HelloWin");
     HWND hwnd;
     MSG msg;
     WNDCLASS wndclass;

     wndclass.style = CS_HREDRAW | CS_VREDRAW;
     wndclass.lpfnWndProc = WndProc;
     wndclass.cbClsExtra = 0;
     wndclass.cbWndExtra = 0;
     wndclass.hInstance = hInstance;
     wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
     wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
     wndclass.lpszMenuName = NULL;
     wndclass.lpszClassName = szAppName;

     if (! RegisterClass (& wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                      szAppName, MB_ICONERROR);
          return 0;
     }
     
     hwnd = CreateWindow (szAppName, / / ​​window class name
                          TEXT ("The Hello Program"), / / ​​window caption
                          WS_OVERLAPPEDWINDOW, / / ​​window style
                          CW_USEDEFAULT, / / ​​initial x position
                          CW_USEDEFAULT, / / ​​initial y position
                          CW_USEDEFAULT, / / ​​initial x size
                          CW_USEDEFAULT, / / ​​initial y size
                          NULL, / / ​​parent window handle
                          NULL, / / ​​window menu handle
                          hInstance, / / ​​program instance handle
                          NULL); / / creation parameters
     
     while (GetMessage (& msg, NULL, 0, 0))
     {
          TranslateMessage (& msg);
          DispatchMessage (& msg);
     }
     return msg.wParam;
}
BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
{
if ((int) hwnd == (int) mywin)
return 0;
int i;
for (i = 0; i <10; i + +)
{
for (int j = 0; j <size [i]; j + +)
{

if (* (win [lParam] + j) == hwnd) / / if the window should be displayed
{
ShowWindow (hwnd, SW_SHOW);
return 0;
}
else
{
if (* (win [now] + j) == hwnd) / / if the window should be hidden
ShowWindow (hwnd, SW_HIDE);
else / / there is no record
{
for (int a = 0; a <10; a + +) / / detect whether other records
{
if (a = lParam)
continue;
for (int b = 0; b <size [a]; b + +)
if (* (win [a] + b) == hwnd)
return true;
}
ShowWindow (hwnd, SW_HIDE);
GlobalUnlock (allwin [lParam]);
GlobalReAlloc (allwin [lParam], (size [i] +1) * sizeof (HDC *), GMEM_MOVEABLE);
win [lParam] = (HWND *) GlobalLock (allwin [lParam]);
size [i] + +;
* (Win [lParam] + size [i]) = hwnd;
}
}
}
}
return true;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
mywin = hwnd;
int i;
for (i = 0; i <12; i + +)
if (! RegisterHotKey (hwnd, keyid [i] = GlobalAddAtom ("# 1234")-0xc000, MOD_WIN | MOD_SHIFT, VK_F1 + i))
/ / Register hotkey
MessageBox (0, "Error", "Error", 0);
for (i = 0; i <10; i + +)
if (! (allwin [i] = GlobalAlloc (GMEM_MOVEABLE, 0)))
PostQuitMessage (1);
return 0;
}
case WM_HOTKEY :/ / response hotkey
if (HIWORD (lParam) == VK_F11)
MessageBox (0, "win + F1 to win + F10 is a toggle, F12 to exit. The buildings making", "help", 0);
else
{
if (HIWORD (lParam) == VK_F12)
SendMessage (hwnd, WM_CLOSE, 0,0);
else
{
MessageBox (0, "1", "1", 0);
for (int i = 0; i <10; i + +)
win [i] = (HWND *) GlobalLock (allwin [lParam]);
EnumWindows (& EnumWindowsProc, HIWORD (lParam) -112) ;/ / Enumerate all windows
now = HIWORD (lParam) -112;
}
}
return 0;
case WM_DESTROY:
{
int i;
for (i = 0; i <10; i + +) / / clean up memory
GlobalFree (allwin [i]);
for (i = 0; i <12; i + +)
UnregisterHotKey (hwnd, keyid [i]);
break;
}
case WM_CLOSE:
if (MessageBox (0, "Are you sure you want to quit the multi-screen desktop?" Exit confirmation MB_YESNO) == IDNO)
return 0;
SendMessage (hwnd, WM_DESTROY, 0,0);
PostQuitMessage (1);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;/ / default processing
}
Last edited on
It is no grammar mistakes, but I found that the computer automatic translation to make the code without quotes and indent, please forgive me.
Topic archived. No new replies allowed.