Beispiel #1
1
/*
 * GetFileName - create a window, and get file info
 */
BOOL GetFileName( HINSTANCE inst, int shcmd, char *fname )
{
    BOOL        rc;
    HWND        mh,win;
    HDC         dchandle;
    TEXTMETRIC  tm;
    int         x,y,avgx,avgy;
    int         xp,yp,xs,ys;
    WNDCLASS    wc;
    MSG         msg;
    HANDLE      accel;

    dataPtr = fname;
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = StartUpDriver;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = inst;
    wc.hIcon = LoadIcon( inst, "ApplIcon" );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground = GetStockObject( WHITE_BRUSH );
    wc.lpszMenuName = ResName( "WSampStartMenu" );
    wc.lpszClassName = startClass;
    rc = RegisterClass( &wc );
    if( !rc ) {
        return( FALSE );
    }

    accel = LoadAccelerators( inst, "ApplAccl" );
    if( accel == NULL ) {
        return( FALSE );
    }

    x = GetSystemMetrics( SM_CXSCREEN );
    y = GetSystemMetrics( SM_CYSCREEN );

    mh = CreateWindow(
        startClass,             /* class */
        "Open Watcom Sampler",  /* caption */
        WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, /* style */
        x/8,                    /* init. x pos */
        y/6,                    /* init. y pos */
        6*x/8,                  /* init. x size */
        y/2,                    /* init. y size */
        NULL,                   /* parent window */
        NULL,                   /* menu handle */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );

    if( !mh ) {
        return( FALSE );
    }
    ShowWindow( mh, shcmd );
    UpdateWindow( mh );

    dchandle = GetDC( mh );
    GetTextMetrics( dchandle, &tm );
    avgx = AvgXChar( tm );
    avgy = AvgYChar( tm );
    ReleaseDC( mh, dchandle );
    mainWindow = mh;

    xp = 32;
    yp = y/8-10;
    ys = avgy+avgy/2;
    xs = (47+1) * avgx+avgx/2;

    win = CreateWindow(
        "STATIC",               /* class */
        "Sampler Options:",     /* caption */
        WS_CHILD | ES_LEFT,
        xp+(14*avgx)-6,         /* init. x pos */
        yp-3-avgy*3/2,          /* init. y pos */
        16*avgx,                /* init. x size */
        ys,                     /* init. y size */
        mh,                     /* parent window */
        NULL,                   /* child id */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );
    ShowWindow( win, SW_SHOWNORMAL );
    UpdateWindow( win );

    win = CreateWindow(
        "EDIT",                 /* class */
        NULL,                   /* caption */
        WS_CHILD | ES_LEFT | WS_BORDER | ES_AUTOHSCROLL,
        xp+7,                   /* init. x pos */
        yp,                     /* init. y pos */
        xs,                     /* init. x size */
        ys,                     /* init. y size */
        mh,                     /* parent window */
        (HMENU)EDIT_ID,         /* child id */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );


    if( win == NULL ) {
        return( FALSE );
    }
    editChild = win;

    ShowWindow( win, SW_SHOWNORMAL );
    UpdateWindow( win );

    oldClassProc = (FARPROC) GetWindowLong( editChild, GWL_WNDPROC );
    SetWindowLong( editChild, GWL_WNDPROC, (LONG) SubClassProc );

    win = CreateWindow(
        "BUTTON",               /* class */
        "&Select File...",      /* caption */
        WS_CHILD | BS_PUSHBUTTON,
        xp+(6*avgx)-6,          /* init. x pos */
        yp+avgy*3,              /* init. y pos */
        16*avgx,                /* init. x size */
        avgy+avgy/2,            /* init. y size */
        mh,                     /* parent window */
        (HMENU)PUSH_GETFILES_ID,/* child id */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );
    ShowWindow( win, SW_SHOWNORMAL );
    UpdateWindow( win );

    win = CreateWindow(
        "BUTTON",               /* class */
        "S&tart Sampling",      /* caption */
        WS_CHILD | BS_PUSHBUTTON,
        xp+(29*avgx)-6,         /* init. x pos */
        yp+avgy*3,              /* init. y pos */
        16*avgx,                /* init. x size */
        avgy+avgy/2,            /* init. y size */
        mh,                     /* parent window */
        (HMENU)PUSH_OK_ID,      /* child id */
        inst,                   /* program handle */
        NULL                    /* create parms */
        );
    ShowWindow( win, SW_SHOWNORMAL );
    UpdateWindow( win );

    SetFocus( editChild );

    while( GetMessage( &msg, NULL, 0, 0 ) ) {
        if( !TranslateAccelerator( mainWindow, accel, &msg ) ) {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
    }

    return( canContinue );

} /* GetFileName */
Beispiel #2
0
void SetWMode(int width, int height, bool state)
{
  // Compatibility for Xen W-Mode
  if ( ghMainWnd && !(GetWindowLong(ghMainWnd, GWL_STYLE) & WS_SYSMENU) )
    return;

  if ( !isCorrectVersion )
    return;

  if ( state )
  {
    wmode = true;
    if ( !ghMainWnd )
      return;

    // Call the DirectDraw destructor
    DDrawDestroy();
    InitializeWModeBitmap(BW::BWDATA::GameScreenBuffer.width(), BW::BWDATA::GameScreenBuffer.height());

    // Hack to enable drawing in Broodwar
    BW::BWDATA::PrimarySurface = (LPDIRECTDRAWSURFACE)1;

    const int shift = gdwProcNum > 1 ? 32 : 0;
    POINT pos = { windowRect.left + shift, windowRect.top + shift };
    // Change the window settings
    SetWindowLong(ghMainWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
    SetWindowPos(ghMainWnd, HWND_NOTOPMOST, pos.x, pos.y, width, height, SWP_SHOWWINDOW);
    ShowWindow(ghMainWnd, SW_RESTORE);

    SIZE border;
    GetBorderSize(ghMainWnd, &border);
    int w = width + border.cx;
    int h = height + border.cy;

    int cx = GetSystemMetrics(SM_CXFULLSCREEN);
    int cy = GetSystemMetrics(SM_CYFULLSCREEN);
    while ( pos.x < 0 )
      pos.x = 0;
    while ( pos.y < 0 )
      pos.y = 0;
    if ( pos.y + h >= cy )
    {
      if (gdwProcNum > 1)
        pos.y -= cy - h;
      else
        pos.y = cy - h;
    }
    if ( pos.x + w >= cx )
    {
      if (gdwProcNum > 1)
        pos.x -= cx - w;
      else
        pos.x = cx - w;
    }
    MoveWindow(ghMainWnd, pos.x, pos.y, w, h, TRUE);
    SetCursor(NULL);
    SetCursorShowState(false);

    SetDIBColorTable(hdcMem, 0, 256, wmodebmp.bmiColors);
    WritePrivateProfileStringA("window", "windowed", "ON", configPath.c_str());
  }
  else
  {
    wmode = false;
    BW::BWDATA::PrimarySurface = NULL;
    if ( hdcMem )
      DeleteDC(hdcMem);
    hdcMem = NULL;

    if (ghMainWnd)
    {
      SetWindowLong(ghMainWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE | WS_SYSMENU);
      SetWindowPos(ghMainWnd, HWND_TOPMOST, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW);
      SetCursor(NULL);
      SetCursorShowState(false);
      SetFocus(ghMainWnd);
    }
    DDrawDestroy();
    DDrawInitialize(width, height);
    WritePrivateProfileStringA("window", "windowed", "OFF", configPath.c_str());
  }
}
Beispiel #3
0
void InitRunDlg(HWND hDlg, LPRUNDLG_DATA lprd)
{
    HWND hCB;
    int i;
#ifdef WINNT
    HANDLE hThread = NULL;
    DWORD dwDummy;
#endif

    if (lprd->lpszTitle)
        SetWindowText(hDlg, lprd->lpszTitle);

    if (lprd->lpszPrompt)
    {
        SetDlgItemText(hDlg, IDD_PROMPT, lprd->lpszPrompt);
    }

    if (lprd->hIcon)
    {
        Static_SetIcon(GetDlgItem(hDlg, IDD_ICON), lprd->hIcon);
    }

    if (lprd->dwFlags & RFD_NOBROWSE)
    {
        HWND hBrowse;

        hBrowse = GetDlgItem(hDlg, IDD_BROWSE);

        ExchangeWindowPos(hBrowse, GetDlgItem(hDlg, IDCANCEL));
        ExchangeWindowPos(hBrowse, GetDlgItem(hDlg, IDOK));

        ShowWindow(hBrowse, SW_HIDE);
    }

    if (lprd->dwFlags & RFD_NOSHOWOPEN)
    {
        ShowWindow(GetDlgItem(hDlg, IDD_RUNDLGOPENPROMPT), SW_HIDE);
    }

#ifdef SHOWSTATES
    /* Note that we need to fill this list first so that the SELCHANGE
     * message sent below will do the right thing.
     */
    hCB = GetDlgItem(hDlg, IDD_STATE);
    for (i = 0; i < ARRAYSIZE(pnStates); ++i)
    {
        if (SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)(LPTSTR)szStates[i]) < 0)
        {
            break;
        }
    }
    SendMessage(hCB, CB_SETCURSEL, 0, 0L);
#endif

    hCB = GetDlgItem(hDlg, IDD_COMMAND);
    SendMessage(hCB, CB_LIMITTEXT, MAX_PATH-1, 0L);

    OpenRunDlgMRU();

    if (g_hMRURunDlg)
    {
        int nMax;
        TCHAR szCommand[MAX_PATH];

        for (nMax=EnumMRUList(g_hMRURunDlg, -1, NULL, 0), i=0; i<nMax; ++i)
        {
            if (EnumMRUList(g_hMRURunDlg, i, szCommand, ARRAYSIZE(szCommand)) > 0)
            {
                PSTARTINFO pStartInfo;

                /* Parse the line into the STARTINFO struct
                 */
                pStartInfo = ParseIniLine(szCommand);

                /* The command to run goes in the combobox.
                 */
                if (SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)(LPTSTR)szCommand)
                        != i)
                {
                    if (pStartInfo)
                    {
                        LocalFree((HLOCAL)pStartInfo);
                    }
                }
                else
                {
                    SendMessage(hCB, CB_SETITEMDATA, i, (LPARAM)(LPSTARTINFO)pStartInfo);
                }
            }
        }
    }

    if (!(lprd->dwFlags & RFD_NODEFFILE))
    {
        SendMessage(hCB, CB_SETCURSEL, 0, 0L);
    }
    SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDD_COMMAND, CBN_SELCHANGE), (LPARAM) hCB);

    SetWindowLong(hDlg, DWL_USER, (LONG)lprd);

    // Make sure the OK button is initialized properly
    EnableOKButton(hDlg, NULL);

#ifdef WINNT
    //
    // Create the thread that will take care of the
    // "Run in Separate Memory Space" checkbox in the background.
    //

    if (lprd->dwFlags & RFD_NOSEPMEMORY_BOX)
    {
        ShowWindow(GetDlgItem(hDlg, IDD_RUNINSEPARATE), SW_HIDE);
    }
    else
    {
        Assert( g_hCheckNow==NULL );
        g_hCheckNow = CreateEvent( NULL, TRUE, FALSE, NULL );
        if (g_hCheckNow) {

            g_bCheckRunInSep = TRUE;
            hThread = CreateThread( NULL,
                                    0,
                                    (LPTHREAD_START_ROUTINE)CheckRunInSeparateThread,
                                    (LPVOID)hDlg,
                                    0,
                                    &dwDummy
                                   );
        }

        if ((g_hCheckNow==NULL) || (!g_bCheckRunInSep) || (hThread==NULL)) {

            //
            // We've encountered a problem setting up, so make the user
            // choose.
            //

            CheckDlgButton( hDlg, IDD_RUNINSEPARATE, 1 );
            EnableWindow( GetDlgItem( hDlg, IDD_RUNINSEPARATE ), TRUE );
            g_bCheckRunInSep = FALSE;
        }

        //
        // These calls will just do nothing if either handle is NULL.
        //
        if (hThread)
            CloseHandle( hThread );
        if (g_hCheckNow)
            SetEvent( g_hCheckNow );
    }

