1

I am creating an winAPI application in c++ I have a photo in preview pane and I want to create two buttons NEXT and PREVIOUS on clicking them I will go to the next page .

Could you please give me the idea how to do that in c++ ??

Do I need to use QT libraray or it can be done using the in built function of WinAPI like -

HWND hwndButton1 = CreateWindow(L"BUTTON",L"NEXT",WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,550,800,100,30,m_hwndPreview,(HMENU)buttonid1,(HINSTANCE)GetWindowLong(m_hwndPreview, -6),NULL);

    HWND hwndButton2 = CreateWindow(L"BUTTON",L"PREVIOUS",WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,650,800,100,30,m_hwndPreview,(HMENU)buttonid2,(HINSTANCE)GetWindowLong(m_hwndPreview, -6),NULL);

and then using WM_COMMAND for both the button clicks.

Am I going right?

I just want my API application work like a .pdf extension file...as in PDF files we have up and down arrow and on clicking upon them we can go to the next page..In winAPIc++ I couldn't find any such arrow function.. please tell me if there is any such arrow up/down function present to go to next page (because I am very less interested in creating NEXT and PREVIOUS button using createwindow function.. It looks odd).

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Sss
  • 1,519
  • 8
  • 37
  • 67
  • 1
    "Am i going right ???" No way. If you are writing Qt applications you should almost never need to directly use CreateWindow or use windows messages. Qt handles the API specific parts for you. – drescherjm Jul 15 '13 at 16:55
  • agree with @drescherjm , it's the whole purpose of qt - to create cross-platform programs, let Qt handle that or don't use qt at all – Shf Jul 15 '13 at 16:57
  • I think I have misunderstood the question. Yes you can make a next and previous button using the bare metal winapi but that generally is more work than using a framework like Qt, MFC, WTL, wxWidgets. But yes it can be done. There is no arrow function in winapi. You would need to implement that yourself. – drescherjm Jul 15 '13 at 17:45
  • yes Drescherjm, you are right so which way you suggest me to do ?? because if i want the buttons exactly in the way the .pdf files are displayed in preview pane (with arrow buttons).. i have No knowledge of Qt ..Is it possible to do exactly this using Qt ?? Could you please give me some link for how to do like that ?? Thanks.. – Sss Jul 15 '13 at 18:00
  • If you do not know Qt, I would suggest creating a ui with 2 buttons is not a good reason to learn Qt. You can do this with winapi if that is what you know best and want to learn. – drescherjm Jul 15 '13 at 18:16
  • But using this method i don't think that i would be able to get that beautiful view as i get in the case of .pdf files in preview pane(as we can see there is a bar at the bottom of the view and on the bar we have two arrows (up/down) and as we click on them it turns the page..using thsi button i will have the buttons on the screen itself...Do you know any other way ??) and thankyou so much... – Sss Jul 15 '13 at 18:23
  • My question is what do you want to learn? Qt (or a 1/2 dozen other frameworks) can make pretty UIs with significantly less effort than bare metal winapi programming however you will need to spend a considerable amount of time learning whatever framework you choose. – drescherjm Jul 15 '13 at 19:02

3 Answers3

1

Most buttons (and other controls) are created using a resource editor, placing the controls on a dialog template or a toolbar resource. If you do that Windows will create the buttons when you create the dialog or toolbar. This method is much preferred because Windows will adjust the size of the buttons as required for the screen settings in use.

If you can't do that you must use CreateWindow as you are doing.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • @ ScottMcP ..Could you please once pay attention th equestion i have asked on this link because i am sure that you have solution for it- http://stackoverflow.com/questions/18097646/how-to-create-a-strip-to-keep-button-on-it-using-resource-editor-in-visual-c?noredirect=1#comment26491888_18097646 – Sss Aug 07 '13 at 08:34
1

You have not mentioned what tools you are using, so we don't know if you have a resouce editor. You should research that in a forum appropriate for the tools. If you think writing one line of code to create a button is "very complicated" then you need a better tool.

If you do not want the buttons to appear on top of the picture then you need another place to put them. One common possibility is a toolbar. It is a strip for buttons along the top or bottom of the main window:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb760435(v=vs.85).aspx

With a resource editor you can draw an arrow on the button. Without a resource editor you can set the button text to a unicode arrow:

SetWindowText(hwndButton1, L"\x25bc"); // down arrow, use 25b2 for up arrow

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • Thanks ScottMcP.. I am trying to do create button usiong toolbar taking the refernce http://msdn.microsoft.com/en-us/library/windows/desktop/hh298381(v=vs.85).aspx and my code is_ LRESULT tr1 =SendMessage(hWndToolbar, TB_SETIMAGELIST,(WPARAM)ImageListID,(LPARAM)g_hImageList); but when i debug this it gives tr1 = 0 hence not showing ant tool bar and same is the condition with other SendMessage function..Could you please tell me what could be the problem ?? after g_hImageList all the send message function are returning zero and there is no compile error.. – Sss Jul 16 '13 at 10:39
  • But there is some thing i want to tell yo what for the first compile it was giving error that IDM_NEW,IDM_OPEN are un defined so i defined them like this #define IDM_NEW 100 but i think it has no role in not displaying the toolbar at preview pane – Sss Jul 16 '13 at 10:42
1

Finally it is done.. I have created the buttons neither using Qt or nor using any createWindowEx..The best and easy approach to follow is resource editor ...just put some button on dialog and use IDD_MAINDIALOG (in my case)

m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this);

and then

BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam) 
    { 
switch(Umsg) // handle these messages
        {  .........
}
....
}

and thats done. Very easy task.

Sss
  • 1,519
  • 8
  • 37
  • 67