Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


CreateMDIWindow & Toolbar

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Fri Oct 02, 2009 1:20 pm    Post subject: CreateMDIWindow & Toolbar Reply with quote

Main Problem:

I'm working on a project in which i want to use MDI windows to make it multi-windowed within the parent window. I've never done it before, so i was looking at some examples online and it seems pretty easy. It worked so far, but there is a problem. When i try to set a toolbar to the window, the MDIClient window fucks with it..

I was going to handle WM_MOVE and stop the windows from coming past the toolbar, but maximizing the MDI window will still fuck with it.

Any suggestions?


Code:
#include <windows.h>
#include <commctrl.h>
#include <TCHAR.h>
#include "resource.h"
#include <string>

typedef std::basic_string<TCHAR> ustring;

#pragma comment(lib, "comctl32.lib")

#define ID_TOOLBAR 106

static HINSTANCE basead;
static HWND hMDIFrame;
static HWND hMDIClient;
static int current = 0;

static LRESULT CALLBACK MDIFrameWndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK MDIChildWndProc(HWND, UINT, WPARAM, LPARAM);

void AddToolbarButton(const HWND,TBBUTTON&,int,const ustring&,
                 BYTE style=TBSTYLE_BUTTON,DWORD_PTR data=0,int cmd=-1,
                 BYTE state=TBSTATE_ENABLED);

enum {
   IDC_TOOLBAR=200,
};


void StartCommonControls(DWORD flags)
{
   //load the common controls dll, specifying the type of control(s) required
   INITCOMMONCONTROLSEX iccx;
   iccx.dwSize=sizeof(INITCOMMONCONTROLSEX);
   iccx.dwICC=flags;
   InitCommonControlsEx(&iccx);
}


int WINAPI WinMain(HINSTANCE handle, HINSTANCE hinst, LPSTR, int)
{

   basead = handle;

   WNDCLASSEX wcex;
   wcex.cbSize = sizeof(WNDCLASSEX);
   wcex.style   = CS_HREDRAW | CS_VREDRAW;
   wcex.lpfnWndProc = MDIFrameWndProc;
   wcex.cbClsExtra = 0;
   wcex.cbWndExtra = 0;
   wcex.hInstance   = basead;
   wcex.hIcon   = LoadIcon(basead, IDI_APPLICATION);
   wcex.hCursor = LoadCursor(0, IDC_ARROW);
   wcex.hbrBackground   = 0;
   wcex.lpszMenuName = L"IDRES_MENU";
   wcex.lpszClassName   = L"MDIFRAMEWINDOW";
   wcex.hIconSm = 0;
   RegisterClassEx(&wcex);

   wcex.cbSize = sizeof(WNDCLASSEX);
   wcex.style   = CS_HREDRAW | CS_VREDRAW;
   wcex.lpfnWndProc = MDIChildWndProc;
   wcex.cbClsExtra = 0;
   wcex.cbWndExtra = sizeof(int);
   wcex.hInstance   = basead;
   wcex.hIcon   = LoadIcon(basead, IDI_APPLICATION);
   wcex.hCursor = LoadCursor(0, IDC_ARROW);
   wcex.hbrBackground   = (HBRUSH)GetStockObject(WHITE_BRUSH);
   wcex.lpszMenuName = 0;
   wcex.lpszClassName   = L"MDICHILDWINDOW";
   wcex.hIconSm = 0;
   RegisterClassEx(&wcex);

   DWORD style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE;
   int x = CW_USEDEFAULT; int y = CW_USEDEFAULT;
   int w = CW_USEDEFAULT; int h = CW_USEDEFAULT;
   hMDIFrame = CreateWindow(L"MDIFRAMEWINDOW", L"Main Window", style, x, y, w, h, 0, 0, basead, 0);

   ShowWindow(hMDIFrame, SW_SHOW);
   UpdateWindow(hMDIFrame);

   MSG msg;
   while(GetMessage(&msg, 0, 0, 0)) {
      if(!TranslateMDISysAccel(hMDIClient, &msg)) {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
   }
}

void AddToolbarButton(const HWND hTb,TBBUTTON& tbb,int bmp,const ustring& txt,
                 BYTE style,DWORD_PTR data,int cmd,BYTE state)
{
   tbb.iBitmap=bmp;
   tbb.idCommand=cmd;
   tbb.fsState=state;
   tbb.fsStyle=style;
   tbb.dwData=data;
   tbb.iString=SendMessage(hTb,TB_ADDSTRING,0,reinterpret_cast<LPARAM>(txt.c_str()));
}

HWND CreateToolbar(const HWND hParent,const HINSTANCE hInst,DWORD dwStyle,
               const RECT& rc,const int id)
{
   dwStyle|=WS_CHILD|WS_VISIBLE;
   return CreateWindowEx(0,                  //extended styles
      TOOLBARCLASSNAME,   //control 'class' name
      0,                  //control caption
      dwStyle,            //wnd style
      rc.left,            //position: left
      rc.top,             //position: top
      rc.right,           //width
      rc.bottom,          //height
      hParent,            //parent window handle
      //control's ID
      reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
      hInst,              //instance
      0);                 //user defined info
}


int OnCreate(const HWND hwnd,CREATESTRUCT *cs)
{
   //handles the WM_CREATE message of the main, parent window; return -1 to fail
   //window creation
   RECT rc={0,0,0,0};  //set dimensions in parent window's WM_SIZE handler
   StartCommonControls(ICC_BAR_CLASSES);

   HWND hToolbar=CreateToolbar(hwnd,cs->hInstance,/*TBSTYLE_FLAT|CCS_ADJUSTABLE|WS_OVERLAPPED|
      CCS_NODIVIDER*/ TBSTYLE_FLAT | WS_CHILD | WS_VISIBLE ,rc,IDC_TOOLBAR);

   SetWindowLongPtr(hwnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(hToolbar));

   TBADDBITMAP tbAddBmp={0};
   TBBUTTON tbb[5];

   //setup and add buttons
   SendMessage(hToolbar,TB_BUTTONSTRUCTSIZE,
      static_cast<WPARAM>(sizeof(TBBUTTON)),0);
   //add images
   tbAddBmp.hInst=HINST_COMMCTRL;
   tbAddBmp.nID=IDB_STD_SMALL_COLOR;
   SendMessage(hToolbar,TB_ADDBITMAP,0,reinterpret_cast<WPARAM>(&tbAddBmp));

   //add buttons
   AddToolbarButton(hToolbar,tbb[0],STD_FILENEW,_T("New"));           
   AddToolbarButton(hToolbar,tbb[1],STD_FILEOPEN,_T("Open"));
   AddToolbarButton(hToolbar,tbb[2],STD_FILESAVE,_T("Save"));
   AddToolbarButton(hToolbar,tbb[3],STD_PRINTPRE,_T("PrintPre"));           
   AddToolbarButton(hToolbar,tbb[4],STD_PRINT,_T("Print"));

   SendMessage(hToolbar,TB_ADDBUTTONS,5,
      reinterpret_cast<LPARAM>(&tbb[0]));

   return 0;
}

void OnSize(const HWND hwnd,int cx,int cy,UINT flags)
{
   //get the header control handle which has been previously stored in the user
   //data associated with the parent window.
   HWND hToolbar=reinterpret_cast<HWND>(static_cast<LONG_PTR>
      (GetWindowLongPtr(hwnd,GWLP_USERDATA)));

   //resize tab common control so that it always fills parent's client area
   MoveWindow(hToolbar,0,0,cx,0,TRUE);
}

LRESULT CALLBACK MDIFrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch(message)
   {
   case WM_CREATE:
      {
         OnCreate(hWnd,reinterpret_cast<CREATESTRUCT*>(lParam));

         // create client window
         CLIENTCREATESTRUCT ccs = { 0, current++ };
         DWORD style = WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL;
         hMDIClient = CreateWindow(L"MDICLIENT", 0, style, 0, 0, 0, 0, hWnd, (HMENU)0xCAC, basead, (LPSTR)&ccs);
         ShowWindow(hMDIClient, SW_SHOW);

         return DefFrameProc(hWnd, hMDIClient, message, wParam, lParam);
      }

      case WM_SIZE:
      {
         OnSize(hWnd,LOWORD(lParam),HIWORD(lParam),static_cast<UINT>(wParam));
         return DefFrameProc(hWnd, hMDIClient, message, wParam, lParam);
      }


   case WM_COMMAND:
      {
         // File->New
         if(LOWORD(wParam) == IDC_NEW)
         {
            CreateMDIWindow( L"MDICHILDWINDOW", L"A WINDOW!!!", WS_VSCROLL, 100, 100, 500, 500, hMDIClient, basead, NULL );
         }
         // File->Exit
         else
            if(LOWORD(wParam) == IDC_EXIT)
               SendMessage(hWnd, WM_CLOSE, 0, 0);

         return DefFrameProc(hWnd, hMDIClient, message, wParam, lParam);
      }

   case WM_DESTROY:
      {
         PostQuitMessage(0);
         break;
      }
   default:
      return DefFrameProc(hWnd, hMDIClient, message, wParam, lParam);
   }
   return 0;
}

LRESULT CALLBACK MDIChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   return DefMDIChildProc(hWnd, message, wParam, lParam);
}


Code put together from various places on the net, not mine. - just testing it for now.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Oct 02, 2009 4:07 pm    Post subject: Reply with quote

create the toolbar before the MDI window
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Fri Oct 02, 2009 8:38 pm    Post subject: Reply with quote

Slugsnack wrote:
create the toolbar before the MDI window


If you take a look at WM_CREATE, you'll see that's what i am doing.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Oct 02, 2009 8:45 pm    Post subject: Reply with quote

handle the WM_SIZE case. that's called with wParam as SIZE_MAXIMIZED on maximize. so for that particular case, you could do SetWindowPos on the child MDI so it's created just below the toolbar with height of 'main window client height - toolbar height'

for SIZE_RESTORED, you can GetWindowRect of the child window and make sure it's y is not less than height of toolbar
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Fri Oct 02, 2009 8:51 pm    Post subject: Reply with quote

Slugsnack wrote:
handle the WM_SIZE case. that's called with wParam as SIZE_MAXIMIZED on maximize. so for that particular case, you could do SetWindowPos on the child MDI so it's created just below the toolbar with height of 'main window client height - toolbar height'

for SIZE_RESTORED, you can GetWindowRect of the child window and make sure it's y is not less than height of toolbar


All of that is unnecessary, and would have to be a temporary solution. It wouldn't look as nice, and i'm sure there is a better way.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites