1 / 8

Programowanie Windows

Programowanie Windows. W środowisku Visual C++ Część II. Anna Tomkowska Politechnika Koszalińska 2007. 1/7. Wyświetlanie tekstu. COLORREF fontColor = RGB(0,0,0); ; … LRESULT CALLBACK WndProc ( … ) { … LOGFONT lf; HFONT hfont; case WM_PAINT: … SetTextColor(hdc, kolorCzcionki);

hiroko
Download Presentation

Programowanie Windows

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programowanie Windows W środowisku Visual C++ Część II Anna Tomkowska Politechnika Koszalińska 2007

  2. 1/7 Wyświetlanie tekstu COLORREF fontColor =RGB(0,0,0);; … LRESULT CALLBACK WndProc(…) { … LOGFONT lf; HFONT hfont; case WM_PAINT: … SetTextColor(hdc, kolorCzcionki); SetBkMode(hdc,TRANSPARENT); memset(&lf,0,sizeof(lf)); lf.lfItalic=1; _tcscpy(lf.lfFaceName,TEXT("Times New Roman")); hfont=CreateFontIndirect(&lf); hfont=(HFONT) SelectObject(hdc,hfont); TextOut(hdc,100,100,TEXT("ABCdefg"),7); DrawText(hdc,TEXT(„ab"),-1,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE); hfont=(HFONT) SelectObject(hdc,hfont); DeleteObject(hfont); … return 0; …

  3. 2/7 Wyświetlanie dialogu BOOL CALLBACK DialogProc(HWND,UINT,WPARAM, LPARAM); … LRESULT CALLBACK WndProc(…) { … case WM_COMMAND: … case ID_OPCJE_KOLOR: if(DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1), hWnd,(DLGPROC)DlgProc)) InvalidateRect(hWnd,0,1); break; … } BOOL CALLBACK DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam, LPARAM lParam) { … }

  4. 3/7 Niestandardowe kontrolki #include <commctrl.h> … int WINAPI(…) { InitCommonControls(); … } Project → Properties Configurations Properties- →Linker →Command Line Additional Options: comctl32.lib Dodać bibliotekę comctl32.lib

  5. 4/7 Ustawianie wart. początkowych BOOL CALLBACK DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam, LPARAM lParam) { static COLORREF kolor=RGB(0,0,0); static HWND hOkienko; switch(uMsg) { case WM_INITDIALOG: hOkienko=GetDlgItem(hDlg,IDC_COLOR); SetDlgItemInt(hDlg,IDC_EDIT1,GetRValue(kolor),0); … SendDlgItemMessage(hDlg,IDC_SLIDER1,TBM_SETRANGE, TRUE,MAKELONG(0,255)); … SendDlgItemMessage(hDlg,IDC_SLIDER1,TBM_SETPOS, TRUE,GetRValue(kolor)); … return 1; case WM_CLOSE: EndDialog(hwndDlg,FALSE); return 1; } …

  6. 5/7 Komunikat WM_COMMAND BOOL CALLBACK DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam, LPARAM lParam) { … case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: fontColor =kolor; EndDialog(hwndDlg,TRUE); return 1; case IDCANCEL: EndDialog(hwndDlg,FALSE); return 1; } return 1; … }

  7. 6/7 Komunikat WM_COMMAND BOOL CALLBACK DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam, LPARAM lParam) { … case WM_COMMAND: switch (LOWORD(wParam)) { … case IDC_EDIT1: { int R=GetDlgItemInt(hDlg,IDC_EDIT1,NULL,0); kolor=RGB(R,GetGValue(kolor),GetBValue(kolor)); SendDlgItemMessage(hDlg,IDC_SLIDER1,TBM_SETPOS, TRUE,GetRValue(kolor)); InvalidateRect(hwndDlg,0,0); } return 1; … } return 1; … }

  8. 7/7 Komunikat WM_PAINT BOOL CALLBACK DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam, LPARAM lParam) { … HBRUSH hbrush; RECT rc; … case WM_PAINT: hdc=BeginPaint(hOkienko,&ps); hbrush=CreateSolidBrush(kolor); hbrush=(HBRUSH) SelectObject(hdc,hbrush); GetClientRect(hOkienko,&rc); Rectangle(hdc,0,0,rc.right,rc.bottom); hbrush=(HBRUSH) SelectObject(hdc,hbrush); DeleteObject(hbrush); EndPaint(hOkienko,&ps); break; … …

More Related