Scrollplane oder sowas ? | 'OPENFILENAME' : nichtdeklarierter Bezeichner
-
Hi, ich würde gerne eine bitmap, die in mein fenster gezeichnet wird, in eine art bereich legen, und ggf. mit scrollbars versehen(wenn das fenster kleiner ist als der bereich oder die bitmap grösser als der bereich!) hat jmd vielleicht n gutes tut zu fensterdesign ?
danköö
edit: jo wir im Titel zu sehen krieg ich bei der benutzung von OPENFILENAME den fehler:
Error C2065: 'OPENFILENAME' : nichtdeklarierter Bezeichnerwie kann das denn sein? windows.h ist included oO
-
Also ich weis jetzt nicht genau was du alles für dein Bitmap so brauchst. Aber guck dir mal folgende Funktionen an.
StretchBlt();
BitBlt();Für OPENFILENAME sollte eigentlich windows.h ausreichen weil die header eigentlich "viele" andere includiert aber ka wie alt dein PSDK ist oder mit welcher IDE du arbeitest.
Ansonsten wie in der MSDNQuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in commdlg.h.
Unicode: Defined as Unicode and ANSI structures.MfG schirrmie
-
schirrmie schrieb:
Also ich weis jetzt nicht genau was du alles für dein Bitmap so brauchst. Aber guck dir mal folgende Funktionen an.
StretchBlt();
BitBlt();Für OPENFILENAME sollte eigentlich windows.h ausreichen weil die header eigentlich "viele" andere includiert aber ka wie alt dein PSDK ist oder mit welcher IDE du arbeitest.
Ansonsten wie in der MSDNQuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in commdlg.h.
Unicode: Defined as Unicode and ANSI structures.MfG schirrmie
danke das include hat mir weitergeholfen!
aber bei der bitmap, da meinte ich was anderes! ich möchte, dass die bitmap, unabhängig ihrer grösse nur in einem sagen wir 500x500pixel grossen bereich dargestellt wird. ist die bitmap grösser als 500x500, so bekommt der bereich scrollbars, mit denen ich die bitmap scrollen kann.danke
-
Ja dann was ist genau dein problem? Weist du nicht wie man Scrollbars erstellt oder wie man die Fenstergröße erhält oder was?
Ich würde bei einer WM_SIZE Message nach der Fenstergröße gucken. Wenn Sie dann kleiner 500x500 ist erstell ich Scrollbars. Dann fängst du die Scrollbars Messages ab und Blittest dein Bitmap entsprechend der größe. So oder so ähnlich

schirrmie
-
schirrmie schrieb:
Ja dann was ist genau dein problem? Weist du nicht wie man Scrollbars erstellt oder wie man die Fenstergröße erhält oder was?
Ich würde bei einer WM_SIZE Message nach der Fenstergröße gucken. Wenn Sie dann kleiner 500x500 ist erstell ich Scrollbars. Dann fängst du die Scrollbars Messages ab und Blittest dein Bitmap entsprechend der größe. So oder so ähnlich

schirrmie
du hasts nicht richtig gelesen
es geht mir weniger um die fenstergrösse, als um die bitmap grösse
edit: und nein, ich weis nicht genau wie ich mit scrollbars arbeite...wär für ein tutorial dankbar
-
Na und die Bitmapgröße kannst du doch verändern und alles mit den Funktionen die ich dir genannt habe. Hast du dir die denn mal angeschaut?
Also in der MSDN gibt es natürlich einen Artikel für Scrollbars (wie für alles andere auch :))
ansonsten hab ich eben mal 20sec. gegoogelt http://www.win-api.de/tutorials.php?tutid=16&SessID=b00bc950f5ced1a6db86121a34406d47
ka ob das was passendes ist aber es geht zumindest um scrollbars
schirrmie
-
hm naja ihc würde erstmal gerne folgendes wissen:
- wieso wird meine scrollbar am anfang nich angezeigt? erst wenn ich das fenster resize oder verschiebe. wenn ich das fenster maximiere, verschwindet sie wieder- wie ändere ich während der laufzeit die maße meine scrollbar
danke
-
Hmm ich (und alle anderen auch) könnte jetzt rätselraten warum das passiert aber einfacher wäre es wenn du den relevanten Code zeigst

Meinst du die gesamte größe der Scrollbar ändern? -> MoveWindow();
Mensch ich hab gerade gesehen in der MSDN gibt es sogar ein ganzes Bsp für dein Fall
Ich poste ihn hier einfach mal rein wenn das nicht ok ist soll ein Mod das ändern will jetzt nur kein link noch suchen 
Example of Scrolling a Bitmap The following example enables the user to capture the screen content into a bitmap and scroll the bitmap in the client area. HDC hdc; PAINTSTRUCT ps; SCROLLINFO si; // These variables are required by BitBlt. static HDC hdcWin; // window DC static HDC hdcScreen; // DC for entire screen static HDC hdcScreenCompat; // memory DC for screen static HBITMAP hbmpCompat; // bitmap handle for old DC static BITMAP bmp; // bitmap data structure static BOOL fBlt; // TRUE if BitBlt occurred static BOOL fScroll; // TRUE if scrolling occurred static BOOL fSize; // TRUE if fBlt & WM_SIZE // These variables are required for horizontal scrolling. static int xMinScroll; // minimum horizontal scroll value static int xCurrentScroll; // current horizontal scroll value static int xMaxScroll; // maximum horizontal scroll value // These variables are required for vertical scrolling. static int yMinScroll; // minimum vertical scroll value static int yCurrentScroll; // current vertical scroll value static int yMaxScroll; // maximum vertical scroll value switch (uMsg) { case WM_CREATE: // Create a normal DC and a memory DC for the entire // screen. The normal DC provides a snapshot of the // screen contents. The memory DC keeps a copy of this // snapshot in the associated bitmap. hdcScreen = CreateDC("DISPLAY", (LPCSTR) NULL, (LPCSTR) NULL, (CONST DEVMODE *) NULL); hdcScreenCompat = CreateCompatibleDC(hdcScreen); // Retrieve the metrics for the bitmap associated with the // regular device context. bmp.bmBitsPixel = (BYTE) GetDeviceCaps(hdcScreen, BITSPIXEL); bmp.bmPlanes = (BYTE) GetDeviceCaps(hdcScreen, PLANES); bmp.bmWidth = GetDeviceCaps(hdcScreen, HORZRES); bmp.bmHeight = GetDeviceCaps(hdcScreen, VERTRES); // The width must be byte-aligned. bmp.bmWidthBytes = ((bmp.bmWidth + 15) &~15)/8; // Create a bitmap for the compatible DC. hbmpCompat = CreateBitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, (CONST VOID *) NULL); // Select the bitmap for the compatible DC. SelectObject(hdcScreenCompat, hbmpCompat); // Initialize the flags. fBlt = FALSE; fScroll = FALSE; fSize = FALSE; // Initialize the horizontal scrolling variables. xMinScroll = 0; xCurrentScroll = 0; xMaxScroll = 0; // Initialize the vertical scrolling variables. yMinScroll = 0; yCurrentScroll = 0; yMaxScroll = 0; break; case WM_SIZE: { int xNewSize; int yNewSize; xNewSize = LOWORD(lParam); yNewSize = HIWORD(lParam); if (fBlt) fSize = TRUE; // The horizontal scrolling range is defined by // (bitmap_width) - (client_width). The current horizontal // scroll value remains within the horizontal scrolling range. xMaxScroll = max(bmp.bmWidth-xNewSize, 0); xCurrentScroll = min(xCurrentScroll, xMaxScroll); si.cbSize = sizeof(si); si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; si.nMin = xMinScroll; si.nMax = xMaxScroll; si.nPage = xNewSize; si.nPos = xCurrentScroll; SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); // The vertical scrolling range is defined by // (bitmap_height) - (client_height). The current vertical // scroll value remains within the vertical scrolling range. yMaxScroll = max(bmp.bmHeight - yNewSize, 0); yCurrentScroll = min(yCurrentScroll, yMaxScroll); si.cbSize = sizeof(si); si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; si.nMin = yMinScroll; si.nMax = yMaxScroll; si.nPage = yNewSize; si.nPos = yCurrentScroll; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); } break; case WM_PAINT: { PRECT prect; hdc = BeginPaint(hwnd, &ps); // If the window has been resized and the user has // captured the screen, use the following call to // BitBlt to paint the window's client area. if (fSize) { BitBlt(ps.hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcScreenCompat, xCurrentScroll, yCurrentScroll, SRCCOPY); fSize = FALSE; } // If scrolling has occurred, use the following call to // BitBlt to paint the invalid rectangle. // // The coordinates of this rectangle are specified in the // RECT structure to which prect points. // // Note that it is necessary to increment the seventh // argument (prect->left) by xCurrentScroll and the // eighth argument (prect->top) by yCurrentScroll in // order to map the correct pixels from the source bitmap. if (fScroll) { prect = &ps.rcPaint; BitBlt(ps.hdc, prect->left, prect->top, (prect->right - prect->left), (prect->bottom - prect->top), hdcScreenCompat, prect->left + xCurrentScroll, prect->top + yCurrentScroll, SRCCOPY); fScroll = FALSE; } EndPaint(hwnd, &ps); } break; case WM_HSCROLL: { int xDelta; // xDelta = new_pos - current_pos int xNewPos; // new position int yDelta = 0; switch (LOWORD(wParam)) { // User clicked the shaft left of the scroll box. case SB_PAGEUP: xNewPos = xCurrentScroll - 50; break; // User clicked the shaft right of the scroll box. case SB_PAGEDOWN: xNewPos = xCurrentScroll + 50; break; // User clicked the left arrow. case SB_LINEUP: xNewPos = xCurrentScroll - 5; break; // User clicked the right arrow. case SB_LINEDOWN: xNewPos = xCurrentScroll + 5; break; // User dragged the scroll box. case SB_THUMBPOSITION: xNewPos = HIWORD(wParam); break; default: xNewPos = xCurrentScroll; } // New position must be between 0 and the screen width. xNewPos = max(0, xNewPos); xNewPos = min(xMaxScroll, xNewPos); // If the current position does not change, do not scroll. if (xNewPos == xCurrentScroll) break; // Set the scroll flag to TRUE. fScroll = TRUE; // Determine the amount scrolled (in pixels). xDelta = xNewPos - xCurrentScroll; // Reset the current scroll position. xCurrentScroll = xNewPos; // Scroll the window. (The system repaints most of the // client area when ScrollWindowEx is called; however, it is // necessary to call UpdateWindow in order to repaint the // rectangle of pixels that were invalidated.) ScrollWindowEx(hwnd, -xDelta, -yDelta, (CONST RECT *) NULL, (CONST RECT *) NULL, (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE); UpdateWindow(hwnd); // Reset the scroll bar. si.cbSize = sizeof(si); si.fMask = SIF_POS; si.nPos = xCurrentScroll; SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); } break; case WM_VSCROLL: { int xDelta = 0; int yDelta; // yDelta = new_pos - current_pos int yNewPos; // new position switch (LOWORD(wParam)) { // User clicked the shaft above the scroll box. case SB_PAGEUP: yNewPos = yCurrentScroll - 50; break; // User clicked the shaft below the scroll box. case SB_PAGEDOWN: yNewPos = yCurrentScroll + 50; break; // User clicked the top arrow. case SB_LINEUP: yNewPos = yCurrentScroll - 5; break; // User clicked the bottom arrow. case SB_LINEDOWN: yNewPos = yCurrentScroll + 5; break; // User dragged the scroll box. case SB_THUMBPOSITION: yNewPos = HIWORD(wParam); break; default: yNewPos = yCurrentScroll; } // New position must be between 0 and the screen height. yNewPos = max(0, yNewPos); yNewPos = min(yMaxScroll, yNewPos); // If the current position does not change, do not scroll. if (yNewPos == yCurrentScroll) break; // Set the scroll flag to TRUE. fScroll = TRUE; // Determine the amount scrolled (in pixels). yDelta = yNewPos - yCurrentScroll; // Reset the current scroll position. yCurrentScroll = yNewPos; // Scroll the window. (The system repaints most of the // client area when ScrollWindowEx is called; however, it is // necessary to call UpdateWindow in order to repaint the // rectangle of pixels that were invalidated.) ScrollWindowEx(hwnd, -xDelta, -yDelta, (CONST RECT *) NULL, (CONST RECT *) NULL, (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE); UpdateWindow(hwnd); // Reset the scroll bar. si.cbSize = sizeof(si); si.fMask = SIF_POS; si.nPos = yCurrentScroll; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); } break; case WM_COMMAND: // uMsg: command from app. menu switch(wParam) { case IDM_STC: // Copy the contents of the current screen // into the compatible DC. BitBlt(hdcScreenCompat, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcScreen, 0, 0, SRCCOPY); // Copy the compatible DC to the client area. hdcWin = GetDC(hwnd); BitBlt(hdcWin, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcScreenCompat, 0, 0, SRCCOPY); ReleaseDC(hwnd, hdcWin); fBlt = TRUE; break; default: return (DefWindowProc(hwnd, uMsg, wParam, lParam)); } break;schirrmie
-
in dem msdn beispiel geht es aber nicht um die scrollbars (deren erstellugn wird nicht einmalo gezeigt)
also ich post mal meinen code und schreibe dazu was momentan nicht geht:
// bildverarbeitung2.cpp : Definiert den Einsprungpunkt für die Anwendung. // #include "stdafx.h" #include "resource.h" #include <windows.h> #include <stdio.h> #include "commdlg.h" LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); HBITMAP hBitmap; BITMAP bitmap; HDC hdc, hdcMem ; HINSTANCE hInstance ; PAINTSTRUCT ps ; SIZE bitmapSize, winSize; HWND imgVScroll, imgHScroll; HBITMAP loadImg(char* path) { if(HBITMAP ret = (HBITMAP)LoadImage(0,path,IMAGE_BITMAP,0,0,LR_LOADFROMFILE)) return ret; else return NULL; } HDC getScreenShot() { return GetDC(0); } HBITMAP getBitmapScreenShot() { HDC screen = getScreenShot(); HDC hdcCompatible = CreateCompatibleDC(screen); HBITMAP screenBitmap = CreateCompatibleBitmap(screen, GetDeviceCaps(screen, HORZRES), GetDeviceCaps(screen, VERTRES)); SelectObject(hdcCompatible, screenBitmap); BitBlt(hdcCompatible,0,0, GetDeviceCaps(screen, HORZRES), GetDeviceCaps(screen, VERTRES), screen, 0,0,SRCCOPY) ; return screenBitmap; } HDC getBitmapHDC(HBITMAP img) { HDC hdcImage = CreateCompatibleDC(GetDC(0)); SelectObject(hdcImage,img); return hdcImage; } SIZE getBitmapSize(HBITMAP img) { BITMAP imgInfo; GetObject(img, sizeof(BITMAP), (LPSTR)&imgInfo); SIZE ret; ret.cx = imgInfo.bmWidth; ret.cy = imgInfo.bmHeight; return ret; } HDC getHDCScaled(float xscale, float yscale, HDC source) { HDC hdcScaled = CreateCompatibleDC(getScreenShot()); HBITMAP hbmScaled = CreateCompatibleBitmap(source, GetDeviceCaps(source, HORZRES) * xscale, GetDeviceCaps(source, VERTRES) * yscale); SelectObject(hdcScaled, hbmScaled); StretchBlt(hdcScaled, 0, 0, GetDeviceCaps(source, HORZRES) * xscale, GetDeviceCaps(source, VERTRES) * yscale, source, 0, 0, GetDeviceCaps(source, HORZRES), GetDeviceCaps(source, VERTRES), SRCCOPY); return hdcScaled; } int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "Name" ; HWND hwnd ; MSG msg ; WNDCLASSEX wndclass ; wndclass.cbSize = sizeof (wndclass) ; wndclass.style = CS_HREDRAW | CS_VREDRAW | ES_AUTOHSCROLL | ES_AUTOVSCROLL ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = CreateSolidBrush(RGB(100, 100, 100)); wndclass.lpszMenuName = (LPCSTR)IDR_MENU2 ; wndclass.lpszClassName = szAppName ; wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ; RegisterClassEx (&wndclass) ; hwnd = CreateWindow (szAppName, "Fenstername", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ) ; imgHScroll = CreateWindow( "SCROLLBAR", // scroll bar control class (LPSTR) NULL, // text for window title bar WS_CHILD | WS_VISIBLE | SBS_HORZ, // scroll bar styles 0, // horizontal position 500, // vertical position 500, // width of the scroll bar 15, // default height hwnd, // handle to main window (HMENU) NULL, // no menu for a scroll bar hInstance, // instance owning this window (LPVOID) NULL // pointer not needed ); ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch (iMsg) { case WM_CREATE : { hInstance = ((LPCREATESTRUCT) lParam)->hInstance ; SendMessage(hwnd, WM_PAINT, NULL, NULL); return 0 ; } case WM_PAINT : { hdc = BeginPaint (hwnd, &ps) ; SelectObject(hdc, GetStockObject(GRAY_BRUSH)); Rectangle(hdc,winSize.cx-200,0,winSize.cx,winSize.cy); Rectangle(hdc,0,winSize.cy-50,winSize.cx,winSize.cy); if(hdcMem) { BitBlt (hdc, 0, 0, winSize.cx-200, winSize.cy-50, hdcMem, 0, 0, SRCCOPY) ; } SetWindowPos(imgHScroll, imgHScroll, 0, winSize.cy-50, winSize.cx-200, 15, SWP_SHOWWINDOW); EndPaint (hwnd, &ps); return 0 ; } case WM_SIZE: winSize.cx = LOWORD(lParam); winSize.cy = HIWORD(lParam); break; case WM_DESTROY : DeleteDC (hdcMem) ; DeleteObject (hBitmap) ; PostQuitMessage (0) ; return 0 ; case WM_COMMAND: switch (LOWORD(wParam)) { case exit:// Menüpunkt Beenden SendMessage(hwnd,WM_DESTROY,0,0); break ; case createColortable:// Menüpunkt Beenden SendMessage(hwnd,WM_DESTROY,0,0); break ; case loadBm: char szFileName[MAX_PATH] = ""; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Bitmaps (*.bmp)\0*.bmp\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "bmp"; if(GetOpenFileName(&ofn)) { // Do something usefull with the filename stored in szFileName hBitmap = loadImg(szFileName); GetObject (hBitmap, sizeof (BITMAP), &bitmap) ; HDC scrShot = getBitmapHDC(hBitmap); hdcMem = getHDCScaled(0.6, 0.6, scrShot); SendMessage(hwnd,WM_PAINT,0,0); } break; } return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }also:
- die scrollbar bleibt auf ihrer anfangsposition, obwohl sie in WM_PAINT eigentlich verschoben werden sollte. ---> Ok danke, movewindow geht
- Das Bild wird nach dem Laden nicht angezeigt, obwohl sogar explizit WM_PAINT gesendet wird. erst wenn das fenster resized wird, zeigt sich das bild.
- Beim neu Painten Flimmert alles, was gemalt wird!
danke für die hilfe
-
Also das SendMessage mit WM_PAINT bei WM_CREATE das bringt dir nix. Weil das fenster erst nach WM_CREATE angezeigt wird.
wegen dem flackern guck mal ob dir das was hilft http://www.winapi.net/index.php?inhalt=tipp4schirrmie
-
schirrmie schrieb:
Also das SendMessage mit WM_PAINT bei WM_CREATE das bringt dir nix. Weil das fenster erst nach WM_CREATE angezeigt wird.
wegen dem flackern guck mal ob dir das was hilft http://www.winapi.net/index.php?inhalt=tipp4schirrmie
- ne das bringt nicht wirklich was gegen's flackern... es verhindert, dass der hintergrund gezeichnet wird. sobald man aber mehr als 1 objekt übereinander zeichnet, flackert es wieder.
- ich rufe WM_PAINT doch auch da auf wo das bild aus der datei geladen wird! da müsste das doch funktionieren! (zeile 197)