1 / 9

Programowanie pod Windows

Programowanie pod Windows. W środowisku Visual C++ Część IV. Anna Tomkowska Politechnika Koszalińska 2007. 1/8. Pasek narzędziowy. #include <commctrl.h> … HWND hToolBar; HINSTANCE hInstance; HWND hStatus; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI ( … ) {

ima
Download Presentation

Programowanie pod 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 pod Windows W środowisku Visual C++ Część IV Anna Tomkowska Politechnika Koszalińska 2007

  2. 1/8 Pasek narzędziowy #include <commctrl.h> … HWND hToolBar; HINSTANCE hInstance; HWND hStatus; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI(…) { InitCommonControls(); … } LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) { … } int WINAPI(HINSTANCE hInst ,…) { InitCommonControls(); hInstance = hInst; … } LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) { … }

  3. 2/8 Pasek narzędziowy / WM_CREATE LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch(msg) { case WM_CREATE: { TBBUTTON przyciski[6]; memset(przyciski, 0, sizeof(TBBUTTON)*6); przyciski[0].iBitmap = 0; przyciski[0].idCommand = CM_NOWY; przyciski[0].fsState = TBSTATE_ENABLED; przyciski[0].fsStyle = TBSTYLE_BUTTON; … przyciski[5].iBitmap=3; … hToolBar = CreateToolbarEx( hwnd, TBSTYLE_TOOLTIPS|WS_VISIBLE|WS_CHILD, 200, 4, hInstance,1, przyciski, 6, 0, 0, 32, 32, sizeof(TBBUTTON)); …

  4. 3/8 Pasek narzędziowy / WM_SIZE LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch(msg) { case WM_CREATE: … case WM_SIZE: SendMessage(hToolBar, WM_SIZE, wParam, lParam); break; } …

  5. 4/8 Pasek narzędziowy / WM_COMMAND LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch(msg) { … case WM_COMMAND: switch(LOWORD(wParam)) { case CM_NOWY: … break; case CM_OTWORZ: … break; … } …

  6. 5/8 Pasek narzędziowy / WM_NOTIFY LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch(msg) { … case WM_NOTIFY: { LPTOOLTIPTEXT lpttt= (LPTOOLTIPTEXT)lParam; if (lpttt->hdr.code == TTN_NEEDTEXT) { switch (lpttt->hdr.idFrom) { case CM_NOWY: lpttt->lpszText = "NowyDocument"; break; case CM_ZAPISZ: lpttt->lpszText = "Zapisz dokument"; break; } } … typedef struct { NMHDR hdr; LPTSTR lpszText; WCHAR szText[80]; HINSTANCE hinst; UINT uflags; } TOOLTIPTEXT, FAR *LPTOOLTIPTEXT; typedef struct tagNMHDR { HWND hwndFrom; UINT idFrom; UINT code; } NMHDR;

  7. 6/8 Dodawanie pliku bmp do zasobów W pliku RC należy dopisać linijkę: identyfikatorBITMAP "NazwaPliku.bmp „ np. BITMAP_5 BITMAP "Toolbar.bmp " W pliku H należy dopisać linijkę: #define identyfikator indeks np. #define BITMAP_5 5

  8. 7/8 Pasek Statusu / WM_CREATE LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch(msg) { case WM_CREATE: { … hStatus= CreateStatusWindow(WS_CHILD|WS_VISIBLE, „napis w pasku", hwnd, 700); break; } } … }

  9. 8/8 Pasek Statusu / WM_SIZE LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch(msg) { case WM_SIZE: { RECT rect; SetRect(&rec, 0, 0, LOWORD(lParam), HIWORD(lParam)); int parts[2] = {rect.right/3,rect.right}; SendMessage(hStatus,WM_SIZE,wParam,lParam); SendMessage(hStatus,SB_SETPARTS,(WPARAM) 2, (LPARAM) parts ); SendMessage(hStatus, SB_SETTEXT, (WPARAM) 0, (LPARAM) "WM_SIZE"); itoa(LOWORD(lParam), tekst,10); strcat(tekst, ", "); itoa(HIWORD(lParam), tekst+strlen(tekst),10); SendMessage(hStatus, SB_SETTEXT, (WPARAM) 1, (LPARAM) tekst); …

More Related