Προς το περιεχόμενο

Win32 API - Window creation with C++ question


Billman

Προτεινόμενες αναρτήσεις

Δημοσ.

Γεια σας!

 

Μήπως ξέρει κάποιος πως γίνεται ένα παράθυρο το οποίο

δημιουργώ, με την CreateWindow(), να μην είναι resizable?

Έψαξα το Windows API Help file, αλλά δεν κατάφερα να βρω

κάτι σχετικό στις παραμέτρους της συναρτήσεως.

 

Ευχαριστώ πολύ.

Δημοσ.

Akou Billman, prepei na xrisimopoiiseis tin CreateWidnowEx anti gia tin CreateWindow

 

The CreateWindowEx function creates an overlapped, pop-up, or child window with an extended window style; otherwise, this function is identical to the CreateWindow function. For more information about creating a window and for full descriptions of the other parameters of CreateWindowEx

 

HWND CreateWindowEx(

DWORD dwExStyle, // extended window style

LPCTSTR lpClassName, // registered class name

LPCTSTR lpWindowName, // window name

DWORD dwStyle, // window style

int x, // horizontal position of window

int y, // vertical position of window

int nWidth, // window width

int nHeight, // window height

HWND hWndParent, // handle to parent or owner window

HMENU hMenu, // menu handle or child identifier

HINSTANCE hInstance, // handle to application instance

LPVOID lpParam // window-creation data

);

 

Sto dwStyle mpainoun sindiasmoi apo afta:

 

WS_BORDER Creates a window that has a thin-line border.

WS_CAPTION Creates a window that has a title bar (includes the WS_BORDER style).

WS_CHILD Creates a child window. A window with this style cannot have a menu bar. This style cannot be used with the WS_POPUP style.

WS_CHILDWINDOW Same as the WS_CHILD style.

WS_CLIPCHILDREN Excludes the area occupied by child windows when drawing occurs within the parent window. This style is used when creating the parent window.

WS_CLIPSIBLINGS Clips child windows relative to each other; that is, when a particular child window receives a WM_PAINT message, the WS_CLIPSIBLINGS style clips all other overlapping child windows out of the region of the child window to be updated. If WS_CLIPSIBLINGS is not specified and child windows overlap, it is possible, when drawing within the client area of a child window, to draw within the client area of a neighboring child window.

WS_DISABLED Creates a window that is initially disabled. A disabled window cannot receive input from the user. To change this after a window has been created, use EnableWindow.

WS_DLGFRAME Creates a window that has a border of a style typically used with dialog boxes. A window with this style cannot have a title bar.

WS_GROUP Specifies the first control of a group of controls. The group consists of this first control and all controls defined after it, up to the next control with the WS_GROUP style. The first control in each group usually has the WS_TABSTOP style so that the user can move from group to group. The user can subsequently change the keyboard focus from one control in the group to the next control in the group by using the direction keys.

You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use SetWindowLong.

 

WS_HSCROLL Creates a window that has a horizontal scroll bar.

WS_ICONIC Creates a window that is initially minimized. Same as the WS_MINIMIZE style.

WS_MAXIMIZE Creates a window that is initially maximized.

WS_MAXIMIZEBOX Creates a window that has a maximize button. Cannot be combined with the WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified.

WS_MINIMIZE Creates a window that is initially minimized. Same as the WS_ICONIC style.

WS_MINIMIZEBOX Creates a window that has a minimize button. Cannot be combined with the WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified.

WS_OVERLAPPED Creates an overlapped window. An overlapped window has a title bar and a border. Same as the WS_TILED style.

WS_OVERLAPPEDWINDOW Creates an overlapped window with the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles. Same as the WS_TILEDWINDOW style.

WS_POPUP Creates a pop-up window. This style cannot be used with the WS_CHILD style.

WS_POPUPWINDOW Creates a pop-up window with WS_BORDER, WS_POPUP, and WS_SYSMENU styles. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible.

WS_SIZEBOX Creates a window that has a sizing border. Same as the WS_THICKFRAME style.

WS_SYSMENU Creates a window that has a window menu on its title bar. The WS_CAPTION style must also be specified.

WS_TABSTOP Specifies a control that can receive the keyboard focus when the user presses the TAB key. Pressing the TAB key changes the keyboard focus to the next control with the WS_TABSTOP style.

You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use SetWindowLong.

 

WS_THICKFRAME Creates a window that has a sizing border. Same as the WS_SIZEBOX style.

