OpisCossack
October 13th, 2008, 05:07 AM
Hey guys, first post in this forum :)
I'm trying to set a window directly onto the desktop, so that clicking the "Show Desktop" shell command wouldn't make it dissapear, here's what I've go so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "resources/resources.h"
LRESULT CALLBACK window_process (HWND, UINT, WPARAM, LPARAM);
void error(char * from);
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev_instance,
PSTR cmd_line, int cmd_show){
HWND hwnd;
MSG window_msg;
WNDCLASS mainwnd;
memset(&mainwnd, 0, sizeof(WNDCLASS));
mainwnd.style = CS_HREDRAW | CS_VREDRAW ;
mainwnd.lpfnWndProc = &window_process;
mainwnd.cbClsExtra = 0;
mainwnd.cbWndExtra = 0;
mainwnd.hInstance = instance;
mainwnd.hIcon = LoadIcon (NULL, IDI_APPLICATION);
mainwnd.hCursor = LoadCursor (NULL, IDC_ARROW); // default IDC_ARROW
mainwnd.hbrBackground = CreateSolidBrush(RGB(250,250,250));
mainwnd.lpszClassName = app_name;
mainwnd.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
if(!RegisterClass(&mainwnd)){
error("RegisterClass");
return 0;
}
hwnd = CreateWindow(app_name, app_name,WS_POPUP,
500, 500, 500, 200, NULL,
NULL, instance, NULL);
if(!hwnd){
error("hwnd");
}
ShowWindow (hwnd, cmd_show);
UpdateWindow(hwnd);
while(GetMessage (&window_msg, NULL, 0, 0)){
TranslateMessage(&window_msg);
DispatchMessage(&window_msg);
}
return window_msg.wParam;
}
LRESULT CALLBACK window_process (HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam){
HDC hdc;
PAINTSTRUCT paint_class;
RECT rect;
long style;
if(message == WM_PAINT){
hdc = BeginPaint(hwnd, &paint_class);
GetClientRect(hwnd, &rect);
EndPaint (hwnd, &paint_class);
}
else if(message == WM_COMMAND){
switch(LOWORD(wParam)){
case ID_FILE_EXIT:
exit(1);
break;
}
}
else if(message == WM_ACTIVATE){
SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSIZE);
SetParent(hwnd, GetDesktopWindow());
GetWindowLong(hwnd, GWL_STYLE);
style = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, style | WS_CHILD);
}
else if(message == WM_DESTROY){
PostQuitMessage(0);
return 0;
}
else if(message == WM_CLOSE){
DestroyWindow(hwnd);
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
void error(char * from){
char formulated[512];
char printed[560];
memset(formulated, 0, 512);
memset(printed, 0, 560);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0,
formulated, 511, NULL);
sprintf(printed, "A fatal %s error has occured: %s", from, formulated);
MessageBox (NULL, printed, app_name, MB_ICONERROR);
exit(1);
}
However, this has a few problems, clicking the "Show Desktop" shell command will not show the window, it flickers when you click the menu, and other display problems.
If anyone has any ideas on how to do this, it'd be greatly appreicated, thanks.
I'm trying to set a window directly onto the desktop, so that clicking the "Show Desktop" shell command wouldn't make it dissapear, here's what I've go so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "resources/resources.h"
LRESULT CALLBACK window_process (HWND, UINT, WPARAM, LPARAM);
void error(char * from);
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev_instance,
PSTR cmd_line, int cmd_show){
HWND hwnd;
MSG window_msg;
WNDCLASS mainwnd;
memset(&mainwnd, 0, sizeof(WNDCLASS));
mainwnd.style = CS_HREDRAW | CS_VREDRAW ;
mainwnd.lpfnWndProc = &window_process;
mainwnd.cbClsExtra = 0;
mainwnd.cbWndExtra = 0;
mainwnd.hInstance = instance;
mainwnd.hIcon = LoadIcon (NULL, IDI_APPLICATION);
mainwnd.hCursor = LoadCursor (NULL, IDC_ARROW); // default IDC_ARROW
mainwnd.hbrBackground = CreateSolidBrush(RGB(250,250,250));
mainwnd.lpszClassName = app_name;
mainwnd.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
if(!RegisterClass(&mainwnd)){
error("RegisterClass");
return 0;
}
hwnd = CreateWindow(app_name, app_name,WS_POPUP,
500, 500, 500, 200, NULL,
NULL, instance, NULL);
if(!hwnd){
error("hwnd");
}
ShowWindow (hwnd, cmd_show);
UpdateWindow(hwnd);
while(GetMessage (&window_msg, NULL, 0, 0)){
TranslateMessage(&window_msg);
DispatchMessage(&window_msg);
}
return window_msg.wParam;
}
LRESULT CALLBACK window_process (HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam){
HDC hdc;
PAINTSTRUCT paint_class;
RECT rect;
long style;
if(message == WM_PAINT){
hdc = BeginPaint(hwnd, &paint_class);
GetClientRect(hwnd, &rect);
EndPaint (hwnd, &paint_class);
}
else if(message == WM_COMMAND){
switch(LOWORD(wParam)){
case ID_FILE_EXIT:
exit(1);
break;
}
}
else if(message == WM_ACTIVATE){
SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSIZE);
SetParent(hwnd, GetDesktopWindow());
GetWindowLong(hwnd, GWL_STYLE);
style = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, style | WS_CHILD);
}
else if(message == WM_DESTROY){
PostQuitMessage(0);
return 0;
}
else if(message == WM_CLOSE){
DestroyWindow(hwnd);
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
void error(char * from){
char formulated[512];
char printed[560];
memset(formulated, 0, 512);
memset(printed, 0, 560);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0,
formulated, 511, NULL);
sprintf(printed, "A fatal %s error has occured: %s", from, formulated);
MessageBox (NULL, printed, app_name, MB_ICONERROR);
exit(1);
}
However, this has a few problems, clicking the "Show Desktop" shell command will not show the window, it flickers when you click the menu, and other display problems.
If anyone has any ideas on how to do this, it'd be greatly appreicated, thanks.