#endif // WINNT


}
Beispiel #4
0
BOOL CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
	{	
	switch(msg){
		case WM_INITDIALOG:{
			DWORD style;
			g_opHdlg=hdlg;
			bOptionsInit=TRUE;
			TranslateDialogDefault(hdlg); 
			if(g_iButtonsCount!=DBGetContactSettingByte(NULL, PLGNAME,"ButtonsCount", 0))
				{
				LOGFONT logFont;
				HFONT hFont;
				bNeedRestart=TRUE;
				EnableWindow(GetDlgItem(hdlg,IDC_BUTTONSLIST),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_BLISTADD),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_BLISTREMOVE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_MENUTREE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_MTREEADD),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_MTREEREMOVE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_BUTTONNAME),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_MENUNAME),FALSE);	
				ShowWindow(GetDlgItem(hdlg,IDC_WARNING),SW_SHOW);

				hFont = (HFONT)SendMessage(GetDlgItem(hdlg, IDC_WARNING), WM_GETFONT, 0, 0);
				GetObject(hFont, sizeof logFont, &logFont);
				logFont.lfWeight = FW_BOLD;
				hFont = CreateFontIndirect(&logFont);
				SendMessage(GetDlgItem(hdlg, IDC_WARNING), WM_SETFONT, (WPARAM)hFont, 0);
				break;
				}
			
			g_iOPButtonsCount=g_iButtonsCount;

			hButtonsList=GetDlgItem(hdlg,IDC_BUTTONSLIST);
			hMenuTree=GetDlgItem(hdlg,IDC_MENUTREE);

			style = GetWindowLong(hButtonsList,GWL_STYLE);
			style |=TVS_NOHSCROLL;
			SetWindowLong(hButtonsList,GWL_STYLE, style);

			style = GetWindowLong(hMenuTree,GWL_STYLE);
			style |=TVS_NOHSCROLL;			
			SetWindowLong(hMenuTree,GWL_STYLE, style);
			BuildButtonsList(hButtonsList);
			
			if(!TreeView_GetCount(hButtonsList)) EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);

			oldBNameProc = (WNDPROC) SetWindowLong(GetDlgItem(hdlg,IDC_BUTTONNAME), GWL_WNDPROC, (LONG) EditSubclassProc);
			oldMNameProc = (WNDPROC) SetWindowLong(GetDlgItem(hdlg,IDC_MENUNAME)  , GWL_WNDPROC, (LONG) EditSubclassProc);

			
			EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
			CheckDlgButton(hdlg,IDC_RAUTOSEND,(g_bRClickAuto=DBGetContactSettingByte(NULL,PLGNAME,"RClickAuto",0)));
			CheckDlgButton(hdlg,IDC_LAUTOSEND,(g_bLClickAuto=DBGetContactSettingByte(NULL,PLGNAME,"LClickAuto",0)));
			CheckDlgButton(hdlg,IDC_ENABLEQUICKMENU,(g_bQuickMenu=DBGetContactSettingByte(NULL, PLGNAME,"QuickMenu", 1)));
		
			bOptionsInit=FALSE;
			}break;

		case WM_LBUTTONUP:
			if(drag) {
				TVHITTESTINFO hti; 
				HTREEITEM htiAfter=NULL;
				ButtonData* bd=NULL;
				TVITEM tvi;
				RECT rc;
				BYTE height;
				BOOLEAN bAsChild = FALSE;

				TreeView_SetInsertMark(hMenuTree, NULL, 0 );
				ReleaseCapture();
				SetCursor( LoadCursor( NULL, IDC_ARROW ) );

				hti.pt.x = ( SHORT )LOWORD( lparam );
				hti.pt.y = ( SHORT )HIWORD( lparam );
				ClientToScreen(hdlg,&hti.pt);
				ScreenToClient(hMenuTree,&hti.pt);
				TreeView_HitTest( hMenuTree, &hti );

				if(TreeView_GetParent(hMenuTree,hti.hItem)&&TreeView_GetChild(hMenuTree,hDragItem))
					break;

				if(TreeView_GetChild(hMenuTree,hti.hItem)&&TreeView_GetChild(hMenuTree,hDragItem))
					break;


					if( hti.flags & TVHT_ABOVE ) {
						htiAfter = TVI_FIRST;
						}
					else
						if( hti.flags & ( TVHT_NOWHERE|TVHT_BELOW ) ) {
							htiAfter = TVI_LAST;
							}
						else
							if( hti.flags & ( TVHT_ONITEM|TVHT_ONITEMRIGHT ) ) {
								// check where over the item, the pointer is
								if( !TreeView_GetItemRect( hMenuTree, hti.hItem, &rc, FALSE ) ) {
									drag=0;
									break;
									}
								height = ( BYTE )( rc.bottom - rc.top );

								if( hti.pt.y - ( height / 3 ) < rc.top ) {
									HTREEITEM hItem = hti.hItem;

									if( !( hti.hItem = TreeView_GetPrevSibling( hMenuTree, hItem ) ) ) {
										if( !( hti.hItem = TreeView_GetParent(hMenuTree, hItem ) ))
											htiAfter = TVI_FIRST;
										else
											bAsChild = TRUE;
										}
									}
								else 
									if( hti.pt.y + ( height / 3 ) <= rc.bottom ) {
										bAsChild = TRUE;
										}
								}	


							if(TreeView_GetChild(hMenuTree,hDragItem)&&bAsChild)
								break;


							if(hti.hItem){
 									tvi.hItem=hti.hItem;
 									tvi.mask=TVIF_PARAM |TVIF_HANDLE;
 									TreeView_GetItem(hMenuTree,&tvi);
									if((bd=(ButtonData*)tvi.lParam)&&(bd->fEntryOpType&QMF_EX_SEPARATOR))
										bAsChild = FALSE;
							 }

							if(TreeView_GetParent(hMenuTree,hti.hItem))
 								bAsChild = FALSE;


							MoveItem( hDragItem, htiAfter?htiAfter:hti.hItem, bAsChild );
							SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
							drag=0;

				}
			break; 

		///////////////////////////////////
		//From UserInfoEx by DeathAxe
		//
		case WM_MOUSEMOVE:
			{
			if (!drag) break;
				{
				TVHITTESTINFO hti;

				hti.pt.x=(short)LOWORD(lparam);
				hti.pt.y=(short)HIWORD(lparam);
				ClientToScreen(hdlg,&hti.pt);
				ScreenToClient(hMenuTree,&hti.pt);
				TreeView_HitTest(hMenuTree,&hti);
				if( hti.flags & ( TVHT_ONITEM|TVHT_ONITEMRIGHT ) ) {
					RECT rc;
					BYTE height;

					if( TreeView_GetItemRect(hMenuTree, hti.hItem, &rc, FALSE ) ) {
						height = ( BYTE )( rc.bottom - rc.top );

						if( hti.pt.y - ( height / 3 ) < rc.top ) {
							SetCursor( LoadCursor( NULL, IDC_ARROW ) );
							TreeView_SetInsertMark( hMenuTree, hti.hItem, 0 );
							}
						else
							if( hti.pt.y + ( height / 3 ) > rc.bottom ) {
								SetCursor( LoadCursor( NULL, IDC_ARROW ) );
								TreeView_SetInsertMark( hMenuTree, hti.hItem, 1 );
								}
							else {
								TreeView_SetInsertMark( hMenuTree, NULL, 0 );
								SetCursor( LoadCursor( GetModuleHandle(NULL), MAKEINTRESOURCE( 183 ) ) );
								}
						}
					}
				else {
					if( hti.flags & TVHT_ABOVE ) SendMessage( hMenuTree, WM_VSCROLL, MAKEWPARAM( SB_LINEUP, 0 ), 0 );
					if( hti.flags & TVHT_BELOW ) SendMessage( hMenuTree, WM_VSCROLL, MAKEWPARAM( SB_LINEDOWN, 0 ), 0 );
					TreeView_SetInsertMark( hMenuTree, NULL, 0 );
					}
				}
			}break;
			/////////////
		case WM_DESTROY:
			if (g_varhelpDlg)
				DestroyWindow(g_varhelpDlg);
			g_varhelpDlg=NULL;
			break;

		case WM_NOTIFY:{
			switch(((LPNMHDR)lparam)->idFrom)	{
		case 0:{
			if (((LPNMHDR)lparam)->code == PSN_APPLY ) {
				if(!bNeedRestart){
				SetMenuEntryProperties(hdlg);
				SaveMenuTree(hdlg); 
				}
				DBWriteContactSettingByte(NULL,PLGNAME,"RClickAuto",(BYTE)(g_bRClickAuto=IsDlgButtonChecked(hdlg,IDC_RAUTOSEND)));
				DBWriteContactSettingByte(NULL,PLGNAME,"LClickAuto",(BYTE)(g_bLClickAuto=IsDlgButtonChecked(hdlg,IDC_LAUTOSEND)));
				DBWriteContactSettingByte(NULL,PLGNAME,"QuickMenu",(BYTE)(g_bQuickMenu=IsDlgButtonChecked(hdlg,IDC_ENABLEQUICKMENU)));
				return 1;
				}
			else if (((LPNMHDR)lparam)->code == PSN_RESET ) {
					if(!bNeedRestart)
						RestoreModuleData(hdlg);
				return 1;
				}
			}
			break; 

		case IDC_MENUTREE:
			switch (((LPNMHDR)lparam)->code){

		case TVN_KEYDOWN:{
			TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*) ((LPNMHDR)lparam);
			if ( pTVKeyDown->wVKey == VK_F2 )
				TreeView_EditLabel(hMenuTree,TreeView_GetSelection(hMenuTree));
			else if ( pTVKeyDown->wVKey == VK_DELETE )
					SendMessage(hdlg,WM_COMMAND,IDC_MTREEREMOVE,0);
			}break;

		case TVN_BEGINLABELEDITA:
		case TVN_BEGINLABELEDITW:
			hwndEdit=TreeView_GetEditControl(hMenuTree);
			oldEditProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) LabelEditSubclassProc);
			break;

		case TVN_ENDLABELEDITA:
		case TVN_ENDLABELEDITW:
			{
			TVITEM tvi;
			ButtonData* bd=NULL;
			TCHAR strbuf[256];
			TCHAR szLabel[256];

			SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) oldEditProc);

			tvi.pszText = strbuf;
			tvi.cchTextMax = sizeof(strbuf);
			tvi.mask=TVIF_TEXT |TVIF_HANDLE|TVIF_PARAM;
			tvi.hItem=TreeView_GetSelection(hMenuTree);
			TreeView_GetItem(hMenuTree,&tvi);

			GetWindowText(hwndEdit, szLabel, sizeof(szLabel));
			hwndEdit=NULL;
			if(!_tcslen(szLabel)) break;
			if (bd = (ButtonData*)tvi.lParam){
				if(!_tcscmp(szLabel,_T("---"))){
					if(TreeView_GetChild(hMenuTree,tvi.hItem))
						break;
					else{
						bd->fEntryOpType=QMF_EX_SEPARATOR;
						EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
						EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
						SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T(""));
						}
					}
				else {
					bd->fEntryOpType&=~QMF_EX_SEPARATOR;
						EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),TRUE);
						EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),TRUE);
						SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),bd->pszOpValue/*?bd->pszOpValue:bd->pszValue*/);
					}

				bd->pszOpName=mir_tstrdup(szLabel);
				
				tvi.pszText=szLabel;
				TreeView_SetItem(hMenuTree, &tvi);
				SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
				}
			}break;

		case NM_KILLFOCUS:
			TreeView_EndEditLabelNow(hButtonsList, 1);
			break;

		case TVN_BEGINDRAGA:
		case TVN_BEGINDRAGW:
			SetCapture(hdlg);
			drag=1;
			hDragItem=((LPNMTREEVIEW)lparam)->itemNew.hItem;
			TreeView_SelectItem(hMenuTree,hDragItem);
			break;

		case TVN_SELCHANGINGA:
		case TVN_SELCHANGINGW:
			{
			TVITEM tvi;
			HTREEITEM hti;
			ButtonData* bd;

			hti=TreeView_GetSelection(hMenuTree);

			if (hti==NULL)
				break;

			tvi.hItem=hti;
			tvi.mask=TVIF_HANDLE|TVIF_PARAM;
			TreeView_GetItem(hMenuTree,&tvi);

			if (tvi.lParam == 0)
				break;

			bd = ( ButtonData* )tvi.lParam;
			if (bd) {
				TCHAR szValue[256];
				GetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE), szValue, sizeof(szValue));
				if(_tcslen(szValue))
					{
					if(bd->pszOpValue&&(bd->pszOpValue!=bd->pszValue))
						mir_free(bd->pszOpValue);
					bd->pszOpValue=mir_tstrdup(szValue);
					}
				bd->bOpInQMenu=IsDlgButtonChecked(hdlg,IDC_INQMENU);
				bd->bIsOpServName=IsDlgButtonChecked(hdlg,IDC_ISSERVNAME);
				}
			}break;
		case TVN_SELCHANGEDA:
		case TVN_SELCHANGEDW:
			{
			TVITEM tvi;
			HTREEITEM hti;
			ButtonData* bd=NULL;

			hti=TreeView_GetSelection(hMenuTree);

			if (hti==NULL)
				break;

			tvi.mask=TVIF_HANDLE|TVIF_PARAM;

			tvi.hItem=hti;
			TreeView_GetItem(hMenuTree,&tvi);


			bd = ( ButtonData* )tvi.lParam;
			if (bd) {
				if(!TreeView_GetChild(hMenuTree, tvi.hItem)&&!(bd->fEntryOpType&QMF_EX_SEPARATOR))
					{
					EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),TRUE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),TRUE);
					EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),TRUE);
					SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),bd->pszOpValue/*?bd->pszOpValue:bd->pszValue*/);
					}
				else
					{
					EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
					if(!(bd->fEntryOpType&QMF_EX_SEPARATOR))
						EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
					SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T(""));
					}
				CheckDlgButton(hdlg,IDC_INQMENU,bd->bOpInQMenu);
				CheckDlgButton(hdlg,IDC_ISSERVNAME,bd->bIsOpServName);
				}
			}
		}break;

		case IDC_BUTTONSLIST:
			switch (((LPNMHDR)lparam)->code) {

		case TVN_KEYDOWN:{
			TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*) ((LPNMHDR)lparam);
			if ( pTVKeyDown->wVKey == VK_F2 )
				TreeView_EditLabel(hButtonsList,TreeView_GetSelection(hButtonsList));
			else if ( pTVKeyDown->wVKey == VK_DELETE )
				SendMessage(hdlg,WM_COMMAND,IDC_BLISTREMOVE,0);
			}break;

		case TVN_BEGINLABELEDITA:
		case TVN_BEGINLABELEDITW:
			hwndEdit=TreeView_GetEditControl(hButtonsList);
			oldEditProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) LabelEditSubclassProc);
			break;

		case TVN_ENDLABELEDITA:
		case TVN_ENDLABELEDITW:{
			TVITEM tvi;
			TCHAR strbuf[128];
			TCHAR szLabel[128];

			SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) oldEditProc);

			tvi.pszText = strbuf;
			tvi.cchTextMax = sizeof(strbuf);
			tvi.mask=TVIF_TEXT |TVIF_HANDLE|TVIF_PARAM;
			tvi.hItem=TreeView_GetSelection(hButtonsList);
			TreeView_GetItem(hButtonsList,&tvi);

			GetWindowText(hwndEdit, szLabel, sizeof(szLabel));
			hwndEdit=NULL;
			if(!_tcslen(szLabel)) break;

			tvi.pszText=szLabel;
			((ListData*)tvi.lParam)->dwOPFlags|=QMF_RENAMED;	

			TreeView_SetItem(hButtonsList, &tvi);
			SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
			}break;

		case TVN_SELCHANGINGA:
		case TVN_SELCHANGINGW:
			SetMenuEntryProperties(hdlg);
			break;

		case TVN_SELCHANGEDA:
		case TVN_SELCHANGEDW:{
			TVITEM tvi;
			HTREEITEM hti;

			hti=TreeView_GetSelection(hButtonsList);

			if(hti==NULL||!TreeView_GetCount(hButtonsList)){
				EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),FALSE);
				SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T(""));
				break;
				}
			
			tvi.mask=TVIF_HANDLE|TVIF_PARAM;
			tvi.hItem=hti;
			TreeView_GetItem(hButtonsList,&tvi);

			if(tvi.lParam==0) break;

			BuildMenuTree(hMenuTree,(SortedList *)((ListData*)tvi.lParam)->sl);

			SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T(""));
			EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),TRUE);
			EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),TRUE);
			CheckDlgButton(hdlg,IDC_ISSERVNAME2,((ListData*)tvi.lParam)->bIsOpServName);

			if(((ListData*)tvi.lParam)->ptszOPQValue) 
				SetWindowText(GetDlgItem(hdlg,IDC_RCLICKVALUE),((ListData*)tvi.lParam)->ptszOPQValue);
			else
				SetWindowText(GetDlgItem(hdlg,IDC_RCLICKVALUE),_T(""));

			}break;
				}break;
				}
			}break;

		case WM_COMMAND:{
		switch(LOWORD(wparam)){
		case IDC_VARHELP:{
			if(!g_varhelpDlg)
				g_varhelpDlg=CreateDialog(hinstance,MAKEINTRESOURCE(IDD_HELPDIALOG), 0, HelpDlgProc);
			else
				//ShowWindow(g_varhelpDlg,SW_SHOWDEFAULT);
				SetWindowPos(g_varhelpDlg,0,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
			}break;
		case IDC_BLISTADD:{
			TVINSERTSTRUCT tvis;
			ListData* ld=NULL;
			TCHAR namebuff[MAX_PATH]={'\0'};
			int count=TreeView_GetCount(hButtonsList);
			if (count>10) break;
			if(g_iOPButtonsCount==99){
				MessageBox(NULL,_T("Congratulation!\n\
								   You have clicked this button 100 times!\n\
								   There was access violation at this point...\n\
								   And now function for freeing resources must be called...\n\
								   But no! there's only break :D"),_T("You win!"),MB_OK);
				break;
				}

			ld=mir_alloc(sizeof(ListData));
			ButtonsList[g_iOPButtonsCount++]=ld;

			ld->sl=li.List_Create(0,1);
			ld->dwOPFlags=QMF_NEW;
			ld->bIsOpServName=0;
			ld->ptszButtonName=NULL;
			ld->ptszOPQValue=NULL;
			ld->ptszQValue=NULL;
			tvis.hParent = NULL;
			tvis.hInsertAfter = TVI_LAST;
			
			GetWindowText(GetDlgItem(hdlg,IDC_BUTTONNAME),namebuff,MAX_PATH);

			tvis.item.mask=TVIF_PARAM|TVIF_TEXT;
			tvis.item.pszText=(_tcslen(namebuff))?namebuff:TranslateT("New Button");
			tvis.item.lParam=(LPARAM)ld;
			TreeView_SelectItem(hButtonsList,TreeView_InsertItem(hButtonsList,&tvis));

			}break;

		case IDC_BLISTREMOVE:{ 
			TVITEM tvi;
			ListData* ld;

			if(!(tvi.hItem=TreeView_GetSelection(hButtonsList)))
				break;

			tvi.mask=TVIF_HANDLE|TVIF_PARAM;
			TreeView_GetItem(hButtonsList,&tvi);

			ld= (ListData*)tvi.lParam;

			ld->dwOPFlags|=QMF_DELETNEEDED;	

			TreeView_DeleteItem(hButtonsList,tvi.hItem);
			if(!TreeView_GetCount(hButtonsList))
				{
				TreeView_DeleteAllItems(hMenuTree);
				EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),FALSE);
				SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T(""));
				SetWindowText(GetDlgItem(hdlg,IDC_RCLICKVALUE),_T(""));
				}
			}break;

		case IDC_MTREEADD:{ 
			TVINSERTSTRUCT tvis;
			TVITEM tvi;
			ButtonData *bd=NULL;
			SortedList *sl=NULL;
			TCHAR namebuff[MAX_PATH]={'\0'};
			
			if(!TreeView_GetCount(hButtonsList)) break;
			if(!(tvi.hItem=TreeView_GetSelection(hButtonsList))) break;
			
			bd=mir_alloc(sizeof(ButtonData));
			memset(bd,0,sizeof(ButtonData));

			GetWindowText(GetDlgItem(hdlg,IDC_MENUNAME),namebuff,MAX_PATH);

			bd->dwOPPos=TreeView_GetCount(hMenuTree)-1;
			bd->pszOpName=_tcslen(namebuff)?mir_tstrdup(namebuff):mir_tstrdup(TranslateT("New Menu Entry"));
			bd->pszOpValue=mir_tstrdup(bd->pszOpName);
			bd->fEntryOpType=!_tcscmp(namebuff,_T("---"))?QMF_EX_SEPARATOR:0;
			bd->dwOPFlags=QMF_NEW;
			bd->pszName=NULL;
			bd->pszValue=NULL;


			tvi.mask=TVIF_HANDLE|TVIF_PARAM;
			
			TreeView_GetItem(hButtonsList,&tvi);

			sl=((ListData*)tvi.lParam)->sl;

			li.List_InsertPtr(sl,bd);

			tvis.hParent = NULL;
			tvis.hInsertAfter = TVI_LAST;
			tvis.item.mask=TVIF_PARAM|TVIF_TEXT;
			tvis.item.pszText=bd->pszOpName;
			tvis.item.lParam=(LPARAM)bd;
			TreeView_SelectItem(hMenuTree,TreeView_InsertItem(hMenuTree,&tvis));
			}break;

		case IDC_MTREEREMOVE:{
			TVITEM tvi;
			TVINSERTSTRUCT tvis;
			HTREEITEM hti=NULL;
			ButtonData *bd=NULL;
			tvi.mask=TVIF_HANDLE|TVIF_PARAM;
			if(!(tvi.hItem=TreeView_GetSelection(hMenuTree)))
				break;
			TreeView_GetItem(hMenuTree,&tvi);
			hti=tvi.hItem;

			bd= (ButtonData*)tvi.lParam;
			bd->dwOPFlags|=QMF_DELETNEEDED;			

			if(tvi.hItem=TreeView_GetChild(hMenuTree,tvi.hItem)){
				TCHAR strbuf[128];
				while(tvi.hItem){
					tvis.hInsertAfter=hti;
					tvi.pszText = strbuf;
					tvi.cchTextMax = sizeof(strbuf);
					tvi.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT;

					TreeView_GetItem(hMenuTree,&tvi); 
					tvis.hParent=NULL;
					tvis.item=tvi;
					TreeView_InsertItem(hMenuTree,&tvis);
					tvi.hItem=TreeView_GetNextSibling(hMenuTree,tvi.hItem);
					}
				}

			TreeView_DeleteItem(hMenuTree,hti);
			if(!TreeView_GetCount(hMenuTree)){
				EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
				EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
				SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T(""));
				}

			}break;

				}
			}break;

		case WM_NCDESTROY: 
			if(oldBNameProc) SetWindowLong(GetDlgItem(hdlg,IDC_BUTTONNAME), GWL_WNDPROC, (LONG) oldBNameProc);
			if(oldMNameProc) SetWindowLong(GetDlgItem(hdlg,IDC_MENUNAME)  , GWL_WNDPROC, (LONG) oldMNameProc);
			break; 

		case WM_CLOSE:
			EndDialog(hdlg,0);
			return 0;
		}
Beispiel #5
0
bool AttachWBCoreToFrame(IWBCoreControler *pWBCoreControler,IWBCoreNotifyer *pNewWBCoreNotifyer,IUIControler *pUIControler)
{
	ATLASSERT( pWBCoreControler && pNewWBCoreNotifyer && pUIControler );
	
	//先获取两个窗口的句柄
	HWND hMainFrame = NULL;
	HWND hCoreWnd = NULL;
	pUIControler->ControlQueryQueryMainFrame( &hMainFrame );
	pWBCoreControler->ControlQueryWnd(&hCoreWnd);

	CRect rcClient;
	pUIControler->ControlQueryClientRect(&rcClient);
	::SetParent(hCoreWnd,hMainFrame);

	DWORD dwStyle = GetWindowLong(hCoreWnd,GWL_STYLE);
	dwStyle|=WS_CHILD;
	SetWindowLong(hCoreWnd,GWL_STYLE,dwStyle);

	pWBCoreControler->ControlMoveWindow(rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height());
	pWBCoreControler->ControlShowWindow(TRUE);


	//通知新的父窗口有新的浏览器窗口插入
	CString strUrl;
	CString strTitle;
	BOOL    bCanBack;
	BOOL    bCanForward;
	PAGEID  nPageID = 0;
	pWBCoreControler->ControlQueryUrl(strUrl.GetBuffer(4000),4000);
	strUrl.ReleaseBuffer();
	pWBCoreControler->ControlQueryTitle(strTitle.GetBuffer(200),200);
	strTitle.ReleaseBuffer();
	pWBCoreControler->ControlQueryBackForwardStatus(&bCanBack,&bCanForward);
	pWBCoreControler->GetPageID(&nPageID);


	//插入到新的通知实例中

	INotifyerInstance *pNotify = dynamic_cast<INotifyerInstance *>(pNewWBCoreNotifyer);

	PAGEINFO info;
	info.hWnd = hCoreWnd;
	info.strUrl = strUrl;
	info.strTitle = strTitle;
	info.pCoreControler = pWBCoreControler;
	info.bCanBack = bCanBack;
	info.bCanForward = bCanForward;
	pNotify->InsertPage(nPageID,&info);


	//修正UI显示
	pUIControler->ControlAddTab(nPageID,strUrl,strTitle);
	pUIControler->ControlSetFocusTab(nPageID);

	pNewWBCoreNotifyer->NotifySetCurrentPage(nPageID);

	//设置浏览器内核新的通知接口
	pWBCoreControler->SetNotifyPtr(pNewWBCoreNotifyer);

	return true;
}
Beispiel #6
0
LRESULT CALLBACK LConProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND view;
	HDC hdc;
	HBRUSH hbr;
	HGDIOBJ oldfont;
	RECT rect;
	int titlelen;
	SIZE size;
	LOGFONT lf;
	TEXTMETRIC tm;
	HINSTANCE inst = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
	DRAWITEMSTRUCT *drawitem;
	CHARFORMAT2W format;

	switch (msg)
	{
	case WM_CREATE:
		// Create game title static control
		memset (&lf, 0, sizeof(lf));
		hdc = GetDC (hWnd);
		lf.lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
		lf.lfCharSet = ANSI_CHARSET;
		lf.lfWeight = FW_BOLD;
		lf.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
		strcpy (lf.lfFaceName, "Trebuchet MS");
		GameTitleFont = CreateFontIndirect (&lf);

		oldfont = SelectObject (hdc, GetStockObject (DEFAULT_GUI_FONT));
		GetTextMetrics (hdc, &tm);
		DefaultGUIFontHeight = tm.tmHeight;
		if (GameTitleFont == NULL)
		{
			GameTitleFontHeight = DefaultGUIFontHeight;
		}
		else
		{
			SelectObject (hdc, GameTitleFont);
			GetTextMetrics (hdc, &tm);
			GameTitleFontHeight = tm.tmHeight;
		}
		SelectObject (hdc, oldfont);

		// Create log read-only edit control
		view = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "RichEdit20W", NULL,
			WS_CHILD | WS_VISIBLE | WS_VSCROLL |
			ES_LEFT | ES_MULTILINE | WS_CLIPSIBLINGS,
			0, 0, 0, 0,
			hWnd, NULL, inst, NULL);
		HRESULT hr;
		hr = GetLastError();
		if (view == NULL)
		{
			ReleaseDC (hWnd, hdc);
			return -1;
		}
		SendMessage (view, EM_SETREADONLY, TRUE, 0);
		SendMessage (view, EM_EXLIMITTEXT, 0, 0x7FFFFFFE);
		SendMessage (view, EM_SETBKGNDCOLOR, 0, RGB(70,70,70));
		// Setup default font for the log.
		//SendMessage (view, WM_SETFONT, (WPARAM)GetStockObject (DEFAULT_GUI_FONT), FALSE);
		format.cbSize = sizeof(format);
		format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
		format.dwEffects = 0;
		format.yHeight = 200;
		format.crTextColor = RGB(223,223,223);
		format.bCharSet = ANSI_CHARSET;
		format.bPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
		wcscpy(format.szFaceName, L"DejaVu Sans");	// At least I have it. :p
		SendMessageW(view, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format);

		ConWindow = view;
		ReleaseDC (hWnd, hdc);

		view = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW, 0, 0, 0, 0, hWnd, NULL, inst, NULL);
		if (view == NULL)
		{
			return -1;
		}
		SetWindowLong (view, GWL_ID, IDC_STATIC_TITLE);
		GameTitleWindow = view;

		return 0;

	case WM_SIZE:
		if (wParam != SIZE_MAXHIDE && wParam != SIZE_MAXSHOW)
		{
			LayoutMainWindow (hWnd, ErrorPane);
		}
		return 0;

	case WM_DRAWITEM:
		// Draw title banner.
		if (wParam == IDC_STATIC_TITLE && DoomStartupInfo.Name.IsNotEmpty())
		{
			const PalEntry *c;

			// Draw the game title strip at the top of the window.
			drawitem = (LPDRAWITEMSTRUCT)lParam;

			// Draw the background.
			rect = drawitem->rcItem;
			rect.bottom -= 1;
			c = (const PalEntry *)&DoomStartupInfo.BkColor;
			hbr = CreateSolidBrush (RGB(c->r,c->g,c->b));
			FillRect (drawitem->hDC, &drawitem->rcItem, hbr);
			DeleteObject (hbr);

			// Calculate width of the title string.
			SetTextAlign (drawitem->hDC, TA_TOP);
			oldfont = SelectObject (drawitem->hDC, GameTitleFont != NULL ? GameTitleFont : (HFONT)GetStockObject (DEFAULT_GUI_FONT));
			titlelen = (int)DoomStartupInfo.Name.Len();
			GetTextExtentPoint32 (drawitem->hDC, DoomStartupInfo.Name, titlelen, &size);

			// Draw the title.
			c = (const PalEntry *)&DoomStartupInfo.FgColor;
			SetTextColor (drawitem->hDC, RGB(c->r,c->g,c->b));
			SetBkMode (drawitem->hDC, TRANSPARENT);
			TextOut (drawitem->hDC, rect.left + (rect.right - rect.left - size.cx) / 2, 2, DoomStartupInfo.Name, titlelen);
			SelectObject (drawitem->hDC, oldfont);
			return TRUE;
		}
		// Draw startup screen
		else if (wParam == IDC_STATIC_STARTUP)
		{
			if (StartupScreen != NULL)
			{
				drawitem = (LPDRAWITEMSTRUCT)lParam;

				rect = drawitem->rcItem;
				// Windows expects DIBs to be bottom-up but ours is top-down,
				// so flip it vertically while drawing it.
				StretchDIBits (drawitem->hDC, rect.left, rect.bottom - 1, rect.right - rect.left, rect.top - rect.bottom,
					0, 0, StartupBitmap->bmiHeader.biWidth, StartupBitmap->bmiHeader.biHeight,
					ST_Util_BitsForBitmap(StartupBitmap), StartupBitmap, DIB_RGB_COLORS, SRCCOPY);

				// If the title banner is gone, then this is an ENDOOM screen, so draw a short prompt
				// where the command prompt would have been in DOS.
				if (GameTitleWindow == NULL)
				{
					static const char QuitText[] = "Press any key or click anywhere in the window to quit.";

					SetTextColor (drawitem->hDC, RGB(240,240,240));
					SetBkMode (drawitem->hDC, TRANSPARENT);
					oldfont = SelectObject (drawitem->hDC, (HFONT)GetStockObject (DEFAULT_GUI_FONT));
					TextOut (drawitem->hDC, 3, drawitem->rcItem.bottom - DefaultGUIFontHeight - 3, QuitText, countof(QuitText)-1);
					SelectObject (drawitem->hDC, oldfont);
				}
				return TRUE;
			}
		}
		// Draw stop icon.
		else if (wParam == IDC_ICONPIC)
		{
			HICON icon;
			POINTL char_pos;
			drawitem = (LPDRAWITEMSTRUCT)lParam;

			// This background color should match the edit control's.
			hbr = CreateSolidBrush (RGB(70,70,70));
			FillRect (drawitem->hDC, &drawitem->rcItem, hbr);
			DeleteObject (hbr);

			// Draw the icon aligned with the first line of error text.
			SendMessage (ConWindow, EM_POSFROMCHAR, (WPARAM)&char_pos, ErrorIconChar);
			icon = (HICON)LoadImage (0, IDI_ERROR, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
			DrawIcon (drawitem->hDC, 6, char_pos.y, icon);
			return TRUE;
		}
		return FALSE;

	case WM_COMMAND:
		if (ErrorIcon != NULL && (HWND)lParam == ConWindow && HIWORD(wParam) == EN_UPDATE)
		{
			// Be sure to redraw the error icon if the edit control changes.
			InvalidateRect (ErrorIcon, NULL, TRUE);
			return 0;
		}
		break;

	case WM_CLOSE:
		PostQuitMessage (0);
		break;

	case WM_DESTROY:
		if (GameTitleFont != NULL)
		{
			DeleteObject (GameTitleFont);
		}
		break;
	}
	return DefWindowProc (hWnd, msg, wParam, lParam);
}
Beispiel #7
0
/*
 * set_hotkey_proc - ホットキー設定ウィンドウプロシージャ
 */
