yah. now i know the STATIC control it's drawed to parent window. so using the same way of the window creation, i can create my own label ;)
cambalinho 142 Practically a Posting Shark
cambalinho 142 Practically a Posting Shark
that image is an animation. and the images are showed 1 above other. the correct is clean the last image and show the newone.
cambalinho 142 Practically a Posting Shark
finally i have the static control transparent:
//creating the form:
hwnd = CreateWindowEx(0, classname, strCaption.c_str(),WS_OVERLAPPEDWINDOW | WS_TABSTOP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
//sending a message for subclassing:
case WM_CTLCOLORSTATIC:
{
return DefWindowProc(HandleWindow, msg, wParam, lParam);
}
break;
//heres how i create a static control with ownerdraw style:
hwnd = CreateWindowEx(
0,
TEXT("CSTATIC"),//these must be the same of LabelClass.lpszClassName
strCaption.c_str(), WS_TABSTOP|
WS_CHILD | WS_VISIBLE | SS_NOTIFY | SS_OWNERDRAW | WS_TABSTOP,
intLeft, intTop, intWidth, intHeight,
parent,
NULL,
mod,
(LPVOID)this);
//now here the static messages for draw it:
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC) wParam;
SetTextColor(hdcStatic, RGB(0,0,0));
SetBkMode (hdcStatic, TRANSPARENT);
return (LRESULT)GetStockObject(NULL_BRUSH);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(inst->hwnd, &ps);//inst is the static object pointer
if(inst->Paint==NULL)
{
if(inst->blnTransparent!=true)
FillRect(ps.hdc,&ps.rcPaint, CreateSolidBrush(inst->clrBackColor));
if(inst->imgtest.haveimage())
DrawHICONtoHDC(ps.hdc, inst->imgtest,1,1);
SetBkMode(ps.hdc,TRANSPARENT);
char *text=(char*)inst->strCaption.c_str();
SetTextColor(ps.hdc,inst->clrTextColor );
DrawTextEx(ps.hdc,text,-1,&ps.rcPaint,DT_LEFT,NULL);
if(inst->blnBorder==true)
DrawEdge(ps.hdc, &ps.rcPaint,BDR_SUNKENINNER | BDR_RAISEDOUTER,BF_RECT);
}
EndPaint(inst->hwnd, &ps);
}
break;
//and now heres the code for make it transparent:
void setTransparent(bool transparent)
{
blnTransparent = transparent;
LONG_PTR s;
if(transparent==true)
{
blnTransparent=true;
s=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
s|=WS_EX_TRANSPARENT;
SetWindowLongPtr(hwnd,GWL_EXSTYLE,s);
}
else
{
s=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
s&=~WS_EX_TRANSPARENT;
SetWindowLongPtr(hwnd,GWL_EXSTYLE,s);
blnTransparent=false;
}
InvalidateRect(hwnd,NULL,FALSE);
}
some code is from my header file. but i think that it's easy to follow.
readers: any problems please tell me.
but these label transparent have 1 problem:
(see the image)
(if i fill 1 color, that color is showed)
how can i clean the image before repaint?
cambalinho 142 Practically a Posting Shark
heres my image class:
class image
{
private:
ULONG_PTR m_gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
HDC hdcimage=CreateCompatibleDC(NULL);
HGDIOBJ obj=NULL;
HBITMAP btBitmap=NULL;
Image *img;
bool isimgused=false;
int imageheight=0;
int imageweight=0;
int framecount=0;
int intSelectFrame=0;
int framedelay=0;
string strfilename="";
Gdiplus::Color clrBackColor=Gdiplus::Color::Transparent;
HDC hdcwindow;
bool blnTransparent=true;
HICON HICONFromHBITMAP(HBITMAP bitmap)
{
BITMAP bmp;
GetObject(bitmap, sizeof(BITMAP), &bmp);
HBITMAP hbmMask = CreateCompatibleBitmap(GetDC(NULL), bmp.bmWidth, bmp.bmHeight);
ICONINFO ii = {0};
ii.fIcon = TRUE;
ii.hbmColor = bitmap;
ii.hbmMask = hbmMask;
HICON hIcon = CreateIconIndirect(&ii);
DeleteObject(hbmMask);
return hIcon;
}
public:
image()
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
btBitmap=CreateCompatibleBitmap(hdcimage,1,1);
obj = SelectObject(hdcimage, btBitmap);
}
image(HDC hdcWindow)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hdcwindow=hdcWindow;
}
image(int width, int height)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hdcimage = CreateCompatibleDC(NULL);
btBitmap = CreateBitmap(width,height,1,32,NULL);
obj = SelectObject(hdcimage, btBitmap);
framecount=1;
imageheight=height;
imageweight=width;
}
image( const string & filename)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
strfilename=filename;
if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
{
//create the transparent icon handle
HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
ICONINFO ii;
BOOL fResult = GetIconInfo(hicon, &ii);
if (fResult)
{
BITMAP bm;
fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
if (fResult)
{
imageweight= bm.bmWidth;
imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
}
if (ii.hbmMask) DeleteObject(ii.hbmMask);
if (ii.hbmColor) DeleteObject(ii.hbmColor);
}
btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
obj = SelectObject(hdcimage, btBitmap);//add the bitmap to memory DC
DrawIconEx(hdcimage,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);//draw the icon to DC with right size
//seems the DrawIcon(), always, draw it with 32X32 size
framecount=1;
DestroyCursor(hicon);
}
else
{
isimgused=true;
Gdiplus::Image img2(towstring(filename).c_str());
btBitmap=CreateBitmap(img2.GetWidth(),img2.GetHeight(),1,32,NULL);
obj = SelectObject(hdcimage, btBitmap);
Gdiplus::Graphics graphics(hdcimage);
graphics.DrawImage(&img2, 0, 0, img2.GetWidth(), img2.GetHeight());
imageweight=img2.GetWidth();
imageheight=img2.GetHeight();
UINT count = 0;
count = img2.GetFrameDimensionsCount(); …
cambalinho 142 Practically a Posting Shark
even so my problem was my own function for get the letter(from button caption). i was doing several errors without notice.
heres my function:
char GettingAltKey(string text)
{
char altkey=-1;//defauld result
int textlenght=text.length()-1;
for(int i=0; i<textlenght;i++)
{
if((text[i]=='&') && (i<textlenght) && (text[i+1]!='&'))
{
altkey=upper((char)text[i+1]);
break;
}
else if((text[i]=='&') && (i>0) && (text[i-1]!='&') )
{
altkey=upper((char)text[i+1]);
break;
}
}
return altkey;
}
//button class constructor:
button(string caption="", HWND parent=WindowMain)
{
++ButtonCount;
if(caption=="")
strCaption=strCaption + to_string(ButtonCount);
else
strCaption=caption;
setParent(parent);//is where i create the button
altkey=GettingAltKey(strCaption);
if(altkey!=-1)
RegisterHotKey(hwnd,altmessage,MOD_ALT,altkey);
}
void setText(string text)
{
strCaption=text;
if(altkey!=-1)
UnregisterHotKey(hwnd,altmessage);
altkey=GettingAltKey(strCaption);
if(altkey!=-1)
RegisterHotKey(hwnd,altmessage,MOD_ALT,altkey);
InvalidateRect(hwnd,NULL,FALSE);
}
~button()
{
--ButtonCount;
if(altkey!=-1)
UnregisterHotKey(hwnd,altmessage);
DestroyCursor(hCursor);
DestroyWindow(hwnd);
hwnd = 0;
}
now works fine.
thanks for all
cambalinho 142 Practically a Posting Shark
the RegisterHotKey() is limited?
everytime that i create a button control the RegisterHotKey() id isn't the same.
//on constructor:
++ButtonCount;
altmessage=ButtonCount;
now the hotkey message:
case WM_HOTKEY:
{
if (wParam==inst->altmessage)
{
SendMessage(inst->hwnd,WM_COMMAND,BN_CLICKED,lParam);
}
}
break;
and now how i regist the hot key:
case WM_DRAWITEM:
{
DRAWITEMSTRUCT *test=(DRAWITEMSTRUCT*) lParam;
UnregisterHotKey(inst->hwnd,inst->altmessage);
RegisterHotKey(inst->hwnd,inst->altmessage,MOD_ALT,inst->altkey);
inst is the button object pointer.
the 1st button that it's created, the alt+altkey is working fine. but the 2nd button is ignored, why?
cambalinho 142 Practically a Posting Shark
thanks for all to all
cambalinho 142 Practically a Posting Shark
let me ask: why, sometimes, we use '*' and othertimes don't with 'this'?
cambalinho 142 Practically a Posting Shark
honestly that types of if's are confused to me:
if(inst->imgtest.haveimage())//same: if(inst->imgtest.haveimage()==true)
//and
if(!inst->imgtest.haveimage())//same: if(inst->imgtest.haveimage()==false)
//correct me if i'm wrong ;)
yes i use C++ 11 type with compiler... my all class's are prepared with some C++ 11 code ;)
cambalinho 142 Practically a Posting Shark
i think:
if(inst->imgtest != NULL)
more easy ;)
because test if imgtest have 1 image or not, of course that i can use haveimage() function ;)
bool haveimage()
{
if(btBitmap==NULL)
return false;
else
return true;
}
//testing
if(inst->imgtest.haveimage()==true)
cambalinho 142 Practically a Posting Shark
now it's fixed:
bool operator != ( nullptr_t ) const
{
return btBitmap != nullptr;
}
i must add these function to my class image and now works fine.
thanks to all
but continue: i have several problems with some overload operators(even reading all tutorials) :(
so what can you advice me?
cambalinho 142 Practically a Posting Shark
my objective is testing if the imgtest.btBitmap(is the image HBITMAP) have any image with != operator, just using my image object name.
cambalinho 142 Practically a Posting Shark
if i do these works fine:
if((HBITMAP)inst->imgtest!=NULL)
but i want avoid the casting...
cambalinho 142 Practically a Posting Shark
Moschops: image.... my own class. see mike post ;)
i'm failling with these operator.
inst is the control object pointer. so the important thing is the imgtest image object.
cambalinho 142 Practically a Posting Shark
i continue with errors, when i do:
if(inst->imgtest!=NULL)
i get errors:
- "ambiguous overload for 'operator!=' (operand types are 'image' and 'int')"
cambalinho 142 Practically a Posting Shark
i'm trying overload the != and == operators, but i'm getting several errors :(
bool operator==(const image &other) const
{
if(other.btBitmap==*this->btBitmap)
return true;
else
return false;
}
bool operator!=(const image &other) const
{
return !(*this == other);
}
what i'm doing wrong?
cambalinho 142 Practically a Posting Shark
sorry i don't use MFC.
i found some problems with debugging:
RECT textrect{0};
int a=DrawText (test->hDC,inst->strCaption.c_str(),-1,&textrect,DT_CALCRECT);
int intwidth=0;
int intheight=0;
if (a==0)
MessageBox(NULL,"error","erro", MB_OK);
if(textrect.bottom<inst->imgtest.height())
intheight=inst->imgtest.height();
else
intheight=textrect.bottom;
if(textrect.right>inst->imgtest.width())
intwidth=inst->imgtest.width();
else
intwidth=textrect.right;
the textrect isn't recive, sometimes, correct values.
cambalinho 142 Practically a Posting Shark
how can i do the control autosize?
i think in these way:
1 - get the text rect:
RECT textrect;
int a=DrawText (test->hDC,inst->strCaption.c_str(),-1,&textrect,DT_CALCRECT);
(the a isn't zero)
2 - testing the rectangle with image size:
if(textrect.bottom<inst->imgtest.height())
inst->intHeight=inst->imgtest.height();
if(textrect.right<inst->imgtest.width())
inst->intWidth=inst->imgtest.width();
3 - change the control size:
SetWindowPos(inst->hwnd, 0, 0, 0, inst->intWidth, inst->intHeight,
SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCOPYBITS);
so why the control size isn't changed? did i forget something?
cambalinho 142 Practically a Posting Shark
anotherthing: why, from DrawThemeIcon(), i only get a black rectangle?
cambalinho 142 Practically a Posting Shark
i'm owner draw some controls.
here what i use for a button:
case WM_DRAWITEM:
{
DRAWITEMSTRUCT *test=(DRAWITEMSTRUCT*) lParam;
HIMAGELIST imlIcon=ImageList_Create(inst->imgtest.width(),inst->imgtest.height(),ILC_COLOR,1,1);
ImageList_Add(imlIcon,inst->imgtest,NULL);
HTHEME hTheme = OpenThemeData(inst->hwnd, L"BUTTON");
//fill the background with button face color
FillRect(test->hDC, &test->rcItem,(HBRUSH) GetSysColor(COLOR_BTNFACE));
if ( test->itemState & ODS_SELECTED) // If it is pressed
{
DrawEdge(test->hDC,&test->rcItem,EDGE_SUNKEN,BF_RECT); // Draw a sunken face
}
else if ( test->itemState & ODS_DISABLED)
{
DrawThemeBackground(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED, &test->rcItem, 0);
}
else
{
DrawEdge(test->hDC, &test->rcItem,EDGE_RAISED,BF_RECT); // Draw a raised face
}
//add the transparent image to the button
if ( test->itemState & ODS_DISABLED)
{
DrawThemeIcon(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED,&test->rcItem,imlIcon,0);
DrawThemeText(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED,(LPCWSTR) inst->strCaption.c_str(),-1,DT_LEFT|DT_HIDEPREFIX,0,&test->rcItem);
}
else
{
TransparentBlt(test->hDC,0,0,inst->imgtest.width(),inst->imgtest.height(),inst->imgtest,0,0,inst->imgtest.width(),inst->imgtest.height(),GetPixel(inst->imgtest,0,0));
SetTextColor(test->hDC,inst->clrTextColor);
SetBkMode(test->hDC,TRANSPARENT);//text background transparent
DrawText(test->hDC,inst->strCaption.c_str(),-1,&test->rcItem,DT_LEFT);
}
//draw the caption
//draw the focus rectangle
HPEN pen = CreatePen(PS_DOT,1,RGB(0,0,0));//these is the must close to the rectangle focus style
SelectObject(test->hDC,pen);
SelectObject(test->hDC,GetStockObject(NULL_BRUSH));//the rectangle will be transparent
if ( (test->itemState & ODS_FOCUS )) // If the button is focused
{
int iChange = 3;
test->rcItem.top += iChange;
test->rcItem.left += iChange;
test->rcItem.right -= iChange;
test->rcItem.bottom -= iChange;
Rectangle(test->hDC, test->rcItem.left, test->rcItem.top, test->rcItem.right, test->rcItem.bottom);
}
CloseThemeData(hTheme);
ImageList_Destroy(imlIcon);
}
break;
i see 1 problem with these 2 lines:
DrawThemeIcon(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED,&test->rcItem,imlIcon,0);
DrawThemeText(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED,(LPCWSTR) inst->strCaption.c_str(),-1,DT_LEFT|DT_HIDEPREFIX,0,&test->rcItem);
1 - the icon isn't drawed black and white. i only see a black rectangle with control size;
2 - the text is drawed, but why i see chinese characteres?
cambalinho 142 Practically a Posting Shark
i did a global variable that i change what form have the focus. so i change the GetFeregroundWindow() to that form, and now works fine ;)
cambalinho 142 Practically a Posting Shark
i found the problem: is my message loop :(
WPARAM MessageLoop()
{
MSG msgEvents;
while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
{
//if(IsChild(WindowMain,msgEvents.hwnd)==TRUE || WindowMain==msgEvents.hwnd)
{
if (!IsDialogMessage(GetForegroundWindow(), &msgEvents))
{
TranslateMessage(&msgEvents);
DispatchMessage(&msgEvents);
}
}
}
return msgEvents.wParam;
}
if i uncomment that line, when the window, loses the focus, the messages aren't executed.
but the GetForegroundWindow() can give me 1 window that isn't from my application. so what you can advice me?
cambalinho 142 Practically a Posting Shark
heres how i create the window:
oid setParent(HWND parent=GetDesktopWindow())
{
if (hwnd==NULL)
{
WNDCLASSEX FormClass;
char classname[20]="Form";
sprintf(classname,"%s",strCaption.c_str());
HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
FormClass.cbSize = sizeof(WNDCLASSEX);
FormClass.style = CS_VREDRAW | CS_HREDRAW;
FormClass.lpfnWndProc = WndProcForm;
FormClass.cbClsExtra = 0;
FormClass.cbWndExtra = 0;
FormClass.hInstance = mod;
FormClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
FormClass.hCursor = LoadCursor(NULL, IDC_ARROW);
FormClass.hbrBackground = (HBRUSH)((COLOR_WINDOW)+1);
FormClass.lpszMenuName = NULL;
FormClass.lpszClassName = classname;
FormClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// register the new window class
RegisterClassEx(&FormClass);
hwnd = CreateWindowEx(0, classname, strCaption.c_str(),WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA);
if (hwnd == NULL)
MessageBox(NULL, "Can't create the control", "error", MB_OK);
}
else
{
SetParent(hwnd,parent);
}
ShowWindow(hwnd, SW_NORMAL);
InvalidateRect(hwnd,NULL,true);
UpdateWindow(hwnd);
clrBackColor =GetDCBrushColor(GetDC(hwnd));
clrTextColor = GetTextColor(GetDC(hwnd));
}
cambalinho 142 Practically a Posting Shark
i have 1 class Timer. the class works fine, but when the windows loses the focus, the timer stops... why these happens?
cambalinho 142 Practically a Posting Shark
the szInfo is the key: if is empty the balloon isn't showed.
strcpy(NID.szInfo , "hello beaury");
if hBalloonIcon class member give us an error about not be a class member, use these line before includes files:
#define NTDDI_VERSION 0x06000000
now we can use, too, the NOTIFYICONDATA_V3_SIZE and NIF_SHOWTIP consts ;)
for use the balloon icon, the dwInfoFlags must be NIIF_USER:
NID.dwInfoFlags = NIIF_USER;
readers for use Notification messages, we must use the NIF_MESSAGE on uFlags class member.
thanks for all
cambalinho 142 Practically a Posting Shark
i'm sorry.... i continue with problems. i don't understand how can i show the balloon :(
cambalinho 142 Practically a Posting Shark
i can show an icon on notify area:
NOTIFYICONDATA NID;
//on main
NID.cbSize = NOTIFYICONDATA_V2_SIZE; //if i use the NOTIFYICONDATA_V3_SIZE
//the compiler enters on conflits
NID.hIcon = test2;
NID.uCallbackMessage = WM_USER + 1;
NID.hWnd = a;
NID.uID = 01;
NID.uVersion=4;
NID.uTimeout=500;
NID.dwInfoFlags = NIIF_INFO;
strcpy(NID.szInfoTitle, "Test Title");
//NID.hBalloonIcon=(HICON)test2;//no member
strcpy(NID.szTip, "System Tray Icon: Hello World");
NID.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE | NIF_INFO | 0x00000080;
//how i show the icon:
Shell_NotifyIcon(NIM_ADD , &NID);
the icon and tooltip are showed, but not the ballon :(
what i'm doing wrong?
cambalinho 142 Practically a Posting Shark
when we move the moouse by items a nice rectangle is showed where is the mouse and hided on last menu item. when these happens the menu item is updated. knowing these i came up with 1 nice ideia ;)
void Refresh()
{
HMENU hMenu = NULL;
if(primeiromenu)
hMenu = mnuBar;
else
hMenu = MenuHandle;
bool IsHighlith=false;
if(GetMenuState(hMenu,ID,MF_BYCOMMAND)==MF_HILITE)
IsHighlith=true;
MENUITEMINFO s={0};
s.cbSize=sizeof(MENUITEMINFO );
s.fMask=MIIM_STATE;
GetMenuItemInfo (hMenu,ID, FALSE, &s);
if(IsHighlith==true)
s.fState|=MFS_HILITE;
else
s.fState|=MFS_UNHILITE;
SetMenuItemInfo (hMenu,ID, FALSE, &s);
if(IsHighlith==true)
{
s={0};//empty the 's' for don't have a garbage data
s.fMask=MIIM_STATE;
GetMenuItemInfo (hMenu,ID, FALSE, &s);
s.fState|=MFS_HILITE;
SetMenuItemInfo (hMenu,ID, FALSE, &s);
}
}
now i can refresh a menu item ;)
cambalinho 142 Practically a Posting Shark
please try with menus. and with gif files(where i see the problem)
cambalinho 142 Practically a Posting Shark
i continue with problems. the HBITMAP isn't copyed to HDC:
void bitmap(image imgImage)
{
DeleteObject(outbitmap);
BITMAP bm;
RECT f={0,0,100,100};
GetObject((HBITMAP)imgImage, sizeof(bm), &bm);
HDC DC = GetDC(NULL);
HDC MemDCExercising = CreateCompatibleDC(DC); //Create a DC compatible with our Display/Monitor.. 32-bit.
outbitmap = CreateCompatibleBitmap(MemDCExercising, bm.bmWidth, bm.bmHeight); //create a bitmap that is compatible with our DC.
HBITMAP oldbitmap = (HBITMAP) SelectObject(MemDCExercising, (HBITMAP)outbitmap);
HDC MemDCExercising2 = CreateCompatibleDC(DC);
HBITMAP oldbitmap2 = (HBITMAP) SelectObject(MemDCExercising2, (HBITMAP)imgImage);
TransparentBlt(MemDCExercising, 0, 0, bm.bmWidth , bm.bmHeight, MemDCExercising2, 0, 0,bm.bmWidth , bm.bmHeight,GetPixel(MemDCExercising2,0,0) );
DrawHBITMAPtoHDC((HBITMAP)imgImage, MemDCExercising); //not showed in these situation
//maybe the memory DC or the HBITMAP selection is wrong
DrawTextEx(MemDCExercising,"hello world",-1,&f,DT_CENTER,NULL);//is showed
SelectObject(MemDCExercising, oldbitmap);
DeleteDC(MemDCExercising);
ReleaseDC(NULL, DC); //good.
HMENU hMenu = NULL;
if(primeiromenu)
hMenu = mnuBar;
else
hMenu = MenuHandle;
SetMenuItemBitmaps(hMenu,ID,MF_BYCOMMAND,(HBITMAP)outbitmap ,(HBITMAP)outbitmap);
}
cambalinho 142 Practically a Posting Shark
sorry i have several mistakes on last code
cambalinho 142 Practically a Posting Shark
the image is showed, but not transparent :(
void bitmap(image imgImage)
{
DeleteObject(outbitmap);
BITMAP bm;
GetObject((HBITMAP)imgImage,sizeof(bm),&bm);
HDC DC = GetDC(NULL);
HDC MemDCExercising = CreateCompatibleDC(DC);
outbitmap=CreateCompatibleBitmap(DC, bm.bmWidth, bm.bmHeight);
HBITMAP oldbitmap =(HBITMAP) SelectObject(MemDCExercising, outbitmap);
DrawHBITMAPtoHDC(imgImage,MemDCExercising);
SelectObject(MemDCExercising,oldbitmap);
DeleteDC(MemDCExercising);
ReleaseDC(NULL, DC);
HMENU hMenu = NULL;
if(primeiromenu)
hMenu = mnuBar;
else
hMenu = MenuHandle;
SetMenuItemBitmaps(hMenu,ID,MF_BYCOMMAND,(HBITMAP)imgImage ,(HBITMAP)imgImage);
}
the outbitmap is a global variable and deleted, too, on destructor.
cambalinho 142 Practically a Posting Shark
i did i nice way for my label control and works:
void DrawHBITMAPtoHDC(HBITMAP hBitmap, HDC hdc)
{
BITMAP bm;
HDC MemDCExercising = CreateCompatibleDC(hdc);
HBITMAP oldbitmap =(HBITMAP) SelectObject(MemDCExercising, hBitmap);
GetObject(hBitmap,sizeof(bm),&bm);
TransparentBlt(hdc, 0, 0, bm.bmWidth , bm.bmHeight, MemDCExercising, 0, 0,bm.bmWidth , bm.bmHeight,GetPixel(MemDCExercising,0,0) );
SelectObject(MemDCExercising,oldbitmap);
DeleteDC(MemDCExercising);
}
//on label paint message:
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(inst->hwnd, &ps);
if(inst->Paint==NULL)
{
RECT f;
HDC hdc=GetDC(inst->hwnd);//getting the control HDC
GetClientRect(inst->hwnd,&f);//getting the
HBRUSH s=CreateSolidBrush(inst->clrBackColor);
HBRUSH oldBrush=(HBRUSH)SelectObject(hdc,(HBRUSH)s);
if (inst->clrBackColor==-1)
{
//hide, copy the parent control and show the control again
ShowWindow(inst->hwnd,SW_HIDE);
BitBlt(hdc,0,0,f.right-f.left,f.bottom-f.top,GetDC(GetParent(inst->hwnd)),inst->intLeft,inst->intTop,SRCCOPY);
ShowWindow(inst->hwnd,SW_SHOW);
}
else
FillRect(hdc,&f,s);
DrawHBITMAPtoHDC(inst->hBitmap,hdc);
SetBkMode(hdc,TRANSPARENT);
char *text=(char*)inst->strCaption.c_str();
SetTextColor(hdc,inst->clrTextColor );
DrawTextEx(hdc,text,-1,&f,DT_CENTER,NULL);
SelectObject(hdc,(HBRUSH)oldBrush);
DeleteObject(s);
}
EndPaint(inst->hwnd, &ps);
i'm trying the same tecnic with menus, but, for now, without sucess.
void bitmap(image imgImage)
{
BITMAP bm;
HDC MemDCExercising = CreateCompatibleDC(NULL);
GetObject((HBITMAP)imgImage,sizeof(bm),&bm);
HBITMAP outbitmap=CreateBitmap(bm.bmWidth,bm.bmHeight,1,32,NULL);
HBITMAP oldbitmap =(HBITMAP) SelectObject(MemDCExercising, outbitmap);
DrawHBITMAPtoHDC(imgImage,MemDCExercising);
SelectObject(MemDCExercising,oldbitmap);
DeleteDC(MemDCExercising);
HMENU hMenu = NULL;
if(primeiromenu)
hMenu = mnuBar;
else
hMenu = MenuHandle;
SetMenuItemBitmaps(hMenu,ID,MF_BYCOMMAND,(HBITMAP)outbitmap ,(HBITMAP)outbitmap);
}
cambalinho 142 Practically a Posting Shark
sorry, in these case i don't have HDC
cambalinho 142 Practically a Posting Shark
can i change the HBITMAP structure for be transparent?
because the gif's files are show me a black background color.
cambalinho 142 Practically a Posting Shark
my message loop is wrong:
//Message Loop
WPARAM MessageLoop()
{
MSG msgEvents;
while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
{
if(IsChild(GetForegroundWindow(),msgEvents.hwnd)==TRUE || GetForegroundWindow()==msgEvents.hwnd)
{
if (!IsDialogMessage(GetForegroundWindow(), &msgEvents))
{
TranslateMessage(&msgEvents);
DispatchMessage(&msgEvents);
}
}
}
return msgEvents.wParam;
}
when i change the menu style with MENUINFO structure and must do, too, for submenus:
MENUINFO mnInfo;
mnInfo.cbSize=sizeof(MENUINFO);
mnInfo.fMask=MIM_STYLE;
if(systmenu==false)
GetMenuInfo(GetMenu(MainHWND),&mnInfo);
else
GetMenuInfo(GetSystemMenu(MainHWND,false),&mnInfo);
mnInfo.cbSize=sizeof(MENUINFO);
mnInfo.fMask=MIM_STYLE | MIM_APPLYTOSUBMENUS;
mnInfo.dwStyle=MNS_NOTIFYBYPOS;
if(systmenu==false)
SetMenuInfo(GetMenu(MainHWND),&mnInfo);
else
SetMenuInfo(GetSystemMenu(MainHWND,false),&mnInfo);
now the menu commands works on menu context's.
thanks to all
cambalinho 142 Practically a Posting Shark
my image class can read animated gif's. using a timer i can change the menu item image. but when the menu item is showed, how can i refresh it?
(i have tryied the DrawMenuBar() and SetMenu() without sucess. the image is, only, updated when i move the mouse from 1 item to another one)
cambalinho 142 Practically a Posting Shark
everytime we use the new keyword(on constructor) and if we need use it again, we must use the delete:
class image
{
private:
ULONG_PTR m_gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
HDC hdcimage=CreateCompatibleDC(NULL);
HGDIOBJ obj=NULL;
HBITMAP btBitmap;
Image *img;
int imageheight=0;
int imageweight=0;
int framecount=0;
int intSelectFrame=0;
int framedelay=0;
string strfilename="";
Gdiplus::Color clrBackColor=Gdiplus::Color::Transparent;
HDC hdcwindow;
bool blnTransparent=true;
HICON HICONFromHBITMAP(HBITMAP bitmap)
{
BITMAP bmp;
GetObject(bitmap, sizeof(BITMAP), &bmp);
HBITMAP hbmMask = CreateCompatibleBitmap(GetDC(NULL), bmp.bmWidth, bmp.bmHeight);
ICONINFO ii = {0};
ii.fIcon = TRUE;
ii.hbmColor = bitmap;
ii.hbmMask = hbmMask;
HICON hIcon = CreateIconIndirect(&ii);
DeleteObject(hbmMask);
return hIcon;
}
public:
image()
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
btBitmap=CreateCompatibleBitmap(hdcimage,1,1);
obj = SelectObject(hdcimage, btBitmap);
}
image(HDC hdcWindow)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hdcwindow=hdcWindow;
}
image(int width, int height)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hdcimage = CreateCompatibleDC(NULL);
btBitmap = CreateCompatibleBitmap(hdcimage,width,height);
obj = SelectObject(hdcimage, btBitmap);
framecount=1;
}
image( const string & filename)
{
strfilename=filename;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
{
//create the transparent icon handle
HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
ICONINFO ii;
BOOL fResult = GetIconInfo(hicon, &ii);
if (fResult)
{
BITMAP bm;
fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
if (fResult)
{
imageweight= bm.bmWidth;
imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
}
if (ii.hbmMask) DeleteObject(ii.hbmMask);
if (ii.hbmColor) DeleteObject(ii.hbmColor);
}
btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
obj = SelectObject(hdcimage, btBitmap);//add the bitmap to memory DC
DrawIconEx(hdcimage,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);//draw the icon to DC with right size
//seems the DrawIcon(), always, draw it with 32X32 size
framecount=1;
DestroyCursor(hicon);
}
else
{
Gdiplus::Image img2(towstring(filename).c_str());
btBitmap=CreateBitmap(img2.GetWidth(),img2.GetHeight(),1,32,NULL);
obj = SelectObject(hdcimage, btBitmap);
Gdiplus::Graphics graphics(hdcimage);
graphics.DrawImage(&img2, 0, 0, img2.GetWidth(), …
cambalinho 142 Practically a Posting Shark
now works without memory leaks. thanks for all
cambalinho 142 Practically a Posting Shark
now i did:
~image()
{
Gdiplus::GdiplusShutdown(m_gdiplusToken);
//delete graphic;//memory leak too
//delete img;
/*if(btBitmap!=NULL ||obj!=NULL)
{
SelectObject(hdcimage, obj);
//DeleteObject(btBitmap);//don't show me the image
}*/
DeleteDC(hdcimage);
}
and no memory leak. unless i return HBITMAP more than once. why?
(your solution helped me very much... thanks)
cambalinho 142 Practically a Posting Shark
i did all the changes, but i continue with problems:
class image
{
private:
ULONG_PTR m_gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
HDC hdcimage=CreateCompatibleDC(NULL);
HGDIOBJ obj=NULL;
HBITMAP btBitmap;
Gdiplus::Graphics *graphic;
Image *img;
int imageheight=0;
int imageweight=0;
int framecount=0;
int intSelectFrame=0;
int framedelay=0;
string strfilename="";
Gdiplus::Color clrBackColor=Gdiplus::Color::Transparent;
HDC hdcwindow;
bool blnTransparent=true;
public:
image()
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
btBitmap=CreateCompatibleBitmap(hdcimage,1,1);
obj = SelectObject(hdcimage, btBitmap);
}
image(HDC hdcWindow)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hdcwindow=hdcWindow;
}
image(int width, int height)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hdcimage = CreateCompatibleDC(NULL);
btBitmap=CreateCompatibleBitmap(hdcimage,width,height);
obj = SelectObject(hdcimage, btBitmap);
framecount=1;
}
image( const string & filename)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
{
//create the transparent icon handle
HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
ICONINFO ii;
BOOL fResult = GetIconInfo(hicon, &ii);
if (fResult)
{
BITMAP bm;
fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
if (fResult)
{
imageweight= bm.bmWidth;
imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
}
if (ii.hbmMask) DeleteObject(ii.hbmMask);
if (ii.hbmColor) DeleteObject(ii.hbmColor);
}
btBitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
obj = SelectObject(hdcimage, btBitmap);//add the bitmap to memory DC
DrawIconEx(hdcimage,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);//draw the icon to DC with right size
//seems the DrawIcon(), always, draw it with 32X32 size
framecount=1;
DestroyCursor(hicon);
}
else
{
Gdiplus::Image img2(towstring(filename).c_str());
btBitmap=CreateBitmap(img2.GetWidth(),img2.GetHeight(),1,32,NULL);
obj = SelectObject(hdcimage, btBitmap);
Gdiplus::Graphics graphics(hdcimage);
graphics.DrawImage(&img2, 0, 0, img2.GetWidth(), img2.GetHeight());
imageweight=img2.GetWidth();
imageheight=img2.GetHeight();
UINT count = 0;
count = img2.GetFrameDimensionsCount();
GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*count);
img2.GetFrameDimensionsList(pDimensionIDs, count);
framecount=img2.GetFrameCount(&pDimensionIDs[0]);
framedelay =img2.GetPropertyItemSize(PropertyTagFrameDelay);
img=new Image(towstring(filename).c_str());
free(pDimensionIDs);
}
}
image (const image &cSource)
{
framecount=cSource.framecount;
framedelay=cSource.framedelay;
clrBackColor=cSource.clrBackColor;
img=cSource.img->Clone();
imageweight=cSource.imageweight;
imageheight=cSource.imageheight;
if(obj==NULL)
{
btBitmap=CreateBitmap(imageweight,imageweight,1,32,NULL);
obj = SelectObject(hdcimage, btBitmap);
}
BitBlt(hdcimage,0,0,imageweight,imageheight,cSource.hdcimage,0,0,SRCCOPY);
}
image& …
cambalinho 142 Practically a Posting Shark
finally works fine:
class image
{
private:
ULONG_PTR m_gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
HDC hdcimage=CreateCompatibleDC(NULL);
HBITMAP btBimap;
Gdiplus::Graphics *graphic;
Image *img;
int imageheight=0;
int imageweight=0;
int framecount=0;
int intSelectFrame=0;
int framedelay=0;
string strfilename="";
Gdiplus::Color clrBackColor=Gdiplus::Color::Transparent;
HDC hdcwindow;
bool blnTransparent=true;
public:
image()
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
btBimap=CreateCompatibleBitmap(hdcimage,1,1);
SelectObject(hdcimage, btBimap);
}
image(HDC hdcWindow)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hdcwindow=hdcWindow;
}
image(int width, int height)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hdcimage = CreateCompatibleDC(NULL);
btBimap=CreateCompatibleBitmap(hdcimage,width,height);
SelectObject(hdcimage, btBimap);
framecount=1;
}
image( const string & filename)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
{
//create the transparent icon handle
HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
ICONINFO ii;
BOOL fResult = GetIconInfo(hicon, &ii);
if (fResult)
{
BITMAP bm;
fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
if (fResult)
{
imageweight= bm.bmWidth;
imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
}
if (ii.hbmMask) DeleteObject(ii.hbmMask);
if (ii.hbmColor) DeleteObject(ii.hbmColor);
}
btBimap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
SelectObject(hdcimage, btBimap);//add the bitmap to memory DC
DrawIconEx(hdcimage,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);//draw the icon to DC with right size
//seems the DrawIcon(), always, draw it with 32X32 size
framecount=1;
}
else
{
Gdiplus::Image img2(towstring(filename).c_str());
btBimap=CreateBitmap(img2.GetWidth(),img2.GetHeight(),1,32,NULL);
SelectObject(hdcimage, btBimap);
Gdiplus::Graphics graphics(hdcimage);
graphics.DrawImage(&img2, 0, 0, img2.GetWidth(), img2.GetHeight());
imageweight=img2.GetWidth();
imageheight=img2.GetHeight();
UINT count = 0;
count = img2.GetFrameDimensionsCount();
GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*count);
img2.GetFrameDimensionsList(pDimensionIDs, count);
framecount=img2.GetFrameCount(&pDimensionIDs[0]);
framedelay =img2.GetPropertyItemSize(PropertyTagFrameDelay);
img=new Image(towstring(filename).c_str());
}
}
image (const image &cSource)
{
framecount=cSource.framecount;
framedelay=cSource.framedelay;
clrBackColor=cSource.clrBackColor;
img=cSource.img->Clone();
imageweight=cSource.imageweight;
imageheight=cSource.imageheight;
btBimap=CreateBitmap(imageweight,imageweight,1,32,NULL);
SelectObject(hdcimage, btBimap);
BitBlt(hdcimage,0,0,imageweight,imageheight,cSource.hdcimage,0,0,SRCCOPY);
}
image& operator= (const image &cSource)
{
framecount=cSource.framecount;
framedelay=cSource.framedelay;
intSelectFrame=cSource.intSelectFrame;
clrBackColor=cSource.clrBackColor;
imageweight=cSource.imageweight;
imageheight=cSource.imageheight;
btBimap=CreateBitmap(imageweight,imageweight,1,32,NULL);
SelectObject(hdcimage, btBimap);
BitBlt(hdcimage,0,0,imageweight,imageheight,cSource.hdcimage,0,0,SRCCOPY);
return *this;
}
property <int> SelectFrame
{
Get(int)
{ …
cambalinho 142 Practically a Posting Shark
triumphost the image isn't showed on menu :(
//on image class
operator HBITMAP()
{
HBITMAP hbitmap=reinterpret_cast<HBITMAP>(GetCurrentObject(hdcimage, OBJ_BITMAP));
return hbitmap;
}
//on menu class
void bitmap(image imgImage)
{
//HBITMAP bitimage = (HBITMAP)LoadImage( NULL, filename.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HMENU hMenu = NULL;
if(primeiromenu)
hMenu = mnuBar;
else
hMenu = MenuHandle;
SetMenuItemBitmaps(hMenu,menuposition,MF_BYPOSITION ,(HBITMAP)imgImage ,(HBITMAP)imgImage);
}
cambalinho 142 Practically a Posting Shark
when do:
operator HBITMAP()
{
HBITMAP hbitmap=CreateBitmap(imageweight,imageheight,1,32,NULL);//create the bitmap with icon size
SelectObject(hdcimage, hbitmap);//add the bitmap to memory DC
MessageBox(NULL,to_string(GetLastError()).c_str(),"error",MB_OK);
return hbitmap;
}
the hdcimage is copyied to hbitmap, right?
cambalinho 142 Practically a Posting Shark
i have these code for show popupmenus:
case WM_USER + 1:
{
if(lParam==WM_RBUTTONUP)
{
POINT pCursor;
GetCursorPos(&pCursor);
HMENU test=GetSubMenu(GetMenu(HandleWindow),0);
SetForegroundWindow(HandleWindow);
TrackPopupMenu(test, TPM_LEFTBUTTON | TPM_RIGHTALIGN, pCursor.x, pCursor.y, 0, HandleWindow, NULL);
PostMessage(HandleWindow, WM_NULL, 0, 0);
}
}
break;
the menu is showed normaly, but why the click message isn't working?
heres the message loop that works normaly:
WPARAM MessageLoop()
{
MSG msgEvents;
while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
{
if(IsChild(GetForegroundWindow(),msgEvents.hwnd)==TRUE || GetForegroundWindow()==msgEvents.hwnd)
{
if(IsDialogMessage(GetForegroundWindow(), &msgEvents) == TRUE)
{
TranslateMessage(&msgEvents);
DispatchMessage(&msgEvents);
}
}
}
return msgEvents.wParam;
}
the menus are using the notification style:
//for get the menu click event
//i'm using menu notifications
case WM_MENUCOMMAND:
{
MENUITEMINFO menuInfo;
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask=MIIM_DATA;
if(GetMenuItemInfo((HMENU)lParam,(UINT) wParam, true, &menuInfo )!=0)
{
Menu *mMenu = (Menu *) menuInfo.dwItemData;
if(mMenu!=NULL)
mMenu->Click();
}
menuhandle=NULL;
}
break;
so why, when i show the menu, the click events aren't working?
strange the mouse leave\enter are working:
//when the mouse move, enter, leave and leave the menu
case WM_MENUSELECT:
{
static int Last_Menu_ID = -1;
if(((HIWORD(wParam) & MF_HILITE) || (HIWORD(wParam) & MF_MOUSESELECT)) && GetMenuState((HMENU)lParam,LOWORD(wParam),MF_BYCOMMAND)!=0xFFFFFFFF)
{
//mouse leave the previous menu item
if(GetMenuState((HMENU)lParam,Last_Menu_ID,MF_BYCOMMAND)!=0xFFFFFFFF)
{
MENUITEMINFO menuInfo;
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask=MIIM_DATA;
GetMenuItemInfo((HMENU)lParam,Last_Menu_ID, FALSE, &menuInfo );
Menu *mMenu = (Menu *) menuInfo.dwItemData;
if (mMenu!=NULL)
{
mMenu->Leave();
}
}
//Mouse Enter on actual menu item
MENUITEMINFO menuInfo1;
menuInfo1.cbSize = sizeof(MENUITEMINFO);
menuInfo1.fMask=MIIM_DATA;
GetMenuItemInfo((HMENU)lParam,LOWORD(wParam), FALSE, &menuInfo1 );
Menu *mMenu = (Menu *) menuInfo1.dwItemData;
if (mMenu!=NULL)
{
mMenu->Enter();
}
Last_Menu_ID = LOWORD(wParam);
}
//testing if the menu item is …
cambalinho 142 Practically a Posting Shark
now it's working nice ;)
i did a diferent tool for make menu shortcuts and works fine:
struct MenuShortCuts
{
//inicializate structure values
MenuShortCuts() : MenuPointer(NULL), key(-1), alt(false), control(false), shift(false) {}
ULONG_PTR MenuPointer;
char key;
bool alt;
bool control;
bool shift;
};
vector<MenuShortCuts> TableMenuShortCuts;//global variable
//on my class menus, after show the menus:
//detetcting the shortcut from caption
String b=UpperCase(strCaption);//is like the normal string, but have the separewordssymbols() and more functions
vector<string> c;
bool HasShortCut=false;
c=b.separewordssymbols();//geting the string separed by '\t' and words
//testing if the caption have '\t' for use the menus shortcuts
for(int i=(c.size()-1); i>0; i--)
{
if(c[i] =="\t")
{
HasShortCut=true;
break;
}
}
if(HasShortCut==true)
{
TableMenuShortCuts.resize(TableMenuShortCuts.size()+1);//have more 1 menu, then more 1 shortcut on list
TableMenuShortCuts[TableMenuShortCuts.size()-1].MenuPointer=(ULONG_PTR)this;
TableMenuShortCuts[TableMenuShortCuts.size()-1].key=(c[c.size()-1])[0]; //recives the 1st letter form right
//testing the control/alt/shit keys
for(int i=(c.size()-1); i>0; i--)
{
if(c[i] =="CTRL")
{
TableMenuShortCuts[TableMenuShortCuts.size()-1].control=true;
}
else if(c[i] =="ALT")
{
TableMenuShortCuts[TableMenuShortCuts.size()-1].alt=true;
}
else if(c[i] =="SHIFT")
{
TableMenuShortCuts[TableMenuShortCuts.size()-1].shift=true;
}
else if(c[i] =="\t")
break;
}
}
//window procedure:
case WM_KEYUP:
{
int a=TableMenuShortCuts.size();
for(int i=0; i<a;i++ )
{
if(keyboard[TableMenuShortCuts[i].key]==true &&(keyboard[VK_CONTROL]==TableMenuShortCuts[i].control)&&(keyboard[VK_SHIFT]==TableMenuShortCuts[i].shift) &&(keyboard[VK_MENU]==TableMenuShortCuts[i].alt))
{
Menu *mMenu = (Menu *)TableMenuShortCuts[i].MenuPointer;
if (mMenu!=NULL)
{
mMenu->Click();
}
}
}
KeyPressed=false;
inst->KeyUp(keyboard,KeyDownCount);
return DefWindowProc(HandleWindow, msg, wParam, lParam);
}
break;
it's a nice way for do the menu shortcuts ;)
i was getting problems with AcceleratorTable functions for my situation ;)
readers: please, i did that mistake with Alt key and now i know why, never forget when the windows messages needs return a value.
WM_KEYUP: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281%28v=vs.85%29.aspx
"An …
cambalinho 142 Practically a Posting Shark
i need ask 1 thing:
//Message Loop
WPARAM MessageLoop()
{
MSG msgEvents;
while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
{
if(IsChild(GetForegroundWindow(),msgEvents.hwnd)==TRUE || GetForegroundWindow()==msgEvents.hwnd)
{
if(IsDialogMessage(GetForegroundWindow(), &msgEvents) == TRUE)
{
TranslateMessage(&msgEvents);
DispatchMessage(&msgEvents);
}
}
}
return msgEvents.wParam;
}
how the IsDialogMessage() can affect the Alt key?
i need use the IsDialogMessage() function for work with keyboard(when we have the child controls), but can affect the Alt key:
1 - press the Alt key: the underline, on menu(the menubar items), is showed;
2 - unpress the Alt key: the underline isn't showed.
why these behavor?
cambalinho 142 Practically a Posting Shark
heres the 2 functions rebuilded:
string UpperCase (const string& in)
{
string out(in);
for (size_t i = 0; i < in.size (); ++i)
{
out[i] = toupper(out[i]);
}
return out;
}
string LowCase (const string& in)
{
string out(in);
for (size_t i = 0; i < in.size (); ++i)
{
out[i] = tolower(out[i]);
}
return out;
}
thanks to all
cambalinho 142 Practically a Posting Shark
by several reasons i'm doing my own table accelerator code ;)
thanks for all
(after finish, i will show the code)
cambalinho 142 Practically a Posting Shark
i'm sorry to both, but i continue with problems :(
string Ustrcaption=UpperCase(strCaption);
String b=Ustrcaption;//is like the normal string, but have the separewordssymbols() and more functions
vector<string> c;
c=b.separewordssymbols();//tested and the results are fine
TableMenuShortCuts.resize(TableMenuShortCuts.size()+1);
TableMenuShortCuts[TableMenuShortCuts.size()-1].MenuPointer=(ULONG_PTR)this;
TableMenuShortCuts[TableMenuShortCuts.size()-1].key=(c)[c.size()-1][0];
if(strCaption=="&Exit\tCtrl+g")
//SetWindowText(MainHWND,(LPCSTR)TableMenuShortCuts[TableMenuShortCuts.size()-1].key);//empty string or even don't change it
SetWindowText(MainHWND,(LPCSTR)c[c.size()-1].c_str());//the char is showed wihtout problems
please read the comments.
the TableMenuShortCuts[TableMenuShortCuts.size()-1].key don't recive the results correctly :(
@NathanOliver: i'm testing what you said too :(