"Henrik" <hla@telenorconnect.com> wrote in message
news:bgqs03$2p8s$1@news.cybercity.dk...
> Hej,
>
> Jeg skal sikre mig at min application altid 'ligger øverst', fullscreen,
og
> at den ikke kan flyttes.
Altid ligger øverst:
* Brug Window Style "WS_EX_TOPMOST"
* Når vinduet deaktiveres modtager det en "WM_ACTIVATE". Herefter kan
vinduet aktiveres igen.
Full screen:
* Kald "ShowWindow" med "SW_MAXIMIZE".
* Sørg for at det forbliver maksimeret ved at fjerne "Minimize",
"Restore", "Move", "Size" kommandoer fra system menuen og ved at sørge for
at caption ikke har knapper til "Minimize" og "Restore".
>
> Det med 'øverst' og fullscreen er let nok, men hvordan med 'ikke flytbar'
/
> 'fixed position' ?.
> Det er en alm. MFC application m. titlebar.
Neden stående Win32 API eksempel viser hvordan det kan gøres.
Det er simpelt at oversætte til MFC.
<C++ kode til MS-Windows>
#include <windows.h>
#define WM_POST_ACTIVE WM_USER
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR
/*lpCmdLine*/, int /*nCmdShow*/)
{
const char* szAppName = "Full Sceen Application";
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) COLOR_WINDOW;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, "Unable to register WNDCLASS!!!",
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindowEx(WS_EX_TOPMOST,
szAppName, szAppName,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
WS_THICKFRAME,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, SW_MAXIMIZE);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT OnWmCreate(HWND hwnd, WPARAM /*wParam*/, LPARAM /*lParam*/)
{
HMENU sysMenu = GetSystemMenu(hwnd, FALSE);
DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_MOVE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_NEXTWINDOW, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_PREVWINDOW, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_RESTORE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_SIZE, MF_BYCOMMAND);
return 0;
}
LRESULT OnWmActivate(HWND hwnd, WPARAM wParam, LPARAM /*lParam*/)
{
if(WA_INACTIVE == LOWORD(wParam)) {
// Reactivate the window,
// when inactivation has been
// fully processed
PostMessage(hwnd, WM_POST_ACTIVE, 0, 0);
}
return 0;
}
LRESULT OnWmPostActivate(HWND hwnd, WPARAM /*wParam*/, LPARAM /*lParam*/)
{
SetForegroundWindow(hwnd);
return 0;
}
LRESULT OnWmDestroy(HWND /*hwnd*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
{
PostQuitMessage(0);
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch (message) {
case WM_CREATE:
return OnWmCreate(hwnd, wParam, lParam);
case WM_DESTROY:
return OnWmDestroy(hwnd, wParam, lParam);
case WM_ACTIVATE:
return OnWmActivate(hwnd, wParam, lParam);
case WM_POST_ACTIVE:
return OnWmPostActivate(hwnd, wParam, lParam);
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
</C++ kode til MS-Windows>
Venlig hilsen
Mogens Hansen
|