static BOOL CALLBACK set_hotkey_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	DATA_INFO *di;
	int i;

	switch (uMsg) {
	case WM_INITDIALOG:
		if ((di = (DATA_INFO *)lParam) == NULL) {
			EndDialog(hDlg, FALSE);
			break;
		}
		// ホットキー
		i = 0;
		if (di->op_modifiers & MOD_SHIFT) {
			i |= HOTKEYF_SHIFT;
		}
		if (di->op_modifiers & MOD_CONTROL) {
			i |= HOTKEYF_CONTROL;
		}
		if (di->op_modifiers & MOD_ALT) {
			i |= HOTKEYF_ALT;
		}
		if (di->op_modifiers & MOD_WIN) {
			CheckDlgButton(hDlg, IDC_CHECK_WIN, 1);
		}
		if (di->op_virtkey != 0) {
			SendDlgItemMessage(hDlg, IDC_HOTKEY_ITEM, HKM_SETHOTKEY,
				(WPARAM)MAKEWORD(di->op_virtkey, i), 0);
			// 貼り付け
			CheckDlgButton(hDlg, IDC_CHECK_PASTE, di->op_paste);
		} else {
			CheckDlgButton(hDlg, IDC_CHECK_PASTE, 1);
		}

		SetWindowLong(hDlg, GWL_USERDATA, lParam);
		break;

	case WM_CLOSE:
		EndDialog(hDlg, FALSE);
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			SendMessage(hDlg, WM_CLOSE, 0, 0);
			break;

		case IDOK:
			di = (DATA_INFO *)GetWindowLong(hDlg, GWL_USERDATA);
			if (di == NULL) {
				EndDialog(hDlg, FALSE);
				break;
			}
			// ホットキー
			i = SendDlgItemMessage(hDlg, IDC_HOTKEY_ITEM, HKM_GETHOTKEY, 0, 0);
			di->op_virtkey = LOBYTE(i);
			i = HIBYTE(i);
			di->op_modifiers = ((i & HOTKEYF_SHIFT) ? MOD_SHIFT : 0) |
				((i & HOTKEYF_CONTROL) ? MOD_CONTROL : 0) |
				((i & HOTKEYF_ALT) ? MOD_ALT : 0);
			if (IsDlgButtonChecked(hDlg, IDC_CHECK_WIN) == 1) {
				di->op_modifiers |= MOD_WIN;
			}
			// 貼り付け
			di->op_paste = IsDlgButtonChecked(hDlg, IDC_CHECK_PASTE);
			EndDialog(hDlg, TRUE);
			break;
		}
		break;

	default:
		return FALSE;
	}
	return TRUE;
}
Beispiel #8
0
LRESULT CALLBACK DlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) {
	switch (message) {
		case WM_INITDIALOG:
			{
				RECT rectOwner, rectDlg, rectDiff;

				GetWindowRect(GetDesktopWindow(), &rectOwner);
				GetWindowRect(hwndDlg, &rectDlg);
				CopyRect(&rectDiff, &rectOwner);

				OffsetRect(&rectDlg, -rectDlg.left, -rectDlg.top);
				OffsetRect(&rectDiff, -rectDiff.left, -rectDiff.top);
				OffsetRect(&rectDiff, -rectDlg.right, -rectDlg.bottom);

				SetWindowPos(hwndDlg, HWND_TOP, rectOwner.left + (rectDiff.right / 2), rectOwner.top + (rectDiff.bottom / 2), 0, 0, SWP_NOSIZE);


				HWND hwndProg = GetDlgItem(hwndDlg, IDC_PROGRESS);
				DWORD dwStyle = GetWindowLong(hwndProg, GWL_STYLE);
				SetWindowLong(hwndProg, GWL_STYLE, dwStyle | PBS_MARQUEE);
				SendMessage(hwndProg, PBM_SETMARQUEE, TRUE, 70 /* = scroll speed */);

				HWND hwndOK = GetDlgItem(hwndDlg, IDC_OK);
				if (silentFlag) {
					RECT rectProg, rectOK;
					GetWindowRect(hwndProg, &rectProg);
					GetWindowRect(hwndOK, &rectOK);

					POINT posProg;
					posProg.x = rectProg.left;
					posProg.y = rectProg.top;
					ScreenToClient(hwndDlg, &posProg);

					MoveWindow(hwndProg, posProg.x, posProg.y, rectOK.right - rectProg.left, rectProg.bottom - rectProg.top, TRUE);

					ShowWindow(hwndOK, SW_HIDE);
				} else {
					EnableWindow(hwndOK, FALSE);
				}
				HWND hwndDetails = GetDlgItem(hwndDlg, IDC_DETAILS);
				ShowWindow(hwndDetails, SW_HIDE);

				LPTSTR dialogText = (LPTSTR)malloc(MAX_STRING_LENGTH * sizeof(TCHAR));
				UINT titleID = (uninstallFlag ? IDS_UNINSTALL : IDS_INSTALL);
				LoadString(GetModuleHandle(NULL), titleID, dialogText, MAX_STRING_LENGTH);
				SetWindowText(hwndDlg, dialogText);

				LoadString(GetModuleHandle(NULL), IDS_CLOSE, dialogText, MAX_STRING_LENGTH);
				SetDlgItemText(hwndDlg, IDC_OK, dialogText);

				LoadString(GetModuleHandle(NULL), IDS_DETAILS, dialogText, MAX_STRING_LENGTH);
				SetDlgItemText(hwndDlg, IDC_DETAILS, dialogText);

				LPTSTR message = (LPTSTR)malloc((2 * MAX_STRING_LENGTH + 10) * sizeof(TCHAR));
				UINT loadingID = (uninstallFlag ? IDS_LOADING_U : IDS_LOADING);
				LoadString(GetModuleHandle(NULL), loadingID, message, MAX_STRING_LENGTH);

				loadingID = (estTime) ? IDS_TIMESPEC : IDS_TIMEUNDEF;
				LoadString(GetModuleHandle(NULL), loadingID, dialogText, MAX_STRING_LENGTH);

				LPTSTR time = (LPTSTR)malloc(9 * sizeof(TCHAR));
				_itot(estTime, time, 10);
				DWORD_PTR messageArguments[] = { (DWORD_PTR)time };
				HLOCAL formattedString = NULL;
				DWORD formatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING |  FORMAT_MESSAGE_ARGUMENT_ARRAY;
				FormatMessage(formatFlags, dialogText, loadingID, 0, (LPTSTR)&formattedString, 0, (va_list*)messageArguments);
				free(time);

				_tcsncat(message, _T("\n"), 2 * MAX_STRING_LENGTH + 10);
				_tcsncat(message, formattedString, 2 * MAX_STRING_LENGTH + 10);

				SetDlgItemText(hwndDlg, IDC_MESSAGE, message);

				LocalFree(formattedString);
				free(dialogText);
				free(message);
			}

			SetTimer(hwndDlg, IDT_TIMER1, 500, (TIMERPROC)NULL);
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam)) {
				case IDOK:
				case IDCANCEL:
					if (hChildProc == 0) {
						EndDialog(hwndDlg, wParam);
						return TRUE;
					}
					break;
				case IDC_DETAILS: {
					LPTSTR errorMsg = _tcserror(exitCode);

					LPTSTR messsageFormat = (LPTSTR)malloc(MAX_STRING_LENGTH);
					LoadString(NULL, IDS_ERRORCODE, messsageFormat, MAX_STRING_LENGTH);

					HLOCAL messageString = NULL;
					DWORD_PTR messageArguments[] = { (DWORD_PTR)exitCode, (DWORD_PTR)errorMsg };
					DWORD formatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING |  FORMAT_MESSAGE_ARGUMENT_ARRAY;
					FormatMessage(formatFlags, messsageFormat, IDS_ERRORCODE, 0, (LPTSTR)&messageString, 0, (va_list*)messageArguments);

					MessageBox(NULL, (LPTSTR)messageString, NULL, MB_OK | MB_ICONEXCLAMATION);

					LocalFree(messageString);
					free(messsageFormat);

					break;
				}
			}
			break;
		case WM_TIMER:
			switch (wParam) {
				case IDT_TIMER1:
					GetExitCodeProcess(hChildProc, &exitCode);
					if (exitCode != STILL_ACTIVE) {
						KillTimer(hwndDlg, IDT_TIMER1);

						hChildProc = 0;

						if (silentFlag) {
							EndDialog(hwndDlg, 0);
						} else {
							FlashWindow(hwndDlg, TRUE);

							HWND hwndProg;
							DWORD dwStyle;
							hwndProg = GetDlgItem(hwndDlg, IDC_PROGRESS);

							SendMessage(hwndProg, PBM_SETMARQUEE, FALSE, 0);
							dwStyle = GetWindowLong(hwndProg, GWL_STYLE);
							SetWindowLong(hwndProg, GWL_STYLE, dwStyle & ~PBS_MARQUEE);
							SendMessage(hwndProg, PBM_SETPOS, 100, 0);

							LPTSTR dialogText = (LPTSTR)malloc(MAX_STRING_LENGTH * sizeof(TCHAR));
							if (exitCode == ERROR_SUCCESS) {
								UINT successID = (uninstallFlag ? IDS_SUCCESS_U : IDS_SUCCESS);
								LoadString(GetModuleHandle(NULL), successID, dialogText, MAX_STRING_LENGTH);
							} else {
								UINT failureID = (uninstallFlag ? IDS_FAILURE_U : IDS_FAILURE);
								LoadString(GetModuleHandle(NULL), failureID, dialogText, MAX_STRING_LENGTH);
								SendMessage(hwndProg, PBM_SETSTATE, PBST_ERROR, 0);

								HWND hwndDetails = GetDlgItem(hwndDlg, IDC_DETAILS);
								ShowWindow(hwndDetails, SW_SHOW);
							}
							SetDlgItemText(hwndDlg, IDC_MESSAGE, dialogText);
							free(dialogText);

							HWND hwndOK = GetDlgItem(hwndDlg, IDC_OK);
							EnableWindow(hwndOK, TRUE);
						}
					}
					break;
			}
			break;
	}

	return FALSE;
}
Beispiel #9
0
LRESULT CALLBACK insert_dlg_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static TABLE_WINDOW *win=0;
	static HWND hlistview=0,hgrippy=0,hedit=0;
	static HFONT hfont=0;
	static WNDPROC origlistview=0;
	if(FALSE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		if(hwnd==hlistview)
			printf("-");
		print_msg(msg,lparam,wparam,hwnd);
		tick=GetTickCount();
	}
	if(origlistview!=0 && hwnd==hlistview){
		if(msg==WM_GETDLGCODE){
			return DLGC_WANTARROWS;
		}
		return CallWindowProc(origlistview,hwnd,msg,wparam,lparam);
	}
	switch(msg){
	case WM_INITDIALOG:
		if(lparam==0){
			EndDialog(hwnd,0);
			break;
		}
		hedit=0;
		win=lparam;
		hlistview=CreateWindow(WC_LISTVIEW,"",WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|LVS_REPORT|LVS_SHOWSELALWAYS,
                                     0,0,
                                     0,0,
                                     hwnd,
                                     IDC_LIST1,
                                     ghinstance,
                                     NULL);
		if(hlistview!=0){
			ListView_SetExtendedListViewStyle(hlistview,LVS_EX_FULLROWSELECT);
			hfont=SendMessage(win->hlistview,WM_GETFONT,0,0);
			if(hfont!=0)
				SendMessage(hlistview,WM_SETFONT,hfont,0);
			populate_insert_dlg(hwnd,hlistview,win);
			ListView_SetItemState(hlistview,0,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
			origlistview=SetWindowLong(hlistview,GWL_WNDPROC,(LONG)insert_dlg_proc);
		}
		set_title(hwnd,win);
		hgrippy=create_grippy(hwnd);
		resize_insert_dlg(hwnd);
		break;
	case WM_NOTIFY:
		{
			NMHDR *nmhdr=lparam;
			if(nmhdr!=0){
				switch(nmhdr->code){
				case NM_DBLCLK:
					if(hedit==0 && nmhdr->hwndFrom==hlistview)
						SendMessage(hwnd,WM_COMMAND,IDOK,0);
					break;
				case  LVN_COLUMNCLICK:
					{
						static sort_dir=0;
						NMLISTVIEW *nmlv=lparam;
						if(nmlv!=0){
							sort_listview(hlistview,sort_dir,nmlv->iSubItem);
							sort_dir=!sort_dir;
						}
					}
					break;
				case LVN_KEYDOWN:
					if(nmhdr->hwndFrom==hlistview)
					{
						LV_KEYDOWN *key=lparam;
						switch(key->wVKey){
						case VK_DOWN:
						case VK_RIGHT:
						case VK_NEXT:
							{
								int count,row_sel;
								count=ListView_GetItemCount(hlistview);
								row_sel=ListView_GetSelectionMark(hlistview);
								if(count>0 && row_sel==count-1)
									SetFocus(GetDlgItem(hwnd,IDOK));
							}
							break;
						case VK_DELETE:
							clear_selected_items(hlistview);
							break;
						case VK_F5:
							if(task_insert_row(win,hlistview))
								SetWindowText(GetDlgItem(hwnd,IDOK),"Busy");
							break;
						case 'A':
							if(GetKeyState(VK_CONTROL)&0x8000){
								int i,count;
								count=ListView_GetItemCount(hlistview);
								for(i=0;i<count;i++){
									ListView_SetItemState(hlistview,i,LVIS_SELECTED,LVIS_SELECTED);
								}
								break;
							}
						default:
							{
								int ignore=FALSE;
								if(!is_entry_key(key->wVKey))
									ignore=TRUE;
								if(GetKeyState(VK_CONTROL)&0x8000)
									ignore=TRUE;
								if(ignore)
									return 1;
							}
						case ' ':
						case VK_F2:
						case VK_INSERT:
							{
								int row_sel=ListView_GetSelectionMark(hlistview);
								if(row_sel>=0 && hedit==0){
									hedit=CreateWindow("EDIT","",WS_THICKFRAME|WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|
											ES_LEFT|ES_AUTOHSCROLL,
											0,0,
											0,0,
											hwnd,
											IDC_EDIT1,
											ghinstance,
											NULL);
									if(hedit!=0){
										RECT rect={0},crect={0};
										int x,y,w,h;
										ListView_GetItemRect(hlistview,row_sel,&rect,LVIR_BOUNDS);
										lv_get_col_rect(hlistview,DATA_POS,&crect);
										x=crect.left-2;
										y=rect.top-2;
										w=crect.right-crect.left+8;
										h=rect.bottom-rect.top+8;
										SetWindowPos(hedit,HWND_TOP,x,y,w,h,0);
										if(hfont!=0)
											SendMessage(hedit,WM_SETFONT,hfont,0);
										if(is_entry_key(key->wVKey)){
											char str[2];
											char c=tolower(key->wVKey);
											if((GetKeyState(VK_SHIFT)&0x8000) || (GetKeyState(VK_CAPITAL)&1))
												c=toupper(c);
											str[0]=c;
											str[1]=0;
											SetWindowText(hedit,str);
											SendMessage(hedit,EM_SETSEL,1,1);

										}else{
											populate_edit_control(hlistview,hedit,row_sel);
										}
										SetFocus(hedit);
										wporigtedit=SetWindowLong(hedit,GWL_WNDPROC,(LONG)sc_edit);
									}
								}
							}
							break;
						}

					}
					break;
				}

			}
		}
		break;
	case WM_HSCROLL:
		if(lparam==hgrippy)
			SetFocus(hlistview);
		break;
	case WM_USER:
		if(hedit!=0 && lparam==hedit){
			hedit=0;
			SetFocus(hlistview);
		}
		else if(lparam==hlistview){
			if(wparam==IDOK){
				add_row_tablewindow(win,hlistview);
			}
			else
				SetFocus(GetDlgItem(hwnd,IDCANCEL));

			SetWindowText(GetDlgItem(hwnd,IDOK),"OK");
		}
		break;
	case WM_SIZE:
		resize_insert_dlg(hwnd);
		grippy_move(hwnd,hgrippy);
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDOK:
			if(hedit!=0){
				if(GetFocus()==hedit){
					char str[80]={0};
					int count,row_sel=ListView_GetSelectionMark(hlistview);
					GetWindowText(hedit,str,sizeof(str));
					resize_column(hwnd,hlistview,str,1);
					lv_update_data(hlistview,row_sel,DATA_POS,str);
					SendMessage(hedit,WM_CLOSE,0,0);
					count=ListView_GetItemCount(hlistview);
					if(row_sel < (count-1)){
						ListView_SetItemState(hlistview,row_sel,0,LVIS_SELECTED|LVIS_FOCUSED);
						row_sel++;
						ListView_SetItemState(hlistview,row_sel,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
						ListView_SetSelectionMark(hlistview,row_sel);
					}
					hedit=0;
				}
				break;
			}
			else if(GetFocus()==hlistview){
				static LV_KEYDOWN lvk={0};
				lvk.hdr.hwndFrom=hlistview;
				lvk.hdr.code=LVN_KEYDOWN;
				lvk.wVKey=VK_INSERT;
				SendMessage(hwnd,WM_NOTIFY,0,&lvk);
				break;
			}
			else{
				if(task_insert_row(win,hlistview))
					SetWindowText(GetDlgItem(hwnd,IDOK),"Busy");

			}
			break;
		case IDCANCEL:
			if(hedit!=0){
				SendMessage(hedit,WM_CLOSE,0,0);
				hedit=0;
				break;
			}
			EndDialog(hwnd,0);
			break;
		}
		break;	
	}
	return 0;
}
Beispiel #10
0
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

	GL_Window* window = (GL_Window*)(GetWindowLong(hWnd, GWL_USERDATA));

	switch (uMsg)														// 取得Window的消息值
	{
	case WM_SYSCOMMAND:													// 截取系统命令
		{
			switch (wParam)												// 监听系统调用
			{
			case SC_SCREENSAVE:											// 要运行屏保(Screensaver)?
			case SC_MONITORPOWER:										// 显示器进入节电模式(Powersave)?
				return 0;												// 提前返回0,防止系统调用执行
			}
			break;														// 退出
		}

	case WM_CREATE:														// 创建Window
		{
			CREATESTRUCT* creation = (CREATESTRUCT*)(lParam);			// 保存窗口结构指针
			window = (GL_Window*)(creation->lpCreateParams);
			SetWindowLong(hWnd, GWL_USERDATA, (LONG)(window));			// 改变窗口属性
			return 0;													// 返回
		}

	case WM_CLOSE:														// 关闭窗口
		{
			PostMessage(window->hWnd, WM_QUIT, 0, 0);					// 结束程序
			g_isProgramLooping = FALSE;
			return 0;
		}

	case WM_SIZE:														// WM_SIZE消息处理
		switch (wParam)													// 判断消息句柄
		{
		case SIZE_MINIMIZED:											// 窗口最小化?
			window->isVisible = FALSE;									// 设置isVisible 为 FALSE
			return 0;

		case SIZE_MAXIMIZED:											// 窗口最大化?
			window->isVisible = TRUE;									// 设置isVisible 为 TRUE
			ResizeWindowGL (LOWORD (lParam), HIWORD (lParam));			// 修改窗口大小为 Width=LoWord, Height=HiWord
			return 0;													// 返回

		case SIZE_RESTORED:												// 窗口还原?
			window->isVisible = TRUE;									// 设置isVisible 为 TRUE
			ResizeWindowGL (LOWORD (lParam), HIWORD (lParam));			// 修改窗口大小为 Width=LoWord, Height=HiWord
			return 0;													// 返回
		}
		break;															// 退出

	case WM_KEYDOWN:													// 更新键盘缓冲区
		if ((wParam >= 0) && (wParam <= 255))							// 按键是否合法?
		{
			window->keys->keyDown[wParam] = TRUE;						// 设相应键为 TRUE (被按下的键)
			return 0;													// 返回
		}
		break;															// 退出

	case WM_KEYUP:														// 松开按键的时候更新键盘缓冲
		if ((wParam >= 0) && (wParam <= 255))							// 按键是否合法?
		{
			window->keys->keyDown[wParam] = FALSE;						// 设相应键为 FALSE (被释放的键)
			return 0;													// 返回
		}
		break;															// 退出

	case WM_TOGGLEFULLSCREEN:											// 切换全屏/窗口模式
		{
			g_createFullScreen = !g_createFullScreen;
			PostMessage(hWnd, WM_QUIT, 0, 0);
			break;														// 退出
		}

	default:
		break;
	}

	return DefWindowProc(hWnd, uMsg, wParam, lParam);					// 将本程序不处理的消息传给 DefWindowProc 
}
Beispiel #11
0
// The main window procedure used by the dialog window
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HWND hRunButtonWnd;                      // A handle to the 'Run' button
    static HWND hExitButtonWnd;                     // A handle to the 'Exit' button

    switch(uMsg)                                    // Search through messages sent to this window procedure
    {
    case WM_INITDIALOG:                             // Creating of the dialog window
        if(SetLayeredWindowAttributes != NULL)      // Make sure that this function exits
        {
            if(destroyCaption == false) {           // Make sure that the caption has not already been destroyed
                DestroyCaption(hwndDlg, pDialogSkin->getBitmapWidth(), pDialogSkin->getBitmapHeight());   // Destroy any window caption that may be set
                destroyCaption = true;              // Set a flag to ensure that this has been accomplished
            }

          SetWindowLong(hwndDlg, GWL_EXSTYLE, GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED); // Set the window style
          SetLayeredWindowAttributes(hwndDlg, colorKey, 0, LWA_COLORKEY);                           // Set the transparency color key
        }
        hRunButtonWnd = ::GetDlgItem(hwndDlg,IDRUN);    // Get the window handle for the 'Run' button
        hExitButtonWnd = ::GetDlgItem(hwndDlg,IDEXIT);  // Get the window handle for the 'Exit' button
    return TRUE;

    // draw our bitmap
    case WM_PAINT:                                  // Draw the dialog window
        {
        BITMAP bm;                                  // Create a bitmap structure
        PAINTSTRUCT ps;                             // Create a paint structure
        HDC hdc = BeginPaint(hwndDlg, &ps);         // Create a device context used for the dialog window
        HDC dcSkin = CreateCompatibleDC(hdc);       // Create a compatible memory device context to copy the color information from the bitmap to
        GetObject(pDialogSkin->getBitmapHandle(), sizeof(bm), &bm);      // Fill bitmap structure with information about the background image bitmap
        SelectObject(dcSkin, pDialogSkin->getBitmapHandle());            // Select this bitmap into the memory device context
        BitBlt(hdc, 0,0,pDialogSkin->getBitmapWidth(),pDialogSkin->getBitmapHeight(), dcSkin, 0, 0, SRCCOPY);   // Performs bit-block transfer of bitmap pixels to the memory device context
        DeleteDC(dcSkin);                           // Release the memory device context
        EndPaint(hwndDlg, &ps);                     // End painting of dialog window
        }
    return true;

    case WM_CLOSE:                                  // Exit application
    {
        EndDialog(hwndDlg, 0);                      // Close down the dialog window
    }
    return TRUE;

    case WM_COMMAND:                                // Button has been clicked
    {
        switch (LOWORD (wParam))
        {
            case IDRUN:                             // 'Run' button was clicked
                EndDialog (hwndDlg, 0) ;            // Close the dialog window (or anything else you want to happen)
                return TRUE ;
            case IDEXIT :                           // 'Exit' button was clicked
                EndDialog (hwndDlg, 0) ;            // Close the dialog window because the user is exiting the application
                return TRUE ;
        }
    }
    return TRUE;

    case WM_MOUSEMOVE:                              // Mouse has been moved while over the dialog window area
    {
        if(pRunButton->isMouseOver()){              // Check to see if the mouse was previously over the 'Run' button
            pRunButton->mouseIsOut();               // Set a flag to signify that the mouse is not hovering over the 'Run' button any more

            if(pRunButton->isMouseLeftButtonDown()){// Check to see if the mouse button was previously flagged as down over the 'Run' button
                pRunButton->mouseLeftUp();          // Set a flag to signify that the 'Run' button does not have the left mouse button clicked over it any more

            }
            InvalidateRgn(hRunButtonWnd, NULL, FALSE);  // Redraw the 'Run' button with the default state
        }
        if(pExitButton->isMouseOver()){             // Check to see if the mouse was previously over the 'Exit' button
            pExitButton->mouseIsOut();                 // Set a flag to signify that the mouse is not hovering over the 'Exit' button any more
            if(pExitButton->isMouseLeftButtonDown()){// Check to see if the mouse button was previously flagged as down over the 'Exit' button
                pExitButton->mouseLeftUp();               // Set a flag to signify that the 'Exit' button does not have the left mouse button clicked over it any more

            }
            InvalidateRgn(hExitButtonWnd, NULL, FALSE); // Redraw the 'Exit' button with the default state
        }
    }
    break;

    // Moves the window when the user clicks anywhere not covered by a control. HTCAPTION specifies
    // that all button clicks originate in the title bar area - even when the window has no title bar.
    case WM_LBUTTONDOWN:
    {
        PostMessage(hwndDlg, WM_NCLBUTTONDOWN, HTCAPTION,0);
    }
    return TRUE;

    case WM_LBUTTONUP:                              // The left mouse button was released
    {
        if(pRunButton->isMouseLeftButtonDown()){    // Check to see if the mouse button was previously flagged as down over the 'Run' button
            pRunButton->mouseLeftUp();              // Set a flag to signify that the 'Run' button does not have the left mouse button clicked over it any more
            InvalidateRgn(hRunButtonWnd, NULL, FALSE);  // Redraw the 'Run' button in its default state
        }
        if(pExitButton->isMouseLeftButtonDown()){   // Check to see if the mouse button was previously flagged as down over the 'Exit' button
            pExitButton->mouseLeftUp();                  // Set a flag to signify that the 'Exit' button does not have the left mouse button clicked over it any more
            InvalidateRgn(hExitButtonWnd, NULL, FALSE); // Redraw the 'Exit' button in its default state
        }
    }

    }
    return FALSE;
}
Beispiel #12
0
static LRESULT CALLBACK BaseBar_WindowProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
    LPBASEBARINFO lpbi = (LPBASEBARINFO)GetProp(hwnd, (LPCTSTR)MAKEWORD(s_hBaseBarAtom, 0));//GetWindowLong(hwnd, GWL_USERDATA);

    switch (uMessage)
    {
    case WM_CREATE:
    {
        LPCREATESTRUCT lpcs    = (LPCREATESTRUCT)lParam;
        DWORD          dwStyle = RBS_VERTICALGRIPPER | RBS_REGISTERDROP | RBS_AUTOSIZE | RBS_VARHEIGHT | RBS_DBLCLKTOGGLE | CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE;
        REBARBANDINFO  rbBand;
        TBBUTTON tbb;

        if (lpcs->lpszName)
            lpbi->pszTitle = String_Duplicate(lpcs->lpszName);

        lpbi->dwAlign = BaseBar_GetAlign(hwnd);
        lpbi->dwAllowableAligns = CCS_LEFT | CCS_RIGHT | CCS_TOP | CCS_BOTTOM;

        if (lpbi->dwAlign == CCS_LEFT || lpbi->dwAlign == CCS_RIGHT)
            dwStyle |= CCS_VERT;

        if (!(lpbi->hwndRebar = CreateWindowEx(0, REBARCLASSNAME, NULL, WS_VISIBLE | WS_BORDER | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | dwStyle,
            0, 0, 0, 0, hwnd, (HMENU) REBARID, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL)))
            return (0);

        SendMessage(lpbi->hwndRebar, RB_SETBKCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNFACE));

        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize     = sizeof(REBARBANDINFO);
        rbBand.fMask      = RBBIM_HEADERSIZE | RBBIM_ID | RBBIM_STYLE | RBBIM_COLORS;
        rbBand.fStyle     = RBBS_FIXEDSIZE | RBBS_VARIABLEHEIGHT | RBBS_NOGRIPPER;
        rbBand.clrFore    = GetSysColor(COLOR_BTNTEXT);
        rbBand.clrBack    = GetSysColor(COLOR_BTNFACE);
        rbBand.cxHeader   = ((lpcs->style & CCS_VERT) ? 21 : 24);
        rbBand.wID        = (UINT)lpcs->hMenu;

        if (lpcs->style & CCS_VERT)
        {
            rbBand.fMask |= RBBIM_TEXT;
            rbBand.lpText = (char*)lpcs->lpszName;
        }

        SendMessage(lpbi->hwndRebar, RB_INSERTBAND, (int) -1, (LPARAM) &rbBand);

        ZeroMemory(&tbb, sizeof(TBBUTTON));

        tbb.iBitmap   = 0; 
        tbb.idCommand = IDM_BAND_CLOSE;
        tbb.fsState   = TBSTATE_ENABLED; 
        tbb.fsStyle   = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;

        lpbi->hwndToolbar = CreateToolbarEx(lpbi->hwndRebar, WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER  | CCS_NOPARENTALIGN | CCS_NOMOVEY | CCS_NORESIZE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT,
            IDC_TOOLBAR, 1, PCPControls_GetHandle(), IDB_CHECKBOX, &tbb, 1, 13, 12, 11, 10, sizeof (TBBUTTON));

        SendMessage(lpbi->hwndToolbar, TB_SETBUTTONSIZE, 0, (LPARAM) MAKELONG(20, 18));
        SendMessage(lpbi->hwndToolbar, TB_SETBITMAPSIZE, 0, (LPARAM) MAKELONG(10, 9));
    }
    return (TRUE);
    case WM_SIZE:
    {
        RECT rcNew;

        GetClientRect(hwnd, &rcNew);

        if (wParam == SIZE_RESTORED && !EqualRect(&rcNew, &lpbi->rcSize))
        {
            NMHDR nmhdr;

            MoveWindow(lpbi->hwndRebar, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);

            nmhdr.code     = RBN_HEIGHTCHANGE;
            nmhdr.hwndFrom = hwnd;
            nmhdr.idFrom   = GetDlgCtrlID(hwnd);
            SendMessage(GetParent(hwnd), WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);

            if (lpbi->hwndToolbar)
            {
                RECT  rcBand;
                DWORD dwSize = (DWORD)SendMessage(lpbi->hwndToolbar, TB_GETBUTTONSIZE, 0, 0);

                SendMessage(lpbi->hwndRebar, RB_GETBANDBORDERS, 0, (LPARAM)&rcBand);

                if (lpbi->dwAlign == CCS_LEFT || lpbi->dwAlign == CCS_RIGHT)
                {
                    int x = (LOWORD(lParam) - 24);
                    int y = ((rcBand.top - HIWORD(dwSize)) / 2);
                    MoveWindow(lpbi->hwndToolbar, x, y, 20, 18, TRUE);
                }
                else
                {
                    MoveWindow(lpbi->hwndToolbar, 2, 2, 20, 18, TRUE);
                }
            }
        }

        GetClientRect(hwnd, &lpbi->rcSize);
    }
    break;
    case WM_NOTIFY:
    {
        LPNMHDR lphdr = (LPNMHDR)lParam;

        if (lphdr->code == NM_NCHITTEST && lphdr->idFrom == REBARID)
        {
            if (HIBYTE(GetAsyncKeyState(VK_RBUTTON)))
            {
                HMENU hMenu = LoadMenu(PCPControls_GetHandle(), MAKEINTRESOURCE(IDR_BANDMENU));
                HMENU hPopupMenu = GetSubMenu(hMenu, 0);
                POINT pt;

                if (lpbi->dwAllowableAligns & CCS_VERT)
                {
                    if (!(lpbi->dwAllowableAligns & CCS_LEFT))
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_LEFT, FALSE);
                    if (!(lpbi->dwAllowableAligns & CCS_RIGHT))
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_RIGHT, FALSE);

                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_TOP, FALSE);
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_BOTTOM, FALSE);
                }
                else
                {
                    if (!(lpbi->dwAllowableAligns & CCS_TOP))
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_TOP, FALSE);
                    if (!(lpbi->dwAllowableAligns & CCS_BOTTOM))
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_BOTTOM, FALSE);

                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_LEFT, FALSE);
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_RIGHT, FALSE);
                }

                GetCursorPos(&pt);

                Menu_TrackPopupMenu(hPopupMenu, pt.x, pt.y, hwnd);
            }
            return (HTCLIENT);
        }
        else if (lphdr->code == NM_CUSTOMDRAW && lphdr->idFrom == REBARID)
        {
            LPNMCUSTOMDRAW lpnmcd = (LPNMCUSTOMDRAW) lParam;

            if (lpnmcd->dwDrawStage == CDDS_PREPAINT)
                return (CDRF_NOTIFYPOSTPAINT);
            else if (lpnmcd->dwDrawStage == CDDS_POSTPAINT && (lpbi->dwAlign == CCS_TOP || lpbi->dwAlign == CCS_BOTTOM))
            {
                DrawEdge(lpnmcd->hdc, &lpnmcd->rc, EDGE_ETCHED, BF_RIGHT);
            }
        }
        else if (lphdr->idFrom == IDC_TOOLBAR)
        {
        }
    }
    return (SendMessage(GetParent(hwnd), uMessage, wParam, lParam));
    case WM_COMMAND:
    {
        DWORD dwAlign;

        switch (LOWORD(wParam))
        {
        case IDM_BAND_LEFT:
            dwAlign = CCS_LEFT;
        break;
        case IDM_BAND_RIGHT:
            dwAlign = CCS_RIGHT;
        break;
        case IDM_BAND_TOP:
            dwAlign = CCS_TOP;
        break;
        case IDM_BAND_BOTTOM:
            dwAlign = CCS_BOTTOM;
        break;
        case IDM_BAND_CLOSE:
        {
            NMHDR nmhdr;

            nmhdr.code     = BBN_CLOSE;
            nmhdr.hwndFrom = hwnd;
            nmhdr.idFrom   = GetDlgCtrlID(hwnd);

            SendMessage(GetParent(hwnd), WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
        }
        return (0);
        default:
        return (0);
        }

        SendMessage(hwnd, BCM_SETALIGNMENT, (WPARAM)dwAlign, 0L);
    }
    case WM_GETMINMAXINFO:
    {
        MINMAXINFO *lpmmi = (MINMAXINFO *)lParam;
        
        if (lpmmi != NULL)
        {
            int cx = GetSystemMetrics(SM_CXSCREEN);
            int cy = GetSystemMetrics(SM_CYSCREEN);
            
            if (lpbi->dwAlign == CCS_LEFT || lpbi->dwAlign == CCS_RIGHT)
                lpmmi->ptMaxTrackSize.x = cx / 2;
            else
                lpmmi->ptMaxTrackSize.y = cy / 2;
            
            if (lpbi->dwAlign == CCS_LEFT)
            {
                lpmmi->ptMinTrackSize.x = 50;
            }
            else if (lpbi->dwAlign == CCS_RIGHT)
            {
                lpmmi->ptMinTrackSize.x = 50;
            }
            else if (lpbi->dwAlign == CCS_TOP)
            {
                lpmmi->ptMinTrackSize.y = 50;
            }
            else if (lpbi->dwAlign == CCS_BOTTOM)
            {
                lpmmi->ptMinTrackSize.y = 50;
            }
            else
            {
                lpmmi->ptMinTrackSize.x = 56;
                lpmmi->ptMinTrackSize.y = 24;
            }
        }
    }
    return (FALSE);
    case WM_NCCREATE:
    {
        lpbi = Mem_Alloc(sizeof(BASEBARINFO));

        if (lpbi == NULL)
            return (FALSE);

        SetProp(hwnd, (LPCTSTR)MAKEWORD(s_hBaseBarAtom, 0), lpbi);
    }
    return (TRUE);
    case WM_NCDESTROY:
    {
        RemoveProp(hwnd, (LPCTSTR)MAKEWORD(s_hBaseBarAtom, 0));

        if (lpbi != NULL)
        {
            if (lpbi->pszTitle != NULL)
                Mem_Free(lpbi->pszTitle);

            Mem_Free(lpbi);
        }
    }
    return (TRUE);
    case WM_NCHITTEST:
    {
        POINT pt = {LOWORD(lParam), HIWORD(lParam)};
        RECT  re;

        GetWindowRect(hwnd, &re);

        if (!PtInRect(&re, pt))
            return (HTNOWHERE);

        if (lpbi->dwAlign == CCS_LEFT)
        {
            re.left = re.right - 4;

            if (PtInRect(&re, pt))
                return (HTRIGHT);
        }
        else if (lpbi->dwAlign == CCS_RIGHT)
        {
            re.right = re.left + 4;

            if (PtInRect(&re, pt))
                return (HTLEFT);
        }
        else if (lpbi->dwAlign == CCS_BOTTOM)
        {
            re.bottom = re.top + 4;

            if (PtInRect(&re, pt))
                return (HTTOP);
        }
        else if (lpbi->dwAlign == CCS_TOP)
        {
            re.top = re.bottom - 4;

            if (PtInRect(&re, pt))
                return (HTBOTTOM);
        }
    }
    return (HTCLIENT);
    case WM_NCCALCSIZE:
    {
        if (wParam == TRUE)
        {
            NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *) lParam;

            if (lpbi->dwAlign == CCS_LEFT)
            {
                ncp->rgrc[0].top    += 4;
                ncp->rgrc[0].right  -= 4;
            }
            else if (lpbi->dwAlign == CCS_RIGHT)
            {
                ncp->rgrc[0].top    += 4;
                ncp->rgrc[0].left   += 4;
            }
            else if (lpbi->dwAlign == CCS_BOTTOM)
            {
                ncp->rgrc[0].top    += 4;
            }
            else if (lpbi->dwAlign == CCS_TOP)
            {
                ncp->rgrc[0].bottom -= 4;
            }
            else
            {
                ncp->rgrc[0].top    += 4;
                ncp->rgrc[0].right  -= 4;
                ncp->rgrc[0].left   += 4;
                ncp->rgrc[0].bottom -= 4;
            }
        }
    }
    break;
    case WM_ERASEBKGND:
    return (TRUE);
    case WM_NCPAINT:
    {
        HDC  hdc = GetWindowDC(hwnd);
        RECT rcWindow, rcClient;

        if (hdc == NULL)
            break;

        GetClientRect(hwnd, &rcClient);
        GetWindowRect(hwnd, &rcWindow);

        MapWindowPoints(NULL, hwnd, (LPPOINT)&rcWindow, 2);
        OffsetRect(&rcClient, -rcWindow.left, -rcWindow.top);
        OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top);
        ExcludeClipRect(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);

        FillRect(hdc, &rcWindow, (HBRUSH)GetSysColorBrush(COLOR_BTNFACE));
        ReleaseDC(hwnd, hdc);
    }
    return (TRUE);
    case BCM_SETCLIENTWND:
    {
        REBARBANDINFO rbBand;
        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize     = sizeof(REBARBANDINFO);
        rbBand.fMask      = RBBIM_CHILDSIZE | RBBIM_CHILD;
        rbBand.cyIntegral = 1;
        rbBand.cyMaxChild = -1;
        rbBand.hwndChild  = (HWND)lParam;

        return (SendMessage(lpbi->hwndRebar, RB_SETBANDINFO, 0, (LPARAM)&rbBand));
    }
    case BCM_GETCLIENTWND:
    {
        REBARBANDINFO rbBand;
        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize     = sizeof(REBARBANDINFO);
        rbBand.fMask      = RBBIM_CHILD;
        SendMessage(lpbi->hwndRebar, RB_GETBANDINFO, 0, (LPARAM)&rbBand);

        return (LRESULT)((IsWindow(rbBand.hwndChild) ? rbBand.hwndChild : NULL));
    }
    case BCM_SETIMAGELIST:
    {
        REBARINFO  rbi;
        HIMAGELIST hilOld = BandCtrl_GetImageList(hwnd);

        rbi.cbSize = sizeof(REBARINFO);
        rbi.fMask  = RBIM_IMAGELIST;
        rbi.himl   = (HIMAGELIST)lParam;

        if (!SendMessage(lpbi->hwndRebar, RB_SETBARINFO, 0, (LPARAM) &rbi))
            return ((LRESULT)NULL);

        return ((LRESULT)hilOld);
    }
    case BCM_GETIMAGELIST:
    {
        REBARINFO rbi;

        rbi.cbSize = sizeof(REBARINFO);
        rbi.fMask  = RBIM_IMAGELIST;
        rbi.himl   = 0;

        if (!SendMessage(lpbi->hwndRebar, RB_GETBARINFO, 0, (LPARAM) &rbi))
            return ((LRESULT)NULL);

        return ((LRESULT)rbi.himl);
    }
    case BCM_SETTITLEIMAGE:
    {
        REBARBANDINFO rbBand;

        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize = sizeof(REBARBANDINFO);
        rbBand.fMask  = RBBIM_IMAGE;
        rbBand.iImage = wParam;

        return (SendMessage(lpbi->hwndRebar, RB_SETBANDINFO, 0, (LPARAM)&rbBand));
    }
    case BCM_GETTITLEIMAGE:
    {
        REBARBANDINFO rbBand;

        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize = sizeof(REBARBANDINFO);
        rbBand.fMask  = RBBIM_IMAGE;
        rbBand.iImage = -1;
        SendMessage(lpbi->hwndRebar, RB_GETBANDINFO, 0, (LPARAM)&rbBand);

        return (rbBand.iImage);
    }
    case BCM_GETALIGNMENT:
    return ((LRESULT)lpbi->dwAlign);
    case BCM_SETALIGNMENT:
    {
        NMHDR nmhdr;
        DWORD dwStyle;

        if (lpbi->dwAlign == wParam)
            return (wParam);

        lpbi->dwAlign = wParam;

        dwStyle = GetWindowLong(lpbi->hwndRebar, GWL_STYLE);
        dwStyle &= ~(CCS_BOTTOM | CCS_TOP | CCS_LEFT | CCS_RIGHT);
        dwStyle |= lpbi->dwAlign;

        SetWindowLong(lpbi->hwndRebar, GWL_STYLE, dwStyle);

        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

        nmhdr.code     = RBN_HEIGHTCHANGE;
        nmhdr.hwndFrom = hwnd;
        nmhdr.idFrom   = GetDlgCtrlID(hwnd);
        SendMessage(GetParent(hwnd), WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);

        return (lpbi->dwAlign);
    }
    case BCM_SETDATA:
    {
        LPARAM lParamOld = lpbi->lParam;
        lpbi->lParam = lParam;
        return (lParamOld);
    }
    case BCM_GETDATA:
    return (lpbi->lParam);
    case BCM_SETALLOWABLEALIGNS:
    {
        DWORD dwOldAllowableAligns = lpbi->dwAllowableAligns;

        lpbi->dwAllowableAligns = lParam;

        return (dwOldAllowableAligns);
    }
    case BCM_GETALLOWABLEALIGNS:
    return (lpbi->dwAllowableAligns);
    }

    return (DefWindowProc(hwnd, uMessage, wParam, lParam));
}
Beispiel #13
0
/*
** Sys_CreateConsole
*/
void Sys_CreateConsole( void ) {
	HDC hDC;
	WNDCLASSA wc;
	RECT rect;
	const char *DEDCLASS = WIN32_CONSOLE_CLASS;
	int nHeight;
	int swidth, sheight;
	int DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX;
	int i;

	memset( &wc, 0, sizeof( wc ) );

	wc.style         = 0;
	wc.lpfnWndProc   = (WNDPROC) ConWndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = win32.hInstance;
	wc.hIcon         = LoadIcon( win32.hInstance, MAKEINTRESOURCE(IDI_ICON1));
	wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
	wc.hbrBackground = (struct HBRUSH__ *)COLOR_WINDOW;
	wc.lpszMenuName  = 0;
	wc.lpszClassName = DEDCLASS;

	if ( !RegisterClassA (&wc) ) {
		return;
	}

	rect.left = 0;
	rect.right = 540;
	rect.top = 0;
	rect.bottom = 450;
	AdjustWindowRect( &rect, DEDSTYLE, FALSE );

	hDC = GetDC( GetDesktopWindow() );
	swidth = GetDeviceCaps( hDC, HORZRES );
	sheight = GetDeviceCaps( hDC, VERTRES );
	ReleaseDC( GetDesktopWindow(), hDC );

	s_wcd.windowWidth = rect.right - rect.left + 1;
	s_wcd.windowHeight = rect.bottom - rect.top + 1;

	//s_wcd.hbmLogo = LoadBitmap( win32.hInstance, MAKEINTRESOURCE( IDB_BITMAP_LOGO) );

	s_wcd.hWnd = CreateWindowExA( 0,
							   DEDCLASS,
							   "DOOM3-FH",
							   DEDSTYLE,
							   ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1,
							   NULL,
							   NULL,
							   win32.hInstance,
							   NULL );

	if ( s_wcd.hWnd == NULL ) {
		return;
	}

	//
	// create fonts
	//
	hDC = GetDC( s_wcd.hWnd );
	nHeight = -MulDiv( 8, GetDeviceCaps( hDC, LOGPIXELSY ), 72 );

	s_wcd.hfBufferFont = CreateFontA( nHeight, 0, 0, 0, FW_LIGHT, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN | FIXED_PITCH, "Courier New" );

	ReleaseDC( s_wcd.hWnd, hDC );

	//
	// create the input line
	//
	s_wcd.hwndInputLine = CreateWindowA( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | 
												ES_LEFT | ES_AUTOHSCROLL,
												6, 400, 528, 20,
												s_wcd.hWnd, 
												( HMENU ) INPUT_ID,	// child window ID
												win32.hInstance, NULL );

	//
	// create the buttons
	//
	s_wcd.hwndButtonCopy = CreateWindowA( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												5, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) COPY_ID,	// child window ID
												win32.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonCopy, WM_SETTEXT, 0, ( LPARAM ) "copy" );

	s_wcd.hwndButtonClear = CreateWindowA( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												82, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) CLEAR_ID,	// child window ID
												win32.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonClear, WM_SETTEXT, 0, ( LPARAM ) "clear" );

	s_wcd.hwndButtonQuit = CreateWindowA( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												462, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) QUIT_ID,	// child window ID
												win32.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonQuit, WM_SETTEXT, 0, ( LPARAM ) "quit" );


	//
	// create the scrollbuffer
	//
	s_wcd.hwndBuffer = CreateWindowA( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | 
												ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
												6, 40, 526, 354,
												s_wcd.hWnd, 
												( HMENU ) EDIT_ID,	// child window ID
												win32.hInstance, NULL );
	SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, ( long ) InputLineWndProc );
	SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

