ztestr |
Отправлено: 02.09.2004, 13:10 |
|
Не зарегистрирован
|
Собственно сабж.
ниже мой исходник.
я монимаю что, что-то не доделал, а вот что?
main.cpp
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "main.h"
#include
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// RegisterAccessBar — registers or unregisters an appbar.
// Returns TRUE if successful, or FALSE otherwise.
// hwndAccessBar — handle to the appbar
// fRegister — register and unregister flag
//
// Global variables
// g_uSide — screen edge (defaults to ABE_TOP)
// g_fAppRegistered — flag indicating whether the bar is registered
bool __fastcall TForm1::RegisterAccessBar(HWND hwndAccessBar, bool fRegister)
{
APPBARDATA abd;
// Specify the structure size and handle to the appbar.
abd.cbSize = sizeof(APPBARDATA);
abd.hWnd = hwndAccessBar;
if (fRegister) {
// Provide an identifier for notification messages.
abd.uCallbackMessage = WM_USER+1234;//APPBAR_CALLBACK;
// Register the appbar.
if (!SHAppBarMessage(ABM_NEW, &abd))
return FALSE;
RECT rc;
GetWindowRect(hwndAccessBar, &rc);
AppBarQuerySetPos(ABE_TOP, &rc, &abd);
// g_uSide = ABE_TOP; // default edge
// g_fAppRegistered = TRUE;
} else {
// Unregister the appbar.
SHAppBarMessage(ABM_REMOVE, &abd);
// g_fAppRegistered = FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
RegisterAccessBar(Application->MainForm->Handle, false);
}
//---------------------------------------------------------------------------
void PASCAL TForm1::AppBarQuerySetPos(UINT uEdge, LPRECT lprc, PAPPBARDATA pabd)
{
int iHeight = 0;
int iWidth = 0;
pabd->rc = *lprc;
pabd->uEdge = uEdge;
// Copy the screen coordinates of the appbar's bounding
// rectangle into the APPBARDATA structure.
if ((uEdge == ABE_LEFT) ||
(uEdge == ABE_RIGHT)) {
iWidth = pabd->rc.right — pabd->rc.left;
pabd->rc.top = 0;
pabd->rc.bottom = GetSystemMetrics(SM_CYSCREEN);
} else {
iHeight = pabd->rc.bottom — pabd->rc.top;
pabd->rc.left = 0;
pabd->rc.right = GetSystemMetrics(SM_CXSCREEN);
}
// Query the system for an approved size and position.
SHAppBarMessage(ABM_QUERYPOS, pabd);
// Adjust the rectangle, depending on the edge to which the
// appbar is anchored.
switch (uEdge) {
case ABE_LEFT:
pabd->rc.right = pabd->rc.left + iWidth;
break;
case ABE_RIGHT:
pabd->rc.left = pabd->rc.right — iWidth;
break;
case ABE_TOP:
pabd->rc.bottom = pabd->rc.top + iHeight;
break;
case ABE_BOTTOM:
pabd->rc.top = pabd->rc.bottom — iHeight;
break;
}
// Pass the final bounding rectangle to the system.
SHAppBarMessage(ABM_SETPOS, pabd);
// Move and size the appbar so that it conforms to the
// bounding rectangle passed to the system.
MoveWindow(pabd->hWnd, pabd->rc.left, pabd->rc.top,
pabd->rc.right — pabd->rc.left,
pabd->rc.bottom — pabd->rc.top, TRUE);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (RegisterAccessBar(Application->MainForm->Handle, true) == true)
ShowMessage("OK!");
}
//---------------------------------------------------------------------------
void PASCAL TForm1::AppBarPosChanged(PAPPBARDATA pabd)
{
RECT rc;
RECT rcWindow;
int iHeight;
int iWidth;
rc.top = 0;
rc.left = 0;
rc.right = GetSystemMetrics(SM_CXSCREEN);
rc.bottom = GetSystemMetrics(SM_CYSCREEN);
GetWindowRect(pabd->hWnd, &rcWindow);
iHeight = rcWindow.bottom — rcWindow.top;
iWidth = rcWindow.right — rcWindow.left;
switch (g_uSide) {
case ABE_TOP:
rc.bottom = rc.top + iHeight;
break;
case ABE_BOTTOM:
rc.top = rc.bottom — iHeight;
break;
case ABE_LEFT:
rc.right = rc.left + iWidth;
break;
case ABE_RIGHT:
rc.left = rc.right — iWidth;
break;
}
AppBarQuerySetPos(g_uSide, &rc, pabd);
}
//---------------------------------------------------------------------------
void TForm1::AppBarCallback(HWND hwndAccessBar, UINT uNotifyMsg, LPARAM lParam)
{
APPBARDATA abd;
UINT uState;
abd.cbSize = sizeof(abd);
abd.hWnd = hwndAccessBar;
switch (uNotifyMsg) {
case ABN_STATECHANGE:
// Check to see if the taskbar's always-on-top state has
// changed and, if it has, change the appbar's state
// accordingly.
uState = SHAppBarMessage(ABM_GETSTATE, &abd);
SetWindowPos(hwndAccessBar,
(ABS_ALWAYSONTOP & uState) ? HWND_TOPMOST : HWND_BOTTOM,
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
break;
case ABN_FULLSCREENAPP:
// A full-screen application has started, or the last full-
// screen application has closed. Set the appbar's
// z-order appropriately.
if (lParam) {
SetWindowPos(hwndAccessBar,
(ABS_ALWAYSONTOP & uState) ? HWND_TOPMOST : HWND_BOTTOM,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
else {
uState = SHAppBarMessage(ABM_GETSTATE, &abd);
if (uState & ABS_ALWAYSONTOP)
SetWindowPos(hwndAccessBar, HWND_TOPMOST,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
case ABN_POSCHANGED:
// The taskbar or another appbar has changed its
// size or position.
AppBarPosChanged(&abd);
break;
}
}
//---------------------------------------------------------------------------
main.h
//---------------------------------------------------------------------------
#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
bool __fastcall RegisterAccessBar(HWND hwndAccessBar, bool fRegister);
void PASCAL AppBarQuerySetPos(UINT uEdge, LPRECT lprc, PAPPBARDATA pabd);
void PASCAL AppBarPosChanged(PAPPBARDATA pabd);
void AppBarCallback(HWND hwndAccessBar, UINT uNotifyMsg, LPARAM lParam);
int g_uSide;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Весь прикол в том что место под appBar выделяется на экране а форма остается на месте. подскажите что делать дальше. |
|
ztestr |
Отправлено: 06.09.2004, 19:35 |
|
Не зарегистрирован
|
Понял, надо сообщения перехватывать и передавать от бара к форме...
Может кто-нибудь знает как это делается в конкретном случае? |
|
|