1. 程式人生 > >c++介面視窗與按鈕設定

c++介面視窗與按鈕設定

1.獲取螢幕寬度:

HDC hdc = ::GetDC(HWND(NULL));
int x = ::GetDeviceCaps(hdc, HORZRES);//獲得螢幕寬度
2.隱藏工作列:
ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW, 1);//工作列隱藏
3.視窗大小和位置:
CDialogEx::SetWindowPos(&wndTopMost, wndx, 0, 205, 61, SWP_SHOWWINDOW);//視窗大小:205*61,位置:x,wndx;y,0
4.系統托盤設定:
NotifyIcon.cbSize = sizeof(NOTIFYICONDATA);
NotifyIcon.hIcon = AfxGetApp()->LoadIcon(IDI_ICONTP);//圖示
NotifyIcon.hWnd = m_hWnd;
NotifyIcon.uID = IDI_ICONTP;
lstrcpy(NotifyIcon.szTip, _T("某某軟體"));//文字提示
NotifyIcon.uCallbackMessage = WM_SYSTEMTRAY;
NotifyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
Shell_NotifyIcon(NIM_ADD, &NotifyIcon); 
5.按鈕大小和位置
CWnd *pWndl;
pWndl = GetDlgItem(IDC_VM1); //獲取控制元件指標
pWndl->MoveWindow(CRect(0, 0, 102, 60)); //左按鈕的大小:102*60,位置:x,0;y,0
6.按鈕圖片設定
HBITMAP hBmp_btn = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP12));
this->SetBitmap(hBmp_btn);
DeleteObject(hBmp_btn);
7.在onpaint中繪製視窗背景圖片:
CPaintDC dc(this); // device context for painting
CImage img;
if (!img.IsNull()) img.Destroy();
HRESULT result = img.Load(_T("./image/BC.bmp"));
if (!img.IsNull()) img.Draw(dc.m_hDC, 0, 0);
img.Destroy();