// don't show it now that we have a splash screen up
	if ( win32.win_viewlog.GetBool() ) {
		ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT);
		UpdateWindow( s_wcd.hWnd );
		SetForegroundWindow( s_wcd.hWnd );
		SetFocus( s_wcd.hwndInputLine );
	}



	s_wcd.consoleField.Clear();

	for ( i = 0 ; i < COMMAND_HISTORY ; i++ ) {
		s_wcd.historyEditLines[i].Clear();
	}
}
static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    MButtonCtrl *bct = (MButtonCtrl *) GetWindowLong(hwndDlg, 0);
    switch (msg) {
        case WM_NCCREATE:
            {
                SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLong(hwndDlg, GWL_STYLE) | BS_OWNERDRAW);
                bct = malloc(sizeof(MButtonCtrl));
                if (bct == NULL)
                    return FALSE;
                bct->hwnd = hwndDlg;
                bct->stateId = PBS_NORMAL;
                bct->focus = 0;
                bct->hFont = GetStockObject(DEFAULT_GUI_FONT);
                bct->arrow = NULL;
                bct->defbutton = 0;
                bct->hIcon = bct->hIconPrivate = 0;
                bct->iIcon = 0;
                bct->hIml = 0;
                bct->hBitmap = NULL;
                bct->pushBtn = 0;
                bct->pbState = 0;
                bct->hThemeButton = NULL;
                bct->hThemeToolbar = NULL;
                bct->cHot = 0;
                bct->flatBtn = 0;
                bct->bThemed = FALSE;
                bct->bSkinned = bct->bSendOnDown = 0;
                bct->buttonItem = NULL;
                LoadTheme(bct);
                SetWindowLong(hwndDlg, 0, (LONG) bct);
                if (((CREATESTRUCTA *) lParam)->lpszName)
                    SetWindowText(hwndDlg, ((CREATESTRUCT *) lParam)->lpszName);
                return TRUE;
            }
        case WM_DESTROY:
            {
                if (bct) {
                    if (hwndToolTips) {
                        TOOLINFO ti;

                        ZeroMemory(&ti, sizeof(ti));
                        ti.cbSize = sizeof(ti);
                        ti.uFlags = TTF_IDISHWND;
                        ti.hwnd = bct->hwnd;
                        ti.uId = (UINT) bct->hwnd;
                        if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM) &ti)) {
                            SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM) &ti);
                        }
                        if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM) &ti) == 0) {
                            DestroyWindow(hwndToolTips);
                            hwndToolTips = NULL;
                        }
                    }
                    if (bct->hIconPrivate)
                        DestroyIcon(bct->hIconPrivate);
                    DestroyTheme(bct);
                    free(bct);
                }
                SetWindowLong(hwndDlg, 0, (LONG) NULL);
                break;  // DONT! fall thru
            }
        case WM_SETTEXT:
            {
                bct->cHot = 0;
                if ((char*) lParam) {
                    char *tmp = (char *) lParam;
                    while (*tmp) {
                        if (*tmp == '&' && *(tmp + 1)) {
                            bct->cHot = tolower(*(tmp + 1));
                            break;
                        }
                        tmp++;
                    }
                    InvalidateRect(bct->hwnd, NULL, TRUE);
                    lstrcpyn(bct->szText, (TCHAR *)lParam, 127);
                    bct->szText[127] = 0;
                }
                break;
            }
        case WM_SYSKEYUP:
            if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == tolower((int) wParam)) {
                if (bct->pushBtn) {
                    if (bct->pbState)
                        bct->pbState = 0;
                    else
                        bct->pbState = 1;
                    InvalidateRect(bct->hwnd, NULL, TRUE);
                }
                if(!bct->bSendOnDown)
					SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg);
                return 0;
            }
            break;
        case WM_THEMECHANGED:
            {
            // themed changed, reload theme object
                if (bct->bThemed)
                    LoadTheme(bct);
                InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
                break;
            }
        case WM_SETFONT:
    // remember the font so we can use it later
            {
                bct->hFont = (HFONT) wParam; // maybe we should redraw?
                break;
            }
        case WM_NCPAINT:
        case WM_PAINT:
            {
                PAINTSTRUCT ps;
                HDC hdcPaint;

                hdcPaint = BeginPaint(hwndDlg, &ps);
                if (hdcPaint) {
                    PaintWorker(bct, hdcPaint);
                    EndPaint(hwndDlg, &ps);
                }
                break;
            }
        case BM_GETIMAGE:
            if(wParam == IMAGE_ICON)
                return (LRESULT)(bct->hIconPrivate ? bct->hIconPrivate : bct->hIcon);
            break;
        case BM_SETIMAGE:
            if(!lParam)
                break;
            bct->hIml = 0;
            bct->iIcon = 0;
            if (wParam == IMAGE_ICON) {
                ICONINFO ii = {0};
                BITMAP bm = {0};

                if (bct->hIconPrivate) {
                    DestroyIcon(bct->hIconPrivate);
                    bct->hIconPrivate = 0;
                }

                GetIconInfo((HICON) lParam, &ii);
                GetObject(ii.hbmColor, sizeof(bm), &bm);
                if (bm.bmWidth > g_cxsmIcon || bm.bmHeight > g_cysmIcon) {
                    HIMAGELIST hImageList;
                    hImageList = ImageList_Create(g_cxsmIcon, g_cysmIcon, IsWinVerXPPlus() ? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0);
                    ImageList_AddIcon(hImageList, (HICON) lParam);
                    bct->hIconPrivate = ImageList_GetIcon(hImageList, 0, ILD_NORMAL);
                    ImageList_RemoveAll(hImageList);
                    ImageList_Destroy(hImageList);
                    bct->hIcon = 0;
                } else {
                    bct->hIcon = (HICON) lParam;
                    bct->hIconPrivate = 0;
                }

                DeleteObject(ii.hbmMask);
                DeleteObject(ii.hbmColor);
                bct->hBitmap = NULL;
                InvalidateRect(bct->hwnd, NULL, TRUE);
            } else if (wParam == IMAGE_BITMAP) {
                bct->hBitmap = (HBITMAP) lParam;
                if (bct->hIconPrivate)
                    DestroyIcon(bct->hIconPrivate);
                bct->hIcon = bct->hIconPrivate = NULL;
                InvalidateRect(bct->hwnd, NULL, TRUE);
            }
            break;
        case BM_SETPRIVATEICON:
            bct->hIml = 0;
            bct->iIcon = 0; {
                if (bct->hIconPrivate)
                    DestroyIcon(bct->hIconPrivate);
                bct->hIconPrivate = DuplicateIcon(g_hInst, (HICON) lParam);
                bct->hIcon = 0;
                break;
            }
        case BM_SETIMLICON:
            {
                if (bct->hIconPrivate)
                    DestroyIcon(bct->hIconPrivate);
                bct->hIml = (HIMAGELIST) wParam;
                bct->iIcon = (int) lParam;
                bct->hIcon = bct->hIconPrivate = 0;
                InvalidateRect(bct->hwnd, NULL, TRUE);
                break;
            }
        case BM_SETSKINNED:
            bct->bSkinned = (DWORD)lParam;
            bct->bThemed = bct->bSkinned ? FALSE : bct->bThemed;
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case BM_SETBTNITEM:
            bct->buttonItem = (ButtonItem *)lParam;
            break;
		case BM_SETASMENUACTION:
			bct->bSendOnDown = wParam ? TRUE : FALSE;
			return 0;
        case BM_SETCHECK:
            if (!bct->pushBtn)
                break;
            if (wParam == BST_CHECKED) {
                bct->pbState = 1;
                bct->stateId = PBS_PRESSED;
            } else if (wParam == BST_UNCHECKED) {
                bct->pbState = 0;
                bct->stateId = PBS_NORMAL;
            }
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case BM_GETCHECK:
            if (bct->pushBtn) {
                return bct->pbState ? BST_CHECKED : BST_UNCHECKED;
            }
            return 0;
        case BUTTONSETARROW:
    // turn arrow on/off
            if (wParam) {
                if (!bct->arrow)
                    bct->arrow = (HICON) LoadImage(g_hInst, MAKEINTRESOURCE(IDI_MINIMIZE), IMAGE_ICON, g_cxsmIcon, g_cysmIcon, 0);
            } else {
                if (bct->arrow) {
                    DestroyIcon(bct->arrow);
                    bct->arrow = NULL;
                }
            }
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case BUTTONSETDEFAULT:
            bct->defbutton = wParam ? 1 : 0;
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case BUTTONSETASPUSHBTN:
            bct->pushBtn = 1;
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case BUTTONSETASFLATBTN:
            bct->flatBtn = lParam == 0 ? 1 : 0;
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case BUTTONSETASFLATBTN + 10:
            bct->bThemed = lParam ? TRUE : FALSE;
            bct->bSkinned = bct->bThemed ? 0 : bct->bSkinned;
            break;
        case BUTTONADDTOOLTIP:
            {
                TOOLINFO ti;

                if (!(char*) wParam)
                    break;
                if (!hwndToolTips) {
                    hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
					SetWindowPos(hwndToolTips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
                }
                ZeroMemory(&ti, sizeof(ti));
                ti.cbSize = sizeof(ti);
                ti.uFlags = TTF_IDISHWND;
                ti.hwnd = bct->hwnd;
                ti.uId = (UINT) bct->hwnd;
                if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM) &ti)) {
                    SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM) &ti);
                }
                ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
                ti.uId = (UINT) bct->hwnd;
                ti.lpszText = (TCHAR *) wParam;
                SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM) &ti);
                break;
            }
        case WM_SETFOCUS:
    // set keybord focus and redraw
            bct->focus = 1;
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case WM_KILLFOCUS:
    // kill focus and redraw
            bct->focus = 0;
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case WM_WINDOWPOSCHANGED:
            InvalidateRect(bct->hwnd, NULL, TRUE);
            break;
        case WM_ENABLE:
    // windows tells us to enable/disable
            {
                bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED;
                InvalidateRect(bct->hwnd, NULL, TRUE);
                break;
            }
        case WM_MOUSELEAVE:
    // faked by the WM_TIMER
            {
                if (bct->stateId != PBS_DISABLED) {
                // don't change states if disabled
                    bct->stateId = PBS_NORMAL;
                    InvalidateRect(bct->hwnd, NULL, TRUE);
                }
                break;
            }
        case WM_LBUTTONDOWN:
            {
                if (bct->stateId != PBS_DISABLED && bct->stateId != PBS_PRESSED) {
                    bct->stateId = PBS_PRESSED;
                    InvalidateRect(bct->hwnd, NULL, TRUE);
					if(bct->bSendOnDown) {
                        SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg);
                        bct->stateId = PBS_NORMAL;
	                    InvalidateRect(bct->hwnd, NULL, TRUE);
                    }
                }
                break;
            }
        case WM_LBUTTONUP:
            {
                if (bct->pushBtn) {
                    if (bct->pbState)
                        bct->pbState = 0;
                    else
                        bct->pbState = 1;
                }
                if (bct->stateId != PBS_DISABLED) {
                // don't change states if disabled
                    if (msg == WM_LBUTTONUP)
                        bct->stateId = PBS_HOT;
                    else
                        bct->stateId = PBS_NORMAL;
                    InvalidateRect(bct->hwnd, NULL, TRUE);
                }
				if(!bct->bSendOnDown)
					SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg);
                break;
            }
        case WM_MOUSEMOVE:
            if (bct->stateId == PBS_NORMAL) {
                bct->stateId = PBS_HOT;
                InvalidateRect(bct->hwnd, NULL, TRUE);
            }
    // Call timer, used to start cheesy TrackMouseEvent faker
            SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL);
            break;
        case WM_NCHITTEST:
            {
                LRESULT lr = SendMessage(GetParent(hwndDlg), WM_NCHITTEST, wParam, lParam);
                if(lr == HTLEFT || lr == HTRIGHT || lr == HTBOTTOM || lr == HTTOP || lr == HTTOPLEFT || lr == HTTOPRIGHT
                   || lr == HTBOTTOMLEFT || lr == HTBOTTOMRIGHT)
                    return HTTRANSPARENT;
                break;
            }
        case WM_TIMER:
    // use a timer to check if they have did a mouseout
            {
                if (wParam == BUTTON_POLLID) {
                    RECT rc;
                    POINT pt;
                    GetWindowRect(hwndDlg, &rc);
                    GetCursorPos(&pt);
                    if (!PtInRect(&rc, pt)) {
                    // mouse must be gone, trigger mouse leave
                        PostMessage(hwndDlg, WM_MOUSELEAVE, 0, 0L);
                        KillTimer(hwndDlg, BUTTON_POLLID);
                    }
                }
                break;
            }
        case WM_ERASEBKGND:
            return 1;
    }
    return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
Beispiel #15
0
static int
SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool created)
{
    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    SDL_WindowData *data;

    /* Allocate the window data */
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        return SDL_OutOfMemory();
    }
    data->window = window;
    data->hwnd = hwnd;
    data->parent = parent;
    data->hdc = GetDC(hwnd);
    data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
    data->created = created;
    data->mouse_button_flags = 0;
    data->videodata = videodata;
    data->initializing = SDL_TRUE;

    window->driverdata = data;

    /* Associate the data with the window */
    if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
        ReleaseDC(hwnd, data->hdc);
        SDL_free(data);
        return WIN_SetError("SetProp() failed");
    }

    /* Set up the window proc function */
#ifdef GWLP_WNDPROC
    data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
    if (data->wndproc == WIN_WindowProc) {
        data->wndproc = NULL;
    } else {
        SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
    }
#else
    data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
    if (data->wndproc == WIN_WindowProc) {
        data->wndproc = NULL;
    } else {
        SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc);
    }
#endif

    /* Fill in the SDL window with the window data */
    {
        RECT rect;
        if (GetClientRect(hwnd, &rect)) {
            int w = rect.right;
            int h = rect.bottom;
            if ((window->windowed.w && window->windowed.w != w) || (window->windowed.h && window->windowed.h != h)) {
                /* We tried to create a window larger than the desktop and Windows didn't allow it.  Override! */
                int x, y;
                /* Figure out what the window area will be */
                WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_FALSE);
                SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
            } else {
                window->w = w;
                window->h = h;
            }
        }
    }
    {
        POINT point;
        point.x = 0;
        point.y = 0;
        if (ClientToScreen(hwnd, &point)) {
            window->x = point.x;
            window->y = point.y;
        }
    }
    {
        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
        if (style & WS_VISIBLE) {
            window->flags |= SDL_WINDOW_SHOWN;
        } else {
            window->flags &= ~SDL_WINDOW_SHOWN;
        }
        if (style & WS_POPUP) {
            window->flags |= SDL_WINDOW_BORDERLESS;
        } else {
            window->flags &= ~SDL_WINDOW_BORDERLESS;
        }
        if (style & WS_THICKFRAME) {
            window->flags |= SDL_WINDOW_RESIZABLE;
        } else {
            window->flags &= ~SDL_WINDOW_RESIZABLE;
        }
#ifdef WS_MAXIMIZE
        if (style & WS_MAXIMIZE) {
            window->flags |= SDL_WINDOW_MAXIMIZED;
        } else
#endif
        {
            window->flags &= ~SDL_WINDOW_MAXIMIZED;
        }
#ifdef WS_MINIMIZE
        if (style & WS_MINIMIZE) {
            window->flags |= SDL_WINDOW_MINIMIZED;
        } else
#endif
        {
            window->flags &= ~SDL_WINDOW_MINIMIZED;
        }
    }
    if (GetFocus() == hwnd) {
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
        SDL_SetKeyboardFocus(data->window);

        if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
            RECT rect;
            GetClientRect(hwnd, &rect);
            ClientToScreen(hwnd, (LPPOINT) & rect);
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
            ClipCursor(&rect);
        }
    }

    /* Enable multi-touch */
    if (videodata->RegisterTouchWindow) {
        videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
    }

    data->initializing = SDL_FALSE;

    /* All done! */
    return 0;
}
Beispiel #16
0
// same as AddPage() but does it at given position
bool wxNotebook::InsertPage(size_t nPage,
                            wxNotebookPage *pPage,
                            const wxString& strText,
                            bool bSelect,
                            int imageId)
{
    wxCHECK_MSG( pPage != NULL, false, wxT("NULL page in wxNotebook::InsertPage") );
    wxCHECK_MSG( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false,
                 wxT("invalid index in wxNotebook::InsertPage") );

    wxASSERT_MSG( pPage->GetParent() == this,
                  wxT("notebook pages must have notebook as parent") );

    // add a new tab to the control
    // ----------------------------

    // init all fields to 0
    TC_ITEM tcItem;
    wxZeroMemory(tcItem);

    // set the image, if any
    if ( imageId != -1 )
    {
        tcItem.mask |= TCIF_IMAGE;
        tcItem.iImage  = imageId;
    }

    // and the text
    if ( !strText.empty() )
    {
        tcItem.mask |= TCIF_TEXT;
        tcItem.pszText = wxMSW_CONV_LPTSTR(strText);
    }

    // hide the page: unless it is selected, it shouldn't be shown (and if it
    // is selected it will be shown later)
    HWND hwnd = GetWinHwnd(pPage);
    SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_VISIBLE);

    // this updates internal flag too -- otherwise it would get out of sync
    // with the real state
    pPage->Show(false);


    // fit the notebook page to the tab control's display area: this should be
    // done before adding it to the notebook or TabCtrl_InsertItem() will
    // change the notebooks size itself!
    AdjustPageSize(pPage);

    // finally do insert it
    if ( TabCtrl_InsertItem(GetHwnd(), nPage, &tcItem) == -1 )
    {
        wxLogError(wxT("Can't create the notebook page '%s'."), strText.c_str());

        return false;
    }

    // need to update the bg brush when the first page is added
    // so the first panel gets the correct themed background
    if ( m_pages.empty() )
    {
#if wxUSE_UXTHEME
        UpdateBgBrush();
#endif // wxUSE_UXTHEME
    }

    // succeeded: save the pointer to the page
    m_pages.Insert(pPage, nPage);

    // we may need to adjust the size again if the notebook size changed:
    // normally this only happens for the first page we add (the tabs which
    // hadn't been there before are now shown) but for a multiline notebook it
    // can happen for any page at all as a new row could have been started
    if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) )
    {
        AdjustPageSize(pPage);

        // Additionally, force the layout of the notebook itself by posting a
        // size event to it. If we don't do it, notebooks with pages on the
        // left or the right side may fail to account for the fact that they
        // are now big enough to fit all all of their pages on one row and
        // still reserve space for the second row of tabs, see #1792.
        const wxSize s = GetSize();
        ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(s.x, s.y));
    }

    // now deal with the selection
    // ---------------------------

    // if the inserted page is before the selected one, we must update the
    // index of the selected page
    if ( int(nPage) <= m_selection )
    {
        // one extra page added
        m_selection++;
    }

    DoSetSelectionAfterInsertion(nPage, bSelect);

    InvalidateBestSize();

    return true;
}
Beispiel #17
0
int APIENTRY _tWinMain(HINSTANCE hinst,	HINSTANCE foo1, LPTSTR foo2, int foo3) {
	MSG msg;
	WNDCLASSEX wcex = {sizeof(wcex)};
	HANDLE htray;
	HMENU hmenu;
	MENUITEMINFO mi = {sizeof(mi)};
	INITCOMMONCONTROLSEX icex;
	RECT rect;
	int style;
	HWND hwnd;

	wcex.lpfnWndProc = WndProc;
	wcex.lpszClassName = WINDOW_CLASS;
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	RegisterClassEx(&wcex);

	icex.dwSize = sizeof(icex);
	icex.dwICC = ICC_DATE_CLASSES;
	InitCommonControlsEx(&icex);

	hwnd = CreateWindowEx(WS_EX_NOACTIVATE | WS_EX_TOPMOST, WINDOW_CLASS, WINDOW_TITLE, 0,
		0, 0, 0, 0, NULL, NULL, hinst, NULL);
	if (!hwnd) return 1;
	style = GetWindowLong(hwnd, GWL_STYLE);
	if (style & WS_CAPTION)  { 
		style ^= WS_CAPTION;
		SetWindowLong(hwnd, GWL_STYLE, style);
		SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
	}

	hcal = CreateWindowEx(0, MONTHCAL_CLASS, _T(""),
		WS_CHILD | WS_VISIBLE | MCS_NOTODAY | MCS_NOTRAILINGDATES | MCS_SHORTDAYSOFWEEK | MCS_NOSELCHANGEONNAV,
		0, 0, 0, 0, hwnd, NULL, hinst, NULL);
	MonthCal_GetMinReqRect(hcal, &rect);
	SetWindowPos(hcal, NULL, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_NOMOVE);
	SetWindowPos(hwnd, NULL, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_NOMOVE);

	tti.hwnd = hwnd;
	tti.hcal = hcal;
	tti.hnotify = CreateEvent(NULL, TRUE, FALSE, NULL);
	tti.exit = FALSE;
	htray = CreateThread(NULL, 0, &TrayThreadProc, &tti, 0, NULL);
	if (!htray) return 1;

	hsubmenu = CreateMenu();
	mi.fMask = MIIM_STRING | MIIM_ID;
	mi.wID = 1;
	mi.dwTypeData = EXIT_STRING;
	InsertMenuItem(hsubmenu, 0, TRUE, &mi);
	hmenu = CreateMenu();
	mi.fMask = MIIM_SUBMENU;
	mi.hSubMenu = hsubmenu;
	InsertMenuItem(hmenu, 0, TRUE, &mi);

	WM_TASKBARCREATED = RegisterWindowMessageA(_T("TaskbarCreated"));
	
	while (GetMessage(&msg, NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	DestroyMenu(hmenu);
	DestroyMenu(hsubmenu);

	WaitForSingleObject(htray, 1000);
	CloseHandle(htray);

	return (int)msg.wParam;
}
Beispiel #18
0
/*
** Sys_CreateConsole
*/
void Sys_CreateConsole( void )
{
	HDC hDC;
	WNDCLASS wc;
	RECT rect;
	const char *DEDCLASS = "Q3 WinConsole";
	int nHeight;
	int swidth, sheight;
	int DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX;

	memset( &wc, 0, sizeof( wc ) );

	wc.style         = 0;
	wc.lpfnWndProc   = (WNDPROC) ConWndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = g_wv.hInstance;
	wc.hIcon         = LoadIcon( g_wv.hInstance, MAKEINTRESOURCE(IDI_ICON1));
	wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszMenuName  = 0;
	wc.lpszClassName = DEDCLASS;

	if ( !RegisterClass (&wc) )
		return;

	rect.left = 0;
	rect.right = 540;
	rect.top = 0;
	rect.bottom = 450;
	AdjustWindowRect( &rect, DEDSTYLE, FALSE );

	hDC = GetDC( GetDesktopWindow() );
	swidth = GetDeviceCaps( hDC, HORZRES );
	sheight = GetDeviceCaps( hDC, VERTRES );
	ReleaseDC( GetDesktopWindow(), hDC );

	s_wcd.windowWidth = rect.right - rect.left + 1;
	s_wcd.windowHeight = rect.bottom - rect.top + 1;

	s_wcd.hWnd = CreateWindowEx( 0,
							   DEDCLASS,
							   CONSOLE_WINDOW_TITLE,
							   DEDSTYLE,
							   ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1,
							   NULL,
							   NULL,
							   g_wv.hInstance,
							   NULL );

	if ( s_wcd.hWnd == NULL )
	{
		return;
	}

	//
	// create fonts
	//
	hDC = GetDC( s_wcd.hWnd );
	nHeight = -MulDiv( 8, GetDeviceCaps( hDC, LOGPIXELSY), 72);

	s_wcd.hfBufferFont = CreateFont( nHeight,
									  0,
									  0,
									  0,
									  FW_LIGHT,
									  0,
									  0,
									  0,
									  DEFAULT_CHARSET,
									  OUT_DEFAULT_PRECIS,
									  CLIP_DEFAULT_PRECIS,
									  DEFAULT_QUALITY,
									  FF_MODERN | FIXED_PITCH,
									  "Courier New" );

	ReleaseDC( s_wcd.hWnd, hDC );

	//
	// create the input line
	//
	s_wcd.hwndInputLine = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | 
												ES_LEFT | ES_AUTOHSCROLL,
												6, 400, 528, 20,
												s_wcd.hWnd, 
												( HMENU ) INPUT_ID,	// child window ID
												g_wv.hInstance, NULL );

	//
	// create the buttons
	//
	s_wcd.hwndButtonCopy = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												5, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) COPY_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonCopy, WM_SETTEXT, 0, ( LPARAM ) "copy" );

	s_wcd.hwndButtonClear = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												82, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) CLEAR_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonClear, WM_SETTEXT, 0, ( LPARAM ) "clear" );

	s_wcd.hwndButtonQuit = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												462, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) QUIT_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonQuit, WM_SETTEXT, 0, ( LPARAM ) "quit" );


	//
	// create the scrollbuffer
	//
	s_wcd.hwndBuffer = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | 
												ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
												6, 40, 526, 354,
												s_wcd.hWnd, 
												( HMENU ) EDIT_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, ( long ) InputLineWndProc );
	SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT);
	UpdateWindow( s_wcd.hWnd );
	SetForegroundWindow( s_wcd.hWnd );
	SetFocus( s_wcd.hwndInputLine );

	s_wcd.visLevel = 1;
}
Beispiel #19
0
void ShowErrorPane(const char *text)
{
	if (Window == NULL || ConWindow == NULL)
	{
		if (text != NULL)
		{
			MessageBox (Window, text,
				GAMESIG " Fatal Error", MB_OK|MB_ICONSTOP|MB_TASKMODAL);
		}
		return;
	}

	if (StartScreen != NULL)	// Ensure that the network pane is hidden.
	{
		StartScreen->NetDone();
	}
	if (text != NULL)
	{
		char caption[100];
		mysnprintf(caption, countof(caption), "Fatal Error - "GAMESIG" %s "X64, GetVersionString());
		SetWindowText (Window, caption);
		ErrorIcon = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW, 0, 0, 0, 0, Window, NULL, g_hInst, NULL);
		if (ErrorIcon != NULL)
		{
			SetWindowLong (ErrorIcon, GWL_ID, IDC_ICONPIC);
		}
	}
	ErrorPane = CreateDialogParam (g_hInst, MAKEINTRESOURCE(IDD_ERRORPANE), Window, ErrorPaneProc, (LONG_PTR)NULL);

	if (text != NULL)
	{
		CHARRANGE end;
		CHARFORMAT2 oldformat, newformat;
		PARAFORMAT2 paraformat;

		// Append the error message to the log.
		end.cpMax = end.cpMin = GetWindowTextLength (ConWindow);
		SendMessage (ConWindow, EM_EXSETSEL, 0, (LPARAM)&end);

		// Remember current charformat.
		oldformat.cbSize = sizeof(oldformat);
		SendMessage (ConWindow, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&oldformat);

		// Use bigger font and standout colors.
		newformat.cbSize = sizeof(newformat);
		newformat.dwMask = CFM_BOLD | CFM_COLOR | CFM_SIZE;
		newformat.dwEffects = CFE_BOLD;
		newformat.yHeight = oldformat.yHeight * 5 / 4;
		newformat.crTextColor = RGB(255,170,170);
		SendMessage (ConWindow, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&newformat);

		// Indent the rest of the text to make the error message stand out a little more.
		paraformat.cbSize = sizeof(paraformat);
		paraformat.dwMask = PFM_STARTINDENT | PFM_OFFSETINDENT | PFM_RIGHTINDENT;
		paraformat.dxStartIndent = paraformat.dxOffset = paraformat.dxRightIndent = 120;
		SendMessage (ConWindow, EM_SETPARAFORMAT, 0, (LPARAM)&paraformat);
		SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)"\n");

		// Find out where the error lines start for the error icon display control.
		SendMessage (ConWindow, EM_EXGETSEL, 0, (LPARAM)&end);
		ErrorIconChar = end.cpMax;

		// Now start adding the actual error message.
		SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)"Execution could not continue.\n\n");

		// Restore old charformat but with light yellow text.
		oldformat.crTextColor = RGB(255,255,170);
		SendMessage (ConWindow, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&oldformat);

		// Add the error text.
		SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)text);

		// Make sure the error text is not scrolled below the window.
		SendMessage (ConWindow, EM_LINESCROLL, 0, SendMessage (ConWindow, EM_GETLINECOUNT, 0, 0));
		// The above line scrolled everything off the screen, so pretend to move the scroll
		// bar thumb, which clamps to not show any extra lines if it doesn't need to.
		SendMessage (ConWindow, EM_SCROLL, SB_PAGEDOWN, 0);
	}

	BOOL bRet;
	MSG msg;

	while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
	{
		if (bRet == -1)
		{
			MessageBox (Window, text,
				GAMESIG " Fatal Error", MB_OK|MB_ICONSTOP|MB_TASKMODAL);
			return;
		}
		else if (!IsDialogMessage (ErrorPane, &msg))
		{
			TranslateMessage (&msg);
			DispatchMessage (&msg);
		}
	}
}
static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static activePage = 0;

	switch (msg)
	{
	/* init */
	case WM_INITDIALOG:
		{
			LOCALDATA *data = LocalAlloc(LPTR, sizeof(LOCALDATA));
			HINSTANCE inst = (HINSTANCE)lParam;
			TCITEM item;

			/* init */
			SetWindowLong(hwnd, GWL_USERDATA, (LONG)data);
			data->htab = GetDlgItem(hwnd, IDC_TABS);
			data->hdlg = NULL;
			/* add pages */
			item.mask = TCIF_TEXT;
			data->all[0] = CreateDialog(inst, MAKEINTRESOURCE(IDD_CONFIG_GENERAL), hwnd, GeneralProc);
			item.pszText = "General";
			TabCtrl_InsertItem(data->htab, 0, &item);

			data->all[1] = CreateDialog(inst, MAKEINTRESOURCE(IDD_CONFIG_OUTPUT), hwnd, OutputProc);
			item.pszText = "Output";
			TabCtrl_InsertItem(data->htab, 1, &item);
			/* get rect (after adding pages) */
			GetWindowRect(data->htab, &data->r);
			ScreenToClientRect(hwnd, &data->r);
			TabCtrl_AdjustRect(data->htab, 0, &data->r);
			/* simulate item change */
			TabCtrl_SetCurSel(data->htab, activePage);
			OnSelChange(hwnd);
		}
		return TRUE;
	/* destory */
	case WM_DESTROY:
		{
			LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA);
			int i;

			activePage = TabCtrl_GetCurSel(data->htab);

			for (i=0; i<NUM_PAGES; i++)
				DestroyWindow(data->all[i]);

			LocalFree(data);
		}
		break;
	/* commands */
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		/* ok/cancel */
		case IDOK:
			BroadcastCommand(hwnd, IDOK);
			/* fall through */
		case IDCANCEL:
			EndDialog(hwnd, LOWORD(wParam));
			return TRUE;
		case IDC_RESET:
			SendCommand(hwnd, IDC_RESET);
			break;
		}
		break;
	/* notification */
	case WM_NOTIFY:
		if (LOWORD(wParam) == IDC_TABS)
		{
			NMHDR *hdr = (NMHDR*)lParam;

			switch (hdr->code)
			{
			case TCN_SELCHANGE:
				OnSelChange(hwnd);
				break;
			}
		}
		break;
	}

	return 0;
}
Beispiel #21
0
/*
================
Con_CreateConsole

create win32 console
================
*/
void Con_CreateConsole( void )
{
#ifdef _WIN32
	HDC	hDC;
	WNDCLASS	wc;
	RECT	rect;
	int	nHeight;
	int	swidth, sheight, fontsize;
	int	DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION;
	int	CONSTYLE = WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_BORDER|WS_EX_CLIENTEDGE|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL|ES_READONLY;
	string	FontName;

	wc.style         = 0;
	wc.lpfnWndProc   = (WNDPROC)Con_WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = host.hInst;
	wc.hIcon         = LoadIcon( host.hInst, MAKEINTRESOURCE( IDI_ICON1 ));
	wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = (void *)COLOR_3DSHADOW;
	wc.lpszClassName = SYSCONSOLE;
	wc.lpszMenuName  = 0;

	if( Sys_CheckParm( "-log" ) && host.developer != 0 )
		s_wcd.log_active = true;

	if( host.type == HOST_NORMAL )
	{
		rect.left = 0;
		rect.right = 536;
		rect.top = 0;
		rect.bottom = 364;
		Q_strncpy( FontName, "Fixedsys", sizeof( FontName ));
		Q_strncpy( s_wcd.title, va( "Xash3D %g", XASH_VERSION ), sizeof( s_wcd.title ));
		Q_strncpy( s_wcd.log_path, "engine.log", sizeof( s_wcd.log_path ));
		fontsize = 8;
	}
	else // dedicated console
	{
		rect.left = 0;
		rect.right = 640;
		rect.top = 0;
		rect.bottom = 392;
		Q_strncpy( FontName, "System", sizeof( FontName ));
		Q_strncpy( s_wcd.title, "Xash Dedicated Server", sizeof( s_wcd.title ));
		Q_strncpy( s_wcd.log_path, "dedicated.log", sizeof( s_wcd.log_path ));
		s_wcd.log_active = true; // always make log
		fontsize = 14;
	}

	Sys_InitLog();
	if( !RegisterClass( &wc ))
	{
		// print into log
		MsgDev( D_ERROR, "Can't register window class '%s'\n", SYSCONSOLE );
		return;
	} 

	AdjustWindowRect( &rect, DEDSTYLE, FALSE );

	hDC = GetDC( GetDesktopWindow() );
	swidth = GetDeviceCaps( hDC, HORZRES );
	sheight = GetDeviceCaps( hDC, VERTRES );
	ReleaseDC( GetDesktopWindow(), hDC );

	s_wcd.windowWidth = rect.right - rect.left;
	s_wcd.windowHeight = rect.bottom - rect.top;

	s_wcd.hWnd = CreateWindowEx( WS_EX_DLGMODALFRAME, SYSCONSOLE, s_wcd.title, DEDSTYLE, ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1, NULL, NULL, host.hInst, NULL );
	if( s_wcd.hWnd == NULL )
	{
		MsgDev( D_ERROR, "Can't create window '%s'\n", s_wcd.title );
		return;
	}

	// create fonts
	hDC = GetDC( s_wcd.hWnd );
	nHeight = -MulDiv( fontsize, GetDeviceCaps( hDC, LOGPIXELSY ), 72 );
	s_wcd.hfBufferFont = CreateFont( nHeight, 0, 0, 0, FW_LIGHT, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN|FIXED_PITCH, FontName );
	ReleaseDC( s_wcd.hWnd, hDC );

	if( host.type == HOST_DEDICATED )
	{
		// create the input line
		s_wcd.hwndInputLine = CreateWindowEx( WS_EX_CLIENTEDGE, "edit", NULL, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL, 0, 366, 550, 25, s_wcd.hWnd, (HMENU)INPUT_ID, host.hInst, NULL );

		s_wcd.hwndButtonSubmit = CreateWindow( "button", NULL, BS_PUSHBUTTON|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, 552, 367, 87, 25, s_wcd.hWnd, (HMENU)SUBMIT_ID, host.hInst, NULL );
		SendMessage( s_wcd.hwndButtonSubmit, WM_SETTEXT, 0, ( LPARAM ) "submit" );
          }
          
	// create the scrollbuffer
	GetClientRect( s_wcd.hWnd, &rect );

	s_wcd.hwndBuffer = CreateWindowEx( WS_EX_DLGMODALFRAME|WS_EX_CLIENTEDGE, "edit", NULL, CONSTYLE, 0, 0, rect.right - rect.left, min(365, rect.bottom), s_wcd.hWnd, (HMENU)EDIT_ID, host.hInst, NULL );
	SendMessage( s_wcd.hwndBuffer, WM_SETFONT, (WPARAM)s_wcd.hfBufferFont, 0 );

	if( host.type == HOST_DEDICATED )
	{
		s_wcd.SysInputLineWndProc = (WNDPROC)SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, (long)Con_InputLineProc );
		SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM )s_wcd.hfBufferFont, 0 );
          }

	// show console if needed
	if( host.con_showalways )
	{          
		// make console visible
		ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT );
		UpdateWindow( s_wcd.hWnd );
		SetForegroundWindow( s_wcd.hWnd );

		if( host.type != HOST_DEDICATED )
			SetFocus( s_wcd.hWnd );
		else SetFocus( s_wcd.hwndInputLine );
		s_wcd.status = true;
          }
	else s_wcd.status = false;
#endif

	if( Sys_CheckParm( "-log" ) && host.developer != 0 )
	{
		s_wcd.log_active = true;
		Q_strncpy( s_wcd.log_path, "engine.log", sizeof( s_wcd.log_path ));
	}

	Sys_InitLog();
}
bool
create_window(void)
{
	WNDCLASSEX wndClass;
	ZeroMemory (&wndClass, sizeof (wndClass));
    wndClass.cbSize        = sizeof (wndClass);
    wndClass.style         = CS_HREDRAW | CS_VREDRAW;
    wndClass.lpfnWndProc   = WndProc;
    wndClass.cbClsExtra    = 0;
    wndClass.cbWndExtra    = 0;
    wndClass.hInstance     = hInst;
    wndClass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
    wndClass.hIconSm       = NULL;
    wndClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
    wndClass.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
    wndClass.lpszMenuName  = NULL;
    wndClass.lpszClassName = "blackscreen";

        if (!RegisterClassEx(&wndClass)) {
 //               return false;
        }

        RECT clientRect;
        clientRect.left = 0;
        clientRect.top = 0;
        clientRect.right = GetSystemMetrics(SM_CXSCREEN);
        clientRect.bottom = GetSystemMetrics(SM_CYSCREEN);

        UINT x(GetSystemMetrics(SM_XVIRTUALSCREEN));
        UINT y(GetSystemMetrics(SM_YVIRTUALSCREEN));
        UINT cx(GetSystemMetrics(SM_CXVIRTUALSCREEN));
        UINT cy(GetSystemMetrics(SM_CYVIRTUALSCREEN));

        clientRect.left = x;
        clientRect.top = y;
        clientRect.right = x + cx;
        clientRect.bottom = y + cy;

        AdjustWindowRect (&clientRect, WS_CAPTION, FALSE);
        hwnd = CreateWindowEx (0,
                               "blackscreen",
                               "blackscreen",
                               WS_POPUP  | WS_CLIPSIBLINGS | WS_CLIPCHILDREN|WS_BORDER,
                               CW_USEDEFAULT,
                               CW_USEDEFAULT,
                               cx,
                               cy,
                               NULL,
                               NULL,
                               hInst,
                               NULL);
		typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);

	PSLWA pSetLayeredWindowAttributes=NULL;
	/*
	* Code that follows allows the program to run in 
	* environment other than windows 2000
	* without crashing only difference being that 
	* there will be no transparency as 
	* the SetLayeredAttributes function is available only in
	* windows 2000
	*/
	HMODULE hDLL = LoadLibrary ("user32");
	if (hDLL) pSetLayeredWindowAttributes = (PSLWA) GetProcAddress(hDLL,"SetLayeredWindowAttributes");
	/*
	* Make the windows a layered window
	*/

#ifndef _X64
	LONG style = GetWindowLong(hwnd, GWL_STYLE);
	style = GetWindowLong(hwnd, GWL_STYLE);
	style &= ~(WS_DLGFRAME | WS_THICKFRAME);
	SetWindowLong(hwnd, GWL_STYLE, style);
#else
	LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
	style = GetWindowLongPtr(hwnd, GWL_STYLE);
	style &= ~(WS_DLGFRAME | WS_THICKFRAME);
	SetWindowLongPtr(hwnd, GWL_STYLE, style);
#endif

	if (pSetLayeredWindowAttributes != NULL) {
#ifndef _X64
		SetWindowLong (hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) |WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST);
#else
		SetWindowLongPtr (hwnd, GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE) |WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST);
#endif
	    ShowWindow (hwnd, SW_SHOWNORMAL);
	}
	if (pSetLayeredWindowAttributes != NULL) {
	/**
	* Second parameter RGB(255,255,255) sets the colorkey to white
	* LWA_COLORKEY flag indicates that color key is valid
	* LWA_ALPHA indicates that ALphablend parameter (factor)
	* is valid
	*/
	pSetLayeredWindowAttributes (hwnd, RGB(255,255,255), 255, LWA_ALPHA);
	}
	SetWindowPos(hwnd,HWND_TOPMOST,x,y,cx,cy, SWP_FRAMECHANGED|SWP_NOACTIVATE);
//SM_CXVIRTUALSCREEN
	return true;
}
Beispiel #23
0
/*
 * InitStatDialog
 */
static void InitStatDialog( HWND hwnd )
{
    int                 i;
    char                buff[256];
    ExceptDlgInfo       *info;
    syminfo             si;
    CreateRegListData   data;
    StatData            *statdata;
    RECT                c_rect;
    HWND                combo;

    info = StatGetExceptDlgInfo( hwnd );
    StatHdl = hwnd;
    statdata = MemAlloc( sizeof( StatData ) );

    /*
     * fill in source information
     */
    GetCurrAddr( &( statdata->curr_addr ), info->regs );
    if( FindWatSymbol( &( statdata->curr_addr ), &si, TRUE ) == FOUND ) {
        RCsprintf( buff, STR_SRC_INFO_FMT, si.linenum, si.filename );
        StatShowSymbols = TRUE;
        CheckDlgButton( hwnd, STAT_SYMBOLS, StatShowSymbols );
    } else {
        RCsprintf( buff, STR_N_A );
        StatShowSymbols = FALSE;
        EnableWindow( GetDlgItem( hwnd, STAT_SYMBOLS ), FALSE );
    }
    SetDlgMonoFont( hwnd, STAT_SRC_INFO );
    SetDlgItemText( hwnd, STAT_SRC_INFO, buff );

#ifdef __NT__
    {
        ProcStats       procinfo;
        HWND            button;
        if( GetProcessInfo( info->procinfo->procid, &procinfo ) ) {
            RCsprintf( buff, STR_STATUS_4_PROC_X, info->procinfo->procid, procinfo.name );
            SetWindowText( hwnd, buff );
        }
        CopyRCString( STR_VIEW_MEM_HT_KEY, buff, sizeof( buff ) );
        SetDlgItemText( hwnd, STAT_SEG_MAP, buff );
        button = GetDlgItem( hwnd, STAT_STACK_TRACE );
        ShowWindow( button, SW_HIDE );
    }
#endif
    InstructionBackward( 2, &( statdata->curr_addr ) );
    for( i = STAT_DISASM_1;i <= STAT_DISASM_8; i++ ) {
        SetDlgCourierFont( hwnd, i );
    }
    DisplayAsmLines( hwnd, &( statdata->curr_addr ) );
    data.index = 0;
    data.parent = hwnd;
    data.max_len = 0;
    combo = GetDlgItem( hwnd, STAT_REGISTER_COMBO );
    MADRegSetWalk( MTK_ALL, CreateAllRegLists, &data );
    if( data.index == 1 ) {
        SendMessage( combo, CB_GETLBTEXT, (WPARAM)0, (LPARAM)buff );
        SetDlgItemText( hwnd, STAT_REGISTER_SET, buff );
        DestroyWindow( combo );
    } else {
        GetChildPos( hwnd, combo, &c_rect );
        SendMessage( combo, CB_SETCURSEL, (WPARAM)0, (LPARAM)0 );
        c_rect.right += data.max_len;
        c_rect.bottom += SendMessage( combo, CB_GETITEMHEIGHT, 0, 0 ) * ( data.index + 1);
        MoveWindow( combo, c_rect.left, c_rect.top, c_rect.right, c_rect.bottom, FALSE );
    }
    SetFocus( GetDlgItem( hwnd, IDOK ) );
    statdata->reg_set_index = 0;
    SetWindowLong(hwnd,DWL_USER,(LONG)statdata);
} /* InitStatDialog */
Beispiel #24
0
BOOL CALLBACK NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PNHRIPWindow data;

    data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA);
    switch (message)
    {
    case WM_INITDIALOG:
        /* set text control font */
        hdc = GetDC(hWnd);
        SendMessage(hWnd, WM_SETFONT,
                    (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
        ReleaseDC(hWnd, hdc);

        SetFocus(GetDlgItem(hWnd, IDOK));
        return FALSE;

    case WM_MSNH_COMMAND:
        onMSNHCommand(hWnd, wParam, lParam);
        break;

    case WM_PAINT:
    {
        int bitmap_offset;
        RECT clientrect;
        RECT textrect;
        HDC hdcBitmap;
        HANDLE OldBitmap;
        PAINTSTRUCT ps;
        HFONT OldFont;

        hdc = BeginPaint (hWnd, &ps);
        OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
        hdcBitmap = CreateCompatibleDC(hdc);
        SetBkMode (hdc, TRANSPARENT);
        GetClientRect (hWnd, &clientrect);
        textrect = clientrect;
        textrect.top += RIP_OFFSET_Y;
        textrect.left += RIP_OFFSET_X;
        textrect.right -= RIP_OFFSET_X;
        if (data->window_text)
        {
            DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
                      DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
            DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
                      DT_LEFT | DT_NOPREFIX);
        }
        OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip);
        SetBkMode (hdc, OPAQUE);
        bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2;
        BitBlt (hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH,
                RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY);
        SetBkMode (hdc, TRANSPARENT);
        if (data->rip_text)
        {
            textrect.left += RIP_GRAVE_X + bitmap_offset;
            textrect.top = textrect.bottom + RIP_GRAVE_Y;
            textrect.right = textrect.left + RIP_GRAVE_WIDTH;
            textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT;
            DrawText (hdc, data->rip_text, strlen(data->rip_text), &textrect,
                      DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK);
        }
        SelectObject (hdcBitmap, OldBitmap);
        SelectObject (hdc, OldFont);
        DeleteDC (hdcBitmap);
        EndPaint (hWnd, &ps);
    }
    break;

    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDOK:
            mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
            if( GetNHApp()->hMainWnd==hWnd )
                GetNHApp()->hMainWnd=NULL;
            DestroyWindow(hWnd);
            SetFocus(GetNHApp()->hMainWnd);
            return TRUE;
        }
        break;

    case WM_CLOSE:
        /* if we get this here, we saved the bones so we can just force a quit */

        mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
        if( GetNHApp()->hMainWnd==hWnd )
            GetNHApp()->hMainWnd=NULL;
        DestroyWindow(hWnd);
        SetFocus(GetNHApp()->hMainWnd);
        program_state.stopprint++;
        return TRUE;

    case WM_DESTROY:
        if( data ) {
            if( data->window_text ) free(data->window_text);
            if( data->rip_text ) free(data->rip_text);
            if (data->rip_bmp != NULL) DeleteObject(data->rip_bmp);
            free(data);
            SetWindowLong(hWnd, GWL_USERDATA, (LONG)0);
        }
        break;

    }
    return FALSE;
}
Beispiel #25
0
/*
 * Download a file from an URL
 * Mostly taken from http://support.microsoft.com/kb/234913
 * If hProgressDialog is not NULL, this function will send INIT and EXIT messages
 * to the dialog in question, with WPARAM being set to nonzero for EXIT on success
 * and also attempt to indicate progress using an IDC_PROGRESS control
 */
BOOL DownloadFile(const char* url, const char* file, HWND hProgressDialog)
{
	HWND hProgressBar = NULL;
	BOOL r = FALSE;
	DWORD dwFlags, dwSize, dwDownloaded, dwTotalSize, dwStatus;
	FILE* fd = NULL;
	LONG progress_style;
	unsigned char buf[DOWNLOAD_BUFFER_SIZE];
	char agent[64], hostname[64], urlpath[128];
	HINTERNET hSession = NULL, hConnection = NULL, hRequest = NULL;
	URL_COMPONENTSA UrlParts = {sizeof(URL_COMPONENTSA), NULL, 1, (INTERNET_SCHEME)0,
		hostname, sizeof(hostname), 0, NULL, 1, urlpath, sizeof(urlpath), NULL, 1};
	int i;
	char msg[MAX_PATH];

	if (hProgressDialog != NULL) {
		// Use the progress control provided, if any
		hProgressBar = GetDlgItem(hProgressDialog, IDC_PROGRESS);
		if (hProgressBar != NULL) {
			progress_style = GetWindowLong(hProgressBar, GWL_STYLE);
			SetWindowLong(hProgressBar, GWL_STYLE, progress_style & (~PBS_MARQUEE));
			SendMessage(hProgressBar, PBM_SETPOS, 0, 0);
		}
		SendMessage(hProgressDialog, UM_DOWNLOAD_INIT, 0, 0);
	}

	safe_sprintf(msg, sizeof(msg), "Downloading %s: Connecting...", file);
	print_status(0, FALSE, msg);
	dprintf("Downloading %s from %s\n", file, url);

	if ( (!InternetCrackUrlA(url, (DWORD)safe_strlen(url), 0, &UrlParts))
	  || (UrlParts.lpszHostName == NULL) || (UrlParts.lpszUrlPath == NULL)) {
		dprintf("Unable to decode URL: %s\n", WindowsErrorString());
		goto out;
	}
	hostname[sizeof(hostname)-1] = 0;

	// Open an Internet session
	for (i=5; (i>0) && (!InternetGetConnectedState(&dwFlags, 0)); i--) {
		Sleep(1000);
	}
	if (i <= 0) {
		// http://msdn.microsoft.com/en-us/library/windows/desktop/aa384702.aspx is wrong...
		SetLastError(ERROR_INTERNET_NOT_INITIALIZED);
		dprintf("Network is unavailable: %s\n", WinInetErrorString());
		goto out;
	}
	safe_sprintf(agent, ARRAYSIZE(agent), APPLICATION_NAME "/%d.%d.%d  (Windows NT %d.%d%s)",
		application_version[0], application_version[1], application_version[2],
		nWindowsVersion >> 4, nWindowsVersion & 0x0F, is_x64() ? "; WOW64" : "");
	hSession = InternetOpenA(agent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hSession == NULL) {
		dprintf("Could not open internet session: %s\n", WinInetErrorString());
		goto out;
	}

	hConnection = InternetConnectA(hSession, UrlParts.lpszHostName, UrlParts.nPort, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)NULL);
	if (hConnection == NULL) {
		dprintf("Could not connect to server %s:%d: %s\n", UrlParts.lpszHostName, UrlParts.nPort, WinInetErrorString());
		goto out;
	}

	hRequest = HttpOpenRequestA(hConnection, "GET", UrlParts.lpszUrlPath, NULL, NULL, (const char**)"*/*\0",
		INTERNET_FLAG_HYPERLINK|INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP|INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS|INTERNET_FLAG_NO_COOKIES|
		INTERNET_FLAG_NO_UI|INTERNET_FLAG_NO_CACHE_WRITE, (DWORD_PTR)NULL);
	if (hRequest == NULL) {
		dprintf("Could not open url %s: %s\n", url, WindowsErrorString());
		goto out;
	}

	if (!HttpSendRequestA(hRequest, NULL, 0, NULL, 0)) {
		dprintf("Unable to send request: %s\n", WinInetErrorString());
		goto out;
	}

	// Get the file size
	dwSize = sizeof(dwStatus);
	dwStatus = 404;
	HttpQueryInfoA(hRequest, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, (LPVOID)&dwStatus, &dwSize, NULL);
	if (dwStatus != 200) {
		download_error = ERROR_SEVERITY_ERROR|ERROR_INTERNET_ITEM_NOT_FOUND;
		dprintf("Unable to access file: Server status %d\n", dwStatus);
		goto out;
	}
	dwSize = sizeof(dwTotalSize);
	if (!HttpQueryInfoA(hRequest, HTTP_QUERY_CONTENT_LENGTH|HTTP_QUERY_FLAG_NUMBER, (LPVOID)&dwTotalSize, &dwSize, NULL)) {
		dprintf("Unable to retrieve file length: %s\n", WinInetErrorString());
		goto out;
	}
	dprintf("File length: %d bytes\n", dwTotalSize);

	fd = fopenU(file, "wb");
	if (fd == NULL) {
		dprintf("Unable to create file '%s': %s\n", file, WinInetErrorString());
		goto out;
	}

	// Keep checking for data until there is nothing left.
	dwSize = 0;
	while (1) {
		if (download_error)
			goto out;

		if (!InternetReadFile(hRequest, buf, sizeof(buf), &dwDownloaded) || (dwDownloaded == 0))
			break;
		dwSize += dwDownloaded;
		SendMessage(hProgressBar, PBM_SETPOS, (WPARAM)(MAX_PROGRESS*((1.0f*dwSize)/(1.0f*dwTotalSize))), 0);
		safe_sprintf(msg, sizeof(msg), "Downloading: %0.1f%%", (100.0f*dwSize)/(1.0f*dwTotalSize));
		print_status(0, FALSE, msg);
		if (fwrite(buf, 1, dwDownloaded, fd) != dwDownloaded) {
			dprintf("Error writing file '%s': %s\n", file, WinInetErrorString());
			goto out;
		}
	}

	if (dwSize != dwTotalSize) {
		dprintf("Could not download complete file - read: %d bytes, expected: %d bytes\n", dwSize, dwTotalSize);
		download_error = ERROR_WRITE_FAULT;
		goto out;
	} else {
		r = TRUE;
		dprintf("Successfully downloaded '%s'\n", file);
	}

out:
	if (hProgressDialog != NULL)
		SendMessage(hProgressDialog, UM_DOWNLOAD_EXIT, (WPARAM)r, 0);
	if (fd != NULL) fclose(fd);
	if (!r) {
		_unlink(file);
		print_status(0, FALSE, "Failed to download file.");
		SetLastError(download_error);
		MessageBoxU(hMain, WinInetErrorString(), "File download", MB_OK|MB_ICONERROR);
	}
	if (hRequest) InternetCloseHandle(hRequest);
	if (hConnection) InternetCloseHandle(hConnection);
	if (hSession) InternetCloseHandle(hSession);

	return r;
}
Beispiel #26
0
void iupwinTipsGetDispInfo(LPARAM lp)
{
  COLORREF color, tip_color;
  NMTTDISPINFO* tips_info;
  Ihandle* ih;
  HWND tips_hwnd;
  char* value;

  if (!lp) return;

  tips_info = (NMTTDISPINFO*)lp;
  ih = iupwinHandleGet(tips_info->hdr.hwndFrom);  /* hwndFrom is the tooltip window */
  if (!ih) return;

  tips_hwnd = (HWND)iupAttribGet(ih, "_IUPWIN_TIPSWIN");
  if (tips_hwnd != tips_info->hdr.hwndFrom) return;

  tips_info->hinst = NULL;
  tips_info->lpszText = IupGetAttribute(ih, "TIP");  /* must use IupGetAttribute to use inheritance */

  {
    HFONT hfont;
    value = iupAttribGetStr(ih, "TIPFONT");
    if (value)
    {
      if (iupStrEqualNoCase(value, "SYSTEM"))
        hfont = NULL;
      else
        hfont = iupwinGetHFont(value);
    }
    else
      hfont = (HFONT)iupwinGetHFontAttrib(ih);

    if (hfont)
    {
      HFONT tip_hfont = (HFONT)SendMessage(tips_hwnd, WM_GETFONT, 0, 0);
      if (tip_hfont != hfont)
        SendMessage(tips_hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE,0));
    }
  }

  iupwinGetColorRef(ih, "TIPBGCOLOR", &color);
  tip_color = (COLORREF)SendMessage(tips_hwnd, TTM_GETTIPBKCOLOR, 0, 0);
  if (color != tip_color)
    SendMessage(tips_hwnd, TTM_SETTIPBKCOLOR, (WPARAM)color, 0);

  iupwinGetColorRef(ih, "TIPFGCOLOR", &color);
  tip_color = (COLORREF)SendMessage(tips_hwnd, TTM_GETTIPTEXTCOLOR, 0, 0);
  if (color != tip_color)
    SendMessage(tips_hwnd, TTM_SETTIPTEXTCOLOR, (WPARAM)color, 0);

  {
    int ballon = IupGetInt(ih, "TIPBALLON");  /* must use IupGetInt to use inheritance */
    DWORD style = GetWindowLong(tips_hwnd, GWL_STYLE);
    int tip_ballon = style & TTS_BALLOON? 1: 0; 
    if (tip_ballon != ballon)
    {
      if (ballon)
        style |= TTS_BALLOON;
      else
        style &= ~TTS_BALLOON;
      SetWindowLong(tips_hwnd, GWL_STYLE, style);
    }

    if (ballon)
    {
      char* ballon_title = IupGetAttribute(ih, "TIPBALLONTITLE"); /* must use IupGetAttribute to use inheritance */
      int ballon_icon = IupGetInt(ih, "TIPBALLONTITLEICON");  /* must use IupGetInt to use inheritance */
      SendMessage(tips_hwnd, TTM_SETTITLEA, ballon_icon, (LPARAM)ballon_title);
    }
    else
      SendMessage(tips_hwnd, TTM_SETTITLEA, 0, 0);
  }

  {
    int delay = IupGetInt(ih, "TIPDELAY"); /* must use IupGetInt to use inheritance */
    int tip_delay = SendMessage(tips_hwnd, TTM_GETDELAYTIME, TTDT_AUTOPOP, 0);
    if (delay != tip_delay)
      SendMessage(tips_hwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, (LPARAM)MAKELONG(delay, 0));
  }

  {
    TOOLINFO ti;

    ZeroMemory(&ti, sizeof(TOOLINFO));
    ti.cbSize = sizeof(TOOLINFO); 
    ti.uId = 0; 
    ti.hwnd = ih->handle;

    value = iupAttribGet(ih, "TIPRECT");
    if (value)
    {
      int x1, x2, y1, y2;
      sscanf(value, "%d %d %d %d", &x1, &y1, &x2, &y2);
      ti.rect.left = x1; ti.rect.right = x2;
      ti.rect.top = y1; ti.rect.bottom = y2;
    }
    else
      GetClientRect(ih->handle, &ti.rect);

    SendMessage(tips_hwnd, TTM_NEWTOOLRECT, 0, (LPARAM)&ti);
  }
}
Beispiel #27
0
static void InitChangeRegisterDialog(HWND hwnd,LPARAM lparam)
{
    RegModifyData   *data;
    char            *name;
    unsigned        len;
    mad_radix       radix;
    mad_type_info   mti;
    mad_type_info   cmp;
    char            s[255];
    RECT            p_rect;
    RECT            c_rect;
    HWND            field;
    int             i;
    unsigned        max_len;
    HDC             dc;
    TEXTMETRIC      tm;
    HWND            cancel;

    SetWindowLong( hwnd, DWL_USER, (LONG)lparam);
    data = (RegModifyData *)lparam;
    len = MADRegFullName( data->curr_info, ".", NULL, 0 );
    if( len > 0 ) {
        name = alloca( ( len + 1 ) * sizeof( char ) );
        MADRegFullName( data->curr_info, ".", name, len );
        SetWindowText( hwnd, name );
    } else {
        SetWindowText( hwnd, "" );
    }

    if( data->num_possible == 1 ) {
        field = GetDlgItem( hwnd, REG_EDIT_FIELD );
    } else {
        field = GetDlgItem( hwnd, CH_REG_COMBO_LIST );
    }
    SetMonoFont( field );
    GetChildPos( hwnd, field, &c_rect);
    dc = GetDC( field );
    GetTextMetrics( dc, &tm );
    MADTypeInfo( data->th, &mti );
    radix = MADTypePreferredRadix( data->th );

    if( data->num_possible == 1 ) {
        if( data->maxv == 0 ) {
            len = 255;
        } else {
            len = data->maxv;
        }
        MADTypeToString( radix, &mti, data->curr_value, s, &len );
        if( data->maxv == 0 ) {
            max_len = strlen( s );
        } else {
            max_len = data->maxv;
        }
        SetDlgItemText(hwnd,REG_EDIT_FIELD,s);
    } else {
        MADTypeInfo( data->curr_info->type, &cmp );
        max_len = 0;
        for( i = 0; i < data->num_possible; i++ ) {
            if( data->m_list[i].name == MAD_MSTR_NIL ) {
                len = sizeof( s );
                MADTypeToString( radix, &mti, data->m_list[i].data, s, &len );
            } else {
                MADCli( String )( data->m_list[i].name, s, sizeof( s ) );
            }
            if( max_len < strlen( s ) )
                max_len = strlen( s );
            SendDlgItemMessage( hwnd, CH_REG_COMBO_LIST, CB_ADDSTRING, 0, (LPARAM)s );
            if( memcmp( data->curr_value, data->m_list[i].data, BITS2BYTES( cmp.b.bits ) ) == 0 ) {
                SendDlgItemMessage( hwnd, CH_REG_COMBO_LIST, CB_SETCURSEL, (WPARAM)i, 0 );
            }
        }
        c_rect.bottom += SendMessage( field, CB_GETITEMHEIGHT, 0, 0 ) * (i + 1);
    }
    max_len *= tm.tmMaxCharWidth;
    if( max_len > c_rect.right ) {
        max_len -= max_len%2;
        GetWindowRect( hwnd, &p_rect );
        p_rect.right -= p_rect.left;
        p_rect.bottom -= p_rect.top;
        p_rect.left -= ( max_len - c_rect.right )/2;
        p_rect.right += ( max_len - c_rect.right );
        MoveWindow( hwnd, p_rect.left, p_rect.top, p_rect.right, p_rect.bottom, FALSE );
        cancel = GetDlgItem( hwnd, IDCANCEL );
        GetChildPos( hwnd, cancel, &p_rect );
        p_rect.left += ( max_len - c_rect.right );
        MoveWindow( cancel, p_rect.left, p_rect.top, p_rect.right, p_rect.bottom, FALSE );
        c_rect.right = max_len;
    }
    ReleaseDC( field, dc );
    MoveWindow( field, c_rect.left, c_rect.top, c_rect.right, c_rect.bottom, FALSE );
}
LRESULT CALLBACK AFPluginsOptionsProc(HWND hwnd, UINT umsg, WPARAM wparm, LPARAM lparm)
{
    char		 str[MAX_PATH+256],dir[MAX_PATH];
	char	     lpszTitle[]="Select audio file plug-in directory:";
    int 		 index;
    PluginNode	*pnode;
    AFPlugin	*plugin;
    LPNMHDR		 lpnmhdr;
	BROWSEINFO   bi;
	LPITEMIDLIST lpidl;

    switch (umsg)
    {
		case WM_INITDIALOG:
			SetDlgItemText(hwnd,ID_PLUGINDIR,"Audio file plug-in &directory (takes effect on startup)");
			SetDlgItemText(hwnd,ID_PLUGINLIST,"Audio file &plug-ins");
			pnode=afFirstPlugin;
			while (pnode!=NULL)
			{
				wsprintf(str,"%s %s (%s)",AFNODE(pnode)->Description,AFNODE(pnode)->Version,pnode->pluginFileName);
				index=(int)SendDlgItemMessage(hwnd,ID_PLUGINS,LB_ADDSTRING,0,(LPARAM)str);
				SendDlgItemMessage(hwnd,ID_PLUGINS,LB_SETITEMDATA,(WPARAM)index,(LPARAM)(AFNODE(pnode)));
				pnode=pnode->next;
			}
			SetCheckBox(hwnd,ID_PLUGINALLOW,opAllowMultipleAFPlugins);
			CorrectDirString(afPluginDir);
			SetDlgItemText(hwnd,ID_DIR,afPluginDir);

			CheckCurAFSel(hwnd);
			DisableApply(hwnd);

			return TRUE;
		case WM_NOTIFY:
			lpnmhdr=(LPNMHDR)lparm;
			switch (lpnmhdr->code)
			{
				case PSN_APPLY:
					TrackPropPage(hwnd,3);
					opAllowMultipleAFPlugins=GetCheckBox(hwnd,ID_PLUGINALLOW);
					GetDlgItemText(hwnd,ID_DIR,afPluginDir,sizeof(afPluginDir));
					CorrectDirString(afPluginDir);
					DisableApply(hwnd);
					SetWindowLong(hwnd,DWL_MSGRESULT,PSNRET_NOERROR);
					break;
				case PSN_RESET:
					DisableApply(hwnd);
					TrackPropPage(hwnd,3);
					break;
				default:
					break;
			}
			break;
		case WM_COMMAND:
			switch (LOWORD(wparm))
			{
				case ID_DIR:
					GetDlgItemText(hwnd,ID_DIR,dir,sizeof(dir));
					if (!DirectoryExists(dir))
						CreateDirectoryRecursive(dir);
					bi.hwndOwner=hwnd;
					bi.pidlRoot=NULL;
					bi.pszDisplayName=dir;
					bi.lpszTitle=lpszTitle;
					bi.ulFlags=BIF_RETURNONLYFSDIRS;
					bi.lpfn=BrowseProc;
					if (dir[lstrlen(dir)-1]=='\\')
						dir[lstrlen(dir)-1]=0;
					bi.lParam=(LPARAM)dir;
					if ((lpidl=SHBrowseForFolder(&bi))!=NULL)
					{
						SHGetPathFromIDList(lpidl,dir);
						CorrectDirString(dir);
						SetDlgItemText(hwnd,ID_DIR,dir);
						EnableApply(hwnd);
					}
					break;
				case ID_PLUGINS:
					switch (HIWORD(wparm))
					{
						case LBN_DBLCLK:
							CheckCurAFSel(hwnd);
							plugin=(AFPlugin*)GetCurPlugin(hwnd);
							if ((plugin!=NULL) && (plugin->Config!=NULL))
								plugin->Config(hwnd);
							break;
						case LBN_KILLFOCUS:
						case LBN_SETFOCUS:
						case LBN_SELCANCEL:
						case LBN_SELCHANGE:
							CheckCurAFSel(hwnd);
							break;
						default:
							break;
					}
					break;
				case ID_PLUGINCONFIG:
					plugin=(AFPlugin*)GetCurPlugin(hwnd);
					if ((plugin!=NULL) && (plugin->Config!=NULL))
						plugin->Config(hwnd);
					break;
				case ID_PLUGINABOUT:
					plugin=(AFPlugin*)GetCurPlugin(hwnd);
					if ((plugin!=NULL) && (plugin->About!=NULL))
						plugin->About(hwnd);
					break;
				case ID_PLUGINALLOW:
					EnableApply(hwnd);
					break;
				default:
					break;
			}
			break;
		default:
			break;
    }
    return FALSE;
}
Beispiel #29
0
Flasher::Flasher(int port)
{
	// Create a dummy window.  We don't use it for anything except
	// receiving socket events, so a seperate listening thread would
	// probably be easier!

	WNDCLASSEX wndclass;

	wndclass.cbSize			= sizeof(wndclass);
	wndclass.style			= CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc	= Flasher::WndProc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= pApp->m_instance;
	wndclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName	= (const char *) NULL;
	wndclass.lpszClassName	= FLASHER_CLASS_NAME;
	wndclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	TRY_CATCH
		RegisterClassForced(wndclass);
	CATCH_LOG()


	m_hwnd = CreateWindow(FLASHER_CLASS_NAME,
				FLASHER_CLASS_NAME,
				WS_OVERLAPPEDWINDOW,
				CW_USEDEFAULT,
				CW_USEDEFAULT,
				200, 200,
				NULL,
				NULL,
				pApp->m_instance,
				NULL);

	// record which client created this window
	SetWindowLong(m_hwnd, GWL_USERDATA, (LONG) this);

	// Select a font for displaying user name
	LOGFONT lf;
	memset(&lf, 0, sizeof(lf));
	lf.lfHeight = FLASHFONTHEIGHT;
	lf.lfWeight = FW_BOLD;
	lf.lfItalic = 1;
	lf.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
	lf.lfFaceName[0] = '\0';
	m_hfont = CreateFontIndirect(&lf);
	if (m_hfont == NULL) 
	{
		//vnclog.Print(1, _T("FAILED TO SELECT FLASHER FONT!\n"));
		Log.Add(_ERROR_, "FAILED TO SELECT FLASHER FONT!");
	}

	// Create a listening socket
    struct sockaddr_in addr;

    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = INADDR_ANY;

    m_sock = socket(AF_INET, SOCK_STREAM, 0);
	if (!m_sock) throw WarningException(sz_G1);
    
	try {
		int one = 1, res = 0;

		// If we use the SO_REUSEADDR option then you can run multiple daemons
		// because the bind doesn't return an error.  Only one gets the accept,
		// but when that process dies it hands back to another.  This may or may
		// not be desirable.  We don't use it.

		//int res = setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, (const char *) &one, sizeof(one));
		//if (res == SOCKET_ERROR) 
		//	throw WarningException("Error setting Flasher socket options");
		
		res = bind(m_sock, (struct sockaddr *)&addr, sizeof(addr));
		if (res == SOCKET_ERROR)
			throw WarningException(sz_G2);
		
		res = listen(m_sock, 5);
		if (res == SOCKET_ERROR)
			throw WarningException(sz_G3);
	} catch (...) {
		closesocket(m_sock);
		m_sock = 0;
		throw;
	}
	
	// Send a message to specified window on an incoming connection
	WSAAsyncSelect (m_sock,  m_hwnd,  WM_SOCKEVENT, FD_ACCEPT | FD_CLOSE);
}
Beispiel #30
0
/*
 * StartUpDriver - the main message handling loop
 */
long __export FAR PASCAL StartUpDriver( HWND hwnd, UINT message,
                                WPARAM wparam, LPARAM lparam )
{
    FARPROC     farproc;
    HWND        tmpw;
    int         len;
    char        data[_MAX_PATH];
    char        tmp[80 + _MAX_PATH];
    HINSTANCE   inst;

    switch( message ) {
    case WM_DESTROY:
        PostQuitMessage( 0 );
        break;

    case WM_COMMAND:
        switch( wparam ) {
        case MSG_ABOUT:
            inst = (HINSTANCE)GetWindowWord( hwnd, GWW_HINSTANCE );
            farproc = MakeProcInstance( (FARPROC)About2, inst );
            DialogBox( inst, ResName( "AboutBox" ), hwnd, (DLGPROC)farproc );
            FreeProcInstance( farproc );
            SetFocus( editChild );
            break;

        case PUSH_GETFILES_ID:
        case MSG_GETFILES:
            data[0] = 0;
            if( getFile( data ) ) {
                GetWindowText( editChild, tmp, sizeof( tmp ) );
                strcat( tmp, data );
                SetWindowText( editChild, tmp );
            }
            SetFocus( editChild );
            break;

        case PUSH_OK_ID:
        case SELECT_ID:
            len = GetWindowTextLength( editChild ) + 1;
            if( len > _MAX_PATH )
                len = _MAX_PATH;
            GetWindowText( editChild, dataPtr, len );
            canContinue = TRUE;
            tmpw = GetParent( editChild );
            SetWindowLong( editChild, GWL_WNDPROC, (LONG) oldClassProc );
            /* fall through, like exit was picked */

        case MSG_EXIT:
            DestroyWindow( mainWindow );
            PostQuitMessage( 0 );
            break;

        } /* switch */
        break;

    default:
        return( DefWindowProc(hwnd,message,wparam,lparam) );

    } /* switch */
    return( 0L );

} /* StartUpDriver */