WS_TILED Creates an overlapped window. An overlapped window has a title bar and a border. Same as the WS_OVERLAPPED style.

WS_TILEDWINDOW Creates an overlapped window with the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles. Same as the WS_OVERLAPPEDWINDOW style.

WS_VISIBLE Creates a window that is initially visible.

This style can be turned on and off by using ShowWindow or SetWindowPos.

 

WS_VSCROLL Creates a window that has a vertical scroll bar.

 

//-------------------------------------------------------

Ama se endiaferei to Win32 kalitera mathe win32 assembly

 

win32asm.cjb.net me polla tutorials

 

Δημοσ.

<pre><font class="small">code:</font><hr>

#include <windows.h>

 

// Global variable

 

HINSTANCE hinst;

 

// Function prototypes.

 

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);

InitApplication(HINSTANCE);

InitInstance(HINSTANCE, int);

LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

 

// Application entry point.

 

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,

LPSTR lpCmdLine, int nCmdShow)

{

MSG msg;

 

if (!InitApplication(hinstance))

return FALSE;

 

if (!InitInstance(hinstance, nCmdShow))

return FALSE;

 

 

 

while (GetMessage(&msg, (HWND) NULL, 0, 0) != 0 && GetMessage(&msg, (HWND) NULL, 0, 0) != -1)

{

TranslateMessage(&msg);

 

switch(Msg)

{

case WM_SIZE:

// Edw pirazeis to mynima gia na min allaxei to megethos sto parathyro.

default:

break;

}

 

DispatchMessage(&msg);

}

return msg.wParam;

UNREFERENCED_PARAMETER(lpCmdLine);

}

 

BOOL InitApplication(HINSTANCE hinstance)

{

WNDCLASSEX wcx;

 

// Fill in the window class structure with parameters

// that describe the main window.

 

wcx.cbSize = sizeof(wcx); // size of structure

wcx.style = CS_HREDRAW |

CS_VREDRAW; // redraw if size changes

wcx.lpfnWndProc = MainWndProc; // points to window procedure

wcx.cbClsExtra = 0; // no extra class memory

wcx.cbWndExtra = 0; // no extra window memory

wcx.hInstance = hinstance; // handle to instance

wcx.hIcon = LoadIcon(NULL,

IDI_APPLICATION); // predefined app. icon

wcx.hCursor = LoadCursor(NULL,

IDC_ARROW); // predefined arrow

wcx.hbrBackground = GetStockObject(

WHITE_BRUSH); // white background brush

wcx.lpszMenuName = "MainMenu"; // name of menu resource

wcx.lpszClassName = "MainWClass"; // name of window class

wcx.hIconSm = LoadImage(hinstance, // small class icon

MAKEINTRESOURCE(5),

IMAGE_ICON,

GetSystemMetrics(SM_CXSMICON),

GetSystemMetrics(SM_CYSMICON),

LR_DEFAULTCOLOR);

 

// Register the window class.

 

return RegisterClassEx(&wcx);

}

 

BOOL InitInstance(HINSTANCE hinstance, int nCmdShow)

{

HWND hwnd;

 

// Save the application-instance handle.

 

hinst = hinstance;

 

// Create the main window.

 

hwnd = CreateWindow(

"MainWClass", // name of window class

"Sample", // title-bar string

WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_CHILD | WS_SYSMENU , // top-level window

CW_USEDEFAULT, // default horizontal position

CW_USEDEFAULT, // default vertical position

CW_USEDEFAULT, // default width

CW_USEDEFAULT, // default height

(HWND) NULL, // no owner window

(HMENU) NULL, // use class menu

hinstance, // handle to application instance

(LPVOID) NULL); // no window-creation data

 

if (!hwnd)

return FALSE;

 

// Show the window and send a WM_PAINT message to the window

// procedure.

 

ShowWindow(hwnd, nCmdShow);

UpdateWindow(hwnd);

return TRUE;

 

}

</pre><hr>

 

sto "case WM_SIZE:" xreiazete na ftiaxeis mia synartisi gia na min perasei to mynima WM_SIZE sto leitourgiko kai allaxei to megethos tou parathyrou.

 

pantws i logiki einai: fiaxneis to parathyro kai diaxeirizese ta mynimata poy dexete to programma sou mesa apo tin WinMain.

 

den xerw pws tha to kaneis apo edw kai pera, kanenas pio empeiros se c++ isws se boithisei. sikwnw ta xeria psila.

 

ps: i

<pre><font class="small">code:</font><hr>

switch(Msg)

{

case WM_SIZE:

// Edw pirazeis to mynima gia na min allaxei to megethos sto parathyro.

default:

break;

}

</pre><hr>

 

mporei na min pigainei ekei alla mia grammi pio panw, isws kai meta apo DispatchMessage(&msg)

Δημοσ.

Ασχετο επειδη βλεπω οτι μερικοι απο εσας ειστε γνωστες του Win32API ..δηλωνω εξαιρετικα αρνητικος απεναντι του .παντως τι γνωμη εχετε για το wrapparisma που εχουν κανει στο win32api μεσω της C#? Εμενα μου φαινεται μια πολυ καλη προσπαθεια να ξεμπλεχτει λιγο αυτο το κουβαρι..και ισως να γινει πιο προσιτο και σε μεγαλυτερο αριθμο ανθρωπων!

Δημοσ.

Ευχαριστώ για τις απαντήσεις σας παιδιά.

 

apoc: Μία φορά κάθησα και διάβασα για την C# ένα tutorial

και επειδή είδα ότι ήταν σχεδόν ίδια με την Java δεν

ασχολήθηκα ξανά μαζί της. Μέχρι στιγμής πάντως το καλύτερο

wrapparisma το έχω δει από την Borland με την VCL. Αφήνει έτη φωτός πίσω της Microsoft τις MFC.

Δημοσ.

Να σου πω την αληθεια δεν εχω ασχοληθει με το VCL της Borland!Παρολα αυτα πιστευω οτι το MFC της Microsoft δεν ειναι τοσο κακη υλοποιηση ..καλυπτει διαφορα κενα...Παντως το WinAPI ειναι ενα αλλο κεφαλαιο..και εκει ετυχε να δω διαφορες αναφορες τις c# και το πως προσεγγιζεις το WinAPI..Θεωρησα τουλαχιστον προσωπικα οτι μου ηταν πιο κατανοητο!

Δημοσ.

Ο προγραμματισμός σε WinAPI είναι σίγουρα μερικές φορές ιδιαίτερα στρυφνός αλλά μονόδρομος αν θες μικρά σε μέγεθος αρχεία ή την εκμετάλλευση δυνατοτήτων του Λ.Σ. που δεν παρέχονται προς το παρόν από κάποιον C++ wrapper ή είναι πιο εύκολο να τα καλέσεις απευθείας σε C.

 

Σε γενικές γραμμές θεωρώ την χρήση του WinAPI επιβεβλημένη σε οποιοδήποτε προγραμματιστή Windows αφού μπορεί λύσει κυριολεκτικά τα χέρια.

 

Όσον αφορά την δημιουργία παραθύρων σε WinAPI (32bit) προτείνω και την χρήση των εντολών DialogBox που επιτρέπουν την δημιουργία Dialogs από Dialog resource της εφαρμογής, απλοποιώντας την διαδικασία σχεδιασμού παραθύρων (και controls) σε σημείο που θυμίζει οπτικά εργαλεία!

 

Πχ. (Έστω ότι έχουμε δημιουργήσει ένα Dialog Box resource με όνομα DialogBox σε .rc ή .res και το ενσωματώνουμε (link) στην εφαρμογή μας, -το έχουμε δε ρυθμίσει ως non-thick frame ώστε το μέγεθος του να είναι fixed)

 

<pre><font class="small">code:</font><hr>

#include <windows.h>

 

WINAPI DlgMsgLoop(HWND hWnd,WORD wMSG,WPARAM wParam,LPARAM lParam)

{

switch(wMSG)

{

case WM_INITDIALOG:

return TRUE;

 

case WM_COMMAND:

switch(wParam)

{

case WM_DESTROY:

PostQuitMessage(0L);

return TRUE;

 

default: return FALSE;

}

return FALSE;

 

default: return FALSE;

}

 

return FALSE;

}

 

WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{

if(DialogBox(hInstance,"DialogBox",NULL,(DLGPROC)DlgMsgLoop)==-1)

{

MessageBox(NULL,"Dialog creation failed!!",NULL,MB_ICONSTOP);

return -1;

}

 

return 0;

}

</pre><hr>

 

Υ.Γ.

 

Για το θέμα του resize γενικά, νομίζω ότι θα πρέπει να ψάξεις τις εντολές GetWindowLong & SetWindowLong που ρυθμίζουν τα «properties» των παραθύρων